From a5573d7819b4c4aecf7dd8d247e7ff21a94cb6b2 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Wed, 17 May 2023 21:25:42 +0200 Subject: [PATCH 1/2] DOC: add missing parameters to offsets classes: BYearBegin, YearEnd, YearBegin --- pandas/_libs/tslibs/offsets.pyx | 47 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 87b511d92ac30..9fc0d20001e8e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2251,9 +2251,13 @@ cdef class BYearEnd(YearOffset): The number of years represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - month : int, default 1 + month : int, default 12 A specific integer for the month of the year. + See Also + -------- + :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. + Examples -------- >>> from pandas.tseries.offsets import BYearEnd @@ -2280,6 +2284,19 @@ cdef class BYearBegin(YearOffset): """ DateOffset increments between the first business day of the year. + Parameters + ---------- + n : int, default 1 + The number of years represented. + normalize : bool, default False + Normalize start/end dates to midnight before generating date range. + month : int, default 1 + A specific integer for the month of the year. + + See Also + -------- + :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. + Examples -------- >>> from pandas.tseries.offsets import BYearBegin @@ -2292,6 +2309,8 @@ cdef class BYearBegin(YearOffset): Timestamp('2020-01-01 05:01:15') >>> ts + BYearBegin(2) Timestamp('2022-01-03 05:01:15') + >>> ts + BYearBegin(month=11) + Timestamp('2020-11-02 05:01:15') """ _outputName = "BusinessYearBegin" @@ -2306,6 +2325,15 @@ cdef class YearEnd(YearOffset): YearEnd goes to the next date which is the end of the year. + Parameters + ---------- + n : int, default 1 + The number of years represented. + normalize : bool, default False + Normalize start/end dates to midnight before generating date range. + month : int, default 12 + A specific integer for the month of the year. + See Also -------- :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. @@ -2320,6 +2348,10 @@ cdef class YearEnd(YearOffset): >>> ts + pd.offsets.YearEnd() Timestamp('2023-12-31 00:00:00') + >>> ts = pd.Timestamp(2022, 1, 1) + >>> ts + pd.offsets.YearEnd(month=2) + Timestamp('2022-02-28 00:00:00') + If you want to get the end of the current year: >>> ts = pd.Timestamp(2022, 12, 31) @@ -2347,6 +2379,15 @@ cdef class YearBegin(YearOffset): YearBegin goes to the next date which is the start of the year. + Parameters + ---------- + n : int, default 1 + The number of years represented. + normalize : bool, default False + Normalize start/end dates to midnight before generating date range. + month : int, default 1 + A specific integer for the month of the year. + See Also -------- :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. @@ -2361,6 +2402,10 @@ cdef class YearBegin(YearOffset): >>> ts + pd.offsets.YearBegin() Timestamp('2024-01-01 00:00:00') + >>> ts = pd.Timestamp(2022, 1, 1) + >>> ts + pd.offsets.YearBegin(month=2) + Timestamp('2022-02-01 00:00:00') + If you want to get the start of the current year: >>> ts = pd.Timestamp(2023, 1, 1) From e07fbf08245a22cc82af28e3fce8d587e8c31942 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Thu, 18 May 2023 11:37:41 +0100 Subject: [PATCH 2/2] update "get to the end of the year" suggestion to use rollforward instead of rollback --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 9fc0d20001e8e..f062db77fb79b 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2355,7 +2355,7 @@ cdef class YearEnd(YearOffset): If you want to get the end of the current year: >>> ts = pd.Timestamp(2022, 12, 31) - >>> pd.offsets.YearEnd().rollback(ts) + >>> pd.offsets.YearEnd().rollforward(ts) Timestamp('2022-12-31 00:00:00') """