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/timeseries.rst
+43-1
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
.. ipython:: python
5
5
:suppress:
6
6
7
-
from datetime import datetime
7
+
from datetime import datetime, timedelta
8
8
import numpy as np
9
9
np.random.seed(123456)
10
10
from pandas import*
@@ -1098,6 +1098,36 @@ frequency.
1098
1098
1099
1099
p -3
1100
1100
1101
+
If ``Period`` freq is daily or higher (``D``, ``H``, ``T``, ``S``, ``L``, ``U``, ``N``), ``offsets`` and ``timedelta``-like can be added if the result can have same freq. Otherise, ``ValueError`` will be raised.
1102
+
1103
+
.. ipython:: python
1104
+
1105
+
p = Period('2014-07-01 09:00', freq='H')
1106
+
p + Hour(2)
1107
+
p + timedelta(minutes=120)
1108
+
p + np.timedelta64(7200, 's')
1109
+
1110
+
.. code-block:: python
1111
+
1112
+
In [1]: p + Minute(5)
1113
+
Traceback
1114
+
...
1115
+
ValueError: Input has different freq from Period(freq=H)
1116
+
1117
+
If ``Period`` has other freqs, only the same ``offsets`` can be added. Otherwise, ``ValueError`` will be raised.
1118
+
1119
+
.. ipython:: python
1120
+
1121
+
p = Period('2014-07', freq='M')
1122
+
p + MonthEnd(3)
1123
+
1124
+
.. code-block:: python
1125
+
1126
+
In [1]: p + MonthBegin(3)
1127
+
Traceback
1128
+
...
1129
+
ValueError: Input has different freq from Period(freq=M)
1130
+
1101
1131
Taking the difference of ``Period`` instances with the same frequency will
1102
1132
return the number of frequency units between them:
1103
1133
@@ -1129,6 +1159,18 @@ objects:
1129
1159
ps = Series(randn(len(prng)), prng)
1130
1160
ps
1131
1161
1162
+
``PeriodIndex`` supports addition and subtraction as the same rule as ``Period``.
Copy file name to clipboardExpand all lines: doc/source/v0.15.0.txt
+15
Original file line number
Diff line number
Diff line change
@@ -271,10 +271,21 @@ Enhancements
271
271
272
272
273
273
274
+
- ``Period`` and ``PeriodIndex`` supports addition/subtraction with ``timedelta``-likes (:issue:`7966`)
274
275
276
+
If ``Period`` freq is ``D``, ``H``, ``T``, ``S``, ``L``, ``U``, ``N``, ``timedelta``-like can be added if the result can have same freq. Otherwise, only the same ``offsets`` can be added.
0 commit comments