From c6fb9ba0f196bab599c3661fe89f87233cdfd1ab Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sun, 14 Nov 2021 10:12:33 -0500 Subject: [PATCH 1/2] TST: check_stacklevel=True in various tests --- pandas/tests/apply/test_frame_apply.py | 3 ++- pandas/tests/arrays/test_datetimelike.py | 3 ++- pandas/tests/dtypes/cast/test_promote.py | 5 +++- pandas/tests/frame/indexing/test_setitem.py | 4 +++- pandas/tests/frame/methods/test_join.py | 3 ++- pandas/tests/frame/test_constructors.py | 23 ++++++++++++++----- pandas/tests/groupby/aggregate/test_cython.py | 4 +++- pandas/tests/groupby/test_function.py | 3 ++- pandas/tests/groupby/test_groupby.py | 3 ++- .../tests/indexes/datetimes/test_indexing.py | 3 ++- pandas/tests/indexes/datetimes/test_misc.py | 3 ++- .../indexes/datetimes/test_scalar_compat.py | 3 ++- pandas/tests/indexing/test_loc.py | 4 +++- pandas/tests/io/formats/style/test_style.py | 5 +++- pandas/tests/resample/test_deprecated.py | 12 +++++++--- pandas/tests/reshape/merge/test_join.py | 4 +++- .../series/accessors/test_cat_accessor.py | 8 +++++-- pandas/tests/series/test_arithmetic.py | 5 +++- pandas/tests/series/test_constructors.py | 8 +++++-- pandas/tests/series/test_logical_ops.py | 6 +++-- pandas/tests/test_expressions.py | 12 +++++----- pandas/tests/window/test_rolling.py | 4 +++- 22 files changed, 91 insertions(+), 37 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index f8c945bb496a8..2dbdfd6a1a232 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1199,7 +1199,8 @@ def test_nuiscance_columns(): tm.assert_frame_equal(result, expected) with tm.assert_produces_warning( - FutureWarning, match="Select only valid", check_stacklevel=False + FutureWarning, + match="Select only valid", ): result = df.agg("sum") expected = Series([6, 6.0, "foobarbaz"], index=["A", "B", "C"]) diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 13fe3c2d427c5..9f1a8623157d4 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -784,7 +784,8 @@ def test_to_perioddelta(self, datetime_index, freqstr): # Deprecation GH#34853 expected = dti.to_perioddelta(freq=freqstr) with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False + FutureWarning, + match=msg, ): # stacklevel is chosen to be "correct" for DatetimeIndex, not # DatetimeArray diff --git a/pandas/tests/dtypes/cast/test_promote.py b/pandas/tests/dtypes/cast/test_promote.py index e8a3b5d28ee63..0f8c3fdc90615 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -411,7 +411,10 @@ 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..aad05d2527c2f 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -949,7 +949,9 @@ 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..fb8fd0d0aedc8 100644 --- a/pandas/tests/frame/methods/test_join.py +++ b/pandas/tests/frame/methods/test_join.py @@ -345,7 +345,8 @@ def test_merge_join_different_levels(self): 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 + FutureWarning, + match=msg, ): # stacklevel is chosen to be correct for pd.merge, not DataFrame.join result = df1.join(df2, on="a") diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 52797862afa14..f27515a627712 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2664,15 +2664,21 @@ 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 +2686,15 @@ 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) @@ -2947,7 +2957,8 @@ def test_tzaware_data_tznaive_dtype(self, constructor): ts_naive = Timestamp("2019") with tm.assert_produces_warning( - FutureWarning, match="Data is timezone-aware", check_stacklevel=False + FutureWarning, + match="Data is timezone-aware", ): result = constructor(ts, dtype="M8[ns]") diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index 694f843ec138f..4ea2448888580 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -97,7 +97,9 @@ 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..a2d0179603f3c 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -155,7 +155,8 @@ def test_averages(self, df, method): ) with tm.assert_produces_warning( - FutureWarning, match="Dropping invalid", check_stacklevel=False + 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..90e9375b25253 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -905,7 +905,8 @@ 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 + FutureWarning, + filter_level="always", ): grouped = df.groupby("A") result = grouped.skew() diff --git a/pandas/tests/indexes/datetimes/test_indexing.py b/pandas/tests/indexes/datetimes/test_indexing.py index beca71969dfcd..6e34d23fde282 100644 --- a/pandas/tests/indexes/datetimes/test_indexing.py +++ b/pandas/tests/indexes/datetimes/test_indexing.py @@ -517,7 +517,8 @@ def test_get_loc_tz_aware(self): ) key = Timestamp("2019-12-12 10:19:25", tz="US/Eastern") with tm.assert_produces_warning( - FutureWarning, match="deprecated", check_stacklevel=False + 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..3fad568584378 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -143,7 +143,8 @@ def test_datetimeindex_accessors4(self): def test_datetimeindex_accessors5(self): with tm.assert_produces_warning( - FutureWarning, match="The 'freq' argument", check_stacklevel=False + FutureWarning, + match="The 'freq' argument", ): tests = [ (Timestamp("2013-06-01", freq="M").is_month_start, 1), diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index fda67e7c0a058..3bdf8d721c17d 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -66,7 +66,8 @@ def test_dti_timestamp_fields(self, field): warn = FutureWarning if field.startswith("is_") else None with tm.assert_produces_warning( - warn, match="Timestamp.freq is deprecated", check_stacklevel=False + 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..4f6f604c4f74e 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2630,7 +2630,9 @@ 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..c713699d86d3a 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -749,7 +749,10 @@ 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..1ebdcf11575af 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -63,12 +63,18 @@ 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..e1bc81da52458 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -630,7 +630,9 @@ 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..2ecf7bd7d69d1 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -51,7 +51,9 @@ 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 +90,9 @@ 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..93f4e3c89272e 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -790,7 +790,10 @@ 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..b0531ef6ab03d 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1645,12 +1645,16 @@ 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..3c2b2e8da1c84 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -280,7 +280,8 @@ def test_reversed_xor_with_index_returns_index(self): expected = Index.symmetric_difference(idx2, ser) with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False + FutureWarning, + match=msg, ): result = idx2 ^ ser tm.assert_index_equal(result, expected) @@ -338,7 +339,8 @@ def test_reverse_ops_with_index(self, op, expected): msg = "operating as a set operation" with tm.assert_produces_warning( - FutureWarning, match=msg, check_stacklevel=False + FutureWarning, + match=msg, ): # behaving as set ops is deprecated, will become logical ops result = op(ser, idx) 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..ecbb0a1e4de15 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -697,7 +697,9 @@ 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) From 31393e704657e1231bb1f4d83a9f0ee9fce63140 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sun, 14 Nov 2021 10:17:58 -0500 Subject: [PATCH 2/2] cleanup --- pandas/tests/apply/test_frame_apply.py | 5 +--- pandas/tests/arrays/test_datetimelike.py | 5 +--- pandas/tests/dtypes/cast/test_promote.py | 5 +--- pandas/tests/frame/indexing/test_setitem.py | 4 +-- pandas/tests/frame/methods/test_join.py | 5 +--- pandas/tests/frame/test_constructors.py | 25 +++++-------------- pandas/tests/groupby/aggregate/test_cython.py | 4 +-- pandas/tests/groupby/test_function.py | 5 +--- pandas/tests/groupby/test_groupby.py | 5 +--- .../tests/indexes/datetimes/test_indexing.py | 5 +--- pandas/tests/indexes/datetimes/test_misc.py | 5 +--- .../indexes/datetimes/test_scalar_compat.py | 5 +--- pandas/tests/indexing/test_loc.py | 4 +-- pandas/tests/io/formats/style/test_style.py | 5 +--- pandas/tests/resample/test_deprecated.py | 12 +++------ pandas/tests/reshape/merge/test_join.py | 4 +-- .../series/accessors/test_cat_accessor.py | 8 ++---- pandas/tests/series/test_arithmetic.py | 5 +--- pandas/tests/series/test_constructors.py | 8 ++---- pandas/tests/series/test_logical_ops.py | 10 ++------ pandas/tests/window/test_rolling.py | 4 +-- 21 files changed, 31 insertions(+), 107 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 2dbdfd6a1a232..6cfcfa778b105 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1198,10 +1198,7 @@ def test_nuiscance_columns(): ) tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning( - FutureWarning, - match="Select only valid", - ): + 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 9f1a8623157d4..3f1739deb4175 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -783,10 +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, - ): + 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 0f8c3fdc90615..a514a9ce9b0e4 100644 --- a/pandas/tests/dtypes/cast/test_promote.py +++ b/pandas/tests/dtypes/cast/test_promote.py @@ -411,10 +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, - ): + 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 aad05d2527c2f..15e62e27c08d5 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -949,9 +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, - ): + 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 fb8fd0d0aedc8..c6bfd94b84908 100644 --- a/pandas/tests/frame/methods/test_join.py +++ b/pandas/tests/frame/methods/test_join.py @@ -344,10 +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, - ): + 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 f27515a627712..359f166b9855e 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2664,21 +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, - ): + 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, - ): + with tm.assert_produces_warning(FutureWarning): result = DataFrame([ts], dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) - with tm.assert_produces_warning( - FutureWarning, - ): + with tm.assert_produces_warning(FutureWarning): result = DataFrame(np.array([ts], dtype=object), dtype="datetime64[ns]") tm.assert_frame_equal(result, expected) @@ -2686,15 +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, - ): + 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, - ): + with tm.assert_produces_warning(FutureWarning): df = DataFrame([[ts]], columns=[0], dtype="datetime64[ns]") tm.assert_equal(df, expected) @@ -2956,10 +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", - ): + 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 4ea2448888580..d9372ba5cbb50 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -97,9 +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, - ): + 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 a2d0179603f3c..c462db526b36d 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -154,10 +154,7 @@ def test_averages(self, df, method): ], ) - with tm.assert_produces_warning( - FutureWarning, - match="Dropping invalid", - ): + 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 90e9375b25253..aa547c1ec5b6c 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -904,10 +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", - ): + 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 6e34d23fde282..9db6567ca1b56 100644 --- a/pandas/tests/indexes/datetimes/test_indexing.py +++ b/pandas/tests/indexes/datetimes/test_indexing.py @@ -516,10 +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", - ): + 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 3fad568584378..76b5b835754aa 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -142,10 +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", - ): + 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 3bdf8d721c17d..c60e56875bfcd 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -65,10 +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", - ): + 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 4f6f604c4f74e..63d1568ed4d43 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2630,9 +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, - ): + 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 c713699d86d3a..85519398b4444 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -749,10 +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, - ): + 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 1ebdcf11575af..3aac7a961fa19 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -63,18 +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, - ): + with tm.assert_produces_warning(FutureWarning): df.groupby("a").resample("3T", base=0).sum() - with tm.assert_produces_warning( - FutureWarning, - ): + 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, - ): + 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 e1bc81da52458..6533cbb1f70cd 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -630,9 +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, - ): + 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 2ecf7bd7d69d1..fb2071ac9c3f6 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -51,9 +51,7 @@ def test_cat_accessor(self): exp = Categorical(["a", "b", np.nan, "a"], categories=["b", "a"]) - with tm.assert_produces_warning( - FutureWarning, - ): + with tm.assert_produces_warning(FutureWarning): # issue #37643 inplace kwarg deprecated return_value = ser.cat.set_categories(["b", "a"], inplace=True) @@ -90,9 +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, - ): + 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 93f4e3c89272e..8d18eba36af5e 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -790,10 +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, - ): + 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 b0531ef6ab03d..692c040a33ff8 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1645,16 +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, - ): + 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, - ): + 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 3c2b2e8da1c84..9648b01492e02 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -279,10 +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, - ): + with tm.assert_produces_warning(FutureWarning, match=msg): result = idx2 ^ ser tm.assert_index_equal(result, expected) @@ -338,10 +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, - ): + 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/window/test_rolling.py b/pandas/tests/window/test_rolling.py index ecbb0a1e4de15..a638ecbe04936 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -697,9 +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, - ): + 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)