Skip to content

Commit 10e5ad7

Browse files
CLN: Deprecate dayofweek/hello day_of_week (#9606) (#37390)
1 parent d2c0674 commit 10e5ad7

File tree

17 files changed

+76
-22
lines changed

17 files changed

+76
-22
lines changed

doc/redirects.csv

+10
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ generated/pandas.DatetimeIndex.date,../reference/api/pandas.DatetimeIndex.date
542542
generated/pandas.DatetimeIndex.day,../reference/api/pandas.DatetimeIndex.day
543543
generated/pandas.DatetimeIndex.day_name,../reference/api/pandas.DatetimeIndex.day_name
544544
generated/pandas.DatetimeIndex.dayofweek,../reference/api/pandas.DatetimeIndex.dayofweek
545+
generated/pandas.DatetimeIndex.day_of_week,../reference/api/pandas.DatetimeIndex.day_of_week
545546
generated/pandas.DatetimeIndex.dayofyear,../reference/api/pandas.DatetimeIndex.dayofyear
547+
generated/pandas.DatetimeIndex.day_of_year,../reference/api/pandas.DatetimeIndex.day_of_year
546548
generated/pandas.DatetimeIndex.floor,../reference/api/pandas.DatetimeIndex.floor
547549
generated/pandas.DatetimeIndex.freq,../reference/api/pandas.DatetimeIndex.freq
548550
generated/pandas.DatetimeIndex.freqstr,../reference/api/pandas.DatetimeIndex.freqstr
@@ -839,7 +841,9 @@ generated/pandas.option_context,../reference/api/pandas.option_context
839841
generated/pandas.Period.asfreq,../reference/api/pandas.Period.asfreq
840842
generated/pandas.Period.day,../reference/api/pandas.Period.day
841843
generated/pandas.Period.dayofweek,../reference/api/pandas.Period.dayofweek
844+
generated/pandas.Period.day_of_week,../reference/api/pandas.Period.day_of_week
842845
generated/pandas.Period.dayofyear,../reference/api/pandas.Period.dayofyear
846+
generated/pandas.Period.day_of_year,../reference/api/pandas.Period.day_of_year
843847
generated/pandas.Period.days_in_month,../reference/api/pandas.Period.days_in_month
844848
generated/pandas.Period.daysinmonth,../reference/api/pandas.Period.daysinmonth
845849
generated/pandas.Period.end_time,../reference/api/pandas.Period.end_time
@@ -850,7 +854,9 @@ generated/pandas.Period,../reference/api/pandas.Period
850854
generated/pandas.PeriodIndex.asfreq,../reference/api/pandas.PeriodIndex.asfreq
851855
generated/pandas.PeriodIndex.day,../reference/api/pandas.PeriodIndex.day
852856
generated/pandas.PeriodIndex.dayofweek,../reference/api/pandas.PeriodIndex.dayofweek
857+
generated/pandas.PeriodIndex.day_of_week,../reference/api/pandas.PeriodIndex.day_of_week
853858
generated/pandas.PeriodIndex.dayofyear,../reference/api/pandas.PeriodIndex.dayofyear
859+
generated/pandas.PeriodIndex.day_of_year,../reference/api/pandas.PeriodIndex.day_of_year
854860
generated/pandas.PeriodIndex.days_in_month,../reference/api/pandas.PeriodIndex.days_in_month
855861
generated/pandas.PeriodIndex.daysinmonth,../reference/api/pandas.PeriodIndex.daysinmonth
856862
generated/pandas.PeriodIndex.end_time,../reference/api/pandas.PeriodIndex.end_time
@@ -993,7 +999,9 @@ generated/pandas.Series.dt.date,../reference/api/pandas.Series.dt.date
993999
generated/pandas.Series.dt.day,../reference/api/pandas.Series.dt.day
9941000
generated/pandas.Series.dt.day_name,../reference/api/pandas.Series.dt.day_name
9951001
generated/pandas.Series.dt.dayofweek,../reference/api/pandas.Series.dt.dayofweek
1002+
generated/pandas.Series.dt.day_of_week,../reference/api/pandas.Series.dt.day_of_week
9961003
generated/pandas.Series.dt.dayofyear,../reference/api/pandas.Series.dt.dayofyear
1004+
generated/pandas.Series.dt.day_of_year,../reference/api/pandas.Series.dt.day_of_year
9971005
generated/pandas.Series.dt.days,../reference/api/pandas.Series.dt.days
9981006
generated/pandas.Series.dt.days_in_month,../reference/api/pandas.Series.dt.days_in_month
9991007
generated/pandas.Series.dt.daysinmonth,../reference/api/pandas.Series.dt.daysinmonth
@@ -1326,7 +1334,9 @@ generated/pandas.Timestamp.date,../reference/api/pandas.Timestamp.date
13261334
generated/pandas.Timestamp.day,../reference/api/pandas.Timestamp.day
13271335
generated/pandas.Timestamp.day_name,../reference/api/pandas.Timestamp.day_name
13281336
generated/pandas.Timestamp.dayofweek,../reference/api/pandas.Timestamp.dayofweek
1337+
generated/pandas.Timestamp.day_of_week,../reference/api/pandas.Timestamp.day_of_week
13291338
generated/pandas.Timestamp.dayofyear,../reference/api/pandas.Timestamp.dayofyear
1339+
generated/pandas.Timestamp.day_of_year,../reference/api/pandas.Timestamp.day_of_year
13301340
generated/pandas.Timestamp.days_in_month,../reference/api/pandas.Timestamp.days_in_month
13311341
generated/pandas.Timestamp.daysinmonth,../reference/api/pandas.Timestamp.daysinmonth
13321342
generated/pandas.Timestamp.dst,../reference/api/pandas.Timestamp.dst

doc/source/reference/arrays.rst

+4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Properties
6363
Timestamp.asm8
6464
Timestamp.day
6565
Timestamp.dayofweek
66+
Timestamp.day_of_week
6667
Timestamp.dayofyear
68+
Timestamp.day_of_year
6769
Timestamp.days_in_month
6870
Timestamp.daysinmonth
6971
Timestamp.fold
@@ -233,7 +235,9 @@ Properties
233235

234236
Period.day
235237
Period.dayofweek
238+
Period.day_of_week
236239
Period.dayofyear
240+
Period.day_of_year
237241
Period.days_in_month
238242
Period.daysinmonth
239243
Period.end_time

doc/source/reference/indexing.rst

+4
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,11 @@ Time/date components
345345
DatetimeIndex.time
346346
DatetimeIndex.timetz
347347
DatetimeIndex.dayofyear
348+
DatetimeIndex.day_of_year
348349
DatetimeIndex.weekofyear
349350
DatetimeIndex.week
350351
DatetimeIndex.dayofweek
352+
DatetimeIndex.day_of_week
351353
DatetimeIndex.weekday
352354
DatetimeIndex.quarter
353355
DatetimeIndex.tz
@@ -461,7 +463,9 @@ Properties
461463

462464
PeriodIndex.day
463465
PeriodIndex.dayofweek
466+
PeriodIndex.day_of_week
464467
PeriodIndex.dayofyear
468+
PeriodIndex.day_of_year
465469
PeriodIndex.days_in_month
466470
PeriodIndex.daysinmonth
467471
PeriodIndex.end_time

doc/source/reference/series.rst

+2
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ Datetime properties
319319
Series.dt.week
320320
Series.dt.weekofyear
321321
Series.dt.dayofweek
322+
Series.dt.day_of_week
322323
Series.dt.weekday
323324
Series.dt.dayofyear
325+
Series.dt.day_of_year
324326
Series.dt.quarter
325327
Series.dt.is_month_start
326328
Series.dt.is_month_end

doc/source/user_guide/timeseries.rst

+2
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,11 @@ There are several time/date properties that one can access from ``Timestamp`` or
803803
time,"Returns datetime.time (does not contain timezone information)"
804804
timetz,"Returns datetime.time as local time with timezone information"
805805
dayofyear,"The ordinal day of year"
806+
day_of_year,"The ordinal day of year"
806807
weekofyear,"The week ordinal of the year"
807808
week,"The week ordinal of the year"
808809
dayofweek,"The number of the day of the week with Monday=0, Sunday=6"
810+
day_of_week,"The number of the day of the week with Monday=0, Sunday=6"
809811
weekday,"The number of the day of the week with Monday=0, Sunday=6"
810812
quarter,"Quarter of the date: Jan-Mar = 1, Apr-Jun = 2, etc."
811813
days_in_month,"The number of days in the month of the datetime"

doc/source/whatsnew/v1.2.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ level-by-level basis.
207207

208208
Other enhancements
209209
^^^^^^^^^^^^^^^^^^
210+
- Added ``day_of_week``(compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`)
211+
- Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`)
210212
- Added :meth:`~DataFrame.set_flags` for setting table-wide flags on a ``Series`` or ``DataFrame`` (:issue:`28394`)
211213
- :meth:`DataFrame.applymap` now supports ``na_action`` (:issue:`23803`)
212214
- :class:`Index` with object dtype supports division and multiplication (:issue:`34160`)

pandas/_libs/tslibs/nattype.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,12 @@ class NaTType(_NaT):
357357

358358
week = property(fget=lambda self: np.nan)
359359
dayofyear = property(fget=lambda self: np.nan)
360+
day_of_year = property(fget=lambda self: np.nan)
360361
weekofyear = property(fget=lambda self: np.nan)
361362
days_in_month = property(fget=lambda self: np.nan)
362363
daysinmonth = property(fget=lambda self: np.nan)
363364
dayofweek = property(fget=lambda self: np.nan)
365+
day_of_week = property(fget=lambda self: np.nan)
364366

365367
# inject Timedelta properties
366368
days = property(fget=lambda self: np.nan)

pandas/_libs/tslibs/period.pyx

+18-15
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ cdef accessor _get_accessor_func(str field):
13731373
return <accessor>pweek
13741374
elif field == "day_of_year":
13751375
return <accessor>pday_of_year
1376-
elif field == "weekday":
1376+
elif field == "weekday" or field == "day_of_week":
13771377
return <accessor>pweekday
13781378
elif field == "days_in_month":
13791379
return <accessor>pdays_in_month
@@ -1475,6 +1475,9 @@ cdef class _Period(PeriodMixin):
14751475
PeriodDtypeBase _dtype
14761476
BaseOffset freq
14771477

1478+
dayofweek = _Period.day_of_week
1479+
dayofyear = _Period.day_of_year
1480+
14781481
def __cinit__(self, int64_t ordinal, BaseOffset freq):
14791482
self.ordinal = ordinal
14801483
self.freq = freq
@@ -1882,7 +1885,7 @@ cdef class _Period(PeriodMixin):
18821885
return self.weekofyear
18831886

18841887
@property
1885-
def dayofweek(self) -> int:
1888+
def day_of_week(self) -> int:
18861889
"""
18871890
Day of the week the period lies in, with Monday=0 and Sunday=6.
18881891

@@ -1900,33 +1903,33 @@ cdef class _Period(PeriodMixin):
19001903

19011904
See Also
19021905
--------
1903-
Period.dayofweek : Day of the week the period lies in.
1904-
Period.weekday : Alias of Period.dayofweek.
1906+
Period.day_of_week : Day of the week the period lies in.
1907+
Period.weekday : Alias of Period.day_of_week.
19051908
Period.day : Day of the month.
19061909
Period.dayofyear : Day of the year.
19071910

19081911
Examples
19091912
--------
19101913
>>> per = pd.Period('2017-12-31 22:00', 'H')
1911-
>>> per.dayofweek
1914+
>>> per.day_of_week
19121915
6
19131916

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

19171920
>>> per = pd.Period('2017-12-31 22:00', '4H')
1918-
>>> per.dayofweek
1921+
>>> per.day_of_week
19191922
6
1920-
>>> per.start_time.dayofweek
1923+
>>> per.start_time.day_of_week
19211924
6
19221925

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

19261929
>>> per = pd.Period('2018-01', 'M')
1927-
>>> per.dayofweek
1930+
>>> per.day_of_week
19281931
2
1929-
>>> per.end_time.dayofweek
1932+
>>> per.end_time.day_of_week
19301933
2
19311934
"""
19321935
base = self._dtype._dtype_code
@@ -1986,7 +1989,7 @@ cdef class _Period(PeriodMixin):
19861989
return self.dayofweek
19871990

19881991
@property
1989-
def dayofyear(self) -> int:
1992+
def day_of_year(self) -> int:
19901993
"""
19911994
Return the day of the year.
19921995

@@ -2002,19 +2005,19 @@ cdef class _Period(PeriodMixin):
20022005
See Also
20032006
--------
20042007
Period.day : Return the day of the month.
2005-
Period.dayofweek : Return the day of week.
2006-
PeriodIndex.dayofyear : Return the day of year of all indexes.
2008+
Period.day_of_week : Return the day of week.
2009+
PeriodIndex.day_of_year : Return the day of year of all indexes.
20072010

20082011
Examples
20092012
--------
20102013
>>> period = pd.Period("2015-10-23", freq='H')
2011-
>>> period.dayofyear
2014+
>>> period.day_of_year
20122015
296
20132016
>>> period = pd.Period("2012-12-31", freq='D')
2014-
>>> period.dayofyear
2017+
>>> period.day_of_year
20152018
366
20162019
>>> period = pd.Period("2013-01-01", freq='D')
2017-
>>> period.dayofyear
2020+
>>> period.day_of_year
20182021
1
20192022
"""
20202023
base = self._dtype._dtype_code

pandas/_libs/tslibs/timestamps.pyx

+4-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ cdef class _Timestamp(ABCTimestamp):
230230

231231
# higher than np.ndarray and np.matrix
232232
__array_priority__ = 100
233+
dayofweek = _Timestamp.day_of_week
234+
dayofyear = _Timestamp.day_of_year
233235

234236
def __hash__(_Timestamp self):
235237
if self.nanosecond:
@@ -538,14 +540,14 @@ cdef class _Timestamp(ABCTimestamp):
538540
return bool(ccalendar.is_leapyear(self.year))
539541

540542
@property
541-
def dayofweek(self) -> int:
543+
def day_of_week(self) -> int:
542544
"""
543545
Return day of the week.
544546
"""
545547
return self.weekday()
546548

547549
@property
548-
def dayofyear(self) -> int:
550+
def day_of_year(self) -> int:
549551
"""
550552
Return the day of the year.
551553
"""

pandas/core/arrays/datetimes.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps):
177177
"week",
178178
"weekday",
179179
"dayofweek",
180+
"day_of_week",
180181
"dayofyear",
182+
"day_of_year",
181183
"quarter",
182184
"days_in_month",
183185
"daysinmonth",
@@ -1533,16 +1535,18 @@ def weekofyear(self):
15331535
2017-01-08 6
15341536
Freq: D, dtype: int64
15351537
"""
1536-
dayofweek = _field_accessor("dayofweek", "dow", _dayofweek_doc)
1537-
weekday = dayofweek
1538+
day_of_week = _field_accessor("day_of_week", "dow", _dayofweek_doc)
1539+
dayofweek = day_of_week
1540+
weekday = day_of_week
15381541

1539-
dayofyear = _field_accessor(
1542+
day_of_year = _field_accessor(
15401543
"dayofyear",
15411544
"doy",
15421545
"""
15431546
The ordinal day of the year.
15441547
""",
15451548
)
1549+
dayofyear = day_of_year
15461550
quarter = _field_accessor(
15471551
"quarter",
15481552
"q",

pandas/core/arrays/period.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ class PeriodArray(PeriodMixin, dtl.DatelikeOps):
140140
"weekday",
141141
"week",
142142
"dayofweek",
143+
"day_of_week",
143144
"dayofyear",
145+
"day_of_year",
144146
"quarter",
145147
"qyear",
146148
"days_in_month",
@@ -381,12 +383,13 @@ def __arrow_array__(self, type=None):
381383
""",
382384
)
383385
week = weekofyear
384-
dayofweek = _field_accessor(
385-
"weekday",
386+
day_of_week = _field_accessor(
387+
"day_of_week",
386388
"""
387389
The day of the week with Monday=0, Sunday=6.
388390
""",
389391
)
392+
dayofweek = day_of_week
390393
weekday = dayofweek
391394
dayofyear = day_of_year = _field_accessor(
392395
"day_of_year",

pandas/core/indexes/datetimes.py

+2
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
164164
time
165165
timetz
166166
dayofyear
167+
day_of_year
167168
weekofyear
168169
week
169170
dayofweek
171+
day_of_week
170172
weekday
171173
quarter
172174
tz

pandas/core/indexes/period.py

+2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
9595
----------
9696
day
9797
dayofweek
98+
day_of_week
9899
dayofyear
100+
day_of_year
99101
days_in_month
100102
daysinmonth
101103
end_time

pandas/tests/generic/test_finalize.py

+2
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,9 @@ def test_datetime_method(method):
678678
"microsecond",
679679
"nanosecond",
680680
"dayofweek",
681+
"day_of_week",
681682
"dayofyear",
683+
"day_of_year",
682684
"quarter",
683685
"is_month_start",
684686
"is_month_end",

pandas/tests/indexes/datetimes/test_scalar_compat.py

+2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def test_dti_date_out_of_range(self, data):
3838
"field",
3939
[
4040
"dayofweek",
41+
"day_of_week",
4142
"dayofyear",
43+
"day_of_year",
4244
"quarter",
4345
"days_in_month",
4446
"is_month_start",

pandas/tests/indexes/period/test_period.py

+2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ def _check_all_fields(self, periodindex):
249249
"weekofyear",
250250
"week",
251251
"dayofweek",
252+
"day_of_week",
252253
"dayofyear",
254+
"day_of_year",
253255
"quarter",
254256
"qyear",
255257
"days_in_month",

0 commit comments

Comments
 (0)