-
-
Notifications
You must be signed in to change notification settings - Fork 26.3k
FIX allow copied parameters in __init__ for clone #22973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Yes, I did predict this would happen, but decided not to mention it on the issue... I don't think it's a major concern, since we're only dealing here with badly behaved constructors, or else we could define a helper to suppress the ValueError. |
Or is your concern that the implementation might intentionally copy the array parameter, or realise a parameter stored in a C struct as an array? If so, let's use a helper. |
I have a similar helper here scikit-learn/sklearn/model_selection/_search.py Lines 50 to 73 in 3d9fd3f
|
Slightly confused by this bit: if v1 is not v2:
return False
with warnings.catch_warnings():
warnings.simplefilter("ignore")
try:
if v1 != v2:
return False
except ValueError:
return False What should the input be for the code to reach if v1 is v2:
continue
with warnings.catch_warnings():
warnings.simplefilter("ignore")
try:
if v1 != v2:
return False
except ValueError:
return False |
I agree that doesn't look right... Makes me wonder about my test coverage. |
pass | ||
|
||
# Register global_random_seed plugin if it is not already registered | ||
if not config.pluginmanager.hasplugin("sklearn.tests.random_seed"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a merge error? This change is already on main
.
def __init__(self, a=np.array([0])): | ||
self.a = a.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this PR still relevant since we now have #24568 ? |
Fixes #22857
There is an issue I hadn't realized: comparing ndarrays raises a
ValueError
and not aRuntimeError
. So if the estimator does a copy of an ndarray input argument, clone would fail with a different error. I'm not sure how to proceed.Also pinging @amueller (you wrote the test which fails with this test I think)