Skip to content

Enhanced the documentation and added examples in pandas tseries offsets Week class #50732

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 15 commits into from
Jan 17, 2023
Merged
Changes from 10 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
28 changes: 22 additions & 6 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2778,17 +2778,33 @@ cdef class SemiMonthBegin(SemiMonthOffset):
cdef class Week(SingleConstructorOffset):
"""
Weekly offset.

Parameters
----------
weekday : int or None, default None
Always generate specific day of week. 0 for Monday.
Always generate specific day of week. 0 for Monday and 6 for Sunday.

Examples
See Also
--------
>>> ts = pd.Timestamp(2022, 1, 1)
>>> ts + pd.offsets.Week()
Timestamp('2022-01-08 00:00:00')
pd.tseries.offsets.WeekOfMonth : Describes monthly dates like "the Tuesday of the 2nd week of each month".

Examples
---------
Comment on lines +2794 to +2795
Copy link
Member

Choose a reason for hiding this comment

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

just noticed, I think the underscores need to be the same length as the title

could you please also build this docstring locally and screenshot it and check it looks alright?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Hi @MarcoGorelli, it looks like this. It looks fine to me :D but should i add one more commit?

Copy link
Member

@MarcoGorelli MarcoGorelli Jan 17, 2023

Choose a reason for hiding this comment

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

that's not the rendered docstring, see https://pandas.pydata.org/docs/dev/development/contributing_documentation.html#building-the-documentation for how to build it

something like

cd doc
python make.py clean && python make.py --single pandas.tseries.offsets.Week

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Hey @MarcoGorelli , this is the rendered docstring, does this work?


>>> date_object = pd.Timestamp("2023-01-13")
>>> date_object
2023-01-13 00:00:00

>>> date_plus_one_week = date_object + pd.tseries.offsets.Week(n=1)
>>> date_plus_one_week
2023-01-20 00:00:00

>>> date_next_monday = date_object + pd.tseries.offsets.Week(weekday=0)
>>> date_next_monday
2023-01-16 00:00:00

>>> date_next_sunday = date_object + pd.tseries.offsets.Week(weekday=6)
>>> date_next_sunday
2023-01-15 00:00:00
"""

_inc = timedelta(weeks=1)
Expand Down