Skip to content

Commit 30c1cac

Browse files
Revert "DEPR: is_all_dates (pandas-dev#36697)"
This reverts commit 90a6135.
1 parent 0805043 commit 30c1cac

File tree

18 files changed

+39
-82
lines changed

18 files changed

+39
-82
lines changed

doc/source/whatsnew/v1.2.0.rst

-2
Original file line numberDiff line numberDiff line change
@@ -524,8 +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`)
528-
- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`)
529527
- 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`)
530528
- 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`)
531529
- :meth:`Rolling.count` with ``min_periods=None`` will default to the size of the window in a future version (:issue:`31302`)

pandas/core/generic.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -9466,13 +9466,7 @@ def truncate(
94669466

94679467
# if we have a date index, convert to dates, otherwise
94689468
# treat like a slice
9469-
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-
)
9469+
if ax.is_all_dates:
94769470
from pandas.core.tools.datetimes import to_datetime
94779471

94789472
before = to_datetime(before)

pandas/core/indexes/base.py

+1-14
Original file line numberDiff line numberDiff line change
@@ -2139,25 +2139,12 @@ def inferred_type(self) -> str_t:
21392139
return lib.infer_dtype(self._values, skipna=False)
21402140

21412141
@cache_readonly
2142-
def _is_all_dates(self) -> bool:
2142+
def is_all_dates(self) -> bool:
21432143
"""
21442144
Whether or not the index values only consist of dates.
21452145
"""
21462146
return is_datetime_array(ensure_object(self._values))
21472147

2148-
@cache_readonly
2149-
def is_all_dates(self):
2150-
"""
2151-
Whether or not the index values only consist of dates.
2152-
"""
2153-
warnings.warn(
2154-
"Index.is_all_dates is deprecated, will be removed in a future version. "
2155-
"check index.inferred_type instead",
2156-
FutureWarning,
2157-
stacklevel=2,
2158-
)
2159-
return self._is_all_dates
2160-
21612148
# --------------------------------------------------------------------
21622149
# Pickle Methods
21632150

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _simple_new(
124124
return result
125125

126126
@property
127-
def _is_all_dates(self) -> bool:
127+
def is_all_dates(self) -> bool:
128128
return True
129129

130130
# ------------------------------------------------------------------------

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def func(self, other, sort=sort):
10211021
# --------------------------------------------------------------------
10221022

10231023
@property
1024-
def _is_all_dates(self) -> bool:
1024+
def is_all_dates(self) -> bool:
10251025
"""
10261026
This is False even when left/right contain datetime-like objects,
10271027
as the check is done on the Interval itself

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ def to_flat_index(self):
18051805
return Index(self._values, tupleize_cols=False)
18061806

18071807
@property
1808-
def _is_all_dates(self) -> bool:
1808+
def is_all_dates(self) -> bool:
18091809
return False
18101810

18111811
def is_lexsorted(self) -> bool:

pandas/core/indexes/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _assert_safe_casting(cls, data, subarr):
176176
pass
177177

178178
@property
179-
def _is_all_dates(self) -> bool:
179+
def is_all_dates(self) -> bool:
180180
"""
181181
Checks that all the labels are datetime objects.
182182
"""

pandas/core/missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _interpolate_scipy_wrapper(
313313
"piecewise_polynomial": _from_derivatives,
314314
}
315315

316-
if getattr(x, "_is_all_dates", False):
316+
if getattr(x, "is_all_dates", False):
317317
# GH 5975, scipy.interp1d can't handle datetime64s
318318
x, new_x = x._values.astype("i8"), new_x.astype("i8")
319319

pandas/core/series.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None:
423423
if not fastpath:
424424
labels = ensure_index(labels)
425425

426-
if labels._is_all_dates:
426+
if labels.is_all_dates:
427427
deep_labels = labels
428428
if isinstance(labels, CategoricalIndex):
429429
deep_labels = labels.categories
@@ -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/plotting/_matplotlib/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ def get_label(i):
12691269
# would be too close together.
12701270
condition = (
12711271
not self._use_dynamic_x()
1272-
and (data.index._is_all_dates and self.use_index)
1272+
and (data.index.is_all_dates and self.use_index)
12731273
and (not self.subplots or (self.subplots and self.sharex))
12741274
)
12751275

pandas/tests/indexes/interval/test_interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ def test_is_all_dates(self):
876876
Timestamp("2017-01-01 00:00:00"), Timestamp("2018-01-01 00:00:00")
877877
)
878878
year_2017_index = IntervalIndex([year_2017])
879-
assert not year_2017_index._is_all_dates
879+
assert not year_2017_index.is_all_dates
880880

881881
@pytest.mark.parametrize("key", [[5], (2, 3)])
882882
def test_get_value_non_scalar_errors(self, key):

pandas/tests/indexes/multi/test_equivalence.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_is_():
260260

261261

262262
def test_is_all_dates(idx):
263-
assert not idx._is_all_dates
263+
assert not idx.is_all_dates
264264

265265

266266
def test_is_numeric(idx):

pandas/tests/indexes/test_base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,7 @@ def test_is_object(self, index, expected):
10331033
indirect=["index"],
10341034
)
10351035
def test_is_all_dates(self, index, expected):
1036-
with tm.assert_produces_warning(FutureWarning):
1037-
assert index.is_all_dates is expected
1036+
assert index.is_all_dates is expected
10381037

10391038
def test_summary(self, index):
10401039
self._check_method_works(Index._summary, index)

pandas/tests/indexing/test_indexing.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,15 @@ def test_string_slice(self):
530530
# string indexing against datetimelike with object
531531
# dtype should properly raises KeyError
532532
df = DataFrame([1], Index([pd.Timestamp("2011-01-01")], dtype=object))
533-
assert df.index._is_all_dates
533+
assert df.index.is_all_dates
534534
with pytest.raises(KeyError, match="'2011'"):
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()
543-
assert not df.index._is_all_dates
541+
assert not df.index.is_all_dates
544542
with pytest.raises(KeyError, match="'2011'"):
545543
df["2011"]
546544

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/series/test_constructors.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ def test_scalar_extension_dtype(self, ea_scalar_and_dtype):
104104
def test_constructor(self, datetime_series):
105105
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
106106
empty_series = Series()
107-
assert datetime_series.index._is_all_dates
107+
assert datetime_series.index.is_all_dates
108108

109109
# Pass in Series
110110
derived = Series(datetime_series)
111-
assert derived.index._is_all_dates
111+
assert derived.index.is_all_dates
112112

113113
assert tm.equalContents(derived.index, datetime_series.index)
114114
# Ensure new index is not created
@@ -119,9 +119,9 @@ def test_constructor(self, datetime_series):
119119
assert mixed.dtype == np.object_
120120
assert mixed[1] is np.NaN
121121

122-
assert not empty_series.index._is_all_dates
122+
assert not empty_series.index.is_all_dates
123123
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False):
124-
assert not Series().index._is_all_dates
124+
assert not Series().index.is_all_dates
125125

126126
# exception raised is of type ValueError GH35744
127127
with pytest.raises(ValueError, match="Data must be 1-dimensional"):

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)