diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index f8c945bb496a8..6cfcfa778b105 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1198,9 +1198,7 @@ def test_nuiscance_columns(): ) tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning( - FutureWarning, match="Select only valid", check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match="Select only valid"): result = df.agg("sum") expected = Series([6, 6.0, "foobarbaz"], index=["A", "B", "C"]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 13fe3c2d427c5..3f1739deb4175 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -783,9 +783,7 @@ def test_to_perioddelta(self, datetime_index, freqstr): with tm.assert_produces_warning(FutureWarning, match=msg): # Deprecation GH#34853 expected = dti.to_perioddelta(freq=freqstr) - with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match=msg): # stacklevel is chosen to be "correct" for DatetimeIndex, not # DatetimeArray result = arr.to_perioddelta(freq=freqstr) diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index e8a3b5d28ee63..a514a9ce9b0e4 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -411,7 +411,7 @@ def test_maybe_promote_any_with_datetime64( # Casting date to dt64 is deprecated warn = FutureWarning - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): + with tm.assert_produces_warning(warn, match=msg): # stacklevel is chosen to make sense when called from higher-level functions _check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar) diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index bb1a1bc72116d..15e62e27c08d5 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -949,7 +949,7 @@ def test_setitem_mask_categorical(self): df = DataFrame({"cats": catsf, "values": valuesf}, index=idxf) exp_fancy = exp_multi_row.copy() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): # issue #37643 inplace kwarg deprecated return_value = exp_fancy["cats"].cat.set_categories( ["a", "b", "c"], inplace=True diff --git a/pandas/tests/frame/methods/test_join.py b/pandas/tests/frame/methods/test_join.py index 30118d20f67a9..c6bfd94b84908 100644 --- a/pandas/tests/frame/methods/test_join.py +++ b/pandas/tests/frame/methods/test_join.py @@ -344,9 +344,7 @@ def test_merge_join_different_levels(self): columns = ["a", "b", ("a", ""), ("c", "c1")] expected = DataFrame(columns=columns, data=[[1, 11, 0, 44], [0, 22, 1, 33]]) msg = "merging between different levels is deprecated" - with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match=msg): # stacklevel is chosen to be correct for pd.merge, not DataFrame.join result = df1.join(df2, on="a") tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 52797862afa14..359f166b9855e 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2664,15 +2664,15 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture, pydt): expected = DataFrame({0: [ts_naive]}) tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = DataFrame({0: ts}, index=[0], dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = DataFrame([ts], dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = DataFrame(np.array([ts], dtype=object), dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) @@ -2680,11 +2680,11 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture, pydt): result = DataFrame(ts, index=[0], columns=[0], dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): df = DataFrame([Series([ts])], dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): df = DataFrame([[ts]], columns=[0], dtype="datetime64[ns]") tm.assert_equal(df, expected) @@ -2946,9 +2946,7 @@ def test_tzaware_data_tznaive_dtype(self, constructor): ts = Timestamp("2019", tz=tz) ts_naive = Timestamp("2019") - with tm.assert_produces_warning( - FutureWarning, match="Data is timezone-aware", check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match="Data is timezone-aware"): result = constructor(ts, dtype="M8[ns]") assert np.all(result.dtypes == "M8[ns]") diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index 694f843ec138f..d9372ba5cbb50 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -97,7 +97,7 @@ def test_cython_agg_nothing_to_agg(): frame = DataFrame({"a": np.random.randint(0, 5, 50), "b": ["foo", "bar"] * 25}) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = frame[["b"]].groupby(frame["a"]).mean() expected = DataFrame([], index=frame["a"].sort_values().drop_duplicates()) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index e5870a206f419..c462db526b36d 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -154,9 +154,7 @@ def test_averages(self, df, method): ], ) - with tm.assert_produces_warning( - FutureWarning, match="Dropping invalid", check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match="Dropping invalid"): result = getattr(gb, method)(numeric_only=False) tm.assert_frame_equal(result.reindex_like(expected), expected) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index f632da9616124..aa547c1ec5b6c 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -904,9 +904,7 @@ def test_omit_nuisance_agg(df, agg_function): def test_omit_nuisance_warnings(df): # GH 38815 - with tm.assert_produces_warning( - FutureWarning, filter_level="always", check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, filter_level="always"): grouped = df.groupby("A") result = grouped.skew() expected = df.loc[:, ["A", "C", "D"]].groupby("A").skew() diff --git a/pandas/tests/indexes/datetimes/test_indexing.py b/pandas/tests/indexes/datetimes/test_indexing.py index beca71969dfcd..9db6567ca1b56 100644 --- a/pandas/tests/indexes/datetimes/test_indexing.py +++ b/pandas/tests/indexes/datetimes/test_indexing.py @@ -516,9 +516,7 @@ def test_get_loc_tz_aware(self): freq="5s", ) key = Timestamp("2019-12-12 10:19:25", tz="US/Eastern") - with tm.assert_produces_warning( - FutureWarning, match="deprecated", check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match="deprecated"): result = dti.get_loc(key, method="nearest") assert result == 7433 diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index 44c353315562a..76b5b835754aa 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -142,9 +142,7 @@ def test_datetimeindex_accessors4(self): assert dti.is_month_start[0] == 1 def test_datetimeindex_accessors5(self): - with tm.assert_produces_warning( - FutureWarning, match="The 'freq' argument", check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match="The 'freq' argument"): tests = [ (Timestamp("2013-06-01", freq="M").is_month_start, 1), (Timestamp("2013-06-01", freq="BM").is_month_start, 0), diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index fda67e7c0a058..c60e56875bfcd 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -65,9 +65,7 @@ def test_dti_timestamp_fields(self, field): expected = getattr(idx, field)[-1] warn = FutureWarning if field.startswith("is_") else None - with tm.assert_produces_warning( - warn, match="Timestamp.freq is deprecated", check_stacklevel=False - ): + with tm.assert_produces_warning(warn, match="Timestamp.freq is deprecated"): result = getattr(Timestamp(idx[-1]), field) assert result == expected diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index ed9b5cc0850b9..63d1568ed4d43 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2630,7 +2630,7 @@ def test_loc_slice_disallows_positional(): with pytest.raises(TypeError, match=msg): df.loc[1:3, 1] - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): # GH#31840 deprecated incorrect behavior df.loc[1:3, 1] = 2 diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index cccfd87f6312b..85519398b4444 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -749,7 +749,7 @@ def test_applymap_subset_multiindex(self, slice_): col = MultiIndex.from_product([["x", "y"], ["A", "B"]]) df = DataFrame(np.random.rand(4, 4), columns=col, index=idx) - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): + with tm.assert_produces_warning(warn, match=msg): df.style.applymap(lambda x: "color: red;", subset=slice_).to_html() def test_applymap_subset_multiindex_code(self): diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index 359c3cea62f9c..3aac7a961fa19 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -63,12 +63,12 @@ def test_deprecating_on_loffset_and_base(): # not checking the stacklevel for .groupby().resample() because it's complicated to # reconcile it with the stacklevel for Series.resample() and DataFrame.resample(); # see GH #37603 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): df.groupby("a").resample("3T", base=0).sum() - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): df.groupby("a").resample("3T", loffset="0s").sum() msg = "'offset' and 'base' cannot be present at the same time" - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): with pytest.raises(ValueError, match=msg): df.groupby("a").resample("3T", base=0, offset=0).sum() diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 48a55022aa484..6533cbb1f70cd 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -630,7 +630,7 @@ def test_join_dups(self): dta = x.merge(y, left_index=True, right_index=True).merge( z, left_index=True, right_index=True, how="outer" ) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): dta = dta.merge(w, left_index=True, right_index=True) expected = concat([x, y, z, w], axis=1) expected.columns = ["x_x", "y_x", "x_y", "y_y", "x_x", "y_x", "x_y", "y_y"] diff --git a/pandas/tests/series/accessors/test_cat_accessor.py b/pandas/tests/series/accessors/test_cat_accessor.py index 289e4cfe9397d..fb2071ac9c3f6 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -51,7 +51,7 @@ def test_cat_accessor(self): exp = Categorical(["a", "b", np.nan, "a"], categories=["b", "a"]) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): # issue #37643 inplace kwarg deprecated return_value = ser.cat.set_categories(["b", "a"], inplace=True) @@ -88,7 +88,7 @@ def test_cat_accessor_updates_on_inplace(self): return_value = ser.drop(0, inplace=True) assert return_value is None - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): return_value = ser.cat.remove_unused_categories(inplace=True) assert return_value is None diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index ed83377f31317..8d18eba36af5e 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -790,7 +790,7 @@ def test_series_ops_name_retention( # GH#37374 logical ops behaving as set ops deprecated warn = FutureWarning if is_rlogical and box is Index else None msg = "operating as a set operation is deprecated" - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): + with tm.assert_produces_warning(warn, match=msg): # stacklevel is correct for Index op, not reversed op result = op(left, right) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 1b488b4cf0b77..692c040a33ff8 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1645,12 +1645,12 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture, pydt): ts = ts.to_pydatetime() ts_naive = Timestamp("2019") - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = Series([ts], dtype="datetime64[ns]") expected = Series([ts_naive]) tm.assert_series_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = Series(np.array([ts], dtype=object), dtype="datetime64[ns]") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/test_logical_ops.py b/pandas/tests/series/test_logical_ops.py index 563c8f63df57d..9648b01492e02 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -279,9 +279,7 @@ def test_reversed_xor_with_index_returns_index(self): tm.assert_index_equal(result, expected) expected = Index.symmetric_difference(idx2, ser) - with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match=msg): result = idx2 ^ ser tm.assert_index_equal(result, expected) @@ -337,9 +335,7 @@ def test_reverse_ops_with_index(self, op, expected): idx = Index([False, True]) msg = "operating as a set operation" - with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False - ): + with tm.assert_produces_warning(FutureWarning, match=msg): # behaving as set ops is deprecated, will become logical ops result = op(ser, idx) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index 1348e62148cb1..c6666a8c91e8d 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -287,32 +287,32 @@ def test_bool_ops_warn_on_arithmetic(self, op_str, opname): return with tm.use_numexpr(True, min_elements=5): - with tm.assert_produces_warning(check_stacklevel=False): + with tm.assert_produces_warning(): r = f(df, df) e = fe(df, df) tm.assert_frame_equal(r, e) - with tm.assert_produces_warning(check_stacklevel=False): + with tm.assert_produces_warning(): r = f(df.a, df.b) e = fe(df.a, df.b) tm.assert_series_equal(r, e) - with tm.assert_produces_warning(check_stacklevel=False): + with tm.assert_produces_warning(): r = f(df.a, True) e = fe(df.a, True) tm.assert_series_equal(r, e) - with tm.assert_produces_warning(check_stacklevel=False): + with tm.assert_produces_warning(): r = f(False, df.a) e = fe(False, df.a) tm.assert_series_equal(r, e) - with tm.assert_produces_warning(check_stacklevel=False): + with tm.assert_produces_warning(): r = f(False, df) e = fe(False, df) tm.assert_frame_equal(r, e) - with tm.assert_produces_warning(check_stacklevel=False): + with tm.assert_produces_warning(): r = f(df, True) e = fe(df, True) tm.assert_frame_equal(r, e) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 27b06e78d8ce2..a638ecbe04936 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -697,7 +697,7 @@ def test_rolling_count_default_min_periods_with_null_values(frame_or_series): expected_counts = [1.0, 2.0, 3.0, 2.0, 2.0, 2.0, 3.0] # GH 31302 - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning): result = frame_or_series(values).rolling(3).count() expected = frame_or_series(expected_counts) tm.assert_equal(result, expected)