From 71cae1dcb1c991876d08a70f39ae3c6c34984085 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Tue, 13 Dec 2022 22:01:26 +0100 Subject: [PATCH 1/6] DOC: add examples to BusinessHour and BusinessDay I --- pandas/_libs/tslibs/offsets.pyx | 62 ++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 60199cacafa4f..de3065aff9868 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1494,11 +1494,29 @@ cdef class BusinessDay(BusinessMixin): """ DateOffset subclass representing possibly n business days. + Parameters + ---------- + n : int, default 1 + The number of days represented. + normalize : bool, default False + Normalize start/end dates to midnight before generating date range. + Examples -------- - >>> ts = pd.Timestamp(2022, 8, 5) - >>> ts + pd.offsets.BusinessDay() - Timestamp('2022-08-08 00:00:00') + You can use the parameter ``n`` to shift the next business day to n days. + + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts.strftime('%a %d %b %Y %H:%M') + 'Fri 09 Dec 2022 15:00' + >>> (ts + pd.offsets.BusinessDay(n=5)).strftime('%a %d %b %Y %H:%M') + 'Fri 16 Dec 2022 15:00' + + Passing the parameter ``normalize`` equal True, you shift the start + of next business day to midnight. + + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts + pd.offsets.BusinessDay(normalize=True) + Timestamp('2022-12-12 00:00:00') """ _period_dtype_code = PeriodDtypeCode.B _prefix = "B" @@ -1610,11 +1628,9 @@ cdef class BusinessHour(BusinessMixin): Parameters ---------- n : int, default 1 - The number of months represented. + The number of hours represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - weekmask : str, Default 'Mon Tue Wed Thu Fri' - Weekmask of valid business days, passed to ``numpy.busdaycalendar``. start : str, time, or list of str/time, default "09:00" Start time of your custom business hour in 24h format. end : str, time, or list of str/time, default: "17:00" @@ -1622,17 +1638,28 @@ cdef class BusinessHour(BusinessMixin): Examples -------- - >>> from datetime import time + You can use the parameter ``n`` to represent the shift to n hours. + + >>> ts = pd.Timestamp(2022, 12, 9, 8) + >>> ts + pd.offsets.BusinessHour(n=5) + Timestamp('2022-12-09 14:00:00') + + You can also change the start and the end of business hours. + >>> ts = pd.Timestamp(2022, 8, 5, 16) - >>> ts + pd.offsets.BusinessHour() - Timestamp('2022-08-08 09:00:00') >>> ts + pd.offsets.BusinessHour(start="11:00") Timestamp('2022-08-08 11:00:00') - >>> ts + pd.offsets.BusinessHour(end=time(19, 0)) - Timestamp('2022-08-05 17:00:00') - >>> ts + pd.offsets.BusinessHour(start=[time(9, 0), "20:00"], - ... end=["17:00", time(22, 0)]) - Timestamp('2022-08-05 20:00:00') + + >>> from datetime import time as dt_time + >>> ts = pd.Timestamp(2022, 8, 5, 22) + >>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0)) + Timestamp('2022-08-08 10:00:00') + + The parameter ``normalize`` equal True forces shift to midnight. + + >>> ts = pd.Timestamp(2022, 12, 9, 8) + >>> ts + pd.offsets.BusinessHour(normalize=True) + Timestamp('2022-12-09 00:00:00') """ _prefix = "BH" @@ -3536,6 +3563,7 @@ cdef class CustomBusinessDay(BusinessDay): Parameters ---------- n : int, default 1 + The number of days represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. weekmask : str, Default 'Mon Tue Wed Thu Fri' @@ -3624,7 +3652,7 @@ cdef class CustomBusinessHour(BusinessHour): Parameters ---------- n : int, default 1 - The number of months represented. + The number of hours represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. weekmask : str, Default 'Mon Tue Wed Thu Fri' @@ -3662,7 +3690,7 @@ cdef class CustomBusinessHour(BusinessHour): >>> ts + pd.offsets.CustomBusinessHour(end=dt_time(19, 0)) Timestamp('2022-08-08 10:00:00') - In the example below we divide our business day hours into several parts. + You can divide your business day hours into several parts. >>> import datetime as dt >>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"], @@ -3692,7 +3720,7 @@ cdef class CustomBusinessHour(BusinessHour): 'Fri 16 Dec 2022 12:00'], dtype='object') - In the example below we define custom holidays by using NumPy business day calendar. + Using NumPy business day calendar you can define custom holidays. >>> import datetime as dt >>> bdc = np.busdaycalendar(holidays=['2022-12-12', '2022-12-14']) From 7aa47474542a3e3159671f65ff1acb103793ddb4 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 15 Dec 2022 01:24:27 +0100 Subject: [PATCH 2/6] DOC: add examples to BusinessHour and BusinessDay II --- pandas/_libs/tslibs/offsets.pyx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index de3065aff9868..2636fd68c3739 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1638,7 +1638,7 @@ cdef class BusinessHour(BusinessMixin): Examples -------- - You can use the parameter ``n`` to represent the shift to n hours. + You can use the parameter ``n`` to represent a shift of n hours. >>> ts = pd.Timestamp(2022, 12, 9, 8) >>> ts + pd.offsets.BusinessHour(n=5) @@ -1655,11 +1655,26 @@ cdef class BusinessHour(BusinessMixin): >>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0)) Timestamp('2022-08-08 10:00:00') - The parameter ``normalize`` equal True forces shift to midnight. + Passing the parameter ``normalize`` equal True, you shift the start + of next business hour to midnight. >>> ts = pd.Timestamp(2022, 12, 9, 8) >>> ts + pd.offsets.BusinessHour(normalize=True) Timestamp('2022-12-09 00:00:00') + + You can divide your business day hours into several parts. + + >>> import datetime as dt + >>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"], + ... end=["08:00", "12:00", "17:00"]) + >>> pd.date_range(dt.datetime(2022, 12, 9), dt.datetime(2022, 12, 13), freq=freq) + DatetimeIndex(['2022-12-09 06:00:00', '2022-12-09 07:00:00', + '2022-12-09 10:00:00', '2022-12-09 11:00:00', + '2022-12-09 15:00:00', '2022-12-09 16:00:00', + '2022-12-12 06:00:00', '2022-12-12 07:00:00', + '2022-12-12 10:00:00', '2022-12-12 11:00:00', + '2022-12-12 15:00:00', '2022-12-12 16:00:00'], + dtype='datetime64[ns]', freq='CBH') """ _prefix = "BH" From 573eaec8a6d590c9383c5c6fe551eef0c7f48be7 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 15 Dec 2022 13:35:09 +0100 Subject: [PATCH 3/6] DOC: add examples to BusinessHour and BusinessDay III --- pandas/_libs/tslibs/offsets.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 2636fd68c3739..2259c1f38b02f 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1665,8 +1665,8 @@ cdef class BusinessHour(BusinessMixin): You can divide your business day hours into several parts. >>> import datetime as dt - >>> freq = pd.offsets.CustomBusinessHour(start=["06:00", "10:00", "15:00"], - ... end=["08:00", "12:00", "17:00"]) + >>> freq = pd.offsets.BusinessHour(start=["06:00", "10:00", "15:00"], + ... end=["08:00", "12:00", "17:00"]) >>> pd.date_range(dt.datetime(2022, 12, 9), dt.datetime(2022, 12, 13), freq=freq) DatetimeIndex(['2022-12-09 06:00:00', '2022-12-09 07:00:00', '2022-12-09 10:00:00', '2022-12-09 11:00:00', @@ -1674,7 +1674,7 @@ cdef class BusinessHour(BusinessMixin): '2022-12-12 06:00:00', '2022-12-12 07:00:00', '2022-12-12 10:00:00', '2022-12-12 11:00:00', '2022-12-12 15:00:00', '2022-12-12 16:00:00'], - dtype='datetime64[ns]', freq='CBH') + dtype='datetime64[ns]', freq='BH') """ _prefix = "BH" From 23222a25097d81901cb2aaab49877ac9dd9d7198 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Thu, 15 Dec 2022 21:06:15 +0100 Subject: [PATCH 4/6] DOC: add examples to BusinessHour and BusinessDay IV --- pandas/_libs/tslibs/offsets.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 2259c1f38b02f..3c1397160bbe7 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1499,11 +1499,11 @@ cdef class BusinessDay(BusinessMixin): n : int, default 1 The number of days represented. normalize : bool, default False - Normalize start/end dates to midnight before generating date range. + Normalize start/end dates to midnight Examples -------- - You can use the parameter ``n`` to shift the next business day to n days. + You can use the parameter ``n`` to represent a shift of n business days. >>> ts = pd.Timestamp(2022, 12, 9, 15) >>> ts.strftime('%a %d %b %Y %H:%M') From b16dab74ed60d58e947f156aff991cc52a4d2b90 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 16 Dec 2022 23:25:42 +0100 Subject: [PATCH 5/6] DOC: add examples to BusinessHour and BusinessDay V --- pandas/_libs/tslibs/offsets.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 3c1397160bbe7..2ee0478223534 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1511,8 +1511,8 @@ cdef class BusinessDay(BusinessMixin): >>> (ts + pd.offsets.BusinessDay(n=5)).strftime('%a %d %b %Y %H:%M') 'Fri 16 Dec 2022 15:00' - Passing the parameter ``normalize`` equal True, you shift the start - of next business day to midnight. + Passing the parameter ``normalize`` equal to True, you shift the start + of the next business day to midnight. >>> ts = pd.Timestamp(2022, 12, 9, 15) >>> ts + pd.offsets.BusinessDay(normalize=True) @@ -1655,8 +1655,8 @@ cdef class BusinessHour(BusinessMixin): >>> ts + pd.offsets.BusinessHour(end=dt_time(19, 0)) Timestamp('2022-08-08 10:00:00') - Passing the parameter ``normalize`` equal True, you shift the start - of next business hour to midnight. + Passing the parameter ``normalize`` equal to True, you shift the start + of the next business hour to midnight. >>> ts = pd.Timestamp(2022, 12, 9, 8) >>> ts + pd.offsets.BusinessHour(normalize=True) From 61e85555baae531cba563b61618960c5d3f1125b Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva Date: Fri, 16 Dec 2022 23:46:53 +0100 Subject: [PATCH 6/6] fixup! DOC: add examples to BusinessHour and BusinessDay V --- 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 2ee0478223534..f9905f297be10 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1499,7 +1499,7 @@ cdef class BusinessDay(BusinessMixin): n : int, default 1 The number of days represented. normalize : bool, default False - Normalize start/end dates to midnight + Normalize start/end dates to midnight. Examples --------