Skip to content

DOC: Add documentation for freq='infer' option of DatetimeIndex and TimedeltaIndex constructors #21128

Closed
@jschendel

Description

@jschendel

There currently doesn't appear to be any information regarding passing freq='infer' to the DatetimeIndex or TimedeltaIndex constructors; I only became aware of this option from reading over the code. Would be nice to document this feature in the docstrings for DatetimeIndex and TimedeltaIndex. Possibly in timeseries.rst and timdeltas.rst too.

Essentially, this allows users to set the frequency of the index as the inferred frequency upon creation:

In [2]: pd.DatetimeIndex(['2018-01-01', '2018-01-03', '2018-01-05'], freq='infer')
Out[2]: DatetimeIndex(['2018-01-01', '2018-01-03', '2018-01-05'], dtype='datetime64[ns]', freq='2D')

Note that the frequency is not automatically inferred if nothing is passed to the freq parameter:

In [3]: pd.DatetimeIndex(['2018-01-01', '2018-01-03', '2018-01-05'])
Out[3]: DatetimeIndex(['2018-01-01', '2018-01-03', '2018-01-05'], dtype='datetime64[ns]', freq=None)

Similar example with TimedeltaIndex:

In [4]: pd.TimedeltaIndex(['0 days', '10 days', '20 days'], freq='infer')
Out[4]: TimedeltaIndex(['0 days', '10 days', '20 days'], dtype='timedelta64[ns]', freq='10D')

In [5]: pd.TimedeltaIndex(['0 days', '10 days', '20 days'])
Out[5]: TimedeltaIndex(['0 days', '10 days', '20 days'], dtype='timedelta64[ns]', freq=None)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions