-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Fix copy-pasted name in .day_name
docstring
#22544
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
You can simply remove See https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-4-returns-or-yields |
@WillAyd Actually, I prefer it that way, did not know it was allowed in Pandas documentation. 😇 Changed it and force-pushed the commit. |
Do these pass the validate_docstring script? I think there is at least a missing period at the end of the descriptions that we should probably just clean up while touching. Maybe a couple more |
Codecov Report
@@ Coverage Diff @@
## master #22544 +/- ##
==========================================
- Coverage 92.04% 92.04% -0.01%
==========================================
Files 169 169
Lines 50787 50787
==========================================
- Hits 46746 46745 -1
- Misses 4041 4042 +1
Continue to review full report at Codecov.
|
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.
As mentioned above if you could run these docstrings against the validation script and fix any issues would be ideal. Should be easy enough to do in one pass
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.
The changes look great.
But as @WillAyd said, if you don't mind taking care of the whole docstring, that would be very useful.
Meaning:
- Replace the parameter type from
string
tostr
- Capitalize the first letter of the parameter description, and finish it with period
- Move that
None
means English locale from the type line, to the description of the parameter line. - Finish the returns description with a period
- Add a simple example
Thanks!
Thanks all for your feedback. Updated the docstrings with some of the @datapythonista suggestions (did not add any examples though). I was unable to run As a side note, did you ever think about releasing that docstring checker as a separate package? I bet many other projects could benefit from it. 😊 |
Looks like you need to build the C extensions python setup.py build_ext --inplace -j 4 Not aware of a conversation to have as a separate package but @gfyoung might have some thoughts on that as well |
@WillAyd Yeah, that failed too with an error, that's when I stopped trying. 😂 I think I just missed the C++ compiler. May try again later... |
@WillAyd Yeah, I was only missing a C++ compiler. Validated the docstrings. No errors found. 👍 |
pandas/core/arrays/datetimes.py
Outdated
locale determining the language in which to return the month name | ||
locale : str | ||
Locale determining the language in which to return the month name. | ||
Default is `None` (English locale). |
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.
Instead of saying this here simply say locale : str, optional
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.
Sorry my previous comment was misleading, let me add more detail.
In the first line, after the name of the parameter and the colon, we have the (Python) type or types, and then the default value, and nothing else (e.g. param_name : int or str, default 0
). In case the default value is None
and this None
is just a flag to indicate something, we use instead of default None
the word optional
. As a example, if fillna(value=None)
means that the None
is the value used to impute, we will still use default None
. If None
meant that we won't impute anything, we would have optional
instead.
What we need to have in this case is that None
means that 'English locale' will be used. But anything except the format mentioned before should go in the description. Besides consistency, the reason is that at some point it'd be nice to be able to parse all the information in the line of the type. And if we have explanations there, they'll be a problem.
You have more documentation here: https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-3-parameters
pandas/core/arrays/datetimes.py
Outdated
locale determining the language in which to return the day name | ||
locale : str | ||
Locale determining the language in which to return the day name. | ||
Default is `None` (English locale). |
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.
Same comment
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.
Thanks for the changes @Peque, looking better.
Besides those comments, do you think you can add a simple example? I think it'd add a lot of value to let people understand easier what the method does.
pandas/core/arrays/datetimes.py
Outdated
locale determining the language in which to return the month name | ||
locale : str | ||
Locale determining the language in which to return the month name. | ||
Default is `None` (English locale). |
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.
Sorry my previous comment was misleading, let me add more detail.
In the first line, after the name of the parameter and the colon, we have the (Python) type or types, and then the default value, and nothing else (e.g. param_name : int or str, default 0
). In case the default value is None
and this None
is just a flag to indicate something, we use instead of default None
the word optional
. As a example, if fillna(value=None)
means that the None
is the value used to impute, we will still use default None
. If None
meant that we won't impute anything, we would have optional
instead.
What we need to have in this case is that None
means that 'English locale' will be used. But anything except the format mentioned before should go in the description. Besides consistency, the reason is that at some point it'd be nice to be able to parse all the information in the line of the type. And if we have explanations there, they'll be a problem.
You have more documentation here: https://python-sprints.github.io/pandas/guide/pandas_docstring.html#section-3-parameters
pandas/core/arrays/datetimes.py
Outdated
month_names : Index | ||
Index of day names | ||
Index | ||
Index of day names. | ||
|
||
.. versionadded:: 0.23.0 |
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 the versionadded
would be more useful / standard after the description, not here at the end. @WillAyd what do you think?
1b473a7
to
937ff6b
Compare
I uploaded some changes to better match the preferred style and add simple examples (this time I read the style guide 😇). PS: in the style guide that you shared with me, the first example is missing dots after descriptions. That may be misleading for the lazy (like me) that only read the first example and "infer" the rules. 😜 |
locale determining the language in which to return the month name | ||
locale : str, optional | ||
Locale determining the language in which to return the month name. | ||
Default is English locale. |
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.
Where is pandas making the default English? Haven't looked in detail but assumed this would be system dependent
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 would expect that to be system independent (when programming, I'd rather have predictable results).
Code is implemented in get_date_name_field()
:
pandas/pandas/_libs/tslibs/fields.pyx
Lines 102 to 103 in 86e8f23
if locale is None: | |
names = np.array(DAYS_FULL, dtype=np.object_) |
pandas/pandas/_libs/tslibs/fields.pyx
Lines 117 to 118 in 86e8f23
if locale is None: | |
names = np.array(MONTHS_FULL, dtype=np.object_) |
DAYS_FULL
and MONTHS_FULL
are hard-coded in Pandas:
pandas/pandas/_libs/tslibs/ccalendar.pyx
Lines 39 to 48 in 86e8f23
MONTHS_FULL = ['', 'January', 'February', 'March', 'April', 'May', 'June', | |
'July', 'August', 'September', 'October', 'November', | |
'December'] | |
MONTH_NUMBERS = {name: num for num, name in enumerate(MONTHS)} | |
MONTH_ALIASES = {(num + 1): name for num, name in enumerate(MONTHS)} | |
MONTH_TO_CAL_NUM = {name: num + 1 for num, name in enumerate(MONTHS)} | |
DAYS = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'] | |
DAYS_FULL = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', | |
'Saturday', 'Sunday'] |
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.
The idea was for day_name
to replace the depreciated weekday_name
which defaulted to hardcoded english names (without localization support).
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.
agree this should say the default is based on the locale
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.
@jreback As you can see in the code snippets above, it is not based on the locale. The default is always English.
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.
@jreback I do not think the code I am running is relevant here. Unless you refer to a trivial example like the one I added in the docstring (but why would you need that?):
idx = pd.DatetimeIndex(start='2018-09-02', freq='D', periods=3)
idx.day_name()
Can you explain why you still say the default when locale=None
is based on the system's locale? I checked the tests, the code and the behavior and everything seems to prove otherwise: the default when locale=None
is English, and hence the proposed docstring. Did you check anything?
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.
@jreback If you tell me exactly what changes to the current docstring you have on your mind (it seems other reviewers are okay with it), I may better understand what you are saying. ❤️
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.
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.
@mroeschke Yeah, but I do prefer the current behavior, so I would rather not open that issue (and note I am not a native English speaker nor live in an English country).
When programming, I prefer everything in English by default. 😜
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.
Gotcha @Peque. I hold a similar opinion for API transition sake.
Therefore, I think there's no action with this docstring here as far as I'm concerned.
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.
lgtm - @datapythonista merge away
locale determining the language in which to return the month name | ||
locale : str, optional | ||
Locale determining the language in which to return the month name. | ||
Default is English locale. |
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.
agree this should say the default is based on the locale
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.
lgtm, added couple of suggestions that I think could make the examples a bit simpler.
Regarding the locale I think you're just misunderstanding each other.
pandas/core/arrays/datetimes.py
Outdated
-------- | ||
>>> idx = pd.DatetimeIndex(start='2018-09', freq='M', periods=3) | ||
>>> idx.month_name() | ||
Index(['September', 'October', 'November'], dtype='object') |
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.
If you don't mind, can you first show idx
(i.e. >>> idx
after creating the index). Also, if we use '2018-01' it'd make the example more obvious.
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.
Sure, will change it and upload it later today. 👍
About the locale discussion, I too think it must be a misunderstanding. With an average of 10 words per comment, I am having a hard time trying to understand what he tries to say. 😅
If you understand both of us, could you help us? 😂
pandas/core/arrays/datetimes.py
Outdated
-------- | ||
>>> idx = pd.DatetimeIndex(start='2018-09-02', freq='D', periods=3) | ||
>>> idx.day_name() | ||
Index(['Sunday', 'Monday', 'Tuesday'], dtype='object') |
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.
Same as before.
- To fix confusing `month_index` return name in `day_name` method - To better match the preferred docstring style. - To add simple examples.
Hello @Peque! Thanks for updating the PR.
|
@datapythonista Updated the PR showing the |
thanks @Peque |
Just a small change... Feel free to close and include this change in any other typo-fixing commit if you like. 😊