From 48b8e82c557c53b78b2d734334659f5aea8240f9 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 22 Mar 2022 11:23:18 -0700 Subject: [PATCH 1/2] DEPR: Timedelta.delta --- doc/source/whatsnew/v1.5.0.rst | 1 + pandas/_libs/tslibs/timedeltas.pyx | 5 +++++ pandas/tests/scalar/timedelta/test_timedelta.py | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 14e9fda1b910c..6bcb0a442eb8d 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -350,6 +350,7 @@ Other Deprecations - Deprecated treating all-bool ``object``-dtype columns as bool-like in :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``, explicitly cast to bool instead (:issue:`46188`) - Deprecated behavior of method :meth:`DataFrame.quantile`, attribute ``numeric_only`` will default False. Including datetime/timedelta columns in the result (:issue:`7308`). - Deprecated :attr:`Timedelta.freq` and :attr:`Timedelta.is_populated` (:issue:`46430`) +- Deprecated :attr:`Timedelta.delta` (:issue:`??`) - .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index fa0db6a46deef..205b28f56721e 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1014,6 +1014,11 @@ cdef class _Timedelta(timedelta): >>> td.delta 42 """ + warnings.warn( + "Timedelta.delta is deprecated and will be removed in a future version.", + FutureWarning, + stacklevel=1, + ) return self.value @property diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index 36520a1983aac..d6ecaf76a23a3 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -681,3 +681,9 @@ def test_is_populated_deprecated(): with pytest.raises(AttributeError, match="is not writable"): td.is_populated = 1 + + +def test_delta_deprecated(): + td = Timedelta(123456546, unit="ns") + with tm.assert_produces_warning(FutureWarning, match="Timedelta.delta is"): + td.delta From a007cbcf4ac48314bc74dfa6f1907ec25c7b688c Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 22 Mar 2022 11:25:02 -0700 Subject: [PATCH 2/2] GH ref --- doc/source/whatsnew/v1.5.0.rst | 2 +- pandas/_libs/tslibs/timedeltas.pyx | 1 + pandas/tests/scalar/timedelta/test_timedelta.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 6bcb0a442eb8d..c200b442d6c91 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -350,7 +350,7 @@ Other Deprecations - Deprecated treating all-bool ``object``-dtype columns as bool-like in :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``, explicitly cast to bool instead (:issue:`46188`) - Deprecated behavior of method :meth:`DataFrame.quantile`, attribute ``numeric_only`` will default False. Including datetime/timedelta columns in the result (:issue:`7308`). - Deprecated :attr:`Timedelta.freq` and :attr:`Timedelta.is_populated` (:issue:`46430`) -- Deprecated :attr:`Timedelta.delta` (:issue:`??`) +- Deprecated :attr:`Timedelta.delta` (:issue:`46476`) - .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 205b28f56721e..627006a7f32c0 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1014,6 +1014,7 @@ cdef class _Timedelta(timedelta): >>> td.delta 42 """ + # Deprecated GH#46476 warnings.warn( "Timedelta.delta is deprecated and will be removed in a future version.", FutureWarning, diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index d6ecaf76a23a3..1ec93c69def99 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -684,6 +684,7 @@ def test_is_populated_deprecated(): def test_delta_deprecated(): + # GH#46476 td = Timedelta(123456546, unit="ns") with tm.assert_produces_warning(FutureWarning, match="Timedelta.delta is"): td.delta