Skip to content

FIX methods in model_selection/_validation accept params=None with metadata routing enabled#30451

Merged
jeremiedbb merged 6 commits intoscikit-learn:mainfrom
adrinjalali:cross_validate
Jan 2, 2025
Merged

FIX methods in model_selection/_validation accept params=None with metadata routing enabled#30451
jeremiedbb merged 6 commits intoscikit-learn:mainfrom
adrinjalali:cross_validate

Conversation

@adrinjalali
Copy link
Copy Markdown
Member

Fixes #30447

This fixes an issue with functions in model_selection/_validation.py where they'd raise if params=None and metadata routing is enabled.

cc @StefanieSenger @OmarManzoor @jeremiedbb

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 10, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 99577c1. Link to the linter CI: here

],
)
@config_context(enable_metadata_routing=True)
def test_cross_validate_params_none(func, extra_args):
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.

Can we add a docstring for the test? It would be difficult to understand what it's testing later otherwise.

Or maybe, we can join this test with the next one (test_passed_unrequested_metadata) and modify the docstring there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

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.

Perfect, thank you. :)

Copy link
Copy Markdown
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @adrinjalali

params = _check_params_groups_deprecation(fit_params, params, groups, "1.8")

X, y, groups = indexable(X, y, groups)
params = params or {}
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.

This one seems redundant since we're calling _check_params_groups_deprecation just before, which already does this. I don't think params can be None here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nice catch!

Copy link
Copy Markdown
Member

@StefanieSenger StefanieSenger Dec 10, 2024

Choose a reason for hiding this comment

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

Wouldn't it make sense to leave it there, because the call to _check_params_groups_deprecation will be removed later?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we'd put it there when we remove that function. And we don't have to worry about it breaking code, cause the test will fail once we remove it.

params = fit_params

params = {} if params is None else params
params = params or {}
Copy link
Copy Markdown
Member

@betatim betatim Dec 10, 2024

Choose a reason for hiding this comment

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

Why change? The original is more specific in only replacing None, and not things like {} and the various other things that are false-y.

(same for the other two instances of this in this PR)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's always a dictionary anyway

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 don't understand this answer. If the user didn't pass any params then we want to replace None with {}. Which in Python is {} if params is None else params, so I don't understand why you want to make the change to something that is less precise in expressing the intention

Copy link
Copy Markdown
Member

@jeremiedbb jeremiedbb Jan 2, 2025

Choose a reason for hiding this comment

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

I directly pushed to revert this change to unblock this PR and the 1.6.1 release. In this context both formulations would have the same behavior, but I agree that we should use the one that expresses the behavior we want as most precisely and unambiguously as possible.

Copy link
Copy Markdown
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM

@jeremiedbb jeremiedbb enabled auto-merge (squash) January 2, 2025 10:51
@jeremiedbb jeremiedbb merged commit 5035b6d into scikit-learn:main Jan 2, 2025
@adrinjalali adrinjalali deleted the cross_validate branch January 2, 2025 11:56
jeremiedbb added a commit to jeremiedbb/scikit-learn that referenced this pull request Jan 8, 2025
…tadata routing enabled (scikit-learn#30451)

Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
jeremiedbb added a commit that referenced this pull request Jan 9, 2025
…tadata routing enabled (#30451)

Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
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.

cross_validate raises an exception when metadata routing is enabled

5 participants