From d1aa17c36abc562c17a68c095374e54e71e9ccb9 Mon Sep 17 00:00:00 2001 From: Vinita Parasrampuria Date: Mon, 4 Dec 2023 20:05:36 -0500 Subject: [PATCH 1/3] add parameters to milli, micro and nano --- pandas/_libs/tslibs/offsets.pyx | 99 ++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 47e507a0150e2..bd1a97d0fc29c 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1194,6 +1194,35 @@ cdef class Second(Tick): cdef class Milli(Tick): + """ + Offset ``n`` milliseconds. + + Parameters + ---------- + n : int, default 1 + The number of milliseconds 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 milliseconds. + + >>> from pandas.tseries.offsets import Milli + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts + Timestamp('2022-12-09 15:00:00') + + >>> ts + Milli(n=10) + Timestamp('2022-12-09 15:00:00.010000') + >>> ts - Milli(n=10) + Timestamp('2022-12-09 14:59:59.990000') + + >>> ts + Milli(n=-10) + Timestamp('2022-12-09 14:59:59.990000') + """ _nanos_inc = 1_000_000 _prefix = "ms" _period_dtype_code = PeriodDtypeCode.L @@ -1201,6 +1230,35 @@ cdef class Milli(Tick): cdef class Micro(Tick): + """ + Offset ``n`` microseconds. + + Parameters + ---------- + n : int, default 1 + The number of microseconds 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 microseconds. + + >>> from pandas.tseries.offsets import Micro + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts + Timestamp('2022-12-09 15:00:00') + + >>> ts + Micro(n=1000) + Timestamp('2022-12-09 15:00:00.001000') + >>> ts - Micro(n=1000) + Timestamp('2022-12-09 14:59:59.999000') + + >>> ts + Micro(n=-1000) + Timestamp('2022-12-09 14:59:59.999000') + """ _nanos_inc = 1000 _prefix = "us" _period_dtype_code = PeriodDtypeCode.U @@ -1208,6 +1266,35 @@ cdef class Micro(Tick): cdef class Nano(Tick): + """ + Offset ``n`` nanoseconds. + + Parameters + ---------- + n : int, default 1 + The number of nanoseconds 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 nanoseconds. + + >>> from pandas.tseries.offsets import Nano + >>> ts = pd.Timestamp(2022, 12, 9, 15) + >>> ts + Timestamp('2022-12-09 15:00:00') + + >>> ts + Nano(n=1000) + Timestamp('2022-12-09 15:00:00.000001') + >>> ts - Nano(n=1000) + Timestamp('2022-12-09 14:59:59.999999') + + >>> ts + Nano(n=-1000) + Timestamp('2022-12-09 14:59:59.999999') + """ _nanos_inc = 1 _prefix = "ns" _period_dtype_code = PeriodDtypeCode.N @@ -3073,9 +3160,12 @@ cdef class SemiMonthEnd(SemiMonthOffset): Parameters ---------- - n : int + n : int, default 1 + The number of months represented. normalize : bool, default False + Normalize start/end dates to midnight before generating date range. day_of_month : int, {1, 3,...,27}, default 15 + A specific integer for the day of the month. Examples -------- @@ -3113,9 +3203,12 @@ cdef class SemiMonthBegin(SemiMonthOffset): Parameters ---------- - n : int + n : int, default 1 + The number of months represented. normalize : bool, default False - day_of_month : int, {2, 3,...,27}, default 15 + Normalize start/end dates to midnight before generating date range. + day_of_month : int, {1, 3,...,27}, default 15 + A specific integer for the day of the month. Examples -------- From 39fd22dae7c8f8ea500212e6996cebabf90596aa Mon Sep 17 00:00:00 2001 From: Vinita Parasrampuria Date: Tue, 5 Dec 2023 13:12:45 -0500 Subject: [PATCH 2/3] corrected spaces between docstring of Milli,Micro, Nano --- pandas/_libs/tslibs/offsets.pyx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index bd1a97d0fc29c..a2bcc863291e0 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1217,6 +1217,7 @@ cdef class Milli(Tick): >>> ts + Milli(n=10) Timestamp('2022-12-09 15:00:00.010000') + >>> ts - Milli(n=10) Timestamp('2022-12-09 14:59:59.990000') @@ -1253,6 +1254,7 @@ cdef class Micro(Tick): >>> ts + Micro(n=1000) Timestamp('2022-12-09 15:00:00.001000') + >>> ts - Micro(n=1000) Timestamp('2022-12-09 14:59:59.999000') @@ -1289,6 +1291,7 @@ cdef class Nano(Tick): >>> ts + Nano(n=1000) Timestamp('2022-12-09 15:00:00.000001') + >>> ts - Nano(n=1000) Timestamp('2022-12-09 14:59:59.999999') From 59c8275b3ecceae1e85a3ade7f4a20685b018df5 Mon Sep 17 00:00:00 2001 From: Vinita Parasrampuria Date: Tue, 5 Dec 2023 16:28:14 -0500 Subject: [PATCH 3/3] removed whitespaces in Nano class --- 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 a2bcc863291e0..3ea8fbf69b28b 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1291,7 +1291,7 @@ cdef class Nano(Tick): >>> ts + Nano(n=1000) Timestamp('2022-12-09 15:00:00.000001') - + >>> ts - Nano(n=1000) Timestamp('2022-12-09 14:59:59.999999')