Skip to content

DOC: update the pandas.Series.dt.dayofweek docstring #20230

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 4 commits into from
Closed
Changes from all commits
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
63 changes: 61 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,67 @@ def freq(self, value):
weekofyear = _field_accessor('weekofyear', 'woy',
"The week ordinal of the year")
week = weekofyear
dayofweek = _field_accessor('dayofweek', 'dow',
"The day of the week with Monday=0, Sunday=6")
_dayofweek_doc = """
The day of the week with Monday=0, Sunday=6.

Return the day of the week. It is assumed the week starts on
Monday, which is denoted by 0 and ends on Sunday which is denoted
by 6. This method is available on both Series with datetime
values or DatetimeIndex

See Also
--------
pandas.Series.dt.dayofweek : Identical method.
Copy link
Contributor

Choose a reason for hiding this comment

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

you can say alias

Copy link
Contributor

Choose a reason for hiding this comment

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

add day_name as well

Copy link
Author

Choose a reason for hiding this comment

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

I've changed it into this now.

    See Also
    --------
    pandas.Series.dt.dayofweek : alias
    pandas.Series.dt.weekday : alias
    pandas.Series.dt.day_name : 
        Return the day names of the DateTimeIndex with specified locale.

Note that the docstring for dayofweek and weekday is the exact same.

    dayofweek = _field_accessor('dayofweek', 'dow', _dayofweek_doc)
    weekday = dayofweek

pandas.Series.dt.weekday : Identical method.

Returns
-------
ndarray
Copy link
Contributor

Choose a reason for hiding this comment

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

these return an Index

Containing integers indicating the day number.

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

we have a method day_name for this

Copy link
Author

Choose a reason for hiding this comment

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

did not know this. i was confused because i saw weekday_name but this was depricated. i've changed the code and added day_name to the "see also" too.

Copy link
Contributor

Choose a reason for hiding this comment

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

change the code here as well and simply use day_name

>>> pd.DataFrame({'dt': s, 'num': s.dt.weekday, 'day': day_name})
dt num day
0 2016-12-31 5 Saturday
1 2017-01-01 6 Sunday
2 2017-01-02 0 Monday
3 2017-01-03 1 Tuesday
4 2017-01-04 2 Wednesday
5 2017-01-05 3 Thursday
6 2017-01-06 4 Friday
7 2017-01-07 5 Saturday
8 2017-01-08 6 Sunday

Note: `pandas.Series.dt.dayofweek`/`pandas.Series.dt.weekday` are the same.
Copy link
Contributor

Choose a reason for hiding this comment

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

you are operating on an Index here (and the doc-string goes for both)

Copy link
Author

Choose a reason for hiding this comment

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

@jreback could you elaborate? im not sure what you mean with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

ignore my comment here


>>> s.dt.dayofweek
0 5
1 6
2 0
3 1
4 2
5 3
6 4
7 5
8 6
dtype: int64
>>> s.dt.weekday
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 show both, just use dayofweek

0 5
1 6
2 0
3 1
4 2
5 3
6 4
7 5
8 6
dtype: int64
"""
dayofweek = _field_accessor('dayofweek', 'dow', _dayofweek_doc)
weekday = dayofweek

weekday_name = _field_accessor(
Expand Down