Skip to content

DOC: add examples to offsets.YearEnd #52942

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 1 commit into from
Apr 26, 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
22 changes: 19 additions & 3 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2291,13 +2291,29 @@ cdef class BYearBegin(YearOffset):

cdef class YearEnd(YearOffset):
"""
DateOffset increments between calendar year ends.
DateOffset increments between calendar year end dates.

YearEnd goes to the next date which is the end of the year.

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

Examples
--------
>>> ts = pd.Timestamp(2022, 1, 1)
>>> ts + pd.offsets.YearEnd()
Timestamp('2022-12-31 00:00:00')

>>> ts = pd.Timestamp(2022, 12, 31)
>>> ts + pd.offsets.YearEnd()
Timestamp('2023-12-31 00:00:00')

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

>>> ts = pd.Timestamp(2022, 12, 31)
>>> pd.offsets.YearEnd().rollback(ts)
Timestamp('2022-12-31 00:00:00')
"""

_default_month = 12
Expand All @@ -2316,9 +2332,9 @@ cdef class YearEnd(YearOffset):

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

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

See Also
--------
Expand Down