diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 72b6aa7853d65..1f599dfdea248 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2372,4 +2372,4 @@ def external_values(values: ArrayLike) -> ArrayLike: # TODO(CoW) we should also mark our ExtensionArrays as read-only - return values \ No newline at end of file + return values diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index 1010e2ce79ff1..04e0cb5780493 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -2329,10 +2329,16 @@ def test_dti_add_series(self, tz_naive_fixture, names): tm.assert_series_equal(result2, expected) expected = index + Timedelta(seconds=5) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result3 = ser.values + index tm.assert_index_equal(result3, expected) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result4 = index + ser.values tm.assert_index_equal(result4, expected) diff --git a/pandas/tests/arrays/test_timedeltas.py b/pandas/tests/arrays/test_timedeltas.py index 384f7b9fb7685..a064d90478f57 100644 --- a/pandas/tests/arrays/test_timedeltas.py +++ b/pandas/tests/arrays/test_timedeltas.py @@ -74,7 +74,10 @@ def test_total_seconds_nanoseconds(self): # issue #48521 start_time = pd.Series(["2145-11-02 06:00:00"]).astype("datetime64[ns]") end_time = pd.Series(["2145-11-02 07:06:00"]).astype("datetime64[ns]") - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): expected = (end_time - start_time).values / np.timedelta64(1, "s") result = (end_time - start_time).dt.total_seconds().values assert result == expected diff --git a/pandas/tests/base/test_value_counts.py b/pandas/tests/base/test_value_counts.py index 6dca664505ed1..0e8b8be1f873c 100644 --- a/pandas/tests/base/test_value_counts.py +++ b/pandas/tests/base/test_value_counts.py @@ -254,7 +254,10 @@ def test_value_counts_datetime64(index_or_series, unit): # with NaT s = df["dt"].copy() - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): s = klass(list(s.values) + [pd.NaT] * 4) if klass is Series: s = s.dt.as_unit(unit) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 8e3a834fadf94..e896e473f06f7 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1507,7 +1507,10 @@ def test_nested_period_index_subscript_expression(self): def test_date_boolean(self, engine, parser): df = DataFrame(np.random.default_rng(2).standard_normal((5, 3))) df["dates1"] = date_range("1/1/2012", periods=5) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = self.eval( "df.dates1 < 20130101", local_dict={"df": df}, diff --git a/pandas/tests/copy_view/test_astype.py b/pandas/tests/copy_view/test_astype.py index fdeef2ffb00b0..3af2175b19ae0 100644 --- a/pandas/tests/copy_view/test_astype.py +++ b/pandas/tests/copy_view/test_astype.py @@ -187,7 +187,10 @@ def test_astype_arrow_timestamp(): }, dtype="M8[ns]", ) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = df.astype("timestamp[ns][pyarrow]") assert not result._mgr._has_no_reference(0) if pa_version_under12p0: diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index f34ef09683228..6c910616f7b6a 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -305,7 +305,10 @@ def test_frame_setitem_datetime64_col_other_units(self, unit): df[unit] = vals assert df[unit].dtype == ex_vals.dtype - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): assert (df[unit].values == ex_vals).all() @pytest.mark.parametrize("unit", ["h", "m", "s", "ms", "D", "M", "Y"]) @@ -323,7 +326,10 @@ def test_frame_setitem_existing_datetime64_col_other_units(self, unit): # We overwrite existing dt64 column with new, non-nano dt64 vals df["dates"] = vals - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): assert (df["dates"].values == ex_vals).all() def test_setitem_dt64tz(self, timezone_frame): diff --git a/pandas/tests/frame/methods/test_convert_dtypes.py b/pandas/tests/frame/methods/test_convert_dtypes.py index d0fdbb070c284..33bbeea9266e9 100644 --- a/pandas/tests/frame/methods/test_convert_dtypes.py +++ b/pandas/tests/frame/methods/test_convert_dtypes.py @@ -61,7 +61,10 @@ def test_pyarrow_dtype_backend(self): "g": pd.Series(pd.timedelta_range("1D", periods=3)), } ) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = df.convert_dtypes(dtype_backend="pyarrow") expected = pd.DataFrame( { @@ -177,7 +180,10 @@ def test_convert_dtypes_pyarrow_timestamp(self): # GH 54191 pytest.importorskip("pyarrow") ser = pd.Series(pd.date_range("2020-01-01", "2020-01-02", freq="1min")) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): expected = ser.astype("timestamp[ms][pyarrow]") result = expected.convert_dtypes(dtype_backend="pyarrow") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_duplicated.py b/pandas/tests/frame/methods/test_duplicated.py index 980234a4e21dc..748615dd721bb 100644 --- a/pandas/tests/frame/methods/test_duplicated.py +++ b/pandas/tests/frame/methods/test_duplicated.py @@ -109,7 +109,10 @@ def test_frame_datetime64_duplicated(): dates = date_range("2010-07-01", end="2010-08-05") tst = DataFrame({"symbol": "AAA", "date": dates}) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = tst.duplicated(["date", "symbol"]) assert (-result).all() diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index 832175f7b3dc4..488a52ecf3acc 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -293,14 +293,20 @@ def test_consolidate_datetime64(self): ) ser_starting = df.starting - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): ser_starting.index = ser_starting.values ser_starting = ser_starting.tz_localize("US/Eastern") ser_starting = ser_starting.tz_convert("UTC") ser_starting.index.name = "starting" ser_ending = df.ending - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): ser_ending.index = ser_ending.values ser_ending = ser_ending.tz_localize("US/Eastern") ser_ending = ser_ending.tz_convert("UTC") diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index 44b69de0df5a8..515ce4ab85046 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -421,7 +421,10 @@ def test_date_query_with_attribute_access(self, engine, parser): df["dates1"] = date_range("1/1/2012", periods=5) df["dates2"] = date_range("1/1/2013", periods=5) df["dates3"] = date_range("1/1/2014", periods=5) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query( "@df.dates1 < 20130101 < @df.dates3", engine=engine, parser=parser ) @@ -433,7 +436,10 @@ def test_date_query_no_attribute_access(self, engine, parser): df["dates1"] = date_range("1/1/2012", periods=5) df["dates2"] = date_range("1/1/2013", periods=5) df["dates3"] = date_range("1/1/2014", periods=5) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query("dates1 < 20130101 < dates3", engine=engine, parser=parser) expec = df[(df.dates1 < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -446,7 +452,10 @@ def test_date_query_with_NaT(self, engine, parser): df["dates3"] = date_range("1/1/2014", periods=n) df.loc[np.random.default_rng(2).random(n) > 0.5, "dates1"] = pd.NaT df.loc[np.random.default_rng(2).random(n) > 0.5, "dates3"] = pd.NaT - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query("dates1 < 20130101 < dates3", engine=engine, parser=parser) expec = df[(df.dates1 < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -458,7 +467,10 @@ def test_date_index_query(self, engine, parser): df["dates3"] = date_range("1/1/2014", periods=n) return_value = df.set_index("dates1", inplace=True, drop=True) assert return_value is None - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query("index < 20130101 < dates3", engine=engine, parser=parser) expec = df[(df.index < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -474,7 +486,10 @@ def test_date_index_query_with_NaT(self, engine, parser): df.iloc[0, 0] = pd.NaT return_value = df.set_index("dates1", inplace=True, drop=True) assert return_value is None - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query("index < 20130101 < dates3", engine=engine, parser=parser) expec = df[(df.index < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -488,7 +503,10 @@ def test_date_index_query_with_NaT_duplicates(self, engine, parser): df.loc[np.random.default_rng(2).random(n) > 0.5, "dates1"] = pd.NaT return_value = df.set_index("dates1", inplace=True, drop=True) assert return_value is None - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query("dates1 < 20130101 < dates3", engine=engine, parser=parser) expec = df[(df.index.to_series() < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -499,18 +517,27 @@ def test_date_query_with_non_date(self, engine, parser): {"dates": date_range("1/1/2012", periods=n), "nondate": np.arange(n)} ) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = df.query("dates == nondate", parser=parser, engine=engine) assert len(result) == 0 - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = df.query("dates != nondate", parser=parser, engine=engine) tm.assert_frame_equal(result, df) msg = r"Invalid comparison between dtype=datetime64\[ns\] and ndarray" for op in ["<", ">", "<=", ">="]: with pytest.raises(TypeError, match=msg): - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): df.query(f"dates {op} nondate", parser=parser, engine=engine) def test_query_syntax_error(self, engine, parser): @@ -757,12 +784,18 @@ def test_check_tz_aware_index_query(self, tz_aware_fixture): ) expected = DataFrame(index=df_index) df = DataFrame(index=df_index) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = df.query('"2018-01-03 00:00:00+00" < time') tm.assert_frame_equal(result, expected) expected = DataFrame(df_index) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = df.reset_index().query('"2018-01-03 00:00:00+00" < time') tm.assert_frame_equal(result, expected) @@ -809,9 +842,14 @@ def test_date_query_no_attribute_access(self, engine, parser): df["dates1"] = date_range("1/1/2012", periods=5) df["dates2"] = date_range("1/1/2013", periods=5) df["dates3"] = date_range("1/1/2014", periods=5) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query( - "(dates1 < 20130101) & (20130101 < dates3)", engine=engine, parser=parser + "(dates1 < 20130101) & (20130101 < dates3)", + engine=engine, + parser=parser, ) expec = df[(df.dates1 < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -824,9 +862,14 @@ def test_date_query_with_NaT(self, engine, parser): df["dates3"] = date_range("1/1/2014", periods=n) df.loc[np.random.default_rng(2).random(n) > 0.5, "dates1"] = pd.NaT df.loc[np.random.default_rng(2).random(n) > 0.5, "dates3"] = pd.NaT - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query( - "(dates1 < 20130101) & (20130101 < dates3)", engine=engine, parser=parser + "(dates1 < 20130101) & (20130101 < dates3)", + engine=engine, + parser=parser, ) expec = df[(df.dates1 < "20130101") & ("20130101" < df.dates3)] tm.assert_frame_equal(res, expec) @@ -838,7 +881,10 @@ def test_date_index_query(self, engine, parser): df["dates3"] = date_range("1/1/2014", periods=n) return_value = df.set_index("dates1", inplace=True, drop=True) assert return_value is None - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query( "(index < 20130101) & (20130101 < dates3)", engine=engine, parser=parser ) @@ -856,7 +902,10 @@ def test_date_index_query_with_NaT(self, engine, parser): df.iloc[0, 0] = pd.NaT return_value = df.set_index("dates1", inplace=True, drop=True) assert return_value is None - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): res = df.query( "(index < 20130101) & (20130101 < dates3)", engine=engine, parser=parser ) @@ -873,7 +922,10 @@ def test_date_index_query_with_NaT_duplicates(self, engine, parser): assert return_value is None msg = r"'BoolOp' nodes are not implemented" with pytest.raises(NotImplementedError, match=msg): - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): df.query("index < 20130101 < dates3", engine=engine, parser=parser) def test_nested_scope(self, engine, parser): diff --git a/pandas/tests/indexing/test_datetime.py b/pandas/tests/indexing/test_datetime.py index b5256ca239114..0222236ed2d92 100644 --- a/pandas/tests/indexing/test_datetime.py +++ b/pandas/tests/indexing/test_datetime.py @@ -175,7 +175,10 @@ def test_getitem_str_slice_millisecond_resolution(self, frame_or_series): def test_getitem_pyarrow_index(self, frame_or_series): # GH 53644 pytest.importorskip("pyarrow") - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): obj = frame_or_series( range(5), index=date_range("2020", freq="D", periods=5).astype( @@ -183,7 +186,10 @@ def test_getitem_pyarrow_index(self, frame_or_series): ), ) result = obj.loc[obj.index[:-3]] - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): expected = frame_or_series( range(2), index=date_range("2020", freq="D", periods=2).astype( diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 1234f1e9fc046..61513776c3634 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -700,9 +700,17 @@ def test_loc_assign_non_ns_datetime(self, unit): } ) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): - df.loc[:, unit] = df.loc[:, "timestamp"].values.astype(f"datetime64[{unit}]") - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): + df.loc[:, unit] = df.loc[:, "timestamp"].values.astype( + f"datetime64[{unit}]" + ) + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): df["expected"] = df.loc[:, "timestamp"].values.astype(f"datetime64[{unit}]") expected = Series(df.loc[:, "expected"], name=unit) tm.assert_series_equal(df.loc[:, unit], expected) diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 5740105f574bf..570992f5ef3e1 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -623,7 +623,11 @@ def test_dtype_backend(self, read_ext, dtype_backend, engine, tmp_excel): import pyarrow as pa from pandas.arrays import ArrowExtensionArray - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): expected = DataFrame( { col: ArrowExtensionArray(pa.array(df[col], from_pandas=True)) diff --git a/pandas/tests/plotting/frame/test_frame_subplots.py b/pandas/tests/plotting/frame/test_frame_subplots.py index 9c31043d9d611..1f0e9ba6c1447 100644 --- a/pandas/tests/plotting/frame/test_frame_subplots.py +++ b/pandas/tests/plotting/frame/test_frame_subplots.py @@ -148,10 +148,16 @@ def test_subplots_timeseries_y_axis(self, col): "text": ["This", "should", "fail"], } testdata = DataFrame(data) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): ax = testdata.plot(y=col) result = ax.get_lines()[0].get_data()[1] - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): expected = testdata[col].values assert (result == expected).all() diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 8b29050926086..100cb5cf8e923 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -119,7 +119,10 @@ def test_dt_namespace_accessor_datetime64(self, freq): assert result.dtype == object result = ser.dt.tz_localize("US/Eastern") - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): exp_values = DatetimeIndex(ser.values).tz_localize("US/Eastern") expected = Series(exp_values, index=ser.index, name="xxx") tm.assert_series_equal(result, expected) @@ -127,12 +130,18 @@ def test_dt_namespace_accessor_datetime64(self, freq): tz_result = result.dt.tz assert str(tz_result) == "US/Eastern" freq_result = ser.dt.freq - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): assert freq_result == DatetimeIndex(ser.values, freq="infer").freq # let's localize, then convert result = ser.dt.tz_localize("UTC").dt.tz_convert("US/Eastern") - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): exp_values = ( DatetimeIndex(ser.values).tz_localize("UTC").tz_convert("US/Eastern") ) @@ -165,7 +174,10 @@ def test_dt_namespace_accessor_datetime64tz(self): tz_result = result.dt.tz assert str(tz_result) == "CET" freq_result = ser.dt.freq - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): assert freq_result == DatetimeIndex(ser.values, freq="infer").freq def test_dt_namespace_accessor_timedelta(self): @@ -207,7 +219,10 @@ def test_dt_namespace_accessor_timedelta(self): assert result.dtype == "float64" freq_result = ser.dt.freq - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): assert freq_result == TimedeltaIndex(ser.values, freq="infer").freq def test_dt_namespace_accessor_period(self): @@ -227,10 +242,12 @@ def test_dt_namespace_accessor_period(self): getattr(ser.dt, prop) freq_result = ser.dt.freq - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): assert freq_result == PeriodIndex(ser.values).freq - def test_dt_namespace_accessor_index_and_values(self): # both index = date_range("20130101", periods=3, freq="D") diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index d7cd9b698994a..dfdc5b838df69 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -259,7 +259,10 @@ def test_astype_datetime64tz(self): expected = Series(ser.astype(object), dtype=object) tm.assert_series_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = Series(ser.values).dt.tz_localize("UTC").dt.tz_convert(ser.dt.tz) # astype - object, preserves on construction @@ -271,12 +274,18 @@ def test_astype_datetime64tz(self): msg = "Cannot use .astype to convert from timezone-naive" with pytest.raises(TypeError, match=msg): # dt64->dt64tz astype deprecated - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): Series(ser.values).astype("datetime64[ns, US/Eastern]") with pytest.raises(TypeError, match=msg): # dt64->dt64tz astype deprecated - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): Series(ser.values).astype(ser.dtype) result = ser.astype("datetime64[ns, CET]") diff --git a/pandas/tests/series/methods/test_copy.py b/pandas/tests/series/methods/test_copy.py index f056f1405a3b0..6fc25b5f8f063 100644 --- a/pandas/tests/series/methods/test_copy.py +++ b/pandas/tests/series/methods/test_copy.py @@ -49,7 +49,10 @@ def test_copy_tzaware(self, deep): # INFO(CoW) a shallow copy doesn't yet copy the data # but parent will not be modified (CoW) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): if deep is None or deep is False: assert np.may_share_memory(ser.values, ser2.values) else: diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index fa10cccd15515..4f0746890c7f5 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -30,10 +30,12 @@ def test_fillna_nat(self): series = Series([0, 1, 2, NaT._value], dtype="M8[ns]") filled = series.ffill() - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): filled2 = series.fillna(value=series.values[2]) - expected = series.copy() expected.iloc[3] = expected.iloc[2] @@ -42,7 +44,10 @@ def test_fillna_nat(self): df = DataFrame({"A": series}) filled = df.ffill() - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): filled2 = df.fillna(value=series.values[2]) expected = DataFrame({"A": expected}) tm.assert_frame_equal(filled, expected) diff --git a/pandas/tests/series/methods/test_isin.py b/pandas/tests/series/methods/test_isin.py index 2f7ebde63591d..abce1074edcef 100644 --- a/pandas/tests/series/methods/test_isin.py +++ b/pandas/tests/series/methods/test_isin.py @@ -50,7 +50,10 @@ def test_isin_datetimelike_mismatched_reso(self): ser = Series(date_range("jan-01-2013", "jan-05-2013")) # fails on dtype conversion in the first place - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): day_values = np.asarray(ser[0:2].values).astype("datetime64[D]") result = ser.isin(day_values) tm.assert_series_equal(result, expected) @@ -80,7 +83,10 @@ def test_isin_with_i8(self): result = s.isin(s[0:2]) tm.assert_series_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = s.isin(s[0:2].values) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/methods/test_values.py b/pandas/tests/series/methods/test_values.py index 924b487902db1..1e5cfd9f80947 100644 --- a/pandas/tests/series/methods/test_values.py +++ b/pandas/tests/series/methods/test_values.py @@ -19,7 +19,10 @@ class TestValues: ) def test_values_object_extension_dtypes(self, data): # https://github.com/pandas-dev/pandas/issues/23995 - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = Series(data).values expected = np.array(data.astype(object)) tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 52eef9b76efe7..0b93457a65871 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1107,7 +1107,10 @@ def test_constructor_with_datetime_tz(self): assert "datetime64[ns, US/Eastern]" in str(s) # export - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = s.values assert isinstance(result, np.ndarray) assert result.dtype == "datetime64[ns]" @@ -1235,7 +1238,10 @@ def test_construction_interval(self, interval_constructor): intervals = interval_constructor.from_breaks(np.arange(3), closed="right") result = Series(intervals) assert result.dtype == "interval[int64, right]" - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): tm.assert_index_equal(Index(result.values), Index(intervals)) @pytest.mark.parametrize( @@ -1272,19 +1278,31 @@ def test_construction_consistency(self): # Pre-2.0 dt64 values were treated as utc, which was inconsistent # with DatetimeIndex, which treats them as wall times, see GH#33401 - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): result = Series(ser.values, dtype=ser.dtype) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): expected = Series(ser.values).dt.tz_localize(ser.dtype.tz) tm.assert_series_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): # one suggested alternative to the deprecated (changed in 2.0) usage middle = Series(ser.values).dt.tz_localize("UTC") result = middle.dt.tz_convert(ser.dtype.tz) tm.assert_series_equal(result, ser) - with tm.assert_produces_warning(FutureWarning, match="series.values will stop converting tz from dt64tz, interval to object and period to object"): + with tm.assert_produces_warning( + FutureWarning, + match="series.values will stop converting tz from dt64tz, interval to object and period to object", + ): # the other suggested alternative to the deprecated usage result = Series(ser.values.view("int64"), dtype=ser.dtype) tm.assert_series_equal(result, ser)