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
59 changes: 58 additions & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,64 @@ def freq(self, value):
nanosecond = _field_accessor('nanosecond', 'ns',
"The nanoseconds of the datetime")
weekofyear = _field_accessor('weekofyear', 'woy',
"The week ordinal of the year")
"""
Copy link
Author

Choose a reason for hiding this comment

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

This is where E128 is still complaining a bit. I don't know what the nicest way is to resolve this since we're a bit unconventional with the _field_accessor accepting a docstring here. I could add tabs to the docstring, but it would make the code much less readable (as well cause ugly things to 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.

@TomAugspurger would love advice.

Copy link
Contributor

Choose a reason for hiding this comment

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

@koaning maybe just make a new variable called _weekofyear_doc and assign it to like

    weekofyear = _field_accessor('weekofyear', 'woy', _weekofyear_doc)

Copy link
Author

Choose a reason for hiding this comment

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

you'll get a lot of variables in that file, but that works for me. will make the change. thanks!

The week ordinal of the year.

Return the week ordinal of the year. Note that there can be
counter intuitive edge cases around the yearchange. For example
the first of january could be in week 52 of the previous year.
Monday indicates the start of a new week.

See Also
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Returns goes before See Also

Copy link
Author

Choose a reason for hiding this comment

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

well spotted. fixed.

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

Returns
-------
ndarray of integers indicating week

Examples
--------
>>> dates = pd.date_range("2016-12-31", "2017-01-08", freq="D")
>>> s = pd.Series(dates)
>>> pd.DataFrame({'date':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.

pep8: space after colons

Copy link
Author

Choose a reason for hiding this comment

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

oops. fixed in next commit.

date 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 what `series.dt.week` and `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
""")
week = weekofyear
dayofweek = _field_accessor('dayofweek', 'dow',
"The day of the week with Monday=0, Sunday=6")
Expand Down