Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions doc/api-hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions doc/api/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ 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`, :pull:`11742`).
- Passing ``chunks=None`` to :py:meth:`Dataset.chunk`, :py:meth:`DataArray.chunk`
or :py:meth:`Variable.chunk`, deprecated since v0.17.0, now raises a
``TypeError``. Use ``chunks={}`` instead (:issue:`11721`, :pull:`11743`).
Expand Down
26 changes: 0 additions & 26 deletions xarray/core/accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
1 change: 0 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@
"date",
"time",
"dayofyear",
"weekofyear",
"dayofweek",
"quarter",
]
Expand Down
32 changes: 9 additions & 23 deletions xarray/tests/test_accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def setup(self):
"second",
"microsecond",
"nanosecond",
"week",
"weekofyear",
"dayofweek",
"weekday",
"day_of_week",
Expand All @@ -76,31 +74,22 @@ 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
data = data.astype("int64")

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
Expand Down Expand Up @@ -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",
Expand All @@ -176,8 +164,6 @@ def test_not_datetime_type(self) -> None:
"second",
"microsecond",
"nanosecond",
"week",
"weekofyear",
"dayofweek",
"weekday",
"day_of_week",
Expand Down
Loading