-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning #8526
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
sklearn/tests/test_base.py
Outdated
@@ -436,6 +436,7 @@ def __init__(self, attribute_pickled=5): | |||
|
|||
def __getstate__(self): |
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.
Remind me, @HolgerPeters, why this method does not call super(...).__getstate__
...?
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.
Hi @jnothman thanks for your review!
I think it may not be appropriate to use super(...).__getstate__
because the next test case is test_pickling_works_when_getstate_is_overwritten_in_the_child_class
.
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.
@jnothman I think this was supposed to test the case where users have implemented an estimator that overrides __getstate__
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.
Yes, that is the intention of the test case. We had written our own serialization logic for estimators, and scikit-learn 0.18 broke all of our modelling code. For what its worth since the BaseEstimator does not contain parameters (and does not contain estimated parameters) scikit-learn shouldn't expect that users inheriting from BaseEstimator
and overwriting __getstate__
make that super(..).__getstate__
call.
sklearn/tests/test_base.py
Outdated
@@ -436,6 +436,7 @@ def __init__(self, attribute_pickled=5): | |||
|
|||
def __getstate__(self): | |||
data = self.__dict__.copy() | |||
data["_sklearn_version"] = sklearn.__version__ |
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 am not entirely sure this is the right fix. I don't remember whether this test was supposed to test estimators outside scikit-learn or not. @HolgerPeters do you remember off the top of your head?
A closer look at #8324 may be needed.
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.
The purpose of this test case is not specifically to test estimators outside of scikit-learn. here we test estimators outside of sklearn.
Yet, implicitly it probably does, because estimators within scikit-learn are probably refactored to work with BaseEstimator
's new __getstate__
/__setstate__
logic
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 still think that BaseEstimator
shouldn't overwrite __getstate__
and scikit-learn should probably just not try to do those version checks. I understand the intention of course, but basically scikit-learn user's must have a strategy in place for making sure that they don't unpickle estimators with the wrong scikit-learn version. To me seems scikit-learn tries here to address a general problem with pickle
in a very scikit-learn specific way, which has unintended side-effects on user code that ran fine for years.
To really address the problem of serialization-versioning would probably mean to introduce special serialization code (which would mean A LOT of code writing). But then, you could start to maintain a versionizable serialization interface.
(@zxcvbnius this comment is not about your code in this PR, but about the background of the code you modify).
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.
Thanks a lot for the details @HolgerPeters!
@zxcvbnius I think your change is fine. Add a comment on the previous line explaining that the line you added avoids a DeprecationWarning about unpickling an estimator from a different version.
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.
@lesteve I reworked my comment and added it to the original ticket because this PR is probably not the best place for this discussion.
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.
@zxcvbnius I also think the change is ok.
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.
@lesteve ok!
@HolgerPeters , really thanks for your detail explanation!
If the test is meant to reflect behaviour for an estimator outside of
scikit-learn, then it's the wrong fix. Ignoring the warning, or hacking the
__module__ would be better, with a comment, imo. This is just a side effect
is us having tests within the package, is it not?
…On 11 Mar 2017 1:34 am, "Holger Peters" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In sklearn/tests/test_base.py
<#8526 (comment)>
:
> @@ -436,6 +436,7 @@ def __init__(self, attribute_pickled=5):
def __getstate__(self):
data = self.__dict__.copy()
+ data["_sklearn_version"] = sklearn.__version__
@zxcvbnius <https://github.com/zxcvbnius> I also think the change is ok.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8526 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6xIHRgOwZHENxXnWeIAmDBlw5cWNks5rkV-HgaJpZM4MTMLu>
.
|
According to #8526 (comment), it looks like this is not the purpose of the test. |
I still suspect ignore_warnings is a more appropriate solution |
Fine with me. @zxcvbnius can add a |
…onWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version
sklearn/tests/test_base.py
Outdated
data["_attribute_not_pickled"] = None | ||
return data | ||
|
||
|
||
@ignore_warnings(category=(DeprecationWarning, UserWarning)) |
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.
why DeprecationWarning?
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.
@jnothman I think I should not be confused by DeprecationWarning
in the title.
According to the following error message:
UserWarning: Trying to unpickle estimator SingleInheritanceEstimator from version pre-0.18 when using version 0.19.dev0. ...
We just need UserWarning
?!
sklearn/tests/test_base.py
Outdated
data["_attribute_not_pickled"] = None | ||
return data | ||
|
||
|
||
@ignore_warnings(category=(DeprecationWarning, UserWarning)) |
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.
…onWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
LGTM (I ran the tests). PS: you are using very strange commit messages. They should describe what change the commit makes. MRG+1, MRG+2 should have nothing to do with your commit message. |
@jnothman yes, you're right. Thanks for your reminder. I will be careful next time. |
Thanks! |
…onWarning (scikit-learn#8526) * Fix test of SingleInheritanceEstimator to not raise DeprecationWarning * [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version * [MRG+2] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
…onWarning (scikit-learn#8526) * Fix test of SingleInheritanceEstimator to not raise DeprecationWarning * [MRG+1 102BB ] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version * [MRG+2] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
…onWarning (scikit-learn#8526) * Fix test of SingleInheritanceEstimator to not raise DeprecationWarning * [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version * [MRG+2] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
…onWarning (scikit-learn#8526) * Fix test of SingleInheritanceEstimator to not raise DeprecationWarning * [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version * [MRG+2] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
…onWarning (scikit-learn#8526) * Fix test of SingleInheritanceEstimator to not raise DeprecationWarning * [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version * [MRG+2] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
…onWarning (scikit-learn#8526) * Fix test of SingleInheritanceEstimator to not raise DeprecationWarning * [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Ignore a DeprecationWarning about unpickling an estimator from a different version * [MRG+2] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) Fix: test of SingleInheritanceEstimator to not raise DeprecationWarning (scikit-learn#8526) - Test of SingleInheritanceEstimator would raise UserWarning, not DeprecationWarning - Ignore a UserWarning about unpickling an estimator from a different version
Reference Issue
Fixes #8506
What does this implement/fix? Explain your changes.
Fix test of SingleInheritanceEstimator to not raise DeprecationWarning.
Set
sklearn.__version__
to the current version.Any other comments?