question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warn subclassed UserWarning when unpickling model using different verison of sklearn

See original GitHub issue

Describe the workflow you want to enable

I want to terminate execution if I’m unpickling a model using a different version of sklearn.

Describe your proposed solution

Currently it warns with a UserWarning:

https://github.com/scikit-learn/scikit-learn/blob/4abd9f2d9e12451fa3e32bd77a97b5c4d8be8b19/sklearn/base.py#L320-L334

If, instead, it used a subclassed UserWarning you could wrap up loading a model in a catch_warnings context manager and filter that warning to raise instead, and then exit if it is raised.

Describe alternatives you’ve considered, if relevant

You could potentially do this by catching UserWarning and checking matching such as user_warning.message.startswith("Trying to unpickle estimator") but this is not very robust.

Additional context

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
thomasjpfancommented, Feb 24, 2022

we’ve gone back and forth on the types of warnings and exceptions we raise.

I’ve seen the specializing issues/expcetions issue pop up from time to time, so there is a demand for them. I think it’s common for a Python library to have specialized warnings and exceptions.

The only documentation we have for exceptions are in the API docs. The last specialized warning we added was PositiveSpectrumWarning which has limited scope.

As for this issue, I think a unpickling warning also has limited scope, which makes it easier to ensure consistency. (Limited scope == less places can use it == less need to think about consistency). To move forward, I think we can move ahead with a PR and see what everyone thinks.

0reactions
adrinjalalicommented, Feb 24, 2022

I agree, happy to see the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn shouldn't warn when unpickling an Estimator ... - GitHub
I got the following warning: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.22 when using version 0.22.1. This might lead ...
Read more >
"Trying to unpickle estimator LinearRegression from version X ...
1 when using version 1.0. 2. This might lead to breaking code or invalid results.
Read more >
scikit-learn user guide
When unpickling a scikit-learn estimator in a different version than the one the estimator was trained with, a. UserWarning is raised ...
Read more >
scikit-learn user guide
When unpickling a scikit-learn estimator in a different version than ... UserWarning is raised, see the documentation on model persistence ...
Read more >
Release history — scikit-learn 0.19.2 documentation
When unpickling a scikit-learn estimator in a different version than the one the estimator was trained with, a UserWarning is raised, see the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found