Skip to content

Commit 2f203d1

Browse files
DOC: 'MS' offset alias does not work as described with pd.date_range() (#44534)
1 parent c8a0804 commit 2f203d1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

doc/source/user_guide/timeseries.rst

+30
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,36 @@ frequencies. We will refer to these aliases as *offset aliases*.
12701270
"U, us", "microseconds"
12711271
"N", "nanoseconds"
12721272

1273+
.. note::
1274+
1275+
When using the offset aliases above, it should be noted that functions
1276+
such as :func:`date_range`, :func:`bdate_range`, will only return
1277+
timestamps that are in the interval defined by ``start_date`` and
1278+
``end_date``. If the ``start_date`` does not correspond to the frequency,
1279+
the returned timestamps will start at the next valid timestamp, same for
1280+
``end_date``, the returned timestamps will stop at the previous valid
1281+
timestamp.
1282+
1283+
For example, for the offset ``MS``, if the ``start_date`` is not the first
1284+
of the month, the returned timestamps will start with the first day of the
1285+
next month. If ``end_date`` is not the first day of a month, the last
1286+
returned timestamp will be the first day of the corresponding month.
1287+
1288+
.. ipython:: python
1289+
1290+
dates_lst_1 = pd.date_range("2020-01-06", "2020-04-03", freq="MS")
1291+
dates_lst_1
1292+
1293+
dates_lst_2 = pd.date_range("2020-01-01", "2020-04-01", freq="MS")
1294+
dates_lst_2
1295+
1296+
We can see in the above example :func:`date_range` and
1297+
:func:`bdate_range` will only return the valid timestamps between the
1298+
``start_date`` and ``end_date``. If these are not valid timestamps for the
1299+
given frequency it will roll to the next value for ``start_date``
1300+
(respectively previous for the ``end_date``)
1301+
1302+
12731303
Combining aliases
12741304
~~~~~~~~~~~~~~~~~
12751305

0 commit comments

Comments
 (0)