Skip to content

day_of_week #26094

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
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PeriodProperties(object):
params = (['M', 'min'],
['year', 'month', 'day', 'hour', 'minute', 'second',
'is_leap_year', 'quarter', 'qyear', 'week', 'daysinmonth',
'dayofweek', 'dayofyear', 'start_time', 'end_time'])
'day_of_week', 'dayofyear', 'start_time', 'end_time'])
param_names = ['freq', 'attr']

def setup(self, freq, attr):
Expand Down
5 changes: 4 additions & 1 deletion asv_bench/benchmarks/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def time_tz(self, tz, freq):
self.ts.tz

def time_dayofweek(self, tz, freq):
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 remove the original one

self.ts.dayofweek
self.ts.day_of_week

def time_day_of_week(self, tz, freq):
Copy link
Contributor

Choose a reason for hiding this comment

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

indent error here

self.ts.day_of_week

def time_weekday_name(self, tz, freq):
self.ts.day_name
Expand Down
15 changes: 10 additions & 5 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ generated/pandas.DatetimeIndex.ceil,../reference/api/pandas.DatetimeIndex.ceil
generated/pandas.DatetimeIndex.date,../reference/api/pandas.DatetimeIndex.date
generated/pandas.DatetimeIndex.day,../reference/api/pandas.DatetimeIndex.day
generated/pandas.DatetimeIndex.day_name,../reference/api/pandas.DatetimeIndex.day_name
generated/pandas.DatetimeIndex.dayofweek,../reference/api/pandas.DatetimeIndex.dayofweek
generated/pandas.DatetimeIndex.dayofweek,../reference/api/pandas.DatetimeIndex.day_of_week
generated/pandas.DatetimeIndex.day_of_week,../reference/api/pandas.DatetimeIndex.day_of_week
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think you need to add the new one, we don't have original pages for it

generated/pandas.DatetimeIndex.dayofyear,../reference/api/pandas.DatetimeIndex.dayofyear
generated/pandas.DatetimeIndex.floor,../reference/api/pandas.DatetimeIndex.floor
generated/pandas.DatetimeIndex.freq,../reference/api/pandas.DatetimeIndex.freq
Expand Down Expand Up @@ -1004,7 +1005,8 @@ generated/pandas.Panel.where,../reference/api/pandas.Panel.where
generated/pandas.Panel.xs,../reference/api/pandas.Panel.xs
generated/pandas.Period.asfreq,../reference/api/pandas.Period.asfreq
generated/pandas.Period.day,../reference/api/pandas.Period.day
generated/pandas.Period.dayofweek,../reference/api/pandas.Period.dayofweek
generated/pandas.Period.dayofweek,../reference/api/pandas.Period.day_of_week
generated/pandas.Period.day_of_week,../reference/api/pandas.Period.day_of_week
generated/pandas.Period.dayofyear,../reference/api/pandas.Period.dayofyear
generated/pandas.Period.days_in_month,../reference/api/pandas.Period.days_in_month
generated/pandas.Period.daysinmonth,../reference/api/pandas.Period.daysinmonth
Expand All @@ -1015,7 +1017,8 @@ generated/pandas.Period.hour,../reference/api/pandas.Period.hour
generated/pandas.Period,../reference/api/pandas.Period
generated/pandas.PeriodIndex.asfreq,../reference/api/pandas.PeriodIndex.asfreq
generated/pandas.PeriodIndex.day,../reference/api/pandas.PeriodIndex.day
generated/pandas.PeriodIndex.dayofweek,../reference/api/pandas.PeriodIndex.dayofweek
generated/pandas.PeriodIndex.dayofweek,../reference/api/pandas.PeriodIndex.day_of_week
generated/pandas.PeriodIndex.day_of_week,../reference/api/pandas.PeriodIndex.day_of_week
generated/pandas.PeriodIndex.dayofyear,../reference/api/pandas.PeriodIndex.dayofyear
generated/pandas.PeriodIndex.days_in_month,../reference/api/pandas.PeriodIndex.days_in_month
generated/pandas.PeriodIndex.daysinmonth,../reference/api/pandas.PeriodIndex.daysinmonth
Expand Down Expand Up @@ -1161,7 +1164,8 @@ generated/pandas.Series.dt.components,../reference/api/pandas.Series.dt.componen
generated/pandas.Series.dt.date,../reference/api/pandas.Series.dt.date
generated/pandas.Series.dt.day,../reference/api/pandas.Series.dt.day
generated/pandas.Series.dt.day_name,../reference/api/pandas.Series.dt.day_name
generated/pandas.Series.dt.dayofweek,../reference/api/pandas.Series.dt.dayofweek
generated/pandas.Series.dt.dayofweek,../reference/api/pandas.Series.dt.day_of_week
generated/pandas.Series.dt.day_of_week,../reference/api/pandas.Series.dt.day_of_week
generated/pandas.Series.dt.dayofyear,../reference/api/pandas.Series.dt.dayofyear
generated/pandas.Series.dt.days,../reference/api/pandas.Series.dt.days
generated/pandas.Series.dt.days_in_month,../reference/api/pandas.Series.dt.days_in_month
Expand Down Expand Up @@ -1506,7 +1510,8 @@ generated/pandas.Timestamp.ctime,../reference/api/pandas.Timestamp.ctime
generated/pandas.Timestamp.date,../reference/api/pandas.Timestamp.date
generated/pandas.Timestamp.day,../reference/api/pandas.Timestamp.day
generated/pandas.Timestamp.day_name,../reference/api/pandas.Timestamp.day_name
generated/pandas.Timestamp.dayofweek,../reference/api/pandas.Timestamp.dayofweek
generated/pandas.Timestamp.dayofweek,../reference/api/pandas.Timestamp.day_of_week
generated/pandas.Timestamp.day_of_week,../reference/api/pandas.Timestamp.day_of_week
generated/pandas.Timestamp.dayofyear,../reference/api/pandas.Timestamp.dayofyear
generated/pandas.Timestamp.days_in_month,../reference/api/pandas.Timestamp.days_in_month
generated/pandas.Timestamp.daysinmonth,../reference/api/pandas.Timestamp.daysinmonth
Expand Down
2 changes: 2 additions & 0 deletions doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Properties
Timestamp.asm8
Timestamp.day
Timestamp.dayofweek
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 remove the original from the docs

Timestamp.day_of_week
Timestamp.dayofyear
Timestamp.days_in_month
Timestamp.daysinmonth
Expand Down Expand Up @@ -223,6 +224,7 @@ Properties

Period.day
Period.dayofweek
Period.day_of_week
Period.dayofyear
Period.days_in_month
Period.daysinmonth
Expand Down
4 changes: 2 additions & 2 deletions doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Time/Date Components
DatetimeIndex.dayofyear
DatetimeIndex.weekofyear
DatetimeIndex.week
DatetimeIndex.dayofweek
DatetimeIndex.day_of_week
DatetimeIndex.weekday
DatetimeIndex.quarter
DatetimeIndex.tz
Expand Down Expand Up @@ -451,7 +451,7 @@ Properties
:toctree: api/

PeriodIndex.day
PeriodIndex.dayofweek
PeriodIndex.day_of_week
PeriodIndex.dayofyear
PeriodIndex.days_in_month
PeriodIndex.daysinmonth
Expand Down
2 changes: 1 addition & 1 deletion doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Datetime Properties
Series.dt.nanosecond
Series.dt.week
Series.dt.weekofyear
Series.dt.dayofweek
Series.dt.day_of_week
Series.dt.weekday
Series.dt.dayofyear
Series.dt.quarter
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ There are several time/date properties that one can access from ``Timestamp`` or
dayofyear,"The ordinal day of year"
weekofyear,"The week ordinal of the year"
week,"The week ordinal of the year"
dayofweek,"The number of the day of the week with Monday=0, Sunday=6"
day_of_week,"The number of the day of the week with Monday=0, Sunday=6"
weekday,"The number of the day of the week with Monday=0, Sunday=6"
weekday_name,"The name of the day in a week (ex: Friday)"
quarter,"Quarter of the date: Jan-Mar = 1, Apr-Jun = 2, etc."
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.16.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Bug Fixes
- Bug where ``Panel.from_dict`` does not set dtype when specified (:issue:`10058`)
- Bug in ``Index.union`` raises ``AttributeError`` when passing array-likes. (:issue:`10149`)
- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``dayofyear``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek`` properties. (:issue:`10096`)
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek``, ``day_of_week`` properties. (:issue:`10096`)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't change the original what's new notes

- Bug in Index repr when using the ``max_seq_items=None`` setting (:issue:`10182`).
- Bug in getting timezone data with ``dateutil`` on various platforms ( :issue:`9059`, :issue:`8639`, :issue:`9663`, :issue:`10121`)
- Bug in displaying datetimes with mixed frequencies; display 'ms' datetimes to the proper precision. (:issue:`10170`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class NaTType(_NaT):
weekofyear = property(fget=lambda self: np.nan)
days_in_month = property(fget=lambda self: np.nan)
daysinmonth = property(fget=lambda self: np.nan)
day_of_week = property(fget=lambda self: np.nan)
dayofweek = property(fget=lambda self: np.nan)
weekday_name = property(fget=lambda self: np.nan)

Expand Down Expand Up @@ -386,7 +387,6 @@ class NaTType(_NaT):
# ----------------------------------------------------------------------
# The remaining methods have docstrings copy/pasted from the analogous
# Timestamp methods.

strptime = _make_error_func('strptime', # noqa:E128
"""
Timestamp.strptime(string, format)
Expand Down
53 changes: 52 additions & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,57 @@ cdef class _Period(object):
"""
return self.weekofyear

@property
def day_of_week(self):
"""
Day of the week the period lies in, with Monday=0 and Sunday=6.

If the period frequency is lower than daily (e.g. hourly), and the
period spans over multiple days, the day at the start of the period is
used.

If the frequency is higher than daily (e.g. monthly), the last day
of the period is used.

Returns
-------
int
Day of the week.

See Also
--------
Period.day_of_week : Day of the week the period lies in.
Period.weekday : Alias of Period.day_of_week.
Period.day : Day of the month.
Period.dayofyear : Day of the year.

Examples
--------
>>> per = pd.Period('2017-12-31 22:00', 'H')
>>> per.day_of_week
6

For periods that span over multiple days, the day at the beginning of
the period is returned.

>>> per = pd.Period('2017-12-31 22:00', '4H')
>>> per.day_of_week
6
>>> per.start_time.day_of_week
6

For periods with a frequency higher than days, the last day of the
period is returned.

>>> per = pd.Period('2018-01', 'M')
>>> per.day_of_week
2
>>> per.end_time.day_of_week
2
"""
base, mult = get_freq_code(self.freq)
return pweekday(self.ordinal, base)

@property
def dayofweek(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

just do

dayofweek = day_of_week

"""
Expand All @@ -1976,7 +2027,7 @@ cdef class _Period(object):

See Also
--------
Period.dayofweek : Day of the week the period lies in.
Period.day_of_week : Day of the week the period lies in.
Period.weekday : Alias of Period.dayofweek.
Period.day : Day of the month.
Period.dayofyear : Day of the year.
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,12 @@ class Timestamp(_Timestamp):
return Period(self, freq=freq)

@property
def dayofweek(self):
def day_of_week(self):
"""
Return day of whe week.
"""
return self.weekday()
dayofweek = day_of_week

def day_name(self, locale=None):
"""
Expand Down
11 changes: 6 additions & 5 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin,
'is_year_end', 'is_leap_year']
_object_ops = ['weekday_name', 'freq', 'tz']
_field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second',
'weekofyear', 'week', 'weekday', 'dayofweek',
'weekofyear', 'week', 'weekday', 'dayofweek', 'day_of_week',
'dayofyear', 'quarter', 'days_in_month',
'daysinmonth', 'microsecond',
'nanosecond']
Expand Down Expand Up @@ -1338,14 +1338,14 @@ def date(self):

See Also
--------
Series.dt.dayofweek : Alias.
Series.dt.day_of_week : Alias.
Series.dt.weekday : Alias.
Series.dt.day_name : Returns the name of the day of the week.

Examples
--------
>>> s = pd.date_range('2016-12-31', '2017-01-08', freq='D').to_series()
>>> s.dt.dayofweek
>>> s.dt.day_of_week
2016-12-31 5
2017-01-01 6
2017-01-02 0
Expand All @@ -1357,8 +1357,9 @@ def date(self):
2017-01-08 6
Freq: D, dtype: int64
"""
dayofweek = _field_accessor('dayofweek', 'dow', _dayofweek_doc)
weekday = dayofweek
day_of_week = _field_accessor('day_of_week', 'dow', _dayofweek_doc)
dayofweek = day_of_week
weekday = day_of_week

weekday_name = _field_accessor(
'weekday_name',
Expand Down
9 changes: 5 additions & 4 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
_bool_ops = ['is_leap_year']
_object_ops = ['start_time', 'end_time', 'freq']
_field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second',
'weekofyear', 'weekday', 'week', 'dayofweek',
'weekofyear', 'weekday', 'week', 'dayofweek', 'day_of_week',
'dayofyear', 'quarter', 'qyear',
'days_in_month', 'daysinmonth']
_datetimelike_ops = _field_ops + _object_ops + _bool_ops
Expand Down Expand Up @@ -299,9 +299,10 @@ def __array__(self, dtype=None):
second = _field_accessor('second', 7, "The second of the period")
weekofyear = _field_accessor('week', 8, "The week ordinal of the year")
week = weekofyear
dayofweek = _field_accessor('dayofweek', 10,
"The day of the week with Monday=0, Sunday=6")
weekday = dayofweek
day_of_week = _field_accessor(
'day_of_week', 10, "The day of the week with Monday=0, Sunday=6")
dayofweek = day_of_week
weekday = day_of_week
dayofyear = day_of_year = _field_accessor('dayofyear', 9,
"The ordinal day of the year")
quarter = _field_accessor('quarter', 2, "The quarter of the date")
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin):
weekofyear
week
dayofweek
day_of_week
weekday
quarter
tz
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
----------
day
dayofweek
day_of_week
dayofyear
days_in_month
daysinmonth
Expand Down