Skip to content

Backport PR #52352 on branch 2.0.x (DOC: update documentation for YearBegin) #52374

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
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
20 changes: 18 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2310,13 +2310,29 @@ cdef class YearEnd(YearOffset):

cdef class YearBegin(YearOffset):
"""
DateOffset increments between calendar year begin dates.
DateOffset of one year at beginning.

YearBegin goes to the next date which is a start of the year.

See Also
--------
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.

Examples
--------
>>> ts = pd.Timestamp(2022, 1, 1)
>>> ts = pd.Timestamp(2022, 12, 1)
>>> ts + pd.offsets.YearBegin()
Timestamp('2023-01-01 00:00:00')

>>> ts = pd.Timestamp(2023, 1, 1)
>>> ts + pd.offsets.YearBegin()
Timestamp('2024-01-01 00:00:00')

If you want to get the start of the current year:

>>> ts = pd.Timestamp(2023, 1, 1)
>>> pd.offsets.YearBegin().rollback(ts)
Timestamp('2023-01-01 00:00:00')
"""

_default_month = 1
Expand Down