You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/timedeltas.rst
+9-21
Original file line number
Diff line number
Diff line change
@@ -251,8 +251,13 @@ yields another ``timedelta64[ns]`` dtypes Series.
251
251
Attributes
252
252
----------
253
253
254
-
You can access various components of the ``Timedelta`` or ``TimedeltaIndex`` directly using the attributes ``days,hours,minutes,seconds,milliseconds,microseconds,nanoseconds``.
255
-
These operations can be directly accessed via the ``.dt`` property of the ``Series`` as well. These return an integer representing that interval (which is signed according to whether the ``Timedelta`` is signed).
254
+
You can access various components of the ``Timedelta`` or ``TimedeltaIndex`` directly using the attributes ``days,seconds,microseconds,nanoseconds``. These are identical to the values returned by ``datetime.timedelta``, in that, for example, the ``.seconds`` attribute represents the number of seconds >= 0 and < 1 day. These are signed according to whether the ``Timedelta`` is signed.
255
+
256
+
These operations can also be directly accessed via the ``.dt`` property of the ``Series`` as well.
257
+
258
+
.. note::
259
+
260
+
Note that the attributes are NOT the displayed values of the ``Timedelta``. Use ``.components`` to retrieve the displayed values.
256
261
257
262
For a ``Series``
258
263
@@ -271,29 +276,12 @@ You can access the component field for a scalar ``Timedelta`` directly.
271
276
(-tds).seconds
272
277
273
278
You can use the ``.components`` property to access a reduced form of the timedelta. This returns a ``DataFrame`` indexed
274
-
similarly to the ``Series``
279
+
similarly to the ``Series``. These are the *displayed* values of the ``Timedelta``.
275
280
276
281
.. ipython:: python
277
282
278
283
td.dt.components
279
-
280
-
.. _timedeltas.attribues_warn:
281
-
282
-
.. warning::
283
-
284
-
``Timedelta`` scalars (and ``TimedeltaIndex``) component fields are *not the same* as the component fields on a ``datetime.timedelta`` object. For example, ``.seconds`` on a ``datetime.timedelta`` object returns the total number of seconds combined between ``hours``, ``minutes`` and ``seconds``. In contrast, the pandas ``Timedelta`` breaks out hours, minutes, microseconds and nanoseconds separately.
- Removed ``center`` argument from all :func:`expanding_ <expanding_apply>` functions (see :ref:`list <api.functions_expanding>`),
406
+
- Removed ``center`` argument from all :func:`expanding_ <expanding_apply>` functions (see :ref:`list <api.functions_expanding>`),
407
407
as the results produced when ``center=True`` did not make much sense. (:issue:`7925`)
408
408
409
409
- Added optional ``ddof`` argument to :func:`expanding_cov` and :func:`rolling_cov`.
@@ -574,20 +574,20 @@ for more details):
574
574
.. code-block:: python
575
575
576
576
In [2]: pd.Categorical.from_codes([0,1,0,2,1], categories=['a', 'b', 'c'])
577
-
Out[2]:
577
+
Out[2]:
578
578
[a, b, a, c, b]
579
579
Categories (3, object): [a, b, c]
580
580
581
581
API changes related to the introduction of the ``Timedelta`` scalar (see
582
582
:ref:`above <whatsnew_0150.timedeltaindex>` for more details):
583
-
583
+
584
584
- Prior to 0.15.0 :func:`to_timedelta` would return a ``Series`` for list-like/Series input,
585
585
and a ``np.timedelta64`` for scalar input. It will now return a ``TimedeltaIndex`` for
586
586
list-like input, ``Series`` for Series input, and ``Timedelta`` for scalar input.
587
587
588
588
For API changes related to the rolling and expanding functions, see detailed overview :ref:`above <whatsnew_0150.roll>`.
589
589
590
-
Other notable API changes:
590
+
Other notable API changes:
591
591
592
592
- Consistency when indexing with ``.loc`` and a list-like indexer when no values are found.
593
593
@@ -872,7 +872,7 @@ Enhancements in the importing/exporting of Stata files:
872
872
objects and columns containing missing values have ``object`` data type. (:issue:`8045`)
873
873
874
874
Enhancements in the plotting functions:
875
-
875
+
876
876
- Added ``layout`` keyword to ``DataFrame.plot``. You can pass a tuple of ``(rows, columns)``, one of which can be ``-1`` to automatically infer (:issue:`6667`, :issue:`8071`).
877
877
- Allow to pass multiple axes to ``DataFrame.plot``, ``hist`` and ``boxplot`` (:issue:`5353`, :issue:`6970`, :issue:`7069`)
878
878
- Added support for ``c``, ``colormap`` and ``colorbar`` arguments for ``DataFrame.plot`` with ``kind='scatter'`` (:issue:`7780`)
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v0.16.0.txt
+35
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,41 @@ Backwards incompatible API changes
27
27
28
28
.. _whatsnew_0160.api_breaking:
29
29
30
+
- 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``.
31
+
32
+
So in v0.16.0, we are restoring the API to match that of ``datetime.timedelta``. However, the component values are still available through the ``.components`` accessor. This affects the ``.seconds`` and ``.microseconds`` accessors, and removes the ``.hours``, ``.minutes``, ``.milliseconds`` accessors. These changes affect ``TimedeltaIndex`` and the Series ``.dt`` accessor as well. (:issue:`9185`, :issue:`9139`)
33
+
34
+
Previous Behavior
35
+
36
+
.. code-block:: python
37
+
38
+
In [2]: t = pd.Timedelta('1 day, 10:11:12.100123')
39
+
40
+
In [3]: t.days
41
+
Out[3]: 1
42
+
43
+
In [4]: t.seconds
44
+
Out[4]: 12
45
+
46
+
In [5]: t.microseconds
47
+
Out[5]: 123
48
+
49
+
New Behavior
50
+
51
+
.. ipython:: python
52
+
53
+
t = pd.Timedelta('1 day, 10:11:12.100123')
54
+
t.days
55
+
t.seconds
56
+
t.microseconds
57
+
58
+
Using ``.components`` allows the full component access
59
+
60
+
.. ipython:: python
61
+
62
+
t.components
63
+
t.components.seconds
64
+
30
65
- ``Index.duplicated`` now returns `np.array(dtype=bool)` rather than `Index(dtype=object)` containing `bool` values. (:issue:`8875`)
31
66
- ``DataFrame.to_json`` now returns accurate type serialisation for each column for frames of mixed dtype (:issue:`9037`)
0 commit comments