Skip to content

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

Merged
merged 23 commits into from
Aug 17, 2022

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli force-pushed the find-stack-level branch 3 times, most recently from 8541084 to 82ea9f5 Compare August 8, 2022 19:23
@mroeschke mroeschke added Testing pandas testing functions or related to the test suite Warnings Warnings that appear or should be added to pandas labels Aug 8, 2022
@@ -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):
Copy link
Member Author

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

Comment on lines +662 to 665
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
axes = _check_plot_works(
df.hist, column="height", by=df.gender, layout=(2, 1)
)
Copy link
Member Author

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

@MarcoGorelli MarcoGorelli marked this pull request as ready for review August 14, 2022 21:20
Copy link
Member

@mroeschke mroeschke left a 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?

@MarcoGorelli
Copy link
Member Author

Should be possible eventually, but at the moment there are some places where it needs setting manually for it to work, e.g.

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 check_stacklevel=True is the default

@mroeschke
Copy link
Member

Thanks for confirming. In any case, a check can be made in a follow up

@mroeschke mroeschke added this to the 1.5 milestone Aug 17, 2022
@MarcoGorelli MarcoGorelli merged commit e94faa2 into pandas-dev:main Aug 17, 2022
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WARN,TST check stacklevel for all warnings
2 participants