Skip to content

ENH: create Timedelta scalar / TimedeltaIndex #8184

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
Sep 13, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ Top-level missing data
isnull
notnull

Top-level dealing with datetimes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Top-level dealing with datetimelike
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
:toctree: generated/
Expand All @@ -157,6 +157,7 @@ Top-level dealing with datetimes
date_range
bdate_range
period_range
timedelta_range

Top-level evaluation
~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -440,13 +441,16 @@ Time series-related

Datetimelike Properties
~~~~~~~~~~~~~~~~~~~~~~~

``Series.dt`` can be used to access the values of the series as
datetimelike and return several properties.
Due to implementation details the methods show up here as methods of the
``DatetimeProperties/PeriodProperties`` classes. These can be accessed like ``Series.dt.<property>``.
``DatetimeProperties/PeriodProperties/TimedeltaProperties`` classes. These can be accessed like ``Series.dt.<property>``.

.. currentmodule:: pandas.tseries.common

**Datetime Properties**

.. autosummary::
:toctree: generated/

Expand All @@ -473,6 +477,37 @@ Due to implementation details the methods show up here as methods of the
DatetimeProperties.is_year_start
DatetimeProperties.is_year_end

**Datetime Methods**

.. autosummary::
:toctree: generated/

DatetimeProperties.to_period
DatetimeProperties.to_pydatetime
DatetimeProperties.tz_localize
DatetimeProperties.tz_convert

**Timedelta Properties**

.. autosummary::
:toctree: generated/

TimedeltaProperties.days
TimedeltaProperties.hours
TimedeltaProperties.minutes
TimedeltaProperties.seconds
TimedeltaProperties.milliseconds
TimedeltaProperties.microseconds
TimedeltaProperties.nanoseconds
TimedeltaProperties.components

**Timedelta Methods**

.. autosummary::
:toctree: generated/

TimedeltaProperties.to_pytimedelta

String handling
~~~~~~~~~~~~~~~
``Series.str`` can be used to access the values of the series as
Expand Down Expand Up @@ -1289,6 +1324,37 @@ Conversion
DatetimeIndex.to_pydatetime
DatetimeIndex.to_series

TimedeltaIndex
--------------

.. autosummary::
:toctree: generated/

TimedeltaIndex

Components
~~~~~~~~~~

.. autosummary::
:toctree: generated/

TimedeltaIndex.days
TimedeltaIndex.hours
TimedeltaIndex.minutes
TimedeltaIndex.seconds
TimedeltaIndex.milliseconds
TimedeltaIndex.microseconds
TimedeltaIndex.nanoseconds
TimedeltaIndex.components

Conversion
~~~~~~~~~~
.. autosummary::
:toctree: generated/

TimedeltaIndex.to_pytimedelta
TimedeltaIndex.to_series

GroupBy
-------
.. currentmodule:: pandas.core.groupby
Expand Down
19 changes: 19 additions & 0 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,16 @@ This enables nice expressions like this:

s[s.dt.day==2]

You can easily produces tz aware transformations:

.. ipython:: python

stz = s.dt.tz_localize('US/Eastern')
stz
stz.dt.tz

The ``.dt`` accessor works for period and timedelta dtypes.

.. ipython:: python

# period
Expand All @@ -1130,6 +1140,15 @@ This enables nice expressions like this:
s.dt.year
s.dt.day

.. ipython:: python
Copy link
Member

Choose a reason for hiding this comment

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

small comment of the line above (line 1138 in new counts): there is s = Series(period_range('20130101',periods=4,freq='D').asobject).

Why is this .asobject needed? And not with timedelta_range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't have a PeriodBlock so periods are currently stored as object dtype. This is also a bug somewhere as it should not coerce. timedelta_range returns a proprerly coerced index. Hmm I will look at the period issue.

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 FYI


# timedelta
s = Series(timedelta_range('1 day 00:00:05',periods=4,freq='s'))
s
s.dt.days
s.dt.seconds
s.dt.components

.. note::

``Series.dt`` will raise a ``TypeError`` if you access with a non-datetimelike values
Expand Down
2 changes: 1 addition & 1 deletion doc/source/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ Computation
Miscellaneous
-------------

The :ref:`Timedeltas <timeseries.timedeltas>` docs.
The :ref:`Timedeltas <timedeltas.timedeltas>` docs.

`Operating with timedeltas
<http://github.com/pydata/pandas/pull/2899>`__
Expand Down
1 change: 1 addition & 0 deletions doc/source/index.rst.template
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ See the package overview for more detail about what's in the library.
merging
reshaping
timeseries
timedeltas
categorical
visualization
rplot
Expand Down
3 changes: 2 additions & 1 deletion doc/source/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ containers for the axis labels:
data, such as time stamps
- ``Float64Index``: a version of ``Index`` highly optimized for 64-bit float data
- ``MultiIndex``: the standard hierarchical index object
- ``DatetimeIndex``: An Index object with Timestamp elements
- ``DatetimeIndex``: An Index object with ``Timestamp`` boxed elements (impl are the int64 values)
- ``TimedeltaIndex``: An Index object with ``Timedelta`` boxed elements (impl are the in64 values)
- ``PeriodIndex``: An Index object with Period elements

These are range generates to make the creation of a regular index easy:
Expand Down
Loading