Skip to content

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

Merged
merged 1 commit into from
Jan 16, 2015

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Jan 15, 2015

closes #9185
closes #9139

@jreback jreback added API Design Timedelta Timedelta data type Compat pandas objects compatability with Numpy or Python functions labels Jan 15, 2015
@jreback jreback added this to the 0.16.0 milestone Jan 15, 2015
@jreback
Copy link
Contributor Author

jreback commented Jan 15, 2015

@shoyer @jorisvandenbossche

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 """
Copy link
Member

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)."

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@shoyer
Copy link
Member

shoyer commented Jan 16, 2015

I think we also need to update the timedelta docs: http://pandas.pydata.org/pandas-docs/stable/timedeltas.html

@jreback
Copy link
Contributor Author

jreback commented Jan 16, 2015

all comments have been addressed.

@jreback jreback force-pushed the td branch 2 times, most recently from 86c8c05 to 6e618d7 Compare January 16, 2015 13:08
@@ -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`)
Copy link
Member

Choose a reason for hiding this comment

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

thru -> through

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jreback jreback force-pushed the td branch 2 times, most recently from 8c97b7a to bf0354d Compare January 16, 2015 14:13
…onds/microseconds accessors (GH9185, GH9139)

+
# this is 5 minutes * 60 + 3 seconds
tds.to_pytimedelta().seconds

td.dt.components.seconds

Copy link
Contributor Author

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

@jorisvandenbossche
Copy link
Member

OK, looks good to me!

jreback added a commit that referenced this pull request Jan 16, 2015
API: restore full datetime.timedelta compat with Timedelta w.r.t. seconds/microseconds accessors (GH9185, GH9139)
@jreback jreback merged commit c1e52f1 into pandas-dev:master Jan 16, 2015
@shoyer
Copy link
Member

shoyer commented Jan 16, 2015

Thanks Jeff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Compat pandas objects compatability with Numpy or Python functions Timedelta Timedelta data type
Projects
None yet
3 participants