Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: to_perioddelta #34853

Merged
merged 3 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -776,6 +776,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`)
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved

.. ---------------------------------------------------------------------------

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