Skip to content

API Enable metadata auto requests by default - #35204

Merged
StefanieSenger merged 21 commits into
scikit-learn:mainfrom
antoinebaker:enable-metadata-auto-requests-default
Nov 6, 2026
Merged

StefanieSenger merged 21 commits into
scikit-learn:mainfrom
antoinebaker:enable-metadata-auto-requests-default

Conversation

@antoinebaker

@antoinebaker antoinebaker commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

See #34901.

What does this implement/fix? Explain your changes.

enable_metadata_auto_requests now defaults to True. Once routing is on, scikit-learn consumers auto-request metadata such as sample_weight, X_val, y_val, sample_weight_val. Third-party estimators are unchanged unless they use AutoRequestMixin.

Many tests were written for the old configuration (enable_metadata_auto_requests=False), so this flag is added in the @config_context decorator of these tests.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation

Any other comments?

To be merged last, after the implementation and documentation PRs listed here #34901 (comment).

cc @ogrisel @StefanieSenger

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Oct 22, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Oct 22, 2026
@antoinebaker
antoinebaker marked this pull request as ready for review October 26, 2026 09:52
@antoinebaker antoinebaker changed the title API Enable metadata auto requests default API Enable metadata auto requests by default Oct 26, 2026
@antoinebaker antoinebaker moved this to PR waiting for reviews in Labs Oct 26, 2026
@antoinebaker
antoinebaker marked this pull request as draft November 2, 2026 09:54

@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 the PR, @antoinebaker. This PR looks good to me, and I only have a few minor cosmetic suggestions.

Comment thread doc/metadata_routing.rst Resolved
Comment thread doc/metadata_routing.rst Resolved
Comment thread sklearn/tests/test_metadata_routing.py Resolved
Comment thread sklearn/tests/test_metadata_routing.py Resolved
@StefanieSenger StefanieSenger added this to the 1.10 milestone Nov 2, 2026
@antoinebaker antoinebaker moved this from PR waiting for reviews to PR in progress in Labs Nov 2, 2026
@antoinebaker
antoinebaker marked this pull request as ready for review November 2, 2026 16:35
@antoinebaker

Copy link
Copy Markdown
Member Author

Thanks for the quick review @StefanieSenger and the helpful suggestions !

Apart from the "sections reordering" to decide, I think all your comments have been addressed.

@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 the quick implementation of the suggestions, @antoinebaker.
I agree that we'd better leave a user guide re-design to a different PR.

Approving. :)

@FrancoisPgm FrancoisPgm 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.

I have a few nits, mainly changing a bit the wording to make it clearer IMO.

Also cursor detected some small things to address :

  • the sample_weight glossary entry still describes the old default (glossary.rst L1957)
  • in MetadataRouter's docstring (_metadata_requests.py L1024) it should be 'score': {'sample_weight': True} now, as the scorer auto-requests sample_weight. Also the .set_fit_request(sample_weight=True) on L1012 is redundant with the new default. If the goal is to show a case where the requests for fit and score are different, enable_metadata_auto_requests should be disabled and re-enabled around the code snippet.
  • test_default_request and test_default_requests mention requests "by default" or "default requests" in comments while their decorators force enable_metadata_auto_requests=False. It could be better to mention in the comments that these are the defaults when auto-requests are disabled.

There is also a point about the user guide (metadata_routing.rst) turning auto-requests off at the beginning, then much later presenting auto-requests off behaviour as the general rule (L245-263). A short sentence to remind that the default has been changed could be nice before the bigger rework of the guide in a subsequent PR, but this seems less important.

Other than that LGTM, thanks :)

Comment thread doc/metadata_routing.rst Resolved
Comment thread sklearn/tests/test_metadata_routing.py Resolved
Comment thread sklearn/utils/_metadata_requests.py Resolved
@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Nov 5, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Nov 5, 2026
@StefanieSenger

StefanieSenger commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Love this PR. Thank you @antoinebaker and @FrancoisPgm! 🫶 Merging. 🚀

Note for downstream projects

When metadata routing is enabled, enable_metadata_auto_requests now defaults to True. Third party libraries that use metadata routing (enable_metadata_routing=True) and check against scikit-learn's nightly build, will notice behaviour changes. This will also go into our 1.10 release end of November.

Auto-requests only take action on scikit-learn estimators and (possibly user defined) scorers, and among these, metadata is routed to new places and some UnsetMetadataPassedError will disappear.

Downstream projects can either use sklearn.set_config(enable_metadata_auto_requests=False) to keep the old behaviour, or update their tests and communicate the new auto-request behaviour to their users.

To fully participate in the auto-request policy in their own estimators, third party projects can inherit from AutoRequestMixin.

Please report any new errors. Changes in training and scoring results are expected.

@StefanieSenger
StefanieSenger merged commit caf832f into scikit-learn:main Nov 6, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from PR in progress to Done in Labs Nov 6, 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.

3 participants