From b0cba8e9a83ba7e868e2524d03d3b247dd61d3c3 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 24 Oct 2020 18:34:15 -0400 Subject: [PATCH 01/10] CLN: Deprecate dayofweek/hello day_of_week (#9606) Rename dayofweek properties in Period, Datetime, and PeriodArray classes. Add day_of_week property to respective tests for each class. --- pandas/_libs/tslibs/nattype.pyx | 3 ++- pandas/_libs/tslibs/period.pyx | 23 +++++++++++-------- pandas/_libs/tslibs/timestamps.pyx | 9 +++++++- pandas/core/arrays/datetimes.py | 6 +++-- pandas/core/arrays/period.py | 6 +++-- pandas/core/indexes/datetimes.py | 1 + pandas/core/indexes/period.py | 1 + pandas/tests/generic/test_finalize.py | 2 ++ .../indexes/datetimes/test_scalar_compat.py | 2 ++ pandas/tests/indexes/period/test_period.py | 2 ++ .../tests/scalar/timestamp/test_timestamp.py | 4 ++++ 11 files changed, 44 insertions(+), 15 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 3a628f997e5d6..a3e90ef77edca 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -361,7 +361,8 @@ class NaTType(_NaT): 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) + # inject Timedelta properties days = property(fget=lambda self: np.nan) seconds = property(fget=lambda self: np.nan) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 27402c8d255b6..0ade26f6494ed 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1373,7 +1373,7 @@ cdef accessor _get_accessor_func(str field): return pweek elif field == "day_of_year": return pday_of_year - elif field == "weekday": + elif field == "weekday" or field == "day_of_week": return pweekday elif field == "days_in_month": return pdays_in_month @@ -1882,7 +1882,7 @@ cdef class _Period(PeriodMixin): return self.weekofyear @property - def dayofweek(self) -> int: + def day_of_week(self) -> int: """ Day of the week the period lies in, with Monday=0 and Sunday=6. @@ -1900,38 +1900,43 @@ cdef class _Period(PeriodMixin): See Also -------- - Period.dayofweek : Day of the week the period lies in. - Period.weekday : Alias of Period.dayofweek. + 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.dayofweek + >>> 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.dayofweek + >>> per.day_of_week 6 - >>> per.start_time.dayofweek + >>> 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.dayofweek + >>> per.day_of_week 2 - >>> per.end_time.dayofweek + >>> per.end_time.day_of_week 2 """ base = self._dtype._dtype_code return pweekday(self.ordinal, base) + @property + def dayofweek(self) -> int: + """This property is deprecated. Please use day_of_week instead.""" + return self.day_of_week + @property def weekday(self) -> int: """ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index a8f6c60bcb300..7cbe1d394cc30 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -538,12 +538,19 @@ cdef class _Timestamp(ABCTimestamp): return bool(ccalendar.is_leapyear(self.year)) @property - def dayofweek(self) -> int: + def day_of_week(self) -> int: """ Return day of the week. """ return self.weekday() + @property + def dayofweek(self) -> int: + """ + Deprecated. Use day_of_week instead. + """ + return self.day_of_week + @property def dayofyear(self) -> int: """ diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 0780dcfef23cc..12152909e7ad7 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -177,6 +177,7 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps): "week", "weekday", "dayofweek", + "day_of_week", "dayofyear", "quarter", "days_in_month", @@ -1533,8 +1534,9 @@ def weekofyear(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 dayofyear = _field_accessor( "dayofyear", diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index c77350d5f54bf..ae720b51cea25 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -140,6 +140,7 @@ class PeriodArray(PeriodMixin, dtl.DatelikeOps): "weekday", "week", "dayofweek", + "day_of_week", "dayofyear", "quarter", "qyear", @@ -381,12 +382,13 @@ def __arrow_array__(self, type=None): """, ) week = weekofyear - dayofweek = _field_accessor( - "weekday", + day_of_week = _field_accessor( + "day_of_week", """ The day of the week with Monday=0, Sunday=6. """, ) + dayofweek = day_of_week weekday = dayofweek dayofyear = day_of_year = _field_accessor( "day_of_year", diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 11417e0b3317e..023c443134d96 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -161,6 +161,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin): weekofyear week dayofweek + day_of_week weekday quarter tz diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 41968c5972ea5..a69d2b5abe1b0 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -95,6 +95,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index): ---------- day dayofweek + day_of_week dayofyear days_in_month daysinmonth diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 211d86c89cde7..25399446c5c35 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -678,6 +678,8 @@ def test_datetime_method(method): "microsecond", "nanosecond", "dayofweek", + # Add better named field for GH-9606 + "day_of_week", "dayofyear", "quarter", "is_month_start", diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index 0d39e034905d2..bf9fc9008ac92 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -38,6 +38,8 @@ def test_dti_date_out_of_range(self, data): "field", [ "dayofweek", + # Add better named field for GH-9606 + "day_of_week", "dayofyear", "quarter", "days_in_month", diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 8467fde0f7021..6e0b6eafb3db7 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -249,6 +249,8 @@ def _check_all_fields(self, periodindex): "weekofyear", "week", "dayofweek", + # Add better named field for GH-9606 + "day_of_week", "dayofyear", "quarter", "qyear", diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index cee7ac450e411..c0d40dd0aa42b 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -26,6 +26,7 @@ def test_properties_business(self): ts = Timestamp("2017-10-01", freq="B") control = Timestamp("2017-10-01") assert ts.dayofweek == 6 + assert ts.day_of_week == 6 assert not ts.is_month_start # not a weekday assert not ts.is_quarter_start # not a weekday # Control case: non-business is month/qtr start @@ -35,6 +36,7 @@ def test_properties_business(self): ts = Timestamp("2017-09-30", freq="B") control = Timestamp("2017-09-30") assert ts.dayofweek == 5 + assert ts.day_of_week == 5 assert not ts.is_month_end # not a weekday assert not ts.is_quarter_end # not a weekday # Control case: non-business is month/qtr start @@ -61,6 +63,7 @@ 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.week, 19) @@ -81,6 +84,7 @@ 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.week, 1) From 65595fba07631bcbacf02b021b4e56d7fcc02cc0 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 24 Oct 2020 18:49:25 -0400 Subject: [PATCH 02/10] Test precommit hook From e65e7b61bbfdd8ced4d0991e3590c7141de21771 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 24 Oct 2020 18:50:03 -0400 Subject: [PATCH 03/10] Retest precommit From 2aab957f0bb558f911287fff462473e3c5dad1e2 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 24 Oct 2020 19:01:36 -0400 Subject: [PATCH 04/10] Fix whitespace --- pandas/_libs/tslibs/nattype.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index a3e90ef77edca..bd57e107d3d2e 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -362,7 +362,7 @@ class NaTType(_NaT): daysinmonth = property(fget=lambda self: np.nan) dayofweek = property(fget=lambda self: np.nan) day_of_week = property(fget=lambda self: np.nan) - + # inject Timedelta properties days = property(fget=lambda self: np.nan) seconds = property(fget=lambda self: np.nan) From e1684b6568aa3d789bf3bde5da42767bc0891be6 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 24 Oct 2020 21:55:58 -0400 Subject: [PATCH 05/10] CLN: Resolve comments from @arw2019 Alias dep. function instead of extra property Remove comments from test files --- pandas/_libs/tslibs/period.pyx | 8 +++----- pandas/_libs/tslibs/timestamps.pyx | 9 ++------- pandas/tests/generic/test_finalize.py | 1 - pandas/tests/indexes/datetimes/test_scalar_compat.py | 1 - pandas/tests/indexes/period/test_period.py | 1 - 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 0ade26f6494ed..1cd34be60ca2d 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1475,6 +1475,9 @@ cdef class _Period(PeriodMixin): PeriodDtypeBase _dtype BaseOffset freq + # Alias dayofweek function to day_of_week (GH-9606) + dayofweek = _Period.day_of_week + def __cinit__(self, int64_t ordinal, BaseOffset freq): self.ordinal = ordinal self.freq = freq @@ -1932,11 +1935,6 @@ cdef class _Period(PeriodMixin): base = self._dtype._dtype_code return pweekday(self.ordinal, base) - @property - def dayofweek(self) -> int: - """This property is deprecated. Please use day_of_week instead.""" - return self.day_of_week - @property def weekday(self) -> int: """ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 7cbe1d394cc30..e59a57e662522 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -230,6 +230,8 @@ cdef class _Timestamp(ABCTimestamp): # higher than np.ndarray and np.matrix __array_priority__ = 100 + # Alias dayofweek function to day_of_week (GH-9606) + dayofweek = _Timestamp.day_of_week def __hash__(_Timestamp self): if self.nanosecond: @@ -544,13 +546,6 @@ cdef class _Timestamp(ABCTimestamp): """ return self.weekday() - @property - def dayofweek(self) -> int: - """ - Deprecated. Use day_of_week instead. - """ - return self.day_of_week - @property def dayofyear(self) -> int: """ diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index 25399446c5c35..f2010a2042870 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -678,7 +678,6 @@ def test_datetime_method(method): "microsecond", "nanosecond", "dayofweek", - # Add better named field for GH-9606 "day_of_week", "dayofyear", "quarter", diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index bf9fc9008ac92..f397388b82aec 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -38,7 +38,6 @@ def test_dti_date_out_of_range(self, data): "field", [ "dayofweek", - # Add better named field for GH-9606 "day_of_week", "dayofyear", "quarter", diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 6e0b6eafb3db7..1d412e8325ed4 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -249,7 +249,6 @@ def _check_all_fields(self, periodindex): "weekofyear", "week", "dayofweek", - # Add better named field for GH-9606 "day_of_week", "dayofyear", "quarter", From 9320a7d122b86edbecb795b3e0dc0c54e558dfea Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 24 Oct 2020 22:21:39 -0400 Subject: [PATCH 06/10] Add proposed change to whatsnew --- doc/source/whatsnew/v1.2.0.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index a9b4ad2e5374a..3d057505d8722 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -13,6 +13,21 @@ including other versions of pandas. Enhancements ~~~~~~~~~~~~ +.. _whatsnew_120.improve_timeseries_accessor_naming: +Improve Timeseries accessors Naming Convention +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In modules like Period, PeriodArray, and Timestamp, there are non-Pythonic property names ``dayofweek`` and ``dayofyear`` (:issue:`9606`). We continue to maintain backwards-compatibility by simply aliasing the old naming convention to the new, properly named functions ``day_of_week`` and ``day_of_year``. + +For example: + +.. ipython:: python + + import pandas as pd + + per = pd.Period('2017-12-31 22:00', 'H') + per.dayofweek == per.day_of_week == 6 + .. _whatsnew_120.duplicate_labels: Optionally disallow duplicate labels From a4b88df82945f86b4f95d7f537b465d6574f71fa Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 25 Oct 2020 10:31:10 -0400 Subject: [PATCH 07/10] ENH: Support day_of_year over dayofyear (#9606) Similar to changes for day_of_week, create aliases for day_of_year and add to respective test files to ensure back-compat. Also fix whatsnew rst file --- doc/source/whatsnew/v1.2.0.rst | 13 +++---------- pandas/_libs/tslibs/nattype.pyx | 1 + pandas/_libs/tslibs/period.pyx | 14 +++++++------- pandas/_libs/tslibs/timestamps.pyx | 4 ++-- pandas/core/arrays/datetimes.py | 4 +++- pandas/core/arrays/period.py | 1 + pandas/core/indexes/datetimes.py | 1 + pandas/core/indexes/period.py | 1 + pandas/tests/generic/test_finalize.py | 1 + .../tests/indexes/datetimes/test_scalar_compat.py | 1 + pandas/tests/indexes/period/test_period.py | 1 + pandas/tests/scalar/timestamp/test_timestamp.py | 2 ++ 12 files changed, 24 insertions(+), 20 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 3d057505d8722..77baa1880aba8 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -15,18 +15,11 @@ Enhancements .. _whatsnew_120.improve_timeseries_accessor_naming: Improve Timeseries accessors Naming Convention -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -In modules like Period, PeriodArray, and Timestamp, there are non-Pythonic property names ``dayofweek`` and ``dayofyear`` (:issue:`9606`). We continue to maintain backwards-compatibility by simply aliasing the old naming convention to the new, properly named functions ``day_of_week`` and ``day_of_year``. - -For example: - -.. ipython:: python +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - import pandas as pd +- Added ``day_of_week`` (compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - per = pd.Period('2017-12-31 22:00', 'H') - per.dayofweek == per.day_of_week == 6 +- Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) .. _whatsnew_120.duplicate_labels: diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index bd57e107d3d2e..88ad008b42c21 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -357,6 +357,7 @@ 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) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 1cd34be60ca2d..b1f9ff71f5faa 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1475,8 +1475,8 @@ cdef class _Period(PeriodMixin): PeriodDtypeBase _dtype BaseOffset freq - # Alias dayofweek function to day_of_week (GH-9606) dayofweek = _Period.day_of_week + dayofyear = _Period.day_of_year def __cinit__(self, int64_t ordinal, BaseOffset freq): self.ordinal = ordinal @@ -1989,7 +1989,7 @@ cdef class _Period(PeriodMixin): return self.dayofweek @property - def dayofyear(self) -> int: + def day_of_year(self) -> int: """ Return the day of the year. @@ -2005,19 +2005,19 @@ cdef class _Period(PeriodMixin): See Also -------- 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. + Period.day_of_week : Return the day of week. + 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 = self._dtype._dtype_code diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index e59a57e662522..9076325d01bab 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -230,8 +230,8 @@ cdef class _Timestamp(ABCTimestamp): # higher than np.ndarray and np.matrix __array_priority__ = 100 - # Alias dayofweek function to day_of_week (GH-9606) dayofweek = _Timestamp.day_of_week + dayofyear = _Timestamp.day_of_year def __hash__(_Timestamp self): if self.nanosecond: @@ -547,7 +547,7 @@ cdef class _Timestamp(ABCTimestamp): return self.weekday() @property - def dayofyear(self) -> int: + def day_of_year(self) -> int: """ Return the day of the year. """ diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 12152909e7ad7..d020279ccf49d 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -179,6 +179,7 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps): "dayofweek", "day_of_week", "dayofyear", + "day_of_year", "quarter", "days_in_month", "daysinmonth", @@ -1538,13 +1539,14 @@ def weekofyear(self): dayofweek = day_of_week weekday = day_of_week - dayofyear = _field_accessor( + day_of_year = _field_accessor( "dayofyear", "doy", """ The ordinal day of the year. """, ) + dayofyear = day_of_year quarter = _field_accessor( "quarter", "q", diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index ae720b51cea25..ef8093660b413 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -142,6 +142,7 @@ class PeriodArray(PeriodMixin, dtl.DatelikeOps): "dayofweek", "day_of_week", "dayofyear", + "day_of_year", "quarter", "qyear", "days_in_month", diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 023c443134d96..3da1057ff8b03 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -158,6 +158,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin): time timetz dayofyear + day_of_year weekofyear week dayofweek diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index a69d2b5abe1b0..dbe15ef4bed8c 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -97,6 +97,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index): dayofweek day_of_week dayofyear + day_of_year days_in_month daysinmonth end_time diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index f2010a2042870..d7aadda990f53 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -680,6 +680,7 @@ def test_datetime_method(method): "dayofweek", "day_of_week", "dayofyear", + "day_of_year", "quarter", "is_month_start", "is_month_end", diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index f397388b82aec..d6016b9e14743 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -40,6 +40,7 @@ def test_dti_date_out_of_range(self, data): "dayofweek", "day_of_week", "dayofyear", + "day_of_year", "quarter", "days_in_month", "is_month_start", diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 1d412e8325ed4..f4773e885829e 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -251,6 +251,7 @@ def _check_all_fields(self, periodindex): "dayofweek", "day_of_week", "dayofyear", + "day_of_year", "quarter", "qyear", "days_in_month", diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index c0d40dd0aa42b..92675f387fe1e 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -66,6 +66,7 @@ def check(value, equal): 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) @@ -87,6 +88,7 @@ def check(value, equal): 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) From 0edff54ab16a0c6231498df0e5add1ef5b2264db Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 25 Oct 2020 11:20:09 -0400 Subject: [PATCH 08/10] Add autogenerated doc references --- doc/redirects.csv | 10 ++++++++++ doc/source/reference/arrays.rst | 4 ++++ doc/source/reference/indexing.rst | 4 ++++ doc/source/reference/series.rst | 2 ++ doc/source/user_guide/timeseries.rst | 2 ++ doc/source/whatsnew/v1.2.0.rst | 6 ++---- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index bceb4b5961324..de69d0168835d 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -542,7 +542,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 @@ -839,7 +841,9 @@ generated/pandas.option_context,../reference/api/pandas.option_context 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 @@ -850,7 +854,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 @@ -993,7 +999,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 @@ -1326,7 +1334,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 5c068d8404cd6..43e2509469488 100644 --- a/doc/source/reference/arrays.rst +++ b/doc/source/reference/arrays.rst @@ -63,7 +63,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 @@ -233,7 +235,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 ba12c19763605..d3f9413dae565 100644 --- a/doc/source/reference/indexing.rst +++ b/doc/source/reference/indexing.rst @@ -345,9 +345,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 @@ -461,7 +463,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 b4a72c030f7cb..8d74c288bf801 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -319,8 +319,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 9fbd02df50d10..af5e172658386 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -803,9 +803,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" quarter,"Quarter of the date: Jan-Mar = 1, Apr-Jun = 2, etc." days_in_month,"The number of days in the month of the datetime" diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 77baa1880aba8..1b985bf902aef 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -14,7 +14,7 @@ Enhancements ~~~~~~~~~~~~ .. _whatsnew_120.improve_timeseries_accessor_naming: -Improve Timeseries accessors Naming Convention +Improve timeseries accessors naming convention ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Added ``day_of_week`` (compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) @@ -26,9 +26,7 @@ Improve Timeseries accessors Naming Convention Optionally disallow duplicate labels ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:class:`Series` and :class:`DataFrame` can now be created with ``allows_duplicate_labels=False`` flag to -control whether the index or columns can contain duplicate labels (:issue:`28394`). This can be used to -prevent accidental introduction of duplicate labels, which can affect downstream operations. +:class:`Series` and :class:`DataFrame` can now be created with ``allows_duplicate_labels=False`` flag to control whether the index or columns can contain duplicate labels (:issue:`28394`). This can be used to prevent accidental introduction of duplicate labels, which can affect downstream operations. By default, duplicates continue to be allowed From 84be52f33951c72e25d099be6ae9968e244f3bb0 Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 25 Oct 2020 20:12:57 -0400 Subject: [PATCH 09/10] Fix newline error Sphinx in whatsnew doc --- doc/source/whatsnew/v1.2.0.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 1b985bf902aef..fa3ed80fcd836 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -13,14 +13,17 @@ including other versions of pandas. Enhancements ~~~~~~~~~~~~ + + .. _whatsnew_120.improve_timeseries_accessor_naming: + Improve timeseries accessors naming convention ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- Added ``day_of_week`` (compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - +- Added ``day_of_week``(compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) + .. _whatsnew_120.duplicate_labels: Optionally disallow duplicate labels From a07e61a4387a40e21ebe99df98a55a710c54fdd6 Mon Sep 17 00:00:00 2001 From: amangla Date: Mon, 26 Oct 2020 09:56:35 -0400 Subject: [PATCH 10/10] Move whatsnew info to Other Enhancements --- doc/source/whatsnew/v1.2.0.rst | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index fa3ed80fcd836..e399ff1741d19 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -13,23 +13,14 @@ including other versions of pandas. Enhancements ~~~~~~~~~~~~ - - -.. _whatsnew_120.improve_timeseries_accessor_naming: - -Improve timeseries accessors naming convention -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -- Added ``day_of_week``(compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) -- Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - - .. _whatsnew_120.duplicate_labels: Optionally disallow duplicate labels ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:class:`Series` and :class:`DataFrame` can now be created with ``allows_duplicate_labels=False`` flag to control whether the index or columns can contain duplicate labels (:issue:`28394`). This can be used to prevent accidental introduction of duplicate labels, which can affect downstream operations. +:class:`Series` and :class:`DataFrame` can now be created with ``allows_duplicate_labels=False`` flag to +control whether the index or columns can contain duplicate labels (:issue:`28394`). This can be used to +prevent accidental introduction of duplicate labels, which can affect downstream operations. By default, duplicates continue to be allowed @@ -216,6 +207,8 @@ level-by-level basis. Other enhancements ^^^^^^^^^^^^^^^^^^ +- Added ``day_of_week``(compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) +- Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - Added :meth:`~DataFrame.set_flags` for setting table-wide flags on a ``Series`` or ``DataFrame`` (:issue:`28394`) - :meth:`DataFrame.applymap` now supports ``na_action`` (:issue:`23803`) - :class:`Index` with object dtype supports division and multiplication (:issue:`34160`)