-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: restore full datetime.timedelta compat with Timedelta w.r.t. seconds/microseconds accessors (GH9185, GH9139) #9257
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
Conversation
I think this should bring us back to the previous behavior. |
def seconds(self): | ||
""" The number of integer seconds for each element """ | ||
""" The number of integer total seconds for each element """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'total' is also not fully correct in the sense it is only a part of the timedelta expressed in seconds.
The docstring of datetime.timedelta.seconds
says it as " Number of seconds (>= 0 and less than 1 day)."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And maybe add a reference to components
to have only the seconds part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I think we also need to update the timedelta docs: http://pandas.pydata.org/pandas-docs/stable/timedeltas.html |
all comments have been addressed. |
86c8c05
to
6e618d7
Compare
@@ -27,6 +27,41 @@ Backwards incompatible API changes | |||
|
|||
.. _whatsnew_0160.api_breaking: | |||
|
|||
- In v0.15.0 a new scalar type ``Timedelta`` was introduced, that is a sub-class of ``datetime.timedelta``. Mentioned :ref:`here <whatsnew_0150.timedeltaindex>` was a notice of an API change w.r.t. the ``.seconds`` accessor. The intent was to provide a user-friendly set of accessors that give the 'natural' value for that unit, e.g. if you had a ``Timedelta('1 day, 10:11:12')``, then ``.seconds`` would return 12. However, this is at odds with the definition of ``datetime.timedelta``, which defines ``.seconds`` as ``10 * 3600 + 11 * 60 + 12 == 36672``. | |||
|
|||
So in v0.16.0, we are restoring the API to match that of ``datetime.timedelta``. However, the component values are still available thru the ``.components`` accessor. This affects the ``.seconds`` and ``.microseconds`` accessors, and removes the ``.hours``, ``.minutes``, ``.milliseconds``, ``.nanoseconds`` accessors. These changes affect ``TimedeltaIndex`` and the Series ``.dt`` accessor as well. (:issue:`9185`, :issue:`9139`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thru -> through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is still nanoseconds as removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
8c97b7a
to
bf0354d
Compare
…onds/microseconds accessors (GH9185, GH9139) +
# this is 5 minutes * 60 + 3 seconds | ||
tds.to_pytimedelta().seconds | ||
|
||
td.dt.components.seconds | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry...was editing something else
OK, looks good to me! |
API: restore full datetime.timedelta compat with Timedelta w.r.t. seconds/microseconds accessors (GH9185, GH9139)
Thanks Jeff! |
closes #9185
closes #9139