-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
Hello @koaning! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on March 10, 2018 at 21:39 Hours UTC |
Mhm. Strange, locally I didn't seem to have PEP8 issues. Will check! |
pandas/core/indexes/datetimes.py
Outdated
@@ -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") | |||
""" |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomAugspurger would love advice.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
pandas/core/indexes/datetimes.py
Outdated
the first of january could be in week 52 of the previous year. | ||
Monday indicates the start of a new week. | ||
|
||
See Also |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well spotted. fixed.
pandas/core/indexes/datetimes.py
Outdated
-------- | ||
>>> 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")}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8: space after colons
There was a problem hiding this comment.
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.
you can see the new output of the validation script below:
|
@TomAugspurger should be good to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple small ones I missed first time around. Ping me here or in chat when you're done.
@@ -1706,9 +1706,67 @@ 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 = """ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
pandas/core/indexes/datetimes.py
Outdated
|
||
Returns | ||
------- | ||
ndarray of integers indicating the week number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thikn
days : ndarray
integers indicating the week number
ndarray is the type, the rest is the ddescription.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, what you're suggesting is different than the docstring guide for the sprint.
Returns
-------
int
The sum of `num1` and `num2`
example found here: https://python-sprints.github.io/pandas/guide/pandas_docstring.html
pandas/core/indexes/datetimes.py
Outdated
7 2017-01-07 1 Saturday | ||
8 2017-01-08 1 Sunday | ||
|
||
Note that `series.dt.week` and `series.dt.weekofyear` are the same. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
series -> Series
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
General question @TomAugspurger : how do we deal with the fact this is docstring for both DatetimeIndex and Series.dt ? |
Good question. How about just noting that "This method is available on both Series with datetime values or DatetimeIndex" in the extended summary? And then both in the example. |
@TomAugspurger will add that. @jorisvandenbossche picking up gitter chat here.
Do we want both properties to have the same docstring? If so, do we mind the verbose example that explains you could do both? |
I think same docstring is fine. |
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 |
There was a problem hiding this comment.
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)
|
||
Returns | ||
------- | ||
ndarry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this returns an Index
-------- | ||
>>> 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")}) |
There was a problem hiding this comment.
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()
7 1 | ||
8 1 | ||
dtype: int64 | ||
>>> s.dt.weekofyear |
There was a problem hiding this comment.
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
Closing as stale. Also, the code this PR is based on does not live there anymore. |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.