Skip to content

Commit 61c6718

Browse files
authored
DEPR: enforce Timedelta freq, delta, is_populated deprecations (#48689)
* DEPR: enforce Timedelta freq, delta, is_populated deprecations * update docs, pyi * fix nat test * move whatsnew
1 parent 7a8d165 commit 61c6718

File tree

6 files changed

+2
-110
lines changed

6 files changed

+2
-110
lines changed

doc/source/reference/arrays.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,6 @@ Properties
238238
Timedelta.asm8
239239
Timedelta.components
240240
Timedelta.days
241-
Timedelta.delta
242-
Timedelta.freq
243-
Timedelta.is_populated
244241
Timedelta.max
245242
Timedelta.microseconds
246243
Timedelta.min

doc/source/whatsnew/v2.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ Removal of prior version deprecations/changes
156156
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
157157
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
158158
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
159+
- Removed deprecated :meth:`Timedelta.delta`, :meth:`Timedelta.is_populated`, and :attr:`Timedelta.freq` (:issue:`46430`, :issue:`46476`)
159160
- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`)
160161
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
161162
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
162163
- Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`)
163164
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
164165
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
166+
-
165167

166168
.. ---------------------------------------------------------------------------
167169
.. _whatsnew_200.performance:

pandas/_libs/tslibs/timedeltas.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,5 @@ class Timedelta(timedelta):
152152
def to_numpy(self) -> np.timedelta64: ...
153153
def view(self, dtype: npt.DTypeLike = ...) -> object: ...
154154
@property
155-
def freq(self) -> None: ...
156-
@property
157-
def is_populated(self) -> bool: ...
158-
@property
159155
def _unit(self) -> str: ...
160156
def _as_unit(self, unit: str, round_ok: bool = ...) -> Timedelta: ...

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,38 +1053,6 @@ cdef class _Timedelta(timedelta):
10531053
# TODO: add nanos/1e9?
10541054
return self.days * 24 * 3600 + self.seconds + self.microseconds / 1_000_000
10551055

1056-
@property
1057-
def freq(self) -> None:
1058-
"""
1059-
Freq property.
1060-
1061-
.. deprecated:: 1.5.0
1062-
This argument is deprecated.
1063-
"""
1064-
# GH#46430
1065-
warnings.warn(
1066-
"Timedelta.freq is deprecated and will be removed in a future version",
1067-
FutureWarning,
1068-
stacklevel=find_stack_level(),
1069-
)
1070-
return None
1071-
1072-
@property
1073-
def is_populated(self) -> bool:
1074-
"""
1075-
Is_populated property.
1076-
1077-
.. deprecated:: 1.5.0
1078-
This argument is deprecated.
1079-
"""
1080-
# GH#46430
1081-
warnings.warn(
1082-
"Timedelta.is_populated is deprecated and will be removed in a future version",
1083-
FutureWarning,
1084-
stacklevel=find_stack_level(),
1085-
)
1086-
return self._is_populated
1087-
10881056
def __hash__(_Timedelta self):
10891057
if self._has_ns():
10901058
# Note: this does *not* satisfy the invariance
@@ -1258,45 +1226,6 @@ cdef class _Timedelta(timedelta):
12581226
return Components(self._d, self._h, self._m, self._s,
12591227
self._ms, self._us, self._ns)
12601228

1261-
@property
1262-
def delta(self):
1263-
"""
1264-
Return the timedelta in nanoseconds (ns), for internal compatibility.
1265-
1266-
.. deprecated:: 1.5.0
1267-
This argument is deprecated.
1268-
1269-
Returns
1270-
-------
1271-
int
1272-
Timedelta in nanoseconds.
1273-
1274-
Examples
1275-
--------
1276-
>>> td = pd.Timedelta('1 days 42 ns')
1277-
>>> td.delta
1278-
86400000000042
1279-
1280-
>>> td = pd.Timedelta('3 s')
1281-
>>> td.delta
1282-
3000000000
1283-
1284-
>>> td = pd.Timedelta('3 ms 5 us')
1285-
>>> td.delta
1286-
3005000
1287-
1288-
>>> td = pd.Timedelta(42, unit='ns')
1289-
>>> td.delta
1290-
42
1291-
"""
1292-
# Deprecated GH#46476
1293-
warnings.warn(
1294-
"Timedelta.delta is deprecated and will be removed in a future version.",
1295-
FutureWarning,
1296-
stacklevel=find_stack_level(),
1297-
)
1298-
return self.value
1299-
13001229
@property
13011230
def asm8(self) -> np.timedelta64:
13021231
"""

pandas/tests/scalar/test_nat.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def test_nat_iso_format(get_nat):
195195
Timedelta,
196196
[
197197
"components",
198-
"delta",
199-
"is_populated",
200198
"resolution_string",
201199
"to_pytimedelta",
202200
"to_timedelta64",

pandas/tests/scalar/timedelta/test_timedelta.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from pandas import (
2121
Timedelta,
2222
TimedeltaIndex,
23-
offsets,
2423
to_timedelta,
2524
)
2625
import pandas._testing as tm
@@ -966,32 +965,3 @@ def test_timedelta_attribute_precision():
966965
result += td.nanoseconds
967966
expected = td.value
968967
assert result == expected
969-
970-
971-
def test_freq_deprecated():
972-
# GH#46430
973-
td = Timedelta(123456546, unit="ns")
974-
with tm.assert_produces_warning(FutureWarning, match="Timedelta.freq"):
975-
freq = td.freq
976-
977-
assert freq is None
978-
979-
with pytest.raises(AttributeError, match="is not writable"):
980-
td.freq = offsets.Day()
981-
982-
983-
def test_is_populated_deprecated():
984-
# GH#46430
985-
td = Timedelta(123456546, unit="ns")
986-
with tm.assert_produces_warning(FutureWarning, match="Timedelta.is_populated"):
987-
td.is_populated
988-
989-
with pytest.raises(AttributeError, match="is not writable"):
990-
td.is_populated = 1
991-
992-
993-
def test_delta_deprecated():
994-
# GH#46476
995-
td = Timedelta(123456546, unit="ns")
996-
with tm.assert_produces_warning(FutureWarning, match="Timedelta.delta is"):
997-
td.delta

0 commit comments

Comments
 (0)