Skip to content

DOC: update the series.dt.weekofyear docstring #20218

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

Closed
wants to merge 10 commits into from
64 changes: 62 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,9 +1706,69 @@ def freq(self, value):
"The microseconds of the datetime")
nanosecond = _field_accessor('nanosecond', 'ns',
"The nanoseconds of the datetime")
weekofyear = _field_accessor('weekofyear', 'woy',
"The week ordinal of the year")
_weekofyear_doc = """
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry could you add a trailing backslash to the end of this line? Then we don't have a blank line at the start of the docstring.

Copy link
Author

Choose a reason for hiding this comment

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

When I do that the validation script gives an error.

Docstring text (summary) should start in the line immediately after the opening quotes (not in the same line, or leaving a blank line in between)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nvm you're good then.

The week ordinal of the year.

Return the week ordinal of the year. Note that there can be
counter intuitive edge cases around a year change. For example
the first of january could be in week 52 of the previous year.
Monday indicates the start of a new week. This method is available
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a link to wikipedia (I think this goes by common week of year)

on both Series with datetime values or DatetimeIndex.

Returns
-------
ndarry
Copy link
Contributor

Choose a reason for hiding this comment

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

this returns an Index

Containing integers indicating the week number.

See Also
--------
pandas.Series.dt.week : Identical method.
pandas.Series.dt.weekofyear : Identical method.

Examples
--------
>>> dates = pd.date_range("2016-12-31", "2017-01-08", freq="D")
>>> s = pd.Series(dates)
>>> pd.DataFrame({'dt': s, 'week': s.dt.week, 'day': s.dt.strftime("%A")})
Copy link
Contributor

Choose a reason for hiding this comment

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

use s.dt.day_name()

dt week day
0 2016-12-31 52 Saturday
1 2017-01-01 52 Sunday
2 2017-01-02 1 Monday
3 2017-01-03 1 Tuesday
4 2017-01-04 1 Wednesday
5 2017-01-05 1 Thursday
6 2017-01-06 1 Friday
7 2017-01-07 1 Saturday
8 2017-01-08 1 Sunday

Note `pandas.Series.dt.week`/`pandas.Series.dt.weekofyear` are the same.

>>> s.dt.week
0 52
1 52
2 1
3 1
4 1
5 1
6 1
7 1
8 1
dtype: int64
>>> s.dt.weekofyear
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to repeat them, use weekofyear one

0 52
1 52
2 1
3 1
4 1
5 1
6 1
7 1
8 1
dtype: int64
"""
weekofyear = _field_accessor('weekofyear', 'woy', _weekofyear_doc)
week = weekofyear

dayofweek = _field_accessor('dayofweek', 'dow',
"The day of the week with Monday=0, Sunday=6")
weekday = dayofweek
Expand Down