Skip to content
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

DOC: add missing parameters to DateOffset classes: Milli, Micro and Nano #56336

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Changes from 1 commit
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
99 changes: 96 additions & 3 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1194,20 +1194,107 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Timestamp('2022-12-09 15:00:00.010000')
>>> 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
_creso = NPY_DATETIMEUNIT.NPY_FR_ms


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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Timestamp('2022-12-09 15:00:00.001000')
>>> 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
_creso = NPY_DATETIMEUNIT.NPY_FR_us


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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Timestamp('2022-12-09 15:00:00.000001')
>>> 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
Expand Down Expand Up @@ -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
--------
Expand Down Expand Up @@ -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
--------
Expand Down
Loading