Skip to content

Commit 75609da

Browse files
authored
TST: unnecessary check_stacklevel=False (#39901)
1 parent 68fe64b commit 75609da

File tree

16 files changed

+20
-20
lines changed

16 files changed

+20
-20
lines changed

pandas/tests/api/test_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ def test_types(self):
5959
def test_deprecated_from_api_types(self):
6060

6161
for t in self.deprecated:
62-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
62+
with tm.assert_produces_warning(FutureWarning):
6363
getattr(types, t)(1)

pandas/tests/apply/test_frame_transform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_transform_bad_dtype(op, frame_or_series):
206206

207207
# tshift is deprecated
208208
warn = None if op != "tshift" else FutureWarning
209-
with tm.assert_produces_warning(warn, check_stacklevel=False):
209+
with tm.assert_produces_warning(warn):
210210
with pytest.raises(ValueError, match=msg):
211211
obj.transform(op)
212212
with pytest.raises(ValueError, match=msg):

pandas/tests/dtypes/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def test_astype_nansafe(val, typ):
724724

725725
msg = "Cannot convert NaT values to integer"
726726
with pytest.raises(ValueError, match=msg):
727-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
727+
with tm.assert_produces_warning(FutureWarning):
728728
# datetimelike astype(int64) deprecated
729729
astype_nansafe(arr, dtype=typ)
730730

pandas/tests/frame/indexing/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_getitem_boolean(
295295
# we are producing a warning that since the passed boolean
296296
# key is not the same as the given index, we will reindex
297297
# not sure this is really necessary
298-
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
298+
with tm.assert_produces_warning(UserWarning):
299299
indexer_obj = indexer_obj.reindex(datetime_frame.index[::-1])
300300
subframe_obj = datetime_frame[indexer_obj]
301301
tm.assert_frame_equal(subframe_obj, subframe)

pandas/tests/frame/methods/test_join.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_suppress_future_warning_with_sort_kw(sort_kw):
227227
if sort_kw is False:
228228
expected = expected.reindex(index=["c", "a", "b"])
229229

230-
with tm.assert_produces_warning(None, check_stacklevel=False):
230+
with tm.assert_produces_warning(None):
231231
result = a.join([b, c], how="outer", sort=sort_kw)
232232
tm.assert_frame_equal(result, expected)
233233

pandas/tests/frame/methods/test_sort_values.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ def test_sort_column_level_and_index_label(
845845
if len(levels) > 1:
846846
# Accessing multi-level columns that are not lexsorted raises a
847847
# performance warning
848-
with tm.assert_produces_warning(PerformanceWarning, check_stacklevel=False):
848+
with tm.assert_produces_warning(PerformanceWarning):
849849
tm.assert_frame_equal(result, expected)
850850
else:
851851
tm.assert_frame_equal(result, expected)

pandas/tests/frame/test_reductions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def test_mode_sortwarning(self):
669669
df = DataFrame({"A": [np.nan, np.nan, "a", "a"]})
670670
expected = DataFrame({"A": ["a", np.nan]})
671671

672-
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
672+
with tm.assert_produces_warning(UserWarning):
673673
result = df.mode(dropna=False)
674674
result = result.sort_values(by="A").reset_index(drop=True)
675675

pandas/tests/indexes/test_any_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_hash_error(index):
3333

3434
def test_copy_dtype_deprecated(index):
3535
# GH#35853
36-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
36+
with tm.assert_produces_warning(FutureWarning):
3737
index.copy(dtype=object)
3838

3939

pandas/tests/indexing/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_getitem_ndarray_3d(self, index, frame_or_series, indexer_sli):
9292

9393
potential_errors = (IndexError, ValueError, NotImplementedError)
9494
with pytest.raises(potential_errors, match=msg):
95-
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
95+
with tm.assert_produces_warning(DeprecationWarning):
9696
idxr[nd3]
9797

9898
def test_setitem_ndarray_3d(self, index, frame_or_series, indexer_sli):

pandas/tests/io/test_compression.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_compression_warning(compression_only):
112112
)
113113
with tm.ensure_clean() as path:
114114
with icom.get_handle(path, "w", compression=compression_only) as handles:
115-
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False):
115+
with tm.assert_produces_warning(RuntimeWarning):
116116
df.to_csv(handles.handle, compression=compression_only)
117117

118118

pandas/tests/reductions/test_reductions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ def test_mode_sortwarning(self):
14201420
expected = Series(["foo", np.nan])
14211421
s = Series([1, "foo", "foo", np.nan, np.nan])
14221422

1423-
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
1423+
with tm.assert_produces_warning(UserWarning):
14241424
result = s.mode(dropna=False)
14251425
result = result.sort_values().reset_index(drop=True)
14261426

pandas/tests/scalar/timestamp/test_timestamp.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def test_to_pydatetime_nonzero_nano(self):
507507
ts = Timestamp("2011-01-01 9:00:00.123456789")
508508

509509
# Warn the user of data loss (nanoseconds).
510-
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
510+
with tm.assert_produces_warning(UserWarning):
511511
expected = datetime(2011, 1, 1, 9, 0, 0, 123456)
512512
result = ts.to_pydatetime()
513513
assert result == expected
@@ -541,13 +541,13 @@ def test_to_datetime_bijective(self):
541541
# Ensure that converting to datetime and back only loses precision
542542
# by going from nanoseconds to microseconds.
543543
exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning
544-
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
544+
with tm.assert_produces_warning(exp_warning):
545545
pydt_max = Timestamp.max.to_pydatetime()
546546

547547
assert Timestamp(pydt_max).value / 1000 == Timestamp.max.value / 1000
548548

549549
exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning
550-
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
550+
with tm.assert_produces_warning(exp_warning):
551551
pydt_min = Timestamp.min.to_pydatetime()
552552

553553
# The next assertion can be enabled once GH#39221 is merged

pandas/tests/series/methods/test_astype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_astype_empty_constructor_equality(self, dtype):
9191
"m", # Generic timestamps raise a ValueError. Already tested.
9292
):
9393
init_empty = Series([], dtype=dtype)
94-
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
94+
with tm.assert_produces_warning(DeprecationWarning):
9595
as_type_empty = Series([]).astype(dtype)
9696
tm.assert_series_equal(init_empty, as_type_empty)
9797

pandas/tests/series/methods/test_replace.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_replace_with_empty_dictlike(self):
266266
s = pd.Series(list("abcd"))
267267
tm.assert_series_equal(s, s.replace({}))
268268

269-
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
269+
with tm.assert_produces_warning(DeprecationWarning):
270270
empty_series = pd.Series([])
271271
tm.assert_series_equal(s, s.replace(empty_series))
272272

@@ -457,6 +457,6 @@ def test_str_replace_regex_default_raises_warning(self, pattern):
457457
msg = r"The default value of regex will change from True to False"
458458
if len(pattern) == 1:
459459
msg += r".*single character regular expressions.*not.*literal strings"
460-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False) as w:
460+
with tm.assert_produces_warning(FutureWarning) as w:
461461
s.str.replace(pattern, "")
462462
assert re.match(msg, str(w[0].message))

pandas/tests/series/test_subclass.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_subclass_unstack(self):
3535
tm.assert_frame_equal(res, exp)
3636

3737
def test_subclass_empty_repr(self):
38-
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
38+
with tm.assert_produces_warning(DeprecationWarning):
3939
sub_series = tm.SubclassedSeries()
4040
assert "SubclassedSeries" in repr(sub_series)
4141

pandas/tests/tseries/offsets/test_offsets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals
194194
exp_warning = UserWarning
195195

196196
# test nanosecond is preserved
197-
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
197+
with tm.assert_produces_warning(exp_warning):
198198
result = func(ts)
199199
assert isinstance(result, Timestamp)
200200
if normalize is False:
@@ -231,7 +231,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals
231231
exp_warning = UserWarning
232232

233233
# test nanosecond is preserved
234-
with tm.assert_produces_warning(exp_warning, check_stacklevel=False):
234+
with tm.assert_produces_warning(exp_warning):
235235
result = func(ts)
236236
assert isinstance(result, Timestamp)
237237
if normalize is False:

0 commit comments

Comments
 (0)