diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 6dc0d0cfaf80b..d947b6a495a75 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -524,7 +524,6 @@ Deprecations - Deprecated indexing :class:`DataFrame` rows with a single datetime-like string as ``df[string]`` (given the ambiguity whether it is indexing the rows or selecting a column), use ``df.loc[string]`` instead (:issue:`36179`) -- Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`) - Deprecated :meth:`Index.is_all_dates` (:issue:`27744`) - The default value of ``regex`` for :meth:`Series.str.replace` will change from ``True`` to ``False`` in a future release. In addition, single character regular expressions will *not* be treated as literal strings when ``regex=True`` is set. (:issue:`24804`) - Deprecated automatic alignment on comparison operations between :class:`DataFrame` and :class:`Series`, do ``frame, ser = frame.align(ser, axis=1, copy=False)`` before e.g. ``frame == ser`` (:issue:`28759`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0985be5193200..2f0f40fb9ed0a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9467,12 +9467,6 @@ def truncate( # if we have a date index, convert to dates, otherwise # treat like a slice if ax._is_all_dates: - if is_object_dtype(ax.dtype): - warnings.warn( - "Treating object-dtype Index of date objects as DatetimeIndex " - "is deprecated, will be removed in a future version.", - FutureWarning, - ) from pandas.core.tools.datetimes import to_datetime before = to_datetime(before) diff --git a/pandas/core/series.py b/pandas/core/series.py index af8acc0a36e13..d4ae5c2245b5b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -436,13 +436,6 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None: # need to set here because we changed the index if fastpath: self._mgr.set_axis(axis, labels) - warnings.warn( - "Automatically casting object-dtype Index of datetimes to " - "DatetimeIndex is deprecated and will be removed in a " - "future version. Explicitly cast to DatetimeIndex instead.", - FutureWarning, - stacklevel=3, - ) except (tslibs.OutOfBoundsDatetime, ValueError): # labels may exceeds datetime bounds, # or not be a DatetimeIndex diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 05d9d1a9bd74f..b39bf980642b1 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -535,9 +535,7 @@ def test_string_slice(self): df["2011"] with pytest.raises(KeyError, match="'2011'"): - with tm.assert_produces_warning(FutureWarning): - # This does an is_all_dates check - df.loc["2011", 0] + df.loc["2011", 0] df = DataFrame() assert not df.index._is_all_dates diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 274efda55414c..3f4c21389daed 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -2441,17 +2441,13 @@ def test_series(self, setup_path): ts = tm.makeTimeSeries() self._check_roundtrip(ts, tm.assert_series_equal, path=setup_path) - with tm.assert_produces_warning(FutureWarning): - # auto-casting object->DatetimeIndex deprecated - ts2 = Series(ts.index, Index(ts.index, dtype=object)) + ts2 = Series(ts.index, Index(ts.index, dtype=object)) self._check_roundtrip(ts2, tm.assert_series_equal, path=setup_path) - with tm.assert_produces_warning(FutureWarning): - # auto-casting object->DatetimeIndex deprecated - ts3 = Series( - ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object) - ) - self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path) + ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)) + self._check_roundtrip( + ts3, tm.assert_series_equal, path=setup_path, check_index_type=False + ) def test_float_index(self, setup_path): diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 397a064f6adad..66a4f9598c49b 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -277,16 +277,9 @@ def test_irreg_hf(self): _, ax = self.plt.subplots() df2 = df.copy() df2.index = df.index.astype(object) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # This warning will be emitted - # pandas/core/frame.py:3216: - # FutureWarning: Automatically casting object-dtype Index of datetimes - # to DatetimeIndex is deprecated and will be removed in a future version. - # Explicitly cast to DatetimeIndex instead. - # return klass(values, index=self.index, name=name, fastpath=True) - df2.plot(ax=ax) - diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff() - assert (np.fabs(diffs[1:] - sec) < 1e-8).all() + df2.plot(ax=ax) + diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff() + assert (np.fabs(diffs[1:] - sec) < 1e-8).all() def test_irregular_datetime64_repr_bug(self): ser = tm.makeTimeSeries() @@ -997,16 +990,9 @@ def test_irreg_dtypes(self): # np.datetime64 idx = date_range("1/1/2000", periods=10) idx = idx[[0, 2, 5, 9]].astype(object) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # This warning will be emitted - # pandas/core/frame.py:3216: - # FutureWarning: Automatically casting object-dtype Index of datetimes - # to DatetimeIndex is deprecated and will be removed in a future version. - # Explicitly cast to DatetimeIndex instead. - # return klass(values, index=self.index, name=name, fastpath=True) - df = DataFrame(np.random.randn(len(idx), 3), idx) - _, ax = self.plt.subplots() - _check_plot_works(df.plot, ax=ax) + df = DataFrame(np.random.randn(len(idx), 3), idx) + _, ax = self.plt.subplots() + _check_plot_works(df.plot, ax=ax) def test_time(self): t = datetime(1, 1, 1, 3, 30, 0) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index eabd6a1eb0743..ca7a171947ca0 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1623,8 +1623,7 @@ def test_constructor_infer_index_tz(self): class TestSeriesConstructorIndexCoercion: def test_series_constructor_datetimelike_index_coercion(self): idx = tm.makeDateIndex(10000) - with tm.assert_produces_warning(FutureWarning): - ser = Series(np.random.randn(len(idx)), idx.astype(object)) + ser = Series(np.random.randn(len(idx)), idx.astype(object)) with tm.assert_produces_warning(FutureWarning): assert ser.index.is_all_dates assert isinstance(ser.index, DatetimeIndex) diff --git a/pandas/tests/series/test_repr.py b/pandas/tests/series/test_repr.py index 75e7f8a17eda3..836135c3d6310 100644 --- a/pandas/tests/series/test_repr.py +++ b/pandas/tests/series/test_repr.py @@ -184,9 +184,7 @@ def test_timeseries_repr_object_dtype(self): index = Index( [datetime(2000, 1, 1) + timedelta(i) for i in range(1000)], dtype=object ) - with tm.assert_produces_warning(FutureWarning): - # Index.is_all_dates deprecated - ts = Series(np.random.randn(len(index)), index) + ts = Series(np.random.randn(len(index)), index) repr(ts) ts = tm.makeTimeSeries(1000) diff --git a/pandas/tests/window/moments/test_moments_rolling_apply.py b/pandas/tests/window/moments/test_moments_rolling_apply.py index e9e672e1d3dae..e48d88b365d8d 100644 --- a/pandas/tests/window/moments/test_moments_rolling_apply.py +++ b/pandas/tests/window/moments/test_moments_rolling_apply.py @@ -122,16 +122,13 @@ def test_center_reindex_series(raw, series): s = [f"x{x:d}" for x in range(12)] minp = 10 - warn = None if raw else FutureWarning - with tm.assert_produces_warning(warn, check_stacklevel=False): - # GH#36697 is_all_dates deprecated - series_xp = ( - series.reindex(list(series.index) + s) - .rolling(window=25, min_periods=minp) - .apply(f, raw=raw) - .shift(-12) - .reindex(series.index) - ) + series_xp = ( + series.reindex(list(series.index) + s) + .rolling(window=25, min_periods=minp) + .apply(f, raw=raw) + .shift(-12) + .reindex(series.index) + ) series_rs = series.rolling(window=25, min_periods=minp, center=True).apply( f, raw=raw ) @@ -143,15 +140,12 @@ def test_center_reindex_frame(raw, frame): s = [f"x{x:d}" for x in range(12)] minp = 10 - warn = None if raw else FutureWarning - with tm.assert_produces_warning(warn, check_stacklevel=False): - # GH#36697 is_all_dates deprecated - frame_xp = ( - frame.reindex(list(frame.index) + s) - .rolling(window=25, min_periods=minp) - .apply(f, raw=raw) - .shift(-12) - .reindex(frame.index) - ) + frame_xp = ( + frame.reindex(list(frame.index) + s) + .rolling(window=25, min_periods=minp) + .apply(f, raw=raw) + .shift(-12) + .reindex(frame.index) + ) frame_rs = frame.rolling(window=25, min_periods=minp, center=True).apply(f, raw=raw) tm.assert_frame_equal(frame_xp, frame_rs)