From 94be5fc27a7144563f91278e10460d1b5d45df60 Mon Sep 17 00:00:00 2001 From: mohansree14 Date: Fri, 16 Oct 2026 00:12:39 +0100 Subject: [PATCH 1/2] Remove deprecated dt.weekofyear and dt.week accessors Deprecated since v0.16.2 (#4534); use dt.isocalendar().week instead. Part of #11721. --- doc/api-hidden.rst | 2 -- doc/api/deprecated.rst | 7 ------- doc/whats-new.rst | 4 ++++ xarray/core/accessor_dt.py | 26 -------------------------- xarray/core/dataset.py | 1 - xarray/tests/test_accessor_dt.py | 32 +++++++++----------------------- 6 files changed, 13 insertions(+), 59 deletions(-) diff --git a/doc/api-hidden.rst b/doc/api-hidden.rst index 0f520d55ba0..b9a0119b723 100644 --- a/doc/api-hidden.rst +++ b/doc/api-hidden.rst @@ -136,9 +136,7 @@ core.accessor_dt.DatetimeAccessor.season core.accessor_dt.DatetimeAccessor.second core.accessor_dt.DatetimeAccessor.time - core.accessor_dt.DatetimeAccessor.week core.accessor_dt.DatetimeAccessor.weekday - core.accessor_dt.DatetimeAccessor.weekofyear core.accessor_dt.DatetimeAccessor.year core.accessor_dt.TimedeltaAccessor.ceil diff --git a/doc/api/deprecated.rst b/doc/api/deprecated.rst index e926b2b84f8..41598e86dd5 100644 --- a/doc/api/deprecated.rst +++ b/doc/api/deprecated.rst @@ -11,10 +11,3 @@ Deprecated / Pending Deprecation Dataset.apply core.groupby.DataArrayGroupBy.apply core.groupby.DatasetGroupBy.apply - -.. autosummary:: - :toctree: ../generated/ - :template: autosummary/accessor_attribute.rst - - DataArray.dt.weekofyear - DataArray.dt.week diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 060730f571f..d4fb8bafbe9 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -55,6 +55,10 @@ New Features Breaking Changes ~~~~~~~~~~~~~~~~ +- The ``DataArray.dt.weekofyear`` and ``DataArray.dt.week`` accessors, + deprecated since v0.16.2, have been removed. Use + ``DataArray.dt.isocalendar().week`` instead (:issue:`11721`). + By `Mohansree Vijayakumar `_. - The ``Variable.to_variable``, ``Variable.to_coord`` and ``IndexVariable.to_coord`` aliases, deprecated since v0.9.0, have been removed. Use :py:meth:`Variable.to_base_variable` and diff --git a/xarray/core/accessor_dt.py b/xarray/core/accessor_dt.py index 8dd5f3a66fd..c2001910929 100644 --- a/xarray/core/accessor_dt.py +++ b/xarray/core/accessor_dt.py @@ -450,32 +450,6 @@ def nanosecond(self) -> T_DataArray: """The nanoseconds of the datetime""" return self._date_field("nanosecond", np.int64) - @property - def weekofyear(self) -> DataArray: - "The week ordinal of the year" - - warnings.warn( - "dt.weekofyear and dt.week have been deprecated. Please use " - "dt.isocalendar().week instead.", - FutureWarning, - stacklevel=2, - ) - - return self.isocalendar().week.rename("weekofyear") - - @property - def week(self) -> DataArray: - "The week ordinal of the year" - - warnings.warn( - "dt.weekofyear and dt.week have been deprecated. Please use " - "dt.isocalendar().week instead.", - FutureWarning, - stacklevel=2, - ) - - return self.isocalendar().week - @property def day_of_week(self) -> T_DataArray: """The day of the week with Monday=0, Sunday=6""" diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index ec85bbb38b7..0ea5ae25507 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -195,7 +195,6 @@ "date", "time", "dayofyear", - "weekofyear", "dayofweek", "quarter", ] diff --git a/xarray/tests/test_accessor_dt.py b/xarray/tests/test_accessor_dt.py index 17d9994847e..4703e57cc16 100644 --- a/xarray/tests/test_accessor_dt.py +++ b/xarray/tests/test_accessor_dt.py @@ -54,8 +54,6 @@ def setup(self): "second", "microsecond", "nanosecond", - "week", - "weekofyear", "dayofweek", "weekday", "day_of_week", @@ -76,17 +74,14 @@ def setup(self): ], ) def test_field_access(self, field) -> None: - if field in ["week", "weekofyear"]: - data = self.times.isocalendar()["week"] - else: - pandas_translations = { - "weekday": "day_of_week", - "dayofweek": "day_of_week", - "daysinmonth": "days_in_month", - "dayofyear": "day_of_year", - } - pandas_name = pandas_translations.get(field, field) - data = getattr(self.times, pandas_name) + pandas_translations = { + "weekday": "day_of_week", + "dayofweek": "day_of_week", + "daysinmonth": "days_in_month", + "dayofyear": "day_of_year", + } + pandas_name = pandas_translations.get(field, field) + data = getattr(self.times, pandas_name) if data.dtype.kind != "b" and field not in ("date", "time"): # pandas 2.0 returns int32 for integer fields now @@ -94,13 +89,7 @@ def test_field_access(self, field) -> None: expected = xr.DataArray(data, name=field, coords=[self.times], dims=["time"]) - if field in ["week", "weekofyear"]: - with pytest.warns( - FutureWarning, match="dt.weekofyear and dt.week have been deprecated" - ): - actual = getattr(self.data.time.dt, field) - else: - actual = getattr(self.data.time.dt, field) + actual = getattr(self.data.time.dt, field) assert not isinstance(actual.variable, xr.IndexVariable) assert expected.dtype == actual.dtype @@ -163,7 +152,6 @@ def test_not_datetime_type(self) -> None: with pytest.raises(AttributeError, match=r"dt"): _ = nontime_data.time.dt - @pytest.mark.filterwarnings("ignore:dt.weekofyear and dt.week have been deprecated") @requires_dask @pytest.mark.parametrize( "field", @@ -176,8 +164,6 @@ def test_not_datetime_type(self) -> None: "second", "microsecond", "nanosecond", - "week", - "weekofyear", "dayofweek", "weekday", "day_of_week", From 9ff2c1b025159a1bc3fa5b4fd48e55787cb3e17e Mon Sep 17 00:00:00 2001 From: mohansree14 Date: Fri, 16 Oct 2026 00:14:05 +0100 Subject: [PATCH 2/2] Add PR number to whats-new entry --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index d4fb8bafbe9..53ac68712ab 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -57,7 +57,7 @@ Breaking Changes ~~~~~~~~~~~~~~~~ - The ``DataArray.dt.weekofyear`` and ``DataArray.dt.week`` accessors, deprecated since v0.16.2, have been removed. Use - ``DataArray.dt.isocalendar().week`` instead (:issue:`11721`). + ``DataArray.dt.isocalendar().week`` instead (:issue:`11721`, :pull:`11742`). By `Mohansree Vijayakumar `_. - The ``Variable.to_variable``, ``Variable.to_coord`` and ``IndexVariable.to_coord`` aliases, deprecated since v0.9.0, have been removed.