-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WARN,TST check stacklevel for all warnings #47998
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
Conversation
8541084
to
82ea9f5
Compare
cf3b28d
to
591b2bb
Compare
@@ -107,7 +107,7 @@ def test_scatter_matrix_axis(self, pass_axis): | |||
df = DataFrame(np.random.randn(100, 3)) | |||
|
|||
# we are plotting multiples on a sub-plot | |||
with tm.assert_produces_warning(UserWarning, raise_on_extra_warnings=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise_on_extra_warnings=True
is the default, so removing it
with tm.assert_produces_warning(UserWarning, check_stacklevel=False): | ||
axes = _check_plot_works( | ||
df.hist, column="height", by=df.gender, layout=(2, 1) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separately it'd be good to have _check_plot_works_check_warnings
(analogous to parser.read_csv_check_warnings
), but for now I'm just ignoring the stacklevel check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's feasible have a precommit check enforce that stacklevel=find_stack_level(inspect.currentframe())
is always set?
Should be possible eventually, but at the moment there are some places where it needs setting manually for it to work, e.g. pandas/pandas/compat/pickle_compat.py Line 108 in a6aaeb6
It looks like there, the going back up the frames temporarily brings us into the standard library: (Pdb) frame
<frame at 0x7f87356b1b20, file '/home/marco/pandas-marco/pandas/compat/pickle_compat.py', line 92, code __new__>
(Pdb) p frame.f_back
<frame at 0x7f873569f7c0, file '/home/marco/pandas-marco/pandas/compat/pickle_compat.py', line 231, code load_newobj>
(Pdb) p frame.f_back.f_back
<frame at 0x7f87356b3640, file '/home/marco/miniconda3/envs/pandas-dev/lib/python3.8/pickle.py', line 1212, code load>
(Pdb) p frame.f_back.f_back
<frame at 0x7f87356b3640, file '/home/marco/miniconda3/envs/pandas-dev/lib/python3.8/pickle.py', line 1212, code load>
(Pdb) p frame.f_back.f_back.f_back
<frame at 0x7f8735765800, file '/home/marco/pandas-marco/pandas/compat/pickle_compat.py', line 277, code load>
(Pdb) p frame.f_back.f_back.f_back.f_back
<frame at 0x7f87356a6c40, file '/home/marco/pandas-marco/pandas/io/pickle.py', line 213, code read_pickle>
(Pdb) p frame.f_back.f_back.f_back.f_back.f_back
<frame at 0x7f873569f400, file '/home/marco/pandas-marco/pandas/tests/io/test_pickle.py', line 240, code test_legacy_sparse_warning> , I'll have a look at what can be done about that Any places where the stacklevel isn't correct should now be caught by the tests anyway, as with this PR it'd be checked for all warnings and |
Thanks for confirming. In any case, a check can be made in a follow up |
* use find_stack_level everywhere * fixup * pyx fixups * fixup test_optional_dependency * fixup api * set check_stacklevel=False for some tests * use lru_cache for currentframe * fixup import in __init__ * add missing imports to pyx files * add missing import * fixup import in conversion * revert some __init__ changes * start n=1 * temporarily dont check stacklevel in _check_plot_works * catch some more warnings * dont check stacklevel in check_plot_works * fixup * ignore stacklevel in check_plot_works
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.