Skip to content

Add shape of stratify in train_test_split documentation - #34510

Merged
StefanieSenger merged 2 commits into
scikit-learn:mainfrom
mathaziz:doc_train_test_split
Jul 18, 2026
Merged

StefanieSenger merged 2 commits into
scikit-learn:mainfrom
mathaziz:doc_train_test_split

Conversation

@mathaziz

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

FIxes #34504

What does this implement/fix? Explain your changes.

Added information in the documentation

First time contributor introduction

I did this fix while participating to the EuroPython 2026 Sprints

AI usage disclosure

Any other comments?

Very nice first issue

Thanks

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR, @mathaziz!
Just a little nit comment, and then we're good to go.

Comment thread sklearn/model_selection/_split.py Outdated
then stratify must be None.

stratify : array-like, default=None
stratify : array-like of shape (shape[0],), default=None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little nit: I think it would be better to use n_samples instead of shape[0]. Otherwise, we would have to define shape of what, and the name of the *arrays can differ.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it is inconsistent with the standard, so I replaced shape[0] with n_samples.

To do that however, I also changed the description of the first parameter *arrays to introduce n_samples.

I took inspiration from the resample documentation : https://github.com/scikit-learn/scikit-learn/blob/cc50648cc/sklearn/utils/_indexing.py#L418

@StefanieSenger StefanieSenger left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's great! Thank you.

The CI failure seems unrelated to your PR (re-running the failed check to see if it is reproducible).

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests now pass. I will merge.
Congrats on your first contribution to scikit-learn, @mathaziz! 🎉 🎉 🎉

(The tests run on different architecture on the CI, and the assertion was only off by a very small number. I don't think it's worth investigating this.)

@StefanieSenger
StefanieSenger merged commit 6d7f1f1 into scikit-learn:main Jul 18, 2026
47 of 49 checks passed
@mathaziz
mathaziz deleted the doc_train_test_split branch July 18, 2026 14:06
@mathaziz

Copy link
Copy Markdown
Contributor Author

Great, thanks @StefanieSenger for your help! A first contribution among many to comes🤞🏼

prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document shape of the stratify param in train_test_split

2 participants