-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG + 1] Fix #9350: Enable has_fit_parameter() and fit_score_takes_y() to work with @deprecated in Python 2 #11277
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
[MRG + 1] Fix #9350: Enable has_fit_parameter() and fit_score_takes_y() to work with @deprecated in Python 2 #11277
Conversation
# a deprecated fit method | ||
|
||
class TestEstimatorWithDeprecatedFitMethod(BaseEstimator): | ||
@deprecated("Deprecated for the purpose of testing check_fit_score_takes_y") |
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.
we checked that also works with the other decorators.
ha, actually fails on Python2.7 with the error we saw! I'm not overly paranoid after all (in this case). |
Aha! Oh, good, that means my tests work! Okay, now on to fix the issue... |
LGTM, thanks! |
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.
I don't see why we are likely to be testing an estimator with a deprecated fit
method. But I suppose this is fine.
def fit(self, X, y, sample_weight=None): | ||
pass | ||
|
||
assert_true(has_fit_parameter(TestClassWithDeprecatedFitMethod, |
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.
Please just use bare assert. We're phasing out the use of assert_true, assert_equals, etc.
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.
Okay, replaced assert_true with assert.
@jnothman same goes for |
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.
I can't see what codecov is complaining about... what line in the diff is not covered?
Otherwise, I'm happy to merge
I don't understand it, either. @amueller - any ideas? |
class TestClassWithDeprecatedFitMethod: | ||
@deprecated("Deprecated for the purpose of testing has_fit_parameter") | ||
def fit(self, X, y, sample_weight=None): | ||
pass |
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.
Ahh I see now. This doesn't have test coverage. That's fine.
Thanks! |
…_takes_y() to work with @deprecated in Python 2 (scikit-learn#11277)
Thanks, all! |
Reference Issues/PRs
Fixes #9350: Bug in common tests: should use utils.testing._get_args
What does this implement/fix? Explain your changes.
This fix does not use
utils.testing._get_args()
but rather adds two new unit tests confirm that #9350 is no longer an issue. I walked through this with @amueller during a sprint and he agrees these tests are the right ones to confirm the issue is resolved.Specifically:
I've added a test in
test_validation.py
that ensureshas_fit_parameter()
works for classes with a deprecatedfit()
method.This issue was referenced in PR [WIP] Adding classes argument to Gaussian Naive Bayes #9290 where
check_fit_score_takes_y()
was retur 8000 ning a "list index out of range" when a method innaive_bayes.py
was marked as@deprecated
, but succeeding when not deprecated. To ensurecheck_fit_score_takes_y()
behaves correctly in this scenario, I've added another test to ensurecheck_fit_score_takes_y()
works on a class that has a deprecatedfit()
method.Any other comments?
These tests were discussed with @amueller during Two Sigma's "TS Open" 2018 sprint.