Warn subclassed UserWarning when unpickling model using different verison of sklearn
See original GitHub issueDescribe 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:
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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
PositiveSpectrumWarningwhich 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.
I agree, happy to see the PR.