Skip to content
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

DEPR: Timedelta.delta #46476

Merged
merged 2 commits into from
Mar 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:`46476`)
-

.. ---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,12 @@ cdef class _Timedelta(timedelta):
>>> td.delta
42
"""
# Deprecated GH#46476
warnings.warn(
"Timedelta.delta is deprecated and will be removed in a future version.",
Copy link
Member

Choose a reason for hiding this comment

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

Probably good to mention the alternative in the message?

Copy link
Member Author

Choose a reason for hiding this comment

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

i'm not sure there is a good alternative. since the meaning of .value may change as we get non-nano working

Copy link
Contributor

Choose a reason for hiding this comment

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

In [96]: td / pd.Timedelta('1ns')
Out[96]: 123456546.0

In [97]: td / pd.Timedelta('1s')
Out[97]: 0.123456546

you can say the alt is to convert a float like this which puts it in the specified units.

Copy link
Member Author

Choose a reason for hiding this comment

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

well neither of those is the same behavior they're getting now.

Telling the user how to "keep the same behavior" really depends on what they are trying to do:

  1. using .value directly is good if they just want to get at the guts of the object
  2. or .view("i8") if for some reason they want the same thing but slower
  3. if they really care about getting a number of nanoseconds then they need obj.to_timedelta64("ns").view("i8") (which risks overflowing in a non-nano world)

I think we deprecate like this and wait to see if anyone complains.

FutureWarning,
stacklevel=1,
)
return self.value

@property
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,10 @@ def test_is_populated_deprecated():

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