Skip to content

Commit

Permalink
DEPR: to_perioddelta (#34853)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jun 18, 2020
1 parent a07748f commit 3c959fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ Deprecations
instead (:issue:`34191`).
- The ``squeeze`` keyword in the ``groupby`` function is deprecated and will be removed in a future version (:issue:`32380`)
- 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`)
- :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`)

.. ---------------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,14 @@ def to_perioddelta(self, freq):
-------
TimedeltaArray/Index
"""
# TODO: consider privatizing (discussion in GH#23113)
# Deprecaation GH#34853
warnings.warn(
"to_perioddelta is deprecated and will be removed in a "
"future version. "
"Use `dtindex - dtindex.to_period(freq).to_timestamp()` instead",
FutureWarning,
stacklevel=3,
)
from pandas.core.arrays.timedeltas import TimedeltaArray

i8delta = self.asi8 - self.to_period(freq).to_timestamp().asi8
Expand Down
9 changes: 7 additions & 2 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,13 @@ def test_to_perioddelta(self, datetime_index, freqstr):
dti = datetime_index
arr = DatetimeArray(dti)

expected = dti.to_perioddelta(freq=freqstr)
result = arr.to_perioddelta(freq=freqstr)
with tm.assert_produces_warning(FutureWarning):
# Deprecation GH#34853
expected = dti.to_perioddelta(freq=freqstr)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
# stacklevel is chosen to be "correct" for DatetimeIndex, not
# DatetimeArray
result = arr.to_perioddelta(freq=freqstr)
assert isinstance(result, TimedeltaArray)

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

0 comments on commit 3c959fc

Please sign in to comment.