Skip to content

Commit ce12646

Browse files
authored
TST: check_stacklevel=True in various tests (#44449)
1 parent 253d26a commit ce12646

File tree

22 files changed

+37
-59
lines changed

22 files changed

+37
-59
lines changed

pandas/tests/apply/test_frame_apply.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,9 +1198,7 @@ def test_nuiscance_columns():
11981198
)
11991199
tm.assert_frame_equal(result, expected)
12001200

1201-
with tm.assert_produces_warning(
1202-
FutureWarning, match="Select only valid", check_stacklevel=False
1203-
):
1201+
with tm.assert_produces_warning(FutureWarning, match="Select only valid"):
12041202
result = df.agg("sum")
12051203
expected = Series([6, 6.0, "foobarbaz"], index=["A", "B", "C"])
12061204
tm.assert_series_equal(result, expected)

pandas/tests/arrays/test_datetimelike.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,7 @@ def test_to_perioddelta(self, datetime_index, freqstr):
783783
with tm.assert_produces_warning(FutureWarning, match=msg):
784784
# Deprecation GH#34853
785785
expected = dti.to_perioddelta(freq=freqstr)
786-
with tm.assert_produces_warning(
787-
FutureWarning, match=msg, check_stacklevel=False
788-
):
786+
with tm.assert_produces_warning(FutureWarning, match=msg):
789787
# stacklevel is chosen to be "correct" for DatetimeIndex, not
790788
# DatetimeArray
791789
result = arr.to_perioddelta(freq=freqstr)

pandas/tests/dtypes/cast/test_promote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def test_maybe_promote_any_with_datetime64(
411411
# Casting date to dt64 is deprecated
412412
warn = FutureWarning
413413

414-
with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False):
414+
with tm.assert_produces_warning(warn, match=msg):
415415
# stacklevel is chosen to make sense when called from higher-level functions
416416
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)
417417

pandas/tests/frame/indexing/test_setitem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ def test_setitem_mask_categorical(self):
949949
df = DataFrame({"cats": catsf, "values": valuesf}, index=idxf)
950950

951951
exp_fancy = exp_multi_row.copy()
952-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
952+
with tm.assert_produces_warning(FutureWarning):
953953
# issue #37643 inplace kwarg deprecated
954954
return_value = exp_fancy["cats"].cat.set_categories(
955955
["a", "b", "c"], inplace=True

pandas/tests/frame/methods/test_join.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,7 @@ def test_merge_join_different_levels(self):
344344
columns = ["a", "b", ("a", ""), ("c", "c1")]
345345
expected = DataFrame(columns=columns, data=[[1, 11, 0, 44], [0, 22, 1, 33]])
346346
msg = "merging between different levels is deprecated"
347-
with tm.assert_produces_warning(
348-
FutureWarning, match=msg, check_stacklevel=False
349-
):
347+
with tm.assert_produces_warning(FutureWarning, match=msg):
350348
# stacklevel is chosen to be correct for pd.merge, not DataFrame.join
351349
result = df1.join(df2, on="a")
352350
tm.assert_frame_equal(result, expected)

pandas/tests/frame/test_constructors.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,27 +2664,27 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture, pydt):
26642664
expected = DataFrame({0: [ts_naive]})
26652665
tm.assert_frame_equal(result, expected)
26662666

2667-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2667+
with tm.assert_produces_warning(FutureWarning):
26682668
result = DataFrame({0: ts}, index=[0], dtype="datetime64[ns]")
26692669
tm.assert_frame_equal(result, expected)
26702670

2671-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2671+
with tm.assert_produces_warning(FutureWarning):
26722672
result = DataFrame([ts], dtype="datetime64[ns]")
26732673
tm.assert_frame_equal(result, expected)
26742674

2675-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2675+
with tm.assert_produces_warning(FutureWarning):
26762676
result = DataFrame(np.array([ts], dtype=object), dtype="datetime64[ns]")
26772677
tm.assert_frame_equal(result, expected)
26782678

26792679
with tm.assert_produces_warning(FutureWarning):
26802680
result = DataFrame(ts, index=[0], columns=[0], dtype="datetime64[ns]")
26812681
tm.assert_frame_equal(result, expected)
26822682

2683-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2683+
with tm.assert_produces_warning(FutureWarning):
26842684
df = DataFrame([Series([ts])], dtype="datetime64[ns]")
26852685
tm.assert_frame_equal(result, expected)
26862686

2687-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
2687+
with tm.assert_produces_warning(FutureWarning):
26882688
df = DataFrame([[ts]], columns=[0], dtype="datetime64[ns]")
26892689
tm.assert_equal(df, expected)
26902690

@@ -2946,9 +2946,7 @@ def test_tzaware_data_tznaive_dtype(self, constructor):
29462946
ts = Timestamp("2019", tz=tz)
29472947
ts_naive = Timestamp("2019")
29482948

2949-
with tm.assert_produces_warning(
2950-
FutureWarning, match="Data is timezone-aware", check_stacklevel=False
2951-
):
2949+
with tm.assert_produces_warning(FutureWarning, match="Data is timezone-aware"):
29522950
result = constructor(ts, dtype="M8[ns]")
29532951

29542952
assert np.all(result.dtypes == "M8[ns]")

pandas/tests/groupby/aggregate/test_cython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_cython_agg_nothing_to_agg():
9797

9898
frame = DataFrame({"a": np.random.randint(0, 5, 50), "b": ["foo", "bar"] * 25})
9999

100-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
100+
with tm.assert_produces_warning(FutureWarning):
101101
result = frame[["b"]].groupby(frame["a"]).mean()
102102
expected = DataFrame([], index=frame["a"].sort_values().drop_duplicates())
103103
tm.assert_frame_equal(result, expected)

pandas/tests/groupby/test_function.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ def test_averages(self, df, method):
154154
],
155155
)
156156

157-
with tm.assert_produces_warning(
158-
FutureWarning, match="Dropping invalid", check_stacklevel=False
159-
):
157+
with tm.assert_produces_warning(FutureWarning, match="Dropping invalid"):
160158
result = getattr(gb, method)(numeric_only=False)
161159
tm.assert_frame_equal(result.reindex_like(expected), expected)
162160

pandas/tests/groupby/test_groupby.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,7 @@ def test_omit_nuisance_agg(df, agg_function):
904904

905905
def test_omit_nuisance_warnings(df):
906906
# GH 38815
907-
with tm.assert_produces_warning(
908-
FutureWarning, filter_level="always", check_stacklevel=False
909-
):
907+
with tm.assert_produces_warning(FutureWarning, filter_level="always"):
910908
grouped = df.groupby("A")
911909
result = grouped.skew()
912910
expected = df.loc[:, ["A", "C", "D"]].groupby("A").skew()

pandas/tests/indexes/datetimes/test_indexing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,7 @@ def test_get_loc_tz_aware(self):
516516
freq="5s",
517517
)
518518
key = Timestamp("2019-12-12 10:19:25", tz="US/Eastern")
519-
with tm.assert_produces_warning(
520-
FutureWarning, match="deprecated", check_stacklevel=False
521-
):
519+
with tm.assert_produces_warning(FutureWarning, match="deprecated"):
522520
result = dti.get_loc(key, method="nearest")
523521
assert result == 7433
524522

0 commit comments

Comments
 (0)