diff --git a/asv_bench/benchmarks/period.py b/asv_bench/benchmarks/period.py index c8ba6c382cb64..e38305e7d681d 100644 --- a/asv_bench/benchmarks/period.py +++ b/asv_bench/benchmarks/period.py @@ -8,7 +8,8 @@ class PeriodProperties: params = (['M', 'min'], ['year', 'month', 'day', 'hour', 'minute', 'second', 'is_leap_year', 'quarter', 'qyear', 'week', 'daysinmonth', - 'dayofweek', 'dayofyear', 'start_time', 'end_time']) + 'days_in_month', 'dayofweek', 'day_of_week', 'dayofyear', + 'day_of_year', 'start_time', 'end_time']) param_names = ['freq', 'attr'] def setup(self, freq, attr): diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py index c6e56804c7b21..eb1fbcba84214 100644 --- a/asv_bench/benchmarks/timestamp.py +++ b/asv_bench/benchmarks/timestamp.py @@ -4,7 +4,7 @@ import pytz from pandas import Timestamp - +from pandas.util._decorators import deprecate class TimestampConstruction: @@ -37,6 +37,9 @@ class TimestampProperties: params = [_tzs, _freqs] param_names = ['tz', 'freq'] + deprecate('time_dayofweek', 'time_day_of_week', '0.25.0') + deprecate('time_dayofyear', 'time_day_of_year', '0.25.0') + def setup(self, tz, freq): self.ts = Timestamp('2017-08-25 08:16:14', tzinfo=tz, freq=freq) @@ -45,6 +48,9 @@ def time_tz(self, tz, freq): def time_dayofweek(self, tz, freq): self.ts.dayofweek + + def time_day_of_week(self, tz, freq): + self.ts.day_of_week def time_weekday_name(self, tz, freq): self.ts.day_name @@ -52,6 +58,9 @@ def time_weekday_name(self, tz, freq): def time_dayofyear(self, tz, freq): self.ts.dayofyear + def time_day_of_year(self, tz, freq): + self.ts.day_of_year + def time_week(self, tz, freq): self.ts.week diff --git a/doc/redirects.csv b/doc/redirects.csv index a7886779c97d5..cd79f23a01839 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -528,7 +528,9 @@ 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.day_of_week,../reference/api/pandas.DatetimeIndex.day_of_week generated/pandas.DatetimeIndex.dayofyear,../reference/api/pandas.DatetimeIndex.dayofyear +generated/pandas.DatetimeIndex.day_of_year,../reference/api/pandas.DatetimeIndex.day_of_year generated/pandas.DatetimeIndex.floor,../reference/api/pandas.DatetimeIndex.floor generated/pandas.DatetimeIndex.freq,../reference/api/pandas.DatetimeIndex.freq generated/pandas.DatetimeIndex.freqstr,../reference/api/pandas.DatetimeIndex.freqstr @@ -1005,7 +1007,9 @@ 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.day_of_week,../reference/api/pandas.Period.day_of_week generated/pandas.Period.dayofyear,../reference/api/pandas.Period.dayofyear +generated/pandas.Period.day_of_year,../reference/api/pandas.Period.day_of_year generated/pandas.Period.days_in_month,../reference/api/pandas.Period.days_in_month generated/pandas.Period.daysinmonth,../reference/api/pandas.Period.daysinmonth generated/pandas.Period.end_time,../reference/api/pandas.Period.end_time @@ -1016,7 +1020,9 @@ 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.day_of_week,../reference/api/pandas.PeriodIndex.day_of_week generated/pandas.PeriodIndex.dayofyear,../reference/api/pandas.PeriodIndex.dayofyear +generated/pandas.PeriodIndex.day_of_year,../reference/api/pandas.PeriodIndex.day_of_year generated/pandas.PeriodIndex.days_in_month,../reference/api/pandas.PeriodIndex.days_in_month generated/pandas.PeriodIndex.daysinmonth,../reference/api/pandas.PeriodIndex.daysinmonth generated/pandas.PeriodIndex.end_time,../reference/api/pandas.PeriodIndex.end_time @@ -1162,7 +1168,9 @@ 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.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.day_of_year,../reference/api/pandas.Series.dt.day_of_year 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 generated/pandas.Series.dt.daysinmonth,../reference/api/pandas.Series.dt.daysinmonth @@ -1507,7 +1515,9 @@ 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.day_of_week,../reference/api/pandas.Timestamp.day_of_week generated/pandas.Timestamp.dayofyear,../reference/api/pandas.Timestamp.dayofyear +generated/pandas.Timestamp.day_of_year,../reference/api/pandas.Timestamp.day_of_year generated/pandas.Timestamp.days_in_month,../reference/api/pandas.Timestamp.days_in_month generated/pandas.Timestamp.daysinmonth,../reference/api/pandas.Timestamp.daysinmonth generated/pandas.Timestamp.dst,../reference/api/pandas.Timestamp.dst diff --git a/doc/source/reference/arrays.rst b/doc/source/reference/arrays.rst index fb9a95b6736d5..70e4a4c2ad195 100644 --- a/doc/source/reference/arrays.rst +++ b/doc/source/reference/arrays.rst @@ -60,7 +60,9 @@ Properties Timestamp.asm8 Timestamp.day Timestamp.dayofweek + Timestamp.day_of_week Timestamp.dayofyear + Timestamp.day_of_year Timestamp.days_in_month Timestamp.daysinmonth Timestamp.fold @@ -228,7 +230,9 @@ Properties Period.day Period.dayofweek + Period.day_of_week Period.dayofyear + Period.day_of_year Period.days_in_month Period.daysinmonth Period.end_time diff --git a/doc/source/reference/indexing.rst b/doc/source/reference/indexing.rst index 42ebf648f299f..a0115c7270491 100644 --- a/doc/source/reference/indexing.rst +++ b/doc/source/reference/indexing.rst @@ -350,9 +350,11 @@ Time/Date Components DatetimeIndex.time DatetimeIndex.timetz DatetimeIndex.dayofyear + DatetimeIndex.day_of_year DatetimeIndex.weekofyear DatetimeIndex.week DatetimeIndex.dayofweek + DatetimeIndex.day_of_week DatetimeIndex.weekday DatetimeIndex.quarter DatetimeIndex.tz @@ -452,7 +454,9 @@ Properties PeriodIndex.day PeriodIndex.dayofweek + PeriodIndex.day_of_week PeriodIndex.dayofyear + PeriodIndex.day_of_year PeriodIndex.days_in_month PeriodIndex.daysinmonth PeriodIndex.end_time diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index b406893e3414a..636091dcd4b89 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -326,8 +326,10 @@ Datetime Properties Series.dt.week Series.dt.weekofyear Series.dt.dayofweek + Series.dt.day_of_week Series.dt.weekday Series.dt.dayofyear + Series.dt.day_of_year Series.dt.quarter Series.dt.is_month_start Series.dt.is_month_end diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index f559b0d073320..5b8630e202d0f 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -812,9 +812,11 @@ There are several time/date properties that one can access from ``Timestamp`` or time,"Returns datetime.time (does not contain timezone information)" timetz,"Returns datetime.time as local time with timezone information" dayofyear,"The ordinal day of year" + day_of_year,"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." diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 7f35a11e57b71..1679e6de81a88 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -313,10 +313,12 @@ class NaTType(_NaT): week = property(fget=lambda self: np.nan) dayofyear = property(fget=lambda self: np.nan) + day_of_year = property(fget=lambda self: np.nan) weekofyear = property(fget=lambda self: np.nan) days_in_month = property(fget=lambda self: np.nan) daysinmonth = property(fget=lambda self: np.nan) dayofweek = property(fget=lambda self: np.nan) + day_of_week = property(fget=lambda self: np.nan) weekday_name = property(fget=lambda self: np.nan) # inject Timedelta properties diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index c68d686ff2bf2..bd7c23515acd0 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1749,8 +1749,10 @@ cdef class _Period: -------- Period.end_time : Return the end Timestamp. Period.dayofyear : Return the day of year. + Period.day_of_year : Return the day of year. Period.daysinmonth : Return the days in that month. Period.dayofweek : Return the day of the week. + Period.day_of_week : Return the day of the week. Examples -------- @@ -1832,7 +1834,9 @@ cdef class _Period: See Also -------- Period.dayofweek : Get the day of the week. + Period.day_of_week : Get the day of the week. Period.dayofyear : Get the day of the year. + Period.day_of_year : Get the day of the year. Examples -------- @@ -1976,9 +1980,11 @@ cdef class _Period: 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. + Period.day_of_year : Day of the year. Examples -------- @@ -2027,9 +2033,11 @@ cdef class _Period: 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. + Period.day_of_year : Day of the year. Examples -------- @@ -2061,7 +2069,7 @@ cdef class _Period: return self.dayofweek @property - def dayofyear(self): + def day_of_year(self): """ Return the day of the year. @@ -2078,18 +2086,18 @@ cdef class _Period: -------- Period.day : Return the day of the month. Period.dayofweek : Return the day of week. - PeriodIndex.dayofyear : Return the day of year of all indexes. + PeriodIndex.day_of_year : Return the day of year of all indexes. Examples -------- >>> period = pd.Period("2015-10-23", freq='H') - >>> period.dayofyear + >>> period.day_of_year 296 >>> period = pd.Period("2012-12-31", freq='D') - >>> period.dayofyear + >>> period.day_of_year 366 >>> period = pd.Period("2013-01-01", freq='D') - >>> period.dayofyear + >>> period.day_of_year 1 """ base, mult = get_freq_code(self.freq) @@ -2190,7 +2198,7 @@ cdef class _Period: See Also -------- Period.days_in_month : Return the days of the month. - Period.dayofyear : Return the day of the year. + Period.day_of_year : Return the day of the year. Examples -------- diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index c8c6efda30fae..ad11ee4f4e39b 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -645,7 +645,7 @@ default 'raise' return self.day_name() @property - def dayofyear(self): + def day_of_year(self): """ Return the day of the year. """ diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index bf7bd0668595d..fa24eb06b4736 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -247,7 +247,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, _object_ops = ['weekday_name', 'freq', 'tz'] _field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second', 'weekofyear', 'week', 'weekday', 'dayofweek', - 'dayofyear', 'quarter', 'days_in_month', + 'day_of_year', 'quarter', 'days_in_month', 'daysinmonth', 'microsecond', 'nanosecond'] _other_ops = ['date', 'time', 'timetz'] @@ -1360,8 +1360,8 @@ def date(self): 'weekday_name', "The name of day in a week (ex: Friday)\n\n.. deprecated:: 0.23.0") - dayofyear = _field_accessor('dayofyear', 'doy', - "The ordinal day of the year.") + day_of_year = _field_accessor('day_of_year', 'doy', + "The ordinal day of the year.") quarter = _field_accessor('quarter', 'q', "The quarter of the date.") days_in_month = _field_accessor( 'days_in_month', diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 8a6640e11ad74..f78e3f65a440b 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -140,7 +140,7 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps): _object_ops = ['start_time', 'end_time', 'freq'] _field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second', 'weekofyear', 'weekday', 'week', 'dayofweek', - 'dayofyear', 'quarter', 'qyear', + 'day_of_year', 'quarter', 'qyear', 'days_in_month', 'daysinmonth'] _datetimelike_ops = _field_ops + _object_ops + _bool_ops _datetimelike_methods = ['strftime', 'to_timestamp', 'asfreq'] @@ -302,8 +302,8 @@ def __array__(self, dtype=None): dayofweek = _field_accessor('dayofweek', 10, "The day of the week with Monday=0, Sunday=6") weekday = dayofweek - dayofyear = day_of_year = _field_accessor('dayofyear', 9, - "The ordinal day of the year") + day_of_year = _field_accessor('day_of_year', 9, + "The ordinal day of the year") quarter = _field_accessor('quarter', 2, "The quarter of the date") qyear = _field_accessor('qyear', 1) days_in_month = _field_accessor('days_in_month', 11, diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 1bf3cb86811cb..793af230b5a29 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -168,7 +168,7 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin): date time timetz - dayofyear + day_of_year weekofyear week dayofweek diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index b20b0c6f853d9..81115816ea529 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -119,7 +119,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin): ---------- day dayofweek - dayofyear + day_of_year days_in_month daysinmonth end_time diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index 91e614cd516b9..71eb2deef0fca 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -107,8 +107,8 @@ def test_datetimeindex_accessors(self): assert dti.microsecond[0] == 0 assert dti.dayofweek[0] == 3 - assert dti.dayofyear[0] == 1 - assert dti.dayofyear[120] == 121 + assert dti.day_of_year[0] == 1 + assert dti.day_of_year[120] == 121 assert dti.weekofyear[0] == 1 assert dti.weekofyear[120] == 18 @@ -145,7 +145,7 @@ def test_datetimeindex_accessors(self): assert len(dti.second) == 365 assert len(dti.microsecond) == 365 assert len(dti.dayofweek) == 365 - assert len(dti.dayofyear) == 365 + assert len(dti.day_of_year) == 365 assert len(dti.weekofyear) == 365 assert len(dti.quarter) == 365 assert len(dti.is_month_start) == 365 diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index ae14396c75398..82557560ba4fa 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -38,7 +38,7 @@ def test_dti_date_out_of_range(self, data): DatetimeIndex(data) @pytest.mark.parametrize('field', [ - 'dayofweek', 'dayofyear', 'week', 'weekofyear', 'quarter', + 'dayofweek', 'day_of_year', 'week', 'weekofyear', 'quarter', 'days_in_month', 'is_month_start', 'is_month_end', 'is_quarter_start', 'is_quarter_end', 'is_year_start', 'is_year_end', 'weekday_name']) diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 2f3f15101e7ca..37f39e5bce204 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -249,7 +249,7 @@ def test_period_index_length(self): def test_fields(self): # year, month, day, hour, minute - # second, weekofyear, week, dayofweek, weekday, dayofyear, quarter + # second, weekofyear, week, dayofweek, weekday, day_of_year, quarter # qyear pi = period_range(freq='A', start='1/1/2001', end='12/1/2005') self._check_all_fields(pi) @@ -282,7 +282,7 @@ def test_fields(self): def _check_all_fields(self, periodindex): fields = ['year', 'month', 'day', 'hour', 'minute', 'second', - 'weekofyear', 'week', 'dayofweek', 'dayofyear', + 'weekofyear', 'week', 'dayofweek', 'day_of_year', 'quarter', 'qyear', 'days_in_month'] periods = list(periodindex) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index cc91bef525eff..32de36056fca0 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1053,10 +1053,10 @@ def test_daily(self): ts = Series(np.random.randn(len(rng)), index=rng) annual = pivot_table(DataFrame(ts), index=ts.index.year, - columns=ts.index.dayofyear) + columns=ts.index.day_of_year) annual.columns = annual.columns.droplevel(0) - doy = np.asarray(ts.index.dayofyear) + doy = np.asarray(ts.index.day_of_year) for i in range(1, 367): subset = ts[doy == i] diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 2a765086af403..8ad71d815a1cd 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -855,6 +855,7 @@ def test_properties_daily(self): assert b_date.day == 1 assert b_date.weekday == 0 assert b_date.dayofyear == 1 + assert b_date.day_of_year == 1 assert b_date.days_in_month == 31 assert Period(freq='B', year=2012, month=2, day=1).days_in_month == 29 @@ -867,6 +868,7 @@ def test_properties_daily(self): assert d_date.day == 1 assert d_date.weekday == 0 assert d_date.dayofyear == 1 + assert d_date.day_of_year == 1 assert d_date.days_in_month == 31 assert Period(freq='D', year=2012, month=2, day=1).days_in_month == 29 @@ -883,6 +885,7 @@ def test_properties_hourly(self): assert h_date.day == 1 assert h_date.weekday == 0 assert h_date.dayofyear == 1 + assert h_date.day_of_year == 1 assert h_date.hour == 0 assert h_date.days_in_month == 31 assert Period(freq='H', year=2012, month=2, day=1, @@ -898,6 +901,7 @@ def test_properties_minutely(self): assert t_date.day == 1 assert t_date.weekday == 0 assert t_date.dayofyear == 1 + assert t_date.day_of_year == 1 assert t_date.hour == 0 assert t_date.minute == 0 assert t_date.days_in_month == 31 @@ -915,6 +919,7 @@ def test_properties_secondly(self): assert s_date.day == 1 assert s_date.weekday == 0 assert s_date.dayofyear == 1 + assert s_date.day_of_year == 1 assert s_date.hour == 0 assert s_date.minute == 0 assert s_date.second == 0 diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 773b4e6f21a19..ab079d1f2aeb5 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -65,8 +65,10 @@ def check(value, equal): check(ts.microsecond, 100) check(ts.nanosecond, 1) check(ts.dayofweek, 6) + check(ts.day_of_week, 6) check(ts.quarter, 2) check(ts.dayofyear, 130) + check(ts.day_of_year, 130) check(ts.week, 19) check(ts.daysinmonth, 31) check(ts.daysinmonth, 31) @@ -85,8 +87,10 @@ def check(value, equal): check(ts.microsecond, 0) check(ts.nanosecond, 0) check(ts.dayofweek, 2) + check(ts.day_of_week, 2) check(ts.quarter, 4) check(ts.dayofyear, 365) + check(ts.day_of_year, 365) check(ts.week, 1) check(ts.daysinmonth, 31)