Skip to content

Commit 257e27a

Browse files
committed
DOC: Add linspace range behavior to the timeseries/timedeltas/interval docs
1 parent 6cc5f23 commit 257e27a

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

doc/source/advanced.rst

+45
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,51 @@ bins, with ``NaN`` representing a missing value similar to other dtypes.
924924
925925
pd.cut([0, 3, 5, 1], bins=c.categories)
926926
927+
If we need intervals on a regular frequency, we can use the :func:`interval_range` function
928+
to create an ``IntervalIndex`` using various combinations of ``start``, ``end``, and ``periods``.
929+
The default frequency for ``interval_range`` is a 1 for numeric intervals, and calendar day for
930+
datetime-like intervals:
931+
932+
.. ipython:: python
933+
934+
pd.interval_range(start=0, end=5)
935+
936+
pd.interval_range(start=pd.Timestamp('2017-01-01'), periods=4)
937+
938+
pd.interval_range(end=pd.Timedelta('3 days'), periods=3)
939+
940+
The ``freq`` parameter can used to specify non-default frequencies, and can utilize a variety
941+
of :ref:`frequency aliases <timeseries.offset_aliases>` with datetime-like intervals:
942+
943+
.. ipython:: python
944+
945+
pd.interval_range(start=0, periods=5, freq=1.5)
946+
947+
pd.interval_range(start=pd.Timestamp('2017-01-01'), periods=4, freq='W')
948+
949+
pd.interval_range(start=pd.Timedelta('0 days'), periods=3, freq='9H')
950+
951+
Additionally, the ``closed`` parameter can be used to specify which side(s) the intervals
952+
are closed on. Intervals are closed on the right side by default.
953+
954+
.. ipython:: python
955+
956+
pd.interval_range(start=0, end=4, closed='both')
957+
958+
pd.interval_range(start=0, end=4, closed='neither')
959+
960+
.. versionadded:: 0.23.0
961+
962+
Specifying ``start``, ``end``, and ``periods`` will generate a range of evenly spaced
963+
intervals from ``start`` to ``end`` inclusively, with ``periods`` number of elements
964+
in the resulting ``IntervalIndex``:
965+
966+
.. ipython:: python
967+
968+
pd.interval_range(start=0, end=6, periods=4)
969+
970+
pd.interval_range(pd.Timestamp('2018-01-01'), pd.Timestamp('2018-02-28'), periods=3)
971+
927972
Miscellaneous indexing FAQ
928973
--------------------------
929974

doc/source/timedeltas.rst

+34-3
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ TimedeltaIndex
353353
--------------
354354

355355
To generate an index with time delta, you can use either the ``TimedeltaIndex`` or
356-
the ``timedelta_range`` constructor.
356+
the :func:`timedelta_range` constructor.
357357

358358
Using ``TimedeltaIndex`` you can pass string-like, ``Timedelta``, ``timedelta``,
359359
or ``np.timedelta64`` objects. Passing ``np.nan/pd.NaT/nat`` will represent missing values.
@@ -363,13 +363,44 @@ 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-
Similarly to ``date_range``, you can construct regular ranges of a ``TimedeltaIndex``:
366+
Similar to ``date_range``, you can construct regular ranges of a ``TimedeltaIndex``
367+
using ``timedelta_range``. The default frequency for ``timedelta_range`` is
368+
calendar day:
369+
370+
.. ipython:: python
371+
372+
pd.timedelta_range(start='1 days', periods=5)
373+
374+
Various combinations of ``start``, ``end``, and ``periods`` can be used with
375+
``timedelta_range``:
376+
377+
.. ipython:: python
378+
379+
pd.timedelta_range(start='1 days', end='5 days')
380+
381+
pd.timedelta_range( end='10 days', periods=4)
382+
383+
The ``freq`` parameter can passed a variety of :ref:`frequency aliases <timeseries.offset_aliases>`:
367384

368385
.. ipython:: python
369386
370-
pd.timedelta_range(start='1 days', periods=5, freq='D')
371387
pd.timedelta_range(start='1 days', end='2 days', freq='30T')
372388
389+
pd.timedelta_range(start='1 days', periods=5, freq='2D5H')
390+
391+
392+
.. versionadded:: 0.23.0
393+
394+
Specifying ``start``, ``end``, and ``periods`` will generate a range of evenly spaced
395+
timedeltas from ``start`` to ``end`` inclusively, with ``periods`` number of elements
396+
in the resulting ``TimedeltaIndex``:
397+
398+
.. ipython:: python
399+
400+
pd.timedelta_range('0 days', '4 days', periods=5)
401+
402+
pd.timedelta_range('0 days', '4 days', periods=10)
403+
373404
Using the TimedeltaIndex
374405
~~~~~~~~~~~~~~~~~~~~~~~~
375406

doc/source/timeseries.rst

+12
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,18 @@ of those specified will not be generated:
393393
394394
pd.bdate_range(start=start, periods=20)
395395
396+
.. versionadded:: 0.23.0
397+
398+
Specifying ``start``, ``end``, and ``periods`` will generate a range of evenly spaced
399+
dates from ``start`` to ``end`` inclusively, with ``periods`` number of elements in the
400+
resulting ``DatetimeIndex``:
401+
402+
.. ipython:: python
403+
404+
pd.date_range('2018-01-01', '2018-01-05', periods=5)
405+
406+
pd.date_range('2018-01-01', '2018-01-05', periods=10)
407+
396408
.. _timeseries.custom-freq-ranges:
397409

398410
Custom Frequency Ranges

0 commit comments

Comments
 (0)