Skip to content

DOC: add missing parameters to offsets classes: Second, Minute, Hour and Day #54427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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