diff --git a/doc/source/getting_started/intro_tutorials/09_timeseries.rst b/doc/source/getting_started/intro_tutorials/09_timeseries.rst index 3c256081d7955..373470913c293 100644 --- a/doc/source/getting_started/intro_tutorials/09_timeseries.rst +++ b/doc/source/getting_started/intro_tutorials/09_timeseries.rst @@ -144,7 +144,7 @@ I want to add a new column to the ``DataFrame`` containing only the month of the By using ``Timestamp`` objects for dates, a lot of time-related properties are provided by pandas. For example the ``month``, but also -``year``, ``weekofyear``, ``quarter``,… All of these properties are +``year``, ``quarter``,… All of these properties are accessible by the ``dt`` accessor. .. raw:: html diff --git a/doc/source/reference/indexing.rst b/doc/source/reference/indexing.rst index 93897723d5d71..b7866a0076d84 100644 --- a/doc/source/reference/indexing.rst +++ b/doc/source/reference/indexing.rst @@ -343,8 +343,6 @@ Time/date components DatetimeIndex.timetz DatetimeIndex.dayofyear DatetimeIndex.day_of_year - DatetimeIndex.weekofyear - DatetimeIndex.week DatetimeIndex.dayofweek DatetimeIndex.day_of_week DatetimeIndex.weekday diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index 3fda5db3a0199..c9604f48dd334 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -311,8 +311,6 @@ Datetime properties Series.dt.second Series.dt.microsecond Series.dt.nanosecond - Series.dt.week - Series.dt.weekofyear Series.dt.dayofweek Series.dt.day_of_week Series.dt.weekday diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 5aa753dffcf7f..50d3952be5148 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -170,6 +170,7 @@ Removal of prior version deprecations/changes - Removed deprecated :meth:`Index.to_native_types`, use ``obj.astype(str)`` instead (:issue:`36418`) - Removed deprecated :meth:`Series.iteritems`, :meth:`DataFrame.iteritems`, use ``obj.items`` instead (:issue:`45321`) - Removed deprecated :meth:`DatetimeIndex.union_many` (:issue:`45018`) +- Removed deprecated ``weekofyear`` and ``week`` attributes of :class:`DatetimeArray`, :class:`DatetimeIndex` and ``dt`` accessor in favor of ``isocalendar().week`` (:issue:`33595`) - Removed deprecated :meth:`RangeIndex._start`, :meth:`RangeIndex._stop`, :meth:`RangeIndex._step`, use ``start``, ``stop``, ``step`` instead (:issue:`30482`) - Removed deprecated :meth:`DatetimeIndex.to_perioddelta`, Use ``dtindex - dtindex.to_period(freq).to_timestamp()`` instead (:issue:`34853`) - Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 1768bb7507dd9..8fc18691fb17e 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -216,8 +216,6 @@ def _scalar_type(self) -> type[Timestamp]: "hour", "minute", "second", - "weekofyear", - "week", "weekday", "dayofweek", "day_of_week", @@ -1365,32 +1363,6 @@ def isocalendar(self) -> DataFrame: iso_calendar_df.iloc[self._isnan] = None return iso_calendar_df - @property - def weekofyear(self): - """ - The week ordinal of the year. - - .. deprecated:: 1.1.0 - - weekofyear and week have been deprecated. - Please use DatetimeIndex.isocalendar().week instead. - """ - warnings.warn( - "weekofyear and week have been deprecated, please use " - "DatetimeIndex.isocalendar().week instead, which returns " - "a Series. To exactly reproduce the behavior of week and " - "weekofyear and return an Index, you may call " - "pd.Int64Index(idx.isocalendar().week)", - FutureWarning, - stacklevel=find_stack_level(), - ) - week_series = self.isocalendar().week - if week_series.hasnans: - return week_series.to_numpy(dtype="float64", na_value=np.nan) - return week_series.to_numpy(dtype="int64") - - week = weekofyear - year = _field_accessor( "year", "Y", diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 46959aa5cd3e2..da2a0a2a87137 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -4,12 +4,9 @@ from __future__ import annotations from typing import TYPE_CHECKING -import warnings import numpy as np -from pandas.util._exceptions import find_stack_level - from pandas.core.dtypes.common import ( is_categorical_dtype, is_datetime64_dtype, @@ -276,31 +273,6 @@ def isocalendar(self) -> DataFrame: """ return self._get_values().isocalendar().set_index(self._parent.index) - @property - def weekofyear(self): - """ - The week ordinal of the year according to the ISO 8601 standard. - - .. deprecated:: 1.1.0 - - Series.dt.weekofyear and Series.dt.week have been deprecated. Please - call :func:`Series.dt.isocalendar` and access the ``week`` column - instead. - """ - warnings.warn( - "Series.dt.weekofyear and Series.dt.week have been deprecated. " - "Please use Series.dt.isocalendar().week instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - week_series = self.isocalendar().week - week_series.name = self.name - if week_series.hasnans: - return week_series.astype("float64") - return week_series.astype("int64") - - week = weekofyear - @delegate_names( delegate=TimedeltaArray, accessors=TimedeltaArray._datetimelike_ops, typ="property" diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index a899e95bac41d..72b2cd15d3222 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -805,18 +805,11 @@ def test_bool_properties(self, arr1d, propname): @pytest.mark.parametrize("propname", DatetimeArray._field_ops) def test_int_properties(self, arr1d, propname): - warn = None - msg = "weekofyear and week have been deprecated, please use" - if propname in ["week", "weekofyear"]: - # GH#33595 Deprecate week and weekofyear - warn = FutureWarning - dti = self.index_cls(arr1d) arr = arr1d - with tm.assert_produces_warning(warn, match=msg): - result = getattr(arr, propname) - expected = np.array(getattr(dti, propname), dtype=result.dtype) + result = getattr(arr, propname) + expected = np.array(getattr(dti, propname), dtype=result.dtype) tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 24779c6e0c89d..babab81dfbe57 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -75,9 +75,6 @@ def test_non_nano(self, unit, reso, dtype): assert tz_compare(dta.tz, dta[0].tz) assert (dta[0] == dta[:1]).all() - @pytest.mark.filterwarnings( - "ignore:weekofyear and week have been deprecated:FutureWarning" - ) @pytest.mark.parametrize( "field", DatetimeArray._field_ops + DatetimeArray._bool_ops ) diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index c69c35ee46307..0e8b0fe83279b 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -98,9 +98,6 @@ def test_datetimeindex_accessors(self): # non boolean accessors -> return Index for accessor in DatetimeArray._field_ops: - if accessor in ["week", "weekofyear"]: - # GH#33595 Deprecate week and weekofyear - continue res = getattr(dti, accessor) assert len(res) == 365 assert isinstance(res, Index) @@ -287,15 +284,6 @@ def test_iter_readonly(): list(dti) -def test_week_and_weekofyear_are_deprecated(): - # GH#33595 Deprecate week and weekofyear - idx = date_range(start="2019-12-29", freq="D", periods=4) - with tm.assert_produces_warning(FutureWarning): - idx.week - with tm.assert_produces_warning(FutureWarning): - idx.weekofyear - - def test_add_timedelta_preserves_freq(): # GH#37295 should hold for any DTI with freq=None or Tick freq tz = "Canada/Eastern" diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 1fd5f5ab7c2a6..79e9e1d4fc68b 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -73,9 +73,6 @@ def test_nat_vector_field_access(): # on NaT/Timestamp for compat with datetime if field == "weekday": continue - if field in ["week", "weekofyear"]: - # GH#33595 Deprecate week and weekofyear - continue result = getattr(idx, field) expected = Index([getattr(x, field) for x in idx]) @@ -88,9 +85,6 @@ def test_nat_vector_field_access(): # on NaT/Timestamp for compat with datetime if field == "weekday": continue - if field in ["week", "weekofyear"]: - # GH#33595 Deprecate week and weekofyear - continue result = getattr(ser.dt, field) expected = [getattr(x, field) for x in idx] diff --git a/pandas/tests/series/accessors/test_cat_accessor.py b/pandas/tests/series/accessors/test_cat_accessor.py index 48a01f0018775..2ac1574adc913 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -218,9 +218,6 @@ def test_dt_accessor_api_for_categorical(self, idx): tm.assert_equal(res, exp) for attr in attr_names: - if attr in ["week", "weekofyear"]: - # GH#33595 Deprecate week and weekofyear - continue res = getattr(cat.dt, attr) exp = getattr(ser.dt, attr) diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 47e59be907929..ccd79d5cc58f4 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -107,8 +107,7 @@ def test_dt_namespace_accessor_datetime64(self, freq): for prop in ok_for_dt: # we test freq below - # we ignore week and weekofyear because they are deprecated - if prop not in ["freq", "week", "weekofyear"]: + if prop != "freq": self._compare(ser, prop) for prop in ok_for_dt_methods: @@ -146,8 +145,7 @@ def test_dt_namespace_accessor_datetime64tz(self): for prop in ok_for_dt: # we test freq below - # we ignore week and weekofyear because they are deprecated - if prop not in ["freq", "week", "weekofyear"]: + if prop != "freq": self._compare(ser, prop) for prop in ok_for_dt_methods: @@ -794,15 +792,6 @@ def test_to_period(self, input_vals): tm.assert_series_equal(result, expected) -def test_week_and_weekofyear_are_deprecated(): - # GH#33595 Deprecate week and weekofyear - series = pd.to_datetime(Series(["2020-01-01"])) - with tm.assert_produces_warning(FutureWarning): - series.dt.week - with tm.assert_produces_warning(FutureWarning): - series.dt.weekofyear - - def test_normalize_pre_epoch_dates(): # GH: 36294 ser = pd.to_datetime(Series(["1969-01-01 09:00:00", "2016-01-01 09:00:00"]))