Skip to content

Commit 3c959fc

Browse files
authored
DEPR: to_perioddelta (#34853)
1 parent a07748f commit 3c959fc

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ Deprecations
777777
instead (:issue:`34191`).
778778
- The ``squeeze`` keyword in the ``groupby`` function is deprecated and will be removed in a future version (:issue:`32380`)
779779
- The ``tz`` keyword in :meth:`Period.to_timestamp` is deprecated and will be removed in a future version; use `per.to_timestamp(...).tz_localize(tz)`` instead (:issue:`34522`)
780+
- :meth:`DatetimeIndex.to_perioddelta` is deprecated and will be removed in a future version. Use ``index - index.to_period(freq).to_timestamp()`` instead (:issue:`34853`)
780781

781782
.. ---------------------------------------------------------------------------
782783

pandas/core/arrays/datetimes.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,14 @@ def to_perioddelta(self, freq):
11251125
-------
11261126
TimedeltaArray/Index
11271127
"""
1128-
# TODO: consider privatizing (discussion in GH#23113)
1128+
# Deprecaation GH#34853
1129+
warnings.warn(
1130+
"to_perioddelta is deprecated and will be removed in a "
1131+
"future version. "
1132+
"Use `dtindex - dtindex.to_period(freq).to_timestamp()` instead",
1133+
FutureWarning,
1134+
stacklevel=3,
1135+
)
11291136
from pandas.core.arrays.timedeltas import TimedeltaArray
11301137

11311138
i8delta = self.asi8 - self.to_period(freq).to_timestamp().asi8

pandas/tests/arrays/test_datetimelike.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,13 @@ def test_to_perioddelta(self, datetime_index, freqstr):
511511
dti = datetime_index
512512
arr = DatetimeArray(dti)
513513

514-
expected = dti.to_perioddelta(freq=freqstr)
515-
result = arr.to_perioddelta(freq=freqstr)
514+
with tm.assert_produces_warning(FutureWarning):
515+
# Deprecation GH#34853
516+
expected = dti.to_perioddelta(freq=freqstr)
517+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
518+
# stacklevel is chosen to be "correct" for DatetimeIndex, not
519+
# DatetimeArray
520+
result = arr.to_perioddelta(freq=freqstr)
516521
assert isinstance(result, TimedeltaArray)
517522

518523
# placeholder until these become actual EA subclasses and we can use

0 commit comments

Comments
 (0)