From 57969824dddb467726f4ee05457eb4cb7569658e Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 17 Jun 2020 08:18:48 -0700 Subject: [PATCH 1/3] DEPR: to_perioddelta --- doc/source/whatsnew/v1.1.0.rst | 1 + pandas/core/arrays/datetimes.py | 8 +++++++- pandas/tests/arrays/test_datetimelike.py | 8 ++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 10522ff797c59..42d511db206ad 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -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:`??`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index b6c27abc321e1..88dac534cd523 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1125,7 +1125,13 @@ def to_perioddelta(self, freq): ------- TimedeltaArray/Index """ - # TODO: consider privatizing (discussion in GH#23113) + 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 diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 1a61b379de943..18fc5019ebc51 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -511,8 +511,12 @@ 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): + 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 From 9a4e0b0aa8f74026be558ba3c7d35e6f337f9f7f Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 17 Jun 2020 08:20:11 -0700 Subject: [PATCH 2/3] GH refs --- doc/source/whatsnew/v1.1.0.rst | 2 +- pandas/core/arrays/datetimes.py | 1 + pandas/tests/arrays/test_datetimelike.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 42d511db206ad..5e938f66ad330 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -776,7 +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:`??`) +- :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`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 88dac534cd523..461f71ff821fa 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1125,6 +1125,7 @@ def to_perioddelta(self, freq): ------- TimedeltaArray/Index """ + # Deprecaation GH#34853 warnings.warn( "to_perioddelta is deprecated and will be removed in a " "future version. " diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 18fc5019ebc51..b1ab700427c28 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -512,6 +512,7 @@ def test_to_perioddelta(self, datetime_index, freqstr): arr = DatetimeArray(dti) 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 From fbc39b76300c81082c22a91a974e90002d2c6c60 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 18 Jun 2020 08:27:33 -0700 Subject: [PATCH 3/3] Update doc/source/whatsnew/v1.1.0.rst Co-authored-by: Joris Van den Bossche --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 5e938f66ad330..2c792d5f10b00 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -776,7 +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`) +- :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`) .. ---------------------------------------------------------------------------