Skip to content

Commit

Permalink
DOC: add missing parameters to offsets classes: Second, Minute, Hour …
Browse files Browse the repository at this point in the history
…and Day (pandas-dev#54427)

* DOC: add missing parameters to offsets classes: Second, Hour and Day

* DOC: offsets removed trailing white spaces from Second, Min
ute, Hour, Day

* DOC: updated offset methods sec, min, h,d (pandas-dev#54427)
  • Loading branch information
dullibri authored and mroeschke committed Aug 18, 2023
1 parent 637cb72 commit 1d5921f
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1089,27 +1089,143 @@ 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
Timestamp('2022-12-09 15:00:00')
>>> ts + Day()
Timestamp('2022-12-10 15:00:00')
>>> ts - Day(4)
Timestamp('2022-12-05 15:00:00')
>>> ts + Day(-4)
Timestamp('2022-12-05 15:00:00')
"""
_nanos_inc = 24 * 3600 * 1_000_000_000
_prefix = "D"
_period_dtype_code = PeriodDtypeCode.D
_creso = NPY_DATETIMEUNIT.NPY_FR_D


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
Timestamp('2022-12-09 15:00:00')
>>> ts + Hour()
Timestamp('2022-12-09 16:00:00')
>>> ts - Hour(4)
Timestamp('2022-12-09 11:00:00')
>>> ts + Hour(-4)
Timestamp('2022-12-09 11:00:00')
"""
_nanos_inc = 3600 * 1_000_000_000
_prefix = "H"
_period_dtype_code = PeriodDtypeCode.H
_creso = NPY_DATETIMEUNIT.NPY_FR_h


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
Timestamp('2022-12-09 15:00: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)
Timestamp('2022-12-09 14:50:00')
"""
_nanos_inc = 60 * 1_000_000_000
_prefix = "T"
_period_dtype_code = PeriodDtypeCode.T
_creso = NPY_DATETIMEUNIT.NPY_FR_m


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
Timestamp('2022-12-09 15:00:00')
>>> 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)
Timestamp('2022-12-09 14:59:50')
"""
_nanos_inc = 1_000_000_000
_prefix = "S"
_period_dtype_code = PeriodDtypeCode.S
Expand Down

0 comments on commit 1d5921f

Please sign in to comment.