From 414d6450d0fc86fd2db6707419aed63a570f6071 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 24 Nov 2019 18:45:17 -0800 Subject: [PATCH 1/2] DEPR: Remove weekday_name --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/_libs/tslibs/fields.pyx | 4 ++-- pandas/_libs/tslibs/nattype.pyx | 1 - pandas/_libs/tslibs/timestamps.pyx | 11 ----------- pandas/core/arrays/datetimes.py | 10 +--------- pandas/tests/indexes/datetimes/test_misc.py | 4 ---- pandas/tests/indexes/datetimes/test_scalar_compat.py | 7 +------ pandas/tests/scalar/timestamp/test_timestamp.py | 4 +--- pandas/tests/series/test_datetime_values.py | 1 - 9 files changed, 6 insertions(+), 38 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index f231c2b31abb1..94db388575b5b 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -414,7 +414,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - :func:`read_stata` and :meth:`DataFrame.to_stata` no longer supports the "encoding" argument (:issue:`21400`) - Removed previously deprecated "raise_conflict" argument from :meth:`DataFrame.update`, use "errors" instead (:issue:`23585`) - Removed previously deprecated keyword "n" from :meth:`DatetimeIndex.shift`, :meth:`TimedeltaIndex.shift`, :meth:`PeriodIndex.shift`, use "periods" instead (:issue:`22458`) -- +- Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`) .. _whatsnew_1000.performance: diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index dfed8d06530aa..8bee7da6231ba 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -90,7 +90,7 @@ def build_field_sarray(const int64_t[:] dtindex): def get_date_name_field(const int64_t[:] dtindex, object field, object locale=None): """ Given a int64-based datetime index, return array of strings of date - name based on requested field (e.g. weekday_name) + name based on requested field (e.g. day_name) """ cdef: Py_ssize_t i, count = len(dtindex) @@ -100,7 +100,7 @@ def get_date_name_field(const int64_t[:] dtindex, object field, object locale=No out = np.empty(count, dtype=object) - if field == 'day_name' or field == 'weekday_name': + if field == 'day_name': if locale is None: names = np.array(DAYS_FULL, dtype=np.object_) else: diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 6fab827f1364a..966f72dcd7889 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -364,7 +364,6 @@ 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) - weekday_name = property(fget=lambda self: np.nan) # inject Timedelta properties days = property(fget=lambda self: np.nan) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 1a278f46a4a2b..90c4278381e0f 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -638,17 +638,6 @@ timedelta}, default 'raise' """ return self._get_date_name_field('month_name', locale) - @property - def weekday_name(self): - """ - .. deprecated:: 0.23.0 - Use ``Timestamp.day_name()`` instead - """ - warnings.warn("`weekday_name` is deprecated and will be removed in a " - "future version. Use `day_name` instead", - FutureWarning) - return self.day_name() - @property def dayofyear(self): """ diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 71420e6e58090..ae228e56f27f1 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -277,7 +277,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps "is_year_end", "is_leap_year", ] - _object_ops = ["weekday_name", "freq", "tz"] + _object_ops = ["freq", "tz"] _field_ops = [ "year", "month", @@ -1509,14 +1509,6 @@ def date(self): dayofweek = _field_accessor("dayofweek", "dow", _dayofweek_doc) weekday = dayofweek - weekday_name = _field_accessor( - "weekday_name", - "weekday_name", - """ - The name of day in a week (ex: Friday)\n\n.. deprecated:: 0.23.0 - """, - ) - dayofyear = _field_accessor( "dayofyear", "doy", diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index ab3107a0798e5..c144f2a447ed3 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -200,7 +200,6 @@ def test_datetimeindex_accessors(self): assert len(dti.is_quarter_end) == 365 assert len(dti.is_year_start) == 365 assert len(dti.is_year_end) == 365 - assert len(dti.weekday_name) == 365 dti.name = "name" @@ -339,11 +338,8 @@ def test_datetime_name_accessors(self, time_locale): ] for day, name, eng_name in zip(range(4, 11), expected_days, english_days): name = name.capitalize() - assert dti.weekday_name[day] == eng_name assert dti.day_name(locale=time_locale)[day] == name ts = Timestamp(datetime(2016, 4, day)) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert ts.weekday_name == eng_name assert ts.day_name(locale=time_locale) == name dti = dti.append(DatetimeIndex([pd.NaT])) assert np.isnan(dti.day_name(locale=time_locale)[-1]) diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index 00310f4fba7c7..62383555f6048 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -50,18 +50,13 @@ def test_dti_date_out_of_range(self, data): "is_quarter_end", "is_year_start", "is_year_end", - "weekday_name", ], ) def test_dti_timestamp_fields(self, field): # extra fields from DatetimeIndex like quarter and week idx = tm.makeDateIndex(100) expected = getattr(idx, field)[-1] - if field == "weekday_name": - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = getattr(Timestamp(idx[-1]), field) - else: - result = getattr(Timestamp(idx[-1]), field) + result = getattr(Timestamp(idx[-1]), field) assert result == expected def test_dti_timestamp_freq_fields(self): diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index f9fa80644d4b9..a33afc8b3ccca 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -108,9 +108,7 @@ def check(value, equal): ) def test_names(self, data, time_locale): # GH 17354 - # Test .weekday_name, .day_name(), .month_name - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - assert data.weekday_name == "Monday" + # Test .day_name(), .month_name if time_locale is None: expected_day = "Monday" expected_month = "August" diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index d038df1747f73..aa56131f05570 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -427,7 +427,6 @@ def test_dt_accessor_datetime_name_accessors(self, time_locale): ] for day, name, eng_name in zip(range(4, 11), expected_days, english_days): name = name.capitalize() - assert s.dt.weekday_name[day] == eng_name assert s.dt.day_name(locale=time_locale)[day] == name s = s.append(Series([pd.NaT])) assert np.isnan(s.dt.day_name(locale=time_locale).iloc[-1]) From 2ed82ec32dbb7e8b62567f56da9952120c2d90c5 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 24 Nov 2019 21:57:53 -0800 Subject: [PATCH 2/2] Fix documentation --- doc/source/user_guide/timeseries.rst | 7 +++---- doc/source/whatsnew/v1.0.0.rst | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 17b02374050d2..08b2ae0a4a837 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -772,7 +772,6 @@ There are several time/date properties that one can access from ``Timestamp`` or week,"The week ordinal of the year" dayofweek,"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." days_in_month,"The number of days in the month of the datetime" is_month_start,"Logical indicating if first day of month (defined by frequency)" @@ -1591,10 +1590,10 @@ labels. s = pd.date_range('2000-01-01', '2000-01-05').to_series() s.iloc[2] = pd.NaT - s.dt.weekday_name + s.dt.day_name() # default: label='left', closed='left' - s.resample('B').last().dt.weekday_name + s.resample('B').last().dt.day_name() Notice how the value for Sunday got pulled back to the previous Friday. To get the behavior where the value for Sunday is pushed to Monday, use @@ -1602,7 +1601,7 @@ labels. .. ipython:: python - s.resample('B', label='right', closed='right').last().dt.weekday_name + s.resample('B', label='right', closed='right').last().dt.day_name() The ``axis`` parameter can be set to 0 or 1 and allows you to resample the specified axis for a ``DataFrame``. diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 94db388575b5b..70d97c69fc05e 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -415,6 +415,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Removed previously deprecated "raise_conflict" argument from :meth:`DataFrame.update`, use "errors" instead (:issue:`23585`) - Removed previously deprecated keyword "n" from :meth:`DatetimeIndex.shift`, :meth:`TimedeltaIndex.shift`, :meth:`PeriodIndex.shift`, use "periods" instead (:issue:`22458`) - Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`) +- .. _whatsnew_1000.performance: