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 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
35 changes: 29 additions & 6 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2490,13 +2490,36 @@ cdef class SemiMonthBegin(SemiMonthOffset):

cdef class Week(SingleConstructorOffset):
"""
Weekly offset.
Weekly offset.
Copy link
Member

Choose a reason for hiding this comment

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

please don't change the indendation


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

Examples
---------
## Below examples explain the usage of this object.
## Importing modules
import pandas as pd
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is necessary, can you try without?


date_format = "%Y-%m-%d"
date_object = pd.to_datetime("2023-01-13",format = date_format)
print(date_object)
## 2023-01-13 00:00:00
Copy link
Member

Choose a reason for hiding this comment

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

this isn't how we write examples, please check https://pandas.pydata.org/docs/development/contributing_docstring.html


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

date_next_Monday = date_object + pd.tseries.offsets.Week(weekday=0)
print(date_next_Monday)
#2023-01-16 00:00:00

date_next_Sunday = date_object + pd.tseries.offsets.Week(weekday=6)
print(date_next_Sunday)
#2023-01-15 00:00:00
"""

_inc = timedelta(weeks=1)
_prefix = "W"
Expand Down