10000 [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning by zxcvbnius · Pull Request #8526 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[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

Merged
merged 4 commits into from
Mar 31, 2017

Conversation

zxcvbnius
Copy link
Contributor

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?

@@ -436,6 +436,7 @@ def __init__(self, attribute_pickled=5):

def __getstate__(self):
Copy link
Member

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__...?

Copy link
Contributor Author
@zxcvbnius zxcvbnius Mar 6, 2017

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.

Copy link
Member

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__

Copy link
Contributor

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.

@@ -436,6 +436,7 @@ def __init__(self, attribute_pickled=5):

def __getstate__(self):
data = self.__dict__.copy()
data["_sklearn_version"] = sklearn.__version__
Copy link
Member

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.

Copy link
Contributor
@HolgerPeters HolgerPeters Mar 10, 2017

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

Copy link
Contributor

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).

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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!

@jnothman
Copy link
Member
jnothman commented Mar 11, 2017 via email

@lesteve
Copy link
Member
lesteve commented Mar 13, 2017

If the test is meant to reflect behaviour for an estimator outside of scikit-learn, then it's the wrong fix

According to #8526 (comment), it looks like this is not the purpose of the test.

@jnothman
Copy link
Member

I still suspect ignore_warnings is a more appropriate solution

@lesteve
Copy link
Member
lesteve commented Mar 13, 2017

I still suspect ignore_warnings is a more appropriate solution

Fine with me. @zxcvbnius can add a @ignore_warnings to the test function please?

…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
data["_attribute_not_pickled"] = None
return data


@ignore_warnings(category=(DeprecationWarning, UserWarning))
Copy link
Member

Choose a reason for hiding this comment

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

why DeprecationWarning?

Copy link
Contributor Author
@zxcvbnius zxcvbnius Mar 20, 2017

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?!

data["_attribute_not_pickled"] = None
return data


@ignore_warnings(category=(DeprecationWarning, UserWarning))
Copy link
Member

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
@jnothman
Copy link
Member

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 jnothman changed the title [MRG] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning [MRG+1] Fix test of SingleInheritanceEstimator to not raise DeprecationWarning Mar 21, 2017
@zxcvbnius
Copy link
Contributor Author
zxcvbnius commented Mar 21, 2017

@jnothman yes, you're right. Thanks for your reminder. I will be careful next time.

@MechCoder MechCoder merged commit 54e8951 into scikit-learn:master Mar 31, 2017
@MechCoder
Copy link
Member

Thanks!

massich pushed a commit to massich/scikit-learn that referenced this pull request Apr 26, 2017
…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
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
…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
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
…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
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…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
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…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
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix test of SingleInheritanceEstimator to not raise DeprecationWarning
5 participants
0