From af8044ebea10c83a7e9ddf03447ca2680152eff6 Mon Sep 17 00:00:00 2001 From: Dirk Ulbricht Date: Fri, 4 Aug 2023 19:38:28 +0200 Subject: [PATCH 1/3] DOC: add missing parameters to offsets classes: Second, Hour and Day --- pandas/_libs/tslibs/offsets.pyx | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 028e79774607d..d598732c20c2f 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1089,6 +1089,34 @@ cdef class Tick(SingleConstructorOffset): cdef class Day(Tick): + """ + Offset ``n`` days. + + Parameters + ---------- + n : int, default 1 + The number of days represented. + + See Also + -------- + :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. + + Examples + -------- + You can use the parameter ``n`` to represent a shift of n days. + >>> from pandas.tseries.offsets import Day + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts.strftime('%a %d %b %Y %H:%M') + 'Fri 09 Dec 2022 15:00' + + >>> (ts + Day()).strftime('%a %d %b %Y %H:%M') + 'Sat 10 Dec 2022 15:00' + >>> (ts - Day(4)).strftime('%a %d %b %Y %H:%M') + 'Mon 05 Dec 2022 15:00' + + >>> (ts + Day(-4)).strftime('%a %d %b %Y %H:%M') + 'Mon 05 Dec 2022 15:00' + """ _nanos_inc = 24 * 3600 * 1_000_000_000 _prefix = "D" _period_dtype_code = PeriodDtypeCode.D @@ -1096,6 +1124,35 @@ cdef class Day(Tick): cdef class Hour(Tick): + """ + Offset ``n`` hours. + + Parameters + ---------- + n : int, default 1 + The number of hours represented. + + See Also + -------- + :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. + + Examples + -------- + You can use the parameter ``n`` to represent a shift of n hours. + + >>> from pandas.tseries.offsets import Hour + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts.strftime('%a %d %b %Y %H:%M') + 'Fri 09 Dec 2022 15:00' + + >>> (ts + Hour()).strftime('%a %d %b %Y %H:%M') + 'Fri 09 Dec 2022 16:00' + >>> (ts - Hour(4)).strftime('%a %d %b %Y %H:%M') + 'Fri 09 Dec 2022 11:00' + + >>> (ts + Hour(-4)).strftime('%a %d %b %Y %H:%M') + 'Fri 09 Dec 2022 11:00' + """ _nanos_inc = 3600 * 1_000_000_000 _prefix = "H" _period_dtype_code = PeriodDtypeCode.H @@ -1103,6 +1160,35 @@ cdef class Hour(Tick): cdef class Minute(Tick): + """ + Offset ``n`` minutes. + + Parameters + ---------- + n : int, default 1 + The number of minutes represented. + + See Also + -------- + :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. + + Examples + -------- + You can use the parameter ``n`` to represent a shift of n minutes. + + >>> from pandas.tseries.offsets import Minute + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts.strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 15:00:00' + + >>> (ts + Minute(n=10)).strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 15:10:00' + >>> (ts - Minute(n=10)).strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 14:50:00' + + >>> (ts + Minute(n=-10)).strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 14:50:00' + """ _nanos_inc = 60 * 1_000_000_000 _prefix = "T" _period_dtype_code = PeriodDtypeCode.T @@ -1110,6 +1196,35 @@ cdef class Minute(Tick): cdef class Second(Tick): + """ + Offset ``n`` seconds. + + Parameters + ---------- + n : int, default 1 + The number of seconds represented. + + See Also + -------- + :class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment. + + Examples + -------- + You can use the parameter ``n`` to represent a shift of n seconds. + + >>> from pandas.tseries.offsets import Second + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts.strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 15:00:00' + + >>> (ts + Second(n=10)).strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 15:00:10' + >>> (ts - Second(n=10)).strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 14:59:50' + + >>> (ts + Second(n=-10)).strftime('%a %d %b %Y %H:%M:%S') + 'Fri 09 Dec 2022 14:59:50' + """ _nanos_inc = 1_000_000_000 _prefix = "S" _period_dtype_code = PeriodDtypeCode.S From 84fb4a73ad2bcf9570d88e68c05510f4585d8796 Mon Sep 17 00:00:00 2001 From: Dirk Ulbricht Date: Sun, 6 Aug 2023 09:18:21 +0200 Subject: [PATCH 2/3] DOC: offsets removed trailing white spaces from Second, Min ute, Hour, Day --- 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 d598732c20c2f..db1e896a25ac2 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1104,7 +1104,7 @@ cdef class Day(Tick): Examples -------- You can use the parameter ``n`` to represent a shift of n days. - >>> from pandas.tseries.offsets import Day + >>> from pandas.tseries.offsets import Day >>> ts = pd.Timestamp(2022, 12, 9, 15) >>> ts.strftime('%a %d %b %Y %H:%M') 'Fri 09 Dec 2022 15:00' @@ -1140,7 +1140,7 @@ cdef class Hour(Tick): -------- You can use the parameter ``n`` to represent a shift of n hours. - >>> from pandas.tseries.offsets import Hour + >>> from pandas.tseries.offsets import Hour >>> ts = pd.Timestamp(2022, 12, 9, 15) >>> ts.strftime('%a %d %b %Y %H:%M') 'Fri 09 Dec 2022 15:00' @@ -1176,7 +1176,7 @@ cdef class Minute(Tick): -------- You can use the parameter ``n`` to represent a shift of n minutes. - >>> from pandas.tseries.offsets import Minute + >>> from pandas.tseries.offsets import Minute >>> ts = pd.Timestamp(2022, 12, 9, 15) >>> ts.strftime('%a %d %b %Y %H:%M:%S') 'Fri 09 Dec 2022 15:00:00' @@ -1212,7 +1212,7 @@ cdef class Second(Tick): -------- You can use the parameter ``n`` to represent a shift of n seconds. - >>> from pandas.tseries.offsets import Second + >>> from pandas.tseries.offsets import Second >>> ts = pd.Timestamp(2022, 12, 9, 15) >>> ts.strftime('%a %d %b %Y %H:%M:%S') 'Fri 09 Dec 2022 15:00:00' From 4bdfb6b44fd6399a40f0f9b083a1a81eba1f51f7 Mon Sep 17 00:00:00 2001 From: Dirk Ulbricht Date: Tue, 8 Aug 2023 20:26:32 +0200 Subject: [PATCH 3/3] DOC: updated offset methods sec, min, h,d (#54427) --- pandas/_libs/tslibs/offsets.pyx | 65 +++++++++++++++++---------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index db1e896a25ac2..958fe1181d309 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1104,18 +1104,19 @@ cdef class Day(Tick): Examples -------- You can use the parameter ``n`` to represent a shift of n days. + >>> from pandas.tseries.offsets import Day >>> ts = pd.Timestamp(2022, 12, 9, 15) - >>> ts.strftime('%a %d %b %Y %H:%M') - 'Fri 09 Dec 2022 15:00' + >>> ts + Timestamp('2022-12-09 15:00:00') - >>> (ts + Day()).strftime('%a %d %b %Y %H:%M') - 'Sat 10 Dec 2022 15:00' - >>> (ts - Day(4)).strftime('%a %d %b %Y %H:%M') - 'Mon 05 Dec 2022 15:00' + >>> ts + Day() + Timestamp('2022-12-10 15:00:00') + >>> ts - Day(4) + Timestamp('2022-12-05 15:00:00') - >>> (ts + Day(-4)).strftime('%a %d %b %Y %H:%M') - 'Mon 05 Dec 2022 15:00' + >>> ts + Day(-4) + Timestamp('2022-12-05 15:00:00') """ _nanos_inc = 24 * 3600 * 1_000_000_000 _prefix = "D" @@ -1142,16 +1143,16 @@ cdef class Hour(Tick): >>> from pandas.tseries.offsets import Hour >>> ts = pd.Timestamp(2022, 12, 9, 15) - >>> ts.strftime('%a %d %b %Y %H:%M') - 'Fri 09 Dec 2022 15:00' + >>> ts + Timestamp('2022-12-09 15:00:00') - >>> (ts + Hour()).strftime('%a %d %b %Y %H:%M') - 'Fri 09 Dec 2022 16:00' - >>> (ts - Hour(4)).strftime('%a %d %b %Y %H:%M') - 'Fri 09 Dec 2022 11:00' + >>> ts + Hour() + Timestamp('2022-12-09 16:00:00') + >>> ts - Hour(4) + Timestamp('2022-12-09 11:00:00') - >>> (ts + Hour(-4)).strftime('%a %d %b %Y %H:%M') - 'Fri 09 Dec 2022 11:00' + >>> ts + Hour(-4) + Timestamp('2022-12-09 11:00:00') """ _nanos_inc = 3600 * 1_000_000_000 _prefix = "H" @@ -1178,16 +1179,16 @@ cdef class Minute(Tick): >>> from pandas.tseries.offsets import Minute >>> ts = pd.Timestamp(2022, 12, 9, 15) - >>> ts.strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 15:00:00' + >>> ts + Timestamp('2022-12-09 15:00:00') - >>> (ts + Minute(n=10)).strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 15:10:00' - >>> (ts - Minute(n=10)).strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 14:50:00' + >>> ts + Minute(n=10) + Timestamp('2022-12-09 15:10:00') + >>> ts - Minute(n=10) + Timestamp('2022-12-09 14:50:00') - >>> (ts + Minute(n=-10)).strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 14:50:00' + >>> ts + Minute(n=-10) + Timestamp('2022-12-09 14:50:00') """ _nanos_inc = 60 * 1_000_000_000 _prefix = "T" @@ -1214,16 +1215,16 @@ cdef class Second(Tick): >>> from pandas.tseries.offsets import Second >>> ts = pd.Timestamp(2022, 12, 9, 15) - >>> ts.strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 15:00:00' + >>> ts + Timestamp('2022-12-09 15:00:00') - >>> (ts + Second(n=10)).strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 15:00:10' - >>> (ts - Second(n=10)).strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 14:59:50' + >>> ts + Second(n=10) + Timestamp('2022-12-09 15:00:10') + >>> ts - Second(n=10) + Timestamp('2022-12-09 14:59:50') - >>> (ts + Second(n=-10)).strftime('%a %d %b %Y %H:%M:%S') - 'Fri 09 Dec 2022 14:59:50' + >>> ts + Second(n=-10) + Timestamp('2022-12-09 14:59:50') """ _nanos_inc = 1_000_000_000 _prefix = "S"