Skip to content

DEPR: Timedelta.freq, Timedelta.is_populated #46430

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 4 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
annotate, make None explicit
  • Loading branch information
jbrockmendel committed Mar 19, 2022
commit c8e9ba8e9a4928bb78a41bf1a4b6fb59f4990172
4 changes: 4 additions & 0 deletions pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ class Timedelta(timedelta):
def __hash__(self) -> int: ...
def isoformat(self) -> str: ...
def to_numpy(self) -> np.timedelta64: ...
@property
def freq(self) -> None: ...
@property
def is_populated(self) -> bool: ...
5 changes: 3 additions & 2 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -833,16 +833,17 @@ cdef class _Timedelta(timedelta):
__array_priority__ = 100

@property
def freq(self):
def freq(self) -> None:
# GH#46430
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do if its called? return None?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make that explcit (and add the annotation)

"Timedelta.freq is deprecated and will be removed in a future version",
FutureWarning,
stacklevel=1,
)
return None

@property
def is_populated(self):
def is_populated(self) -> bool:
# GH#46430
warnings.warn(
"Timedelta.is_populated is deprecated and will be removed in a future version",
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ def test_freq_deprecated():
# GH#46430
td = Timedelta(123456546, unit="ns")
with tm.assert_produces_warning(FutureWarning, match="Timedelta.freq"):
td.freq
freq = td.freq

assert freq is None

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