Skip to content

Commit 506935c

Browse files
jschendeljreback
authored andcommitted
DOC: Add documentation for freq='infer' option of DatetimeIndex and TimedeltaIndex constructors (#21566)
1 parent b36b451 commit 506935c

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

doc/source/timedeltas.rst

+7
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ or ``np.timedelta64`` objects. Passing ``np.nan/pd.NaT/nat`` will represent miss
363363
pd.TimedeltaIndex(['1 days', '1 days, 00:00:05',
364364
np.timedelta64(2,'D'), datetime.timedelta(days=2,seconds=2)])
365365
366+
The string 'infer' can be passed in order to set the frequency of the index as the
367+
inferred frequency upon creation:
368+
369+
.. ipython:: python
370+
371+
pd.TimedeltaIndex(['0 days', '10 days', '20 days'], freq='infer')
372+
366373
Generating Ranges of Time Deltas
367374
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
368375

doc/source/timeseries.rst

+13
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ options like ``dayfirst`` or ``format``, so use ``to_datetime`` if these are req
185185
186186
pd.Timestamp('2010/11/12')
187187
188+
You can also use the ``DatetimeIndex`` constructor directly:
189+
190+
.. ipython:: python
191+
192+
pd.DatetimeIndex(['2018-01-01', '2018-01-03', '2018-01-05'])
193+
194+
The string 'infer' can be passed in order to set the frequency of the index as the
195+
inferred frequency upon creation:
196+
197+
.. ipython:: python
198+
199+
pd.DatetimeIndex(['2018-01-01', '2018-01-03', '2018-01-05'], freq='infer')
200+
188201
Providing a Format Argument
189202
~~~~~~~~~~~~~~~~~~~~~~~~~~~
190203

pandas/core/indexes/datetimes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
187187
copy : bool
188188
Make a copy of input ndarray
189189
freq : string or pandas offset object, optional
190-
One of pandas date offset strings or corresponding objects
190+
One of pandas date offset strings or corresponding objects. The string
191+
'infer' can be passed in order to set the frequency of the index as the
192+
inferred frequency upon creation
193+
191194
start : starting value, datetime-like, optional
192195
If data is None, start is used as the start point in generating regular
193196
timestamp data.

pandas/core/indexes/timedeltas.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ class TimedeltaIndex(DatetimeIndexOpsMixin, TimelikeOps, Int64Index):
107107
Optional timedelta-like data to construct index with
108108
unit: unit of the arg (D,h,m,s,ms,us,ns) denote the unit, optional
109109
which is an integer/float number
110-
freq: a frequency for the index, optional
110+
freq : string or pandas offset object, optional
111+
One of pandas date offset strings or corresponding objects. The string
112+
'infer' can be passed in order to set the frequency of the index as the
113+
inferred frequency upon creation
111114
copy : bool
112115
Make a copy of input ndarray
113116
start : starting value, timedelta-like, optional

0 commit comments

Comments
 (0)