Skip to content

Commit 591b2bb

Browse files
committed
temporarily dont check stacklevel in _check_plot_works
1 parent 89b5f52 commit 591b2bb

File tree

10 files changed

+37
-39
lines changed

10 files changed

+37
-39
lines changed

.pre-commit-config.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ repos:
147147
# Check for deprecated messages without sphinx directive
148148
|(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)
149149
types_or: [python, cython, rst]
150-
- id: stacklevel
151-
name: Use find_stack_level instead of setting stacklevel manually
152-
language: pygrep
153-
entry: 'stacklevel=\d+'
154-
types_or: [python, cython, rst]
155-
exclude: pandas/__init__\.py
156150
- id: cython-casting
157151
name: Check Cython casting is `<type>obj`, not `<type> obj`
158152
language: pygrep

pandas/compat/pickle_compat.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import contextlib
77
import copy
8-
import inspect
98
import io
109
import pickle as pkl
1110
from typing import (
@@ -18,7 +17,6 @@
1817

1918
from pandas._libs.arrays import NDArrayBacked
2019
from pandas._libs.tslibs import BaseOffset
21-
from pandas.util._exceptions import find_stack_level
2220

2321
from pandas import Index
2422
from pandas.core.arrays import (
@@ -89,7 +87,7 @@ def __new__(cls) -> Series: # type: ignore[misc]
8987
warnings.warn(
9088
_sparse_msg.format(cls="SparseSeries", new="Series"),
9189
FutureWarning,
92-
stacklevel=find_stack_level(inspect.currentframe()),
90+
stacklevel=6,
9391
)
9492

9593
return Series(dtype=object)
@@ -107,7 +105,7 @@ def __new__(cls) -> DataFrame: # type: ignore[misc]
107105
warnings.warn(
108106
_sparse_msg.format(cls="SparseDataFrame", new="DataFrame"),
109107
FutureWarning,
110-
stacklevel=find_stack_level(inspect.currentframe()),
108+
stacklevel=6,
111109
)
112110

113111
return DataFrame()

pandas/core/internals/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import inspect
2-
31
from pandas.core.internals.api import make_block
42
from pandas.core.internals.array_manager import (
53
ArrayManager,
@@ -43,6 +41,7 @@
4341

4442

4543
def __getattr__(name: str):
44+
import inspect
4645
import warnings
4746

4847
from pandas.util._exceptions import find_stack_level

pandas/tests/indexes/test_common.py

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def test_astype_preserves_name(self, index, dtype):
406406
with tm.assert_produces_warning(
407407
warn,
408408
raise_on_extra_warnings=is_pyarrow_str,
409+
check_stacklevel=False,
409410
):
410411
result = index.astype(dtype)
411412
except (ValueError, TypeError, NotImplementedError, SystemError):

pandas/tests/io/parser/test_dialect.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ def test_dialect_conflict_delimiter(all_parsers, custom_dialect, kwargs, warning
146146
data = "a:b\n1:2"
147147

148148
with tm.with_csv_dialect(dialect_name, **dialect_kwargs):
149-
with tm.assert_produces_warning(warning_klass):
150-
result = parser.read_csv(StringIO(data), dialect=dialect_name, **kwargs)
151-
tm.assert_frame_equal(result, expected)
149+
result = parser.read_csv_check_warnings(
150+
warning_klass,
151+
"Conflicting values for 'delimiter'",
152+
StringIO(data),
153+
dialect=dialect_name,
154+
**kwargs,
155+
)
156+
tm.assert_frame_equal(result, expected)

pandas/tests/io/parser/test_python_parser_only.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,9 @@ def test_on_bad_lines_callable_not_expected_length(python_parser_only):
424424
"""
425425
bad_sio = StringIO(data)
426426

427-
with tm.assert_produces_warning(ParserWarning, match="Length of header or names"):
428-
result = parser.read_csv(bad_sio, on_bad_lines=lambda x: x)
427+
result = parser.read_csv_check_warnings(
428+
ParserWarning, "Length of header or names", bad_sio, on_bad_lines=lambda x: x
429+
)
429430
expected = DataFrame({"a": [1, 2, 3], "b": [2, 3, 4]})
430431
tm.assert_frame_equal(result, expected)
431432

pandas/tests/plotting/frame/test_hist_box_by.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_hist_plot_empty_list_string_tuple_by(self, by, column, hist_df):
164164
def test_hist_plot_layout_with_by(self, by, column, layout, axes_num, hist_df):
165165
# GH 15079
166166
# _check_plot_works adds an ax so catch warning. see GH #13188
167-
with tm.assert_produces_warning(UserWarning):
167+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
168168
axes = _check_plot_works(
169169
hist_df.plot.hist, column=column, by=by, layout=layout
170170
)

pandas/tests/plotting/test_boxplot_method.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_boxplot_legacy2(self):
7777
df = DataFrame(np.random.rand(10, 2), columns=["Col1", "Col2"])
7878
df["X"] = Series(["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
7979
df["Y"] = Series(["A"] * 10)
80-
with tm.assert_produces_warning(UserWarning):
80+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
8181
_check_plot_works(df.boxplot, by="X")
8282

8383
# When ax is supplied and required number of axes is 1,

pandas/tests/plotting/test_hist_method.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def test_hist_legacy(self, ts):
3131
_check_plot_works(ts.hist, grid=False)
3232
_check_plot_works(ts.hist, figsize=(8, 10))
3333
# _check_plot_works adds an ax so catch warning. see GH #13188
34-
with tm.assert_produces_warning(UserWarning):
34+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
3535
_check_plot_works(ts.hist, by=ts.index.month)
36-
with tm.assert_produces_warning(UserWarning):
36+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
3737
_check_plot_works(ts.hist, by=ts.index.month, bins=5)
3838

3939
fig, ax = self.plt.subplots(1, 1)
@@ -74,31 +74,31 @@ def test_hist_layout_with_by(self, hist_df):
7474
# _check_plot_works adds an `ax` kwarg to the method call
7575
# so we get a warning about an axis being cleared, even
7676
# though we don't explicing pass one, see GH #13188
77-
with tm.assert_produces_warning(UserWarning):
77+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
7878
axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1))
7979
self._check_axes_shape(axes, axes_num=2, layout=(2, 1))
8080

81-
with tm.assert_produces_warning(UserWarning):
81+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
8282
axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1))
8383
self._check_axes_shape(axes, axes_num=2, layout=(3, 1))
8484

85-
with tm.assert_produces_warning(UserWarning):
85+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
8686
axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1))
8787
self._check_axes_shape(axes, axes_num=4, layout=(4, 1))
8888

89-
with tm.assert_produces_warning(UserWarning):
89+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
9090
axes = _check_plot_works(df.height.hist, by=df.category, layout=(2, -1))
9191
self._check_axes_shape(axes, axes_num=4, layout=(2, 2))
9292

93-
with tm.assert_produces_warning(UserWarning):
93+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
9494
axes = _check_plot_works(df.height.hist, by=df.category, layout=(3, -1))
9595
self._check_axes_shape(axes, axes_num=4, layout=(3, 2))
9696

97-
with tm.assert_produces_warning(UserWarning):
97+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
9898
axes = _check_plot_works(df.height.hist, by=df.category, layout=(-1, 4))
9999
self._check_axes_shape(axes, axes_num=4, layout=(1, 4))
100100

101-
with tm.assert_produces_warning(UserWarning):
101+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
102102
axes = _check_plot_works(df.height.hist, by=df.classroom, layout=(2, 2))
103103
self._check_axes_shape(axes, axes_num=3, layout=(2, 2))
104104

@@ -235,7 +235,7 @@ class TestDataFramePlots(TestPlotBase):
235235
def test_hist_df_legacy(self, hist_df):
236236
from matplotlib.patches import Rectangle
237237

238-
with tm.assert_produces_warning(UserWarning):
238+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
239239
_check_plot_works(hist_df.hist)
240240

241241
# make sure layout is handled
@@ -248,7 +248,7 @@ def test_hist_df_legacy(self, hist_df):
248248
dtype=np.int64,
249249
)
250250
)
251-
with tm.assert_produces_warning(UserWarning):
251+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
252252
axes = _check_plot_works(df.hist, grid=False)
253253
self._check_axes_shape(axes, axes_num=3, layout=(2, 2))
254254
assert not axes[1, 1].get_visible()
@@ -267,20 +267,20 @@ def test_hist_df_legacy(self, hist_df):
267267
dtype=np.int64,
268268
)
269269
)
270-
with tm.assert_produces_warning(UserWarning):
270+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
271271
axes = _check_plot_works(df.hist, layout=(4, 2))
272272
self._check_axes_shape(axes, axes_num=6, layout=(4, 2))
273273

274274
# make sure sharex, sharey is handled
275-
with tm.assert_produces_warning(UserWarning):
275+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
276276
_check_plot_works(df.hist, sharex=True, sharey=True)
277277

278278
# handle figsize arg
279-
with tm.assert_produces_warning(UserWarning):
279+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
280280
_check_plot_works(df.hist, figsize=(8, 10))
281281

282282
# check bins argument
283-
with tm.assert_produces_warning(UserWarning):
283+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
284284
_check_plot_works(df.hist, bins=5)
285285

286286
# make sure xlabelsize and xrot are handled
@@ -659,13 +659,13 @@ def test_grouped_hist_layout(self, hist_df):
659659
with pytest.raises(ValueError, match=msg):
660660
df.hist(column="height", by=df.category, layout=(-1, -1))
661661

662-
with tm.assert_produces_warning(UserWarning):
662+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
663663
axes = _check_plot_works(
664664
df.hist, column="height", by=df.gender, layout=(2, 1)
665665
)
666666
self._check_axes_shape(axes, axes_num=2, layout=(2, 1))
667667

668-
with tm.assert_produces_warning(UserWarning):
668+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
669669
axes = _check_plot_works(
670670
df.hist, column="height", by=df.gender, layout=(2, -1)
671671
)
@@ -682,14 +682,14 @@ def test_grouped_hist_layout(self, hist_df):
682682
tm.close()
683683

684684
# GH 6769
685-
with tm.assert_produces_warning(UserWarning):
685+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
686686
axes = _check_plot_works(
687687
df.hist, column="height", by="classroom", layout=(2, 2)
688688
)
689689
self._check_axes_shape(axes, axes_num=3, layout=(2, 2))
690690

691691
# without column
692-
with tm.assert_produces_warning(UserWarning):
692+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
693693
axes = _check_plot_works(df.hist, by="classroom")
694694
self._check_axes_shape(axes, axes_num=3, layout=(2, 2))
695695

pandas/tests/plotting/test_misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_scatter_matrix_axis(self, pass_axis):
125125
df[0] = (df[0] - 2) / 3
126126

127127
# we are plotting multiples on a sub-plot
128-
with tm.assert_produces_warning(UserWarning):
128+
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
129129
axes = _check_plot_works(
130130
scatter_matrix,
131131
filterwarnings="always",

0 commit comments

Comments
 (0)