-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
FutureWarnings should specify a stacklevel #9584
Comments
@njsmith I changed the title, as this is not specific to the categorical example This was brought to my attention again by the discussion in ipython about changing the default visibility of DeprecationWarnings (ipython/ipython#8478) Basically, in plain warning calls, we should use |
Rule of thumb: Calling Here's a summary of what's at stake, since as @jorisvandenbossche pointed out in the ipython discussion the docs are somewhat confusing. It's actually pretty simple. Say I have this code:
If |
Thanks @njsmith for the overview! For pandas it means that
|
For warn-on-import for deprecated modules/packages, you should also use |
Running my test suite, I see:
Okay, fair enough. But the problem is that all of the listed lines of code are inside pandas, so I have no idea which parts of my code are actually doing the wrong thing.
warnings.warn
provides astacklevel
argument, where the idea is that you should pass a non-zero value so that warnings are attributed to the code that actually needs to be changed. E.g.,stacklevel=1
means that the code which is doing something wrong is the code which called the function containing the call towarnings.warn
.The text was updated successfully, but these errors were encountered: