Skip to content

Commit ac3f04f

Browse files
simonjayhawkinsluckyvs1
authored andcommitted
Revert "Deprecated casting an object-dtype index of datetime objects to DatetimeIndex in the Series constructor (23598)" (pandas-dev#38679)
* Revert "DEPR: is_all_dates (pandas-dev#36697)" This reverts commit 90a6135. * revert Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`) only * Revert "BUG: record warnings related to DatetimeIndex (pandas-dev#37193)" This reverts commit 23c41bd. * remove assert_produces_warning added in TST/REF: collect tests by method, some misplaced pandas-dev#37354
1 parent a67279d commit ac3f04f

File tree

9 files changed

+28
-71
lines changed

9 files changed

+28
-71
lines changed

doc/source/whatsnew/v1.2.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ Deprecations
524524
- Deprecated indexing :class:`DataFrame` rows with a single datetime-like string as ``df[string]``
525525
(given the ambiguity whether it is indexing the rows or selecting a column), use
526526
``df.loc[string]`` instead (:issue:`36179`)
527-
- Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`)
528527
- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`)
529528
- 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`)
530529
- 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`)

pandas/core/generic.py

-6
Original file line numberDiff line numberDiff line change
@@ -9467,12 +9467,6 @@ def truncate(
94679467
# if we have a date index, convert to dates, otherwise
94689468
# treat like a slice
94699469
if ax._is_all_dates:
9470-
if is_object_dtype(ax.dtype):
9471-
warnings.warn(
9472-
"Treating object-dtype Index of date objects as DatetimeIndex "
9473-
"is deprecated, will be removed in a future version.",
9474-
FutureWarning,
9475-
)
94769470
from pandas.core.tools.datetimes import to_datetime
94779471

94789472
before = to_datetime(before)

pandas/core/series.py

-7
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,6 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None:
436436
# need to set here because we changed the index
437437
if fastpath:
438438
self._mgr.set_axis(axis, labels)
439-
warnings.warn(
440-
"Automatically casting object-dtype Index of datetimes to "
441-
"DatetimeIndex is deprecated and will be removed in a "
442-
"future version. Explicitly cast to DatetimeIndex instead.",
443-
FutureWarning,
444-
stacklevel=3,
445-
)
446439
except (tslibs.OutOfBoundsDatetime, ValueError):
447440
# labels may exceeds datetime bounds,
448441
# or not be a DatetimeIndex

pandas/tests/indexing/test_indexing.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,7 @@ def test_string_slice(self):
535535
df["2011"]
536536

537537
with pytest.raises(KeyError, match="'2011'"):
538-
with tm.assert_produces_warning(FutureWarning):
539-
# This does an is_all_dates check
540-
df.loc["2011", 0]
538+
df.loc["2011", 0]
541539

542540
df = DataFrame()
543541
assert not df.index._is_all_dates

pandas/tests/io/pytables/test_store.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -2441,17 +2441,13 @@ def test_series(self, setup_path):
24412441
ts = tm.makeTimeSeries()
24422442
self._check_roundtrip(ts, tm.assert_series_equal, path=setup_path)
24432443

2444-
with tm.assert_produces_warning(FutureWarning):
2445-
# auto-casting object->DatetimeIndex deprecated
2446-
ts2 = Series(ts.index, Index(ts.index, dtype=object))
2444+
ts2 = Series(ts.index, Index(ts.index, dtype=object))
24472445
self._check_roundtrip(ts2, tm.assert_series_equal, path=setup_path)
24482446

2449-
with tm.assert_produces_warning(FutureWarning):
2450-
# auto-casting object->DatetimeIndex deprecated
2451-
ts3 = Series(
2452-
ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)
2453-
)
2454-
self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path)
2447+
ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object))
2448+
self._check_roundtrip(
2449+
ts3, tm.assert_series_equal, path=setup_path, check_index_type=False
2450+
)
24552451

24562452
def test_float_index(self, setup_path):
24572453

pandas/tests/plotting/test_datetimelike.py

+6-20
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,9 @@ def test_irreg_hf(self):
277277
_, ax = self.plt.subplots()
278278
df2 = df.copy()
279279
df2.index = df.index.astype(object)
280-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
281-
# This warning will be emitted
282-
# pandas/core/frame.py:3216:
283-
# FutureWarning: Automatically casting object-dtype Index of datetimes
284-
# to DatetimeIndex is deprecated and will be removed in a future version.
285-
# Explicitly cast to DatetimeIndex instead.
286-
# return klass(values, index=self.index, name=name, fastpath=True)
287-
df2.plot(ax=ax)
288-
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
289-
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()
280+
df2.plot(ax=ax)
281+
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
282+
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()
290283

291284
def test_irregular_datetime64_repr_bug(self):
292285
ser = tm.makeTimeSeries()
@@ -997,16 +990,9 @@ def test_irreg_dtypes(self):
997990
# np.datetime64
998991
idx = date_range("1/1/2000", periods=10)
999992
idx = idx[[0, 2, 5, 9]].astype(object)
1000-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
1001-
# This warning will be emitted
1002-
# pandas/core/frame.py:3216:
1003-
# FutureWarning: Automatically casting object-dtype Index of datetimes
1004-
# to DatetimeIndex is deprecated and will be removed in a future version.
1005-
# Explicitly cast to DatetimeIndex instead.
1006-
# return klass(values, index=self.index, name=name, fastpath=True)
1007-
df = DataFrame(np.random.randn(len(idx), 3), idx)
1008-
_, ax = self.plt.subplots()
1009-
_check_plot_works(df.plot, ax=ax)
993+
df = DataFrame(np.random.randn(len(idx), 3), idx)
994+
_, ax = self.plt.subplots()
995+
_check_plot_works(df.plot, ax=ax)
1010996

1011997
def test_time(self):
1012998
t = datetime(1, 1, 1, 3, 30, 0)

pandas/tests/series/test_constructors.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1623,8 +1623,7 @@ def test_constructor_infer_index_tz(self):
16231623
class TestSeriesConstructorIndexCoercion:
16241624
def test_series_constructor_datetimelike_index_coercion(self):
16251625
idx = tm.makeDateIndex(10000)
1626-
with tm.assert_produces_warning(FutureWarning):
1627-
ser = Series(np.random.randn(len(idx)), idx.astype(object))
1626+
ser = Series(np.random.randn(len(idx)), idx.astype(object))
16281627
with tm.assert_produces_warning(FutureWarning):
16291628
assert ser.index.is_all_dates
16301629
assert isinstance(ser.index, DatetimeIndex)

pandas/tests/series/test_repr.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ def test_timeseries_repr_object_dtype(self):
184184
index = Index(
185185
[datetime(2000, 1, 1) + timedelta(i) for i in range(1000)], dtype=object
186186
)
187-
with tm.assert_produces_warning(FutureWarning):
188-
# Index.is_all_dates deprecated
189-
ts = Series(np.random.randn(len(index)), index)
187+
ts = Series(np.random.randn(len(index)), index)
190188
repr(ts)
191189

192190
ts = tm.makeTimeSeries(1000)

pandas/tests/window/moments/test_moments_rolling_apply.py

+14-20
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,13 @@ def test_center_reindex_series(raw, series):
122122
s = [f"x{x:d}" for x in range(12)]
123123
minp = 10
124124

125-
warn = None if raw else FutureWarning
126-
with tm.assert_produces_warning(warn, check_stacklevel=False):
127-
# GH#36697 is_all_dates deprecated
128-
series_xp = (
129-
series.reindex(list(series.index) + s)
130-
.rolling(window=25, min_periods=minp)
131-
.apply(f, raw=raw)
132-
.shift(-12)
133-
.reindex(series.index)
134-
)
125+
series_xp = (
126+
series.reindex(list(series.index) + s)
127+
.rolling(window=25, min_periods=minp)
128+
.apply(f, raw=raw)
129+
.shift(-12)
130+
.reindex(series.index)
131+
)
135132
series_rs = series.rolling(window=25, min_periods=minp, center=True).apply(
136133
f, raw=raw
137134
)
@@ -143,15 +140,12 @@ def test_center_reindex_frame(raw, frame):
143140
s = [f"x{x:d}" for x in range(12)]
144141
minp = 10
145142

146-
warn = None if raw else FutureWarning
147-
with tm.assert_produces_warning(warn, check_stacklevel=False):
148-
# GH#36697 is_all_dates deprecated
149-
frame_xp = (
150-
frame.reindex(list(frame.index) + s)
151-
.rolling(window=25, min_periods=minp)
152-
.apply(f, raw=raw)
153-
.shift(-12)
154-
.reindex(frame.index)
155-
)
143+
frame_xp = (
144+
frame.reindex(list(frame.index) + s)
145+
.rolling(window=25, min_periods=minp)
146+
.apply(f, raw=raw)
147+
.shift(-12)
148+
.reindex(frame.index)
149+
)
156150
frame_rs = frame.rolling(window=25, min_periods=minp, center=True).apply(f, raw=raw)
157151
tm.assert_frame_equal(frame_xp, frame_rs)

0 commit comments

Comments
 (0)