@@ -56,6 +56,10 @@ You can construct a ``Timedelta`` scalar thru various arguments:
5656 Timedelta(timedelta(days = 1 ,seconds = 1 ))
5757 Timedelta(np.timedelta64(1 ,' ms' ))
5858
59+ # negative Timedeltas have this string repr
60+ # to be more consistent with datetime.timedelta conventions
61+ Timedelta(' -1us' )
62+
5963 # a NaT
6064 Timedelta(' nan' )
6165 Timedelta(' nat' )
@@ -160,7 +164,7 @@ Operands can also appear in a reversed order (a singular object operated with a
160164 df.idxmin()
161165 df.idxmax()
162166
163- ``min, max, idxmin, idxmax `` operations are supported on Series / DataFrames . A single result will be a ``Timedelta ``.
167+ ``min, max, idxmin, idxmax `` operations are supported on Series as well . A scalar result will be a ``Timedelta ``.
164168
165169.. ipython :: python
166170
@@ -184,6 +188,7 @@ You can also negate, multiply and use ``abs`` on ``Timedeltas``
184188.. ipython :: python
185189
186190 td1 = Timedelta(' -1 days 2 hours 3 seconds' )
191+ tdi
187192 - 1 * td1
188193 - td1
189194 abs (td1)
@@ -193,14 +198,17 @@ You can also negate, multiply and use ``abs`` on ``Timedeltas``
193198Reductions
194199----------
195200
196- Numeric reduction operation for ``timedelta64[ns] `` will return ``Timedelta `` objects.
201+ Numeric reduction operation for ``timedelta64[ns] `` will return ``Timedelta `` objects. As usual
202+ ``NaT `` are skipped during evaluation.
197203
198204.. ipython :: python
199205
200- y2 = y.fillna(timedelta( days = - 1 , seconds = 5 ))
206+ y2 = Series(to_timedelta([ ' -1 days +00:00:05 ' , ' nat ' , ' -1 days +00:00:05 ' , ' 1 days ' ] ))
201207 y2
202208 y2.mean()
209+ y2.median()
203210 y2.quantile(.1 )
211+ y2.sum()
204212
205213 .. _timedeltas.timedeltas_convert :
206214
@@ -336,6 +344,9 @@ Furthermore you can use partial string selection and the range will be inferred:
336344
337345 s[' 1 day' :' 1 day 5 hours' ]
338346
347+ Operations
348+ ~~~~~~~~~~
349+
339350Finally, the combination of ``TimedeltaIndex `` with ``DatetimeIndex `` allow certain combination operations that are NaT preserving:
340351
341352.. ipython :: python
@@ -347,18 +358,32 @@ Finally, the combination of ``TimedeltaIndex`` with ``DatetimeIndex`` allow cert
347358 (dti + tdi).tolist()
348359 (dti - tdi).tolist()
349360
361+ Conversions
362+ ~~~~~~~~~~~
363+
350364Similarly to frequency conversion on a ``Series `` above, you can convert these indices to yield another Index.
351365
352366.. ipython :: python
353367
354368 tdi / np.timedelta64(1 ,' s' )
355369 tdi.astype(' timedelta64[s]' )
356370
357- Scalars type ops work as well
371+ Scalars type ops work as well. These can potentially return a * different * type of index.
358372
359373.. ipython :: python
360374
375+ # adding or timedelta and date -> datelike
361376 tdi + Timestamp(' 20130101' )
362- tdi + Timedelta(' 10 days' )
377+
378+ # subtraction of a date and a timedelta -> datelike
379+ # note that trying to subtract a date from a Timedelta will raise an exception
363380 (Timestamp(' 20130101' ) - tdi).tolist()
381+
382+ # timedelta + timedelta -> timedelta
383+ tdi + Timedelta(' 10 days' )
384+
385+ # division can result in a Timedelta if the divisor is an integer
386+ tdi / 2
387+
388+ # or a Float64Index if the divisor is a Timedelta
364389 tdi / tdi[0 ]
0 commit comments