Skip to content
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

warnings.filterwarnings -- please don't do this. it's bad behavior. #11792

Closed
dfee opened this issue Aug 10, 2018 · 3 comments
Closed

warnings.filterwarnings -- please don't do this. it's bad behavior. #11792

dfee opened this issue Aug 10, 2018 · 3 comments

Comments

@dfee
Copy link

dfee commented Aug 10, 2018

# Make sure that DeprecationWarning within this package always gets printed
warnings.filterwarnings('always', category=DeprecationWarning,
module=r'^{0}\.'.format(re.escape(__name__)))

via __init__.py

This is really quite bad behavior. If you feel like you really must do this, please use append=True

@rth
Copy link
Member

rth commented Aug 10, 2018

Could you please elaborate in what way this is a problem for your application? From the comments, it sound like it should only affect DeprecationWarnings within scikit-learn.

(Also see related discussion in #6930)

@dfee
Copy link
Author

dfee commented Aug 10, 2018

Could you please elaborate on why sklearn overrides a customized warning configuration?

If you add append=True, then you wouldn't be overriding a warning configuration that's not been customized.

The problem is that my applications global state should not be affected by importing your package. I also wouldn't want you doing things like changing my logging configuration.

@rth
Copy link
Member

rth commented Aug 11, 2018

If you add append=True, then you wouldn't be overriding a warning configuration that's not been customized.

Tried, that, by installing sklearn from sources, and manually raising a deprecation in sklearn.utils.__init__.py. With the default configuration the warning it raised as expected when calling python -c "import sklearn.utils". If we add append=True to warnings.filterwarnings used in sklearn/__init__.py the DeprecationWarning is no longer raised. I have not investigated why.

I agree the current situation is bad, I was just curious to know what kind of practical issues you run into with this setup (beyond the fact that it's bad on principle). Having a good understanding of the use cases, would also help us to come up with the right solution. This problem was discussed in #9857 (see in particular #9857 (comment) and #9857 (comment)) which outlines the reason for the current situations.

Closing this as a duplicate of #9857 (to avoid fragmenting the same discussion over multiple issues). You are very welcome to comment or propose solutions there though.

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

No branches or pull requests

2 participants