diff --git a/pandas/tests/api/test_types.py b/pandas/tests/api/test_types.py index 71804bded3e44..7b6cc9412e03d 100644 --- a/pandas/tests/api/test_types.py +++ b/pandas/tests/api/test_types.py @@ -59,5 +59,5 @@ def test_types(self): def test_deprecated_from_api_types(self): for t in self.deprecated: - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): getattr(types, t)(1) diff --git a/pandas/tests/apply/test_frame_transform.py b/pandas/tests/apply/test_frame_transform.py index 6cee8b8a4b440..7718ec5215499 100644 --- a/pandas/tests/apply/test_frame_transform.py +++ b/pandas/tests/apply/test_frame_transform.py @@ -206,7 +206,7 @@ def test_transform_bad_dtype(op, frame_or_series): # tshift is deprecated warn = None if op != "tshift" else FutureWarning - with tm.assert_produces_warning(warn, check_stacklevel=False): + with tm.assert_produces_warning(warn): with pytest.raises(ValueError, match=msg): obj.transform(op) with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index a5522e503c7f4..2b689364c5002 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -724,7 +724,7 @@ def test_astype_nansafe(val, typ): msg = "Cannot convert NaT values to integer" with pytest.raises(ValueError, match=msg): - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): # datetimelike astype(int64) deprecated astype_nansafe(arr, dtype=typ) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 4da9ed76844af..cb60de9695568 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -295,7 +295,7 @@ def test_getitem_boolean( # we are producing a warning that since the passed boolean # key is not the same as the given index, we will reindex # not sure this is really necessary - with tm.assert_produces_warning(UserWarning, check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): indexer_obj = indexer_obj.reindex(datetime_frame.index[::-1]) subframe_obj = datetime_frame[indexer_obj] tm.assert_frame_equal(subframe_obj, subframe) diff --git a/pandas/tests/frame/methods/test_join.py b/pandas/tests/frame/methods/test_join.py index 11e83a3d94151..26c6010c753cc 100644 --- a/pandas/tests/frame/methods/test_join.py +++ b/pandas/tests/frame/methods/test_join.py @@ -227,7 +227,7 @@ def test_suppress_future_warning_with_sort_kw(sort_kw): if sort_kw is False: expected = expected.reindex(index=["c", "a", "b"]) - with tm.assert_produces_warning(None, check_stacklevel=False): + with tm.assert_produces_warning(None): result = a.join([b, c], how="outer", sort=sort_kw) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_sort_values.py b/pandas/tests/frame/methods/test_sort_values.py index 24ff20872baef..eaea22df3adfe 100644 --- a/pandas/tests/frame/methods/test_sort_values.py +++ b/pandas/tests/frame/methods/test_sort_values.py @@ -845,7 +845,7 @@ def test_sort_column_level_and_index_label( if len(levels) > 1: # Accessing multi-level columns that are not lexsorted raises a # performance warning - with tm.assert_produces_warning(PerformanceWarning, check_stacklevel=False): + with tm.assert_produces_warning(PerformanceWarning): tm.assert_frame_equal(result, expected) else: tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index e85b399e69874..3595da61bda11 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -669,7 +669,7 @@ def test_mode_sortwarning(self): df = DataFrame({"A": [np.nan, np.nan, "a", "a"]}) expected = DataFrame({"A": ["a", np.nan]}) - with tm.assert_produces_warning(UserWarning, check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): result = df.mode(dropna=False) result = result.sort_values(by="A").reset_index(drop=True) diff --git a/pandas/tests/indexes/test_any_index.py b/pandas/tests/indexes/test_any_index.py index c9c86f9eebde9..60fa8f1a0c083 100644 --- a/pandas/tests/indexes/test_any_index.py +++ b/pandas/tests/indexes/test_any_index.py @@ -33,7 +33,7 @@ def test_hash_error(index): def test_copy_dtype_deprecated(index): # GH#35853 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): index.copy(dtype=object) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index efd99df9a5e4f..32f30c1646a2b 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -96,7 +96,7 @@ def test_getitem_ndarray_3d(self, index, frame_or_series, indexer_sli): potential_errors = (IndexError, ValueError, NotImplementedError) with pytest.raises(potential_errors, match=msg): - with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): + with tm.assert_produces_warning(DeprecationWarning): idxr[nd3] def test_setitem_ndarray_3d(self, index, frame_or_series, indexer_sli): diff --git a/pandas/tests/io/test_compression.py b/pandas/tests/io/test_compression.py index 76bc188afdd1f..66c238bbd0962 100644 --- a/pandas/tests/io/test_compression.py +++ b/pandas/tests/io/test_compression.py @@ -112,7 +112,7 @@ def test_compression_warning(compression_only): ) with tm.ensure_clean() as path: with icom.get_handle(path, "w", compression=compression_only) as handles: - with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False): + with tm.assert_produces_warning(RuntimeWarning): df.to_csv(handles.handle, compression=compression_only) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 9de0422917e7b..decff32baa970 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1420,7 +1420,7 @@ def test_mode_sortwarning(self): expected = Series(["foo", np.nan]) s = Series([1, "foo", "foo", np.nan, np.nan]) - with tm.assert_produces_warning(UserWarning, check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): result = s.mode(dropna=False) result = result.sort_values().reset_index(drop=True) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 6bd794b1933a2..54f3f21dc9f6f 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -507,7 +507,7 @@ def test_to_pydatetime_nonzero_nano(self): ts = Timestamp("2011-01-01 9:00:00.123456789") # Warn the user of data loss (nanoseconds). - with tm.assert_produces_warning(UserWarning, check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): expected = datetime(2011, 1, 1, 9, 0, 0, 123456) result = ts.to_pydatetime() assert result == expected @@ -541,13 +541,13 @@ def test_to_datetime_bijective(self): # Ensure that converting to datetime and back only loses precision # by going from nanoseconds to microseconds. exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning - with tm.assert_produces_warning(exp_warning, check_stacklevel=False): + with tm.assert_produces_warning(exp_warning): pydt_max = Timestamp.max.to_pydatetime() assert Timestamp(pydt_max).value / 1000 == Timestamp.max.value / 1000 exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning - with tm.assert_produces_warning(exp_warning, check_stacklevel=False): + with tm.assert_produces_warning(exp_warning): pydt_min = Timestamp.min.to_pydatetime() # The next assertion can be enabled once GH#39221 is merged diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index d14261fef67a6..a3785518c860d 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -91,7 +91,7 @@ def test_astype_empty_constructor_equality(self, dtype): "m", # Generic timestamps raise a ValueError. Already tested. ): init_empty = Series([], dtype=dtype) - with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): + with tm.assert_produces_warning(DeprecationWarning): as_type_empty = Series([]).astype(dtype) tm.assert_series_equal(init_empty, as_type_empty) diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 3f3a3af658969..69dd7d083119f 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -266,7 +266,7 @@ def test_replace_with_empty_dictlike(self): s = pd.Series(list("abcd")) tm.assert_series_equal(s, s.replace({})) - with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): + with tm.assert_produces_warning(DeprecationWarning): empty_series = pd.Series([]) tm.assert_series_equal(s, s.replace(empty_series)) @@ -457,6 +457,6 @@ def test_str_replace_regex_default_raises_warning(self, pattern): msg = r"The default value of regex will change from True to False" if len(pattern) == 1: msg += r".*single character regular expressions.*not.*literal strings" - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False) as w: + with tm.assert_produces_warning(FutureWarning) as w: s.str.replace(pattern, "") assert re.match(msg, str(w[0].message)) diff --git a/pandas/tests/series/test_subclass.py b/pandas/tests/series/test_subclass.py index 86330b7cc6993..da5faeab49a8d 100644 --- a/pandas/tests/series/test_subclass.py +++ b/pandas/tests/series/test_subclass.py @@ -35,7 +35,7 @@ def test_subclass_unstack(self): tm.assert_frame_equal(res, exp) def test_subclass_empty_repr(self): - with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): + with tm.assert_produces_warning(DeprecationWarning): sub_series = tm.SubclassedSeries() assert "SubclassedSeries" in repr(sub_series) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 50bfc21637407..d36bea72908a3 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -194,7 +194,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals exp_warning = UserWarning # test nanosecond is preserved - with tm.assert_produces_warning(exp_warning, check_stacklevel=False): + with tm.assert_produces_warning(exp_warning): result = func(ts) assert isinstance(result, Timestamp) if normalize is False: @@ -231,7 +231,7 @@ def _check_offsetfunc_works(self, offset, funcname, dt, expected, normalize=Fals exp_warning = UserWarning # test nanosecond is preserved - with tm.assert_produces_warning(exp_warning, check_stacklevel=False): + with tm.assert_produces_warning(exp_warning): result = func(ts) assert isinstance(result, Timestamp) if normalize is False: