Skip to content

DEPR: enforce Timedelta freq, delta, is_populated deprecations #48689

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

Merged
merged 10 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,6 @@ Properties
Timedelta.asm8
Timedelta.components
Timedelta.days
Timedelta.delta
Timedelta.freq
Timedelta.is_populated
Timedelta.max
Timedelta.microseconds
Timedelta.min
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ Removal of prior version deprecations/changes
- Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`)
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Removed deprecated :meth:`Timedelta.delta`, :meth:`Timedelta.is_populated`, and :attr:`Timedelta.freq` (:issue:`46430`, :issue:`46476`)
- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`)
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
- Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`)
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
-

.. ---------------------------------------------------------------------------
.. _whatsnew_200.performance:
Expand Down
4 changes: 0 additions & 4 deletions pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,5 @@ class Timedelta(timedelta):
def to_numpy(self) -> np.timedelta64: ...
def view(self, dtype: npt.DTypeLike = ...) -> object: ...
@property
def freq(self) -> None: ...
@property
def is_populated(self) -> bool: ...
@property
def _unit(self) -> str: ...
def _as_unit(self, unit: str, round_ok: bool = ...) -> Timedelta: ...
71 changes: 0 additions & 71 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1053,38 +1053,6 @@ cdef class _Timedelta(timedelta):
# TODO: add nanos/1e9?
return self.days * 24 * 3600 + self.seconds + self.microseconds / 1_000_000

@property
def freq(self) -> None:
"""
Freq property.

.. deprecated:: 1.5.0
This argument is deprecated.
"""
# GH#46430
warnings.warn(
"Timedelta.freq is deprecated and will be removed in a future version",
FutureWarning,
stacklevel=find_stack_level(),
)
return None

@property
def is_populated(self) -> bool:
"""
Is_populated property.

.. deprecated:: 1.5.0
This argument is deprecated.
"""
# GH#46430
warnings.warn(
"Timedelta.is_populated is deprecated and will be removed in a future version",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._is_populated

def __hash__(_Timedelta self):
if self._has_ns():
# Note: this does *not* satisfy the invariance
Expand Down Expand Up @@ -1258,45 +1226,6 @@ cdef class _Timedelta(timedelta):
return Components(self._d, self._h, self._m, self._s,
self._ms, self._us, self._ns)

@property
def delta(self):
"""
Return the timedelta in nanoseconds (ns), for internal compatibility.

.. deprecated:: 1.5.0
This argument is deprecated.

Returns
-------
int
Timedelta in nanoseconds.

Examples
--------
>>> td = pd.Timedelta('1 days 42 ns')
>>> td.delta
86400000000042

>>> td = pd.Timedelta('3 s')
>>> td.delta
3000000000

>>> td = pd.Timedelta('3 ms 5 us')
>>> td.delta
3005000

>>> td = pd.Timedelta(42, unit='ns')
>>> td.delta
42
"""
# Deprecated GH#46476
warnings.warn(
"Timedelta.delta is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.value

@property
def asm8(self) -> np.timedelta64:
"""
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/scalar/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ def test_nat_iso_format(get_nat):
Timedelta,
[
"components",
"delta",
"is_populated",
"resolution_string",
"to_pytimedelta",
"to_timedelta64",
Expand Down
30 changes: 0 additions & 30 deletions pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from pandas import (
Timedelta,
TimedeltaIndex,
offsets,
to_timedelta,
)
import pandas._testing as tm
Expand Down Expand Up @@ -966,32 +965,3 @@ def test_timedelta_attribute_precision():
result += td.nanoseconds
expected = td.value
assert result == expected


def test_freq_deprecated():
# GH#46430
td = Timedelta(123456546, unit="ns")
with tm.assert_produces_warning(FutureWarning, match="Timedelta.freq"):
freq = td.freq

assert freq is None

with pytest.raises(AttributeError, match="is not writable"):
td.freq = offsets.Day()


def test_is_populated_deprecated():
# GH#46430
td = Timedelta(123456546, unit="ns")
with tm.assert_produces_warning(FutureWarning, match="Timedelta.is_populated"):
td.is_populated

with pytest.raises(AttributeError, match="is not writable"):
td.is_populated = 1


def test_delta_deprecated():
# GH#46476
td = Timedelta(123456546, unit="ns")
with tm.assert_produces_warning(FutureWarning, match="Timedelta.delta is"):
td.delta