Skip to content

Commit bd99e04

Browse files
committed
Hold off on deprecating xarray versions of these attributes
1 parent a3a6f44 commit bd99e04

File tree

5 files changed

+21
-101
lines changed

5 files changed

+21
-101
lines changed

doc/whats-new.rst

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ New Features
1919
By `Alfonso Ladino <https://github.com/aladinor>`_.
2020
- Added complex dtype support to FillValueCoder for the Zarr backend. (:pull:`11151`)
2121
By `Max Jones <https://github.com/maxrjones>`_.
22+
- Following pandas, xarray's
23+
:py:class:`~xarray.core.accessor_dt.DatetimeAccessor` now supports
24+
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.day_of_week` and
25+
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.day_of_year` attributes,
26+
which are alternative names for the existing
27+
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.dayofweek` and
28+
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.dayofyear` attributes.
29+
These alternative attributes have similarly been added to
30+
:py:class:`~xarray.CFTimeIndex` (:pull:`11270`). By `Spencer Clark
31+
<https://github.com/spencerkclark>`_.
2232

2333
Breaking Changes
2434
~~~~~~~~~~~~~~~~
@@ -104,25 +114,7 @@ Breaking Changes
104114

105115
Deprecations
106116
~~~~~~~~~~~~
107-
- Following pandas, on xarray's
108-
:py:class:`~xarray.core.accessor_dt.DatetimeAccessor`,
109-
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.daysinmonth`
110-
is deprecated in favor of
111-
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.days_in_month`;
112-
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.dayofweek` and
113-
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.weekday` are deprecated
114-
in favor of :py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.day_of_week`;
115-
and :py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.dayofyear` is
116-
deprecated in favor of
117-
:py:attr:`~xarray.core.accessor_dt.DatetimeAccessor.day_of_year`
118-
(:issue:`11268`, :pull:`11270`). By `Spencer Clark
119-
<https://github.com/spencerkclark>`_.
120-
- Following pandas, on xarray's :py:class:`~xarray.CFTimeIndex`,
121-
:py:attr:`~xarray.CFTimeIndex.dayofweek` and
122-
:py:attr:`~xarray.CFTimeIndex.dayofyear` are deprecated in favor of
123-
:py:attr:`~xarray.CFTimeIndex.day_of_week` and
124-
:py:attr:`~xarray.CFTimeIndex.day_of_year`, respectively (:pull:`11270`).
125-
By `Spencer Clark <https://github.com/spencerkclark>`_.
117+
-
126118

127119
Bug Fixes
128120
~~~~~~~~~

xarray/coding/cftimeindex.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def _field_accessor(
131131
name: str,
132132
docstring: str | None = None,
133133
min_cftime_version: str = "0.0",
134-
deprecation_pair: tuple[str, str] | None = None,
135134
):
136135
"""Adapted from pandas.tseries.index._field_accessor"""
137136

@@ -141,14 +140,6 @@ def f(self, min_cftime_version=min_cftime_version):
141140
else:
142141
cftime = attempt_import("cftime")
143142

144-
if deprecation_pair is not None:
145-
original, replacement = deprecation_pair
146-
emit_user_level_warning(
147-
f"CFTimeIndex.{original} is deprecated and will be removed in "
148-
f"a future version. Use CFTimeIndex.{replacement} instead",
149-
FutureWarning,
150-
)
151-
152143
if Version(cftime.__version__) >= Version(min_cftime_version):
153144
return get_date_field(self._data, name)
154145
else:
@@ -265,13 +256,11 @@ class CFTimeIndex(pd.Index):
265256
"dayofyr",
266257
"The ordinal day of year of the datetime",
267258
"1.0.2.1",
268-
("dayofyear", "day_of_year"),
269259
)
270260
dayofweek = _field_accessor(
271261
"dayofwk",
272262
"The day of week of the datetime",
273263
"1.0.2.1",
274-
("dayofweek", "day_of_week"),
275264
)
276265
day_of_year = _field_accessor(
277266
"dayofyr", "The ordinal day of year of the datetime", "1.0.2.1"

xarray/core/accessor_dt.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
is_np_timedelta_like,
1717
)
1818
from xarray.core.types import T_DataArray
19-
from xarray.core.utils import emit_user_level_warning
2019
from xarray.core.variable import IndexVariable, Variable
2120
from xarray.namedarray.utils import is_duck_dask_array
2221

@@ -471,40 +470,15 @@ def day_of_week(self) -> T_DataArray:
471470
"""The day of the week with Monday=0, Sunday=6"""
472471
return self._date_field("day_of_week", np.int64)
473472

474-
@property
475-
def dayofweek(self) -> T_DataArray:
476-
"""The day of the week with Monday=0, Sunday=6"""
477-
emit_user_level_warning(
478-
"dt.dayofweek is deprecated and will be removed in a future "
479-
"version. Use dt.day_of_week instead.",
480-
FutureWarning,
481-
)
482-
return self._date_field("day_of_week", np.int64)
483-
484-
@property
485-
def weekday(self) -> T_DataArray:
486-
"""The day of the week with Monday=0, Sunday=6"""
487-
emit_user_level_warning(
488-
"dt.weekday is deprecated and will be removed in a "
489-
"future version. Use dt.day_of_week instead.",
490-
FutureWarning,
491-
)
492-
return self._date_field("day_of_week", np.int64)
473+
dayofweek = day_of_week
474+
weekday = day_of_week
493475

494476
@property
495477
def day_of_year(self) -> T_DataArray:
496478
"""The ordinal day of the year"""
497479
return self._date_field("day_of_year", np.int64)
498480

499-
@property
500-
def dayofyear(self) -> T_DataArray:
501-
"""The ordinal day of the year"""
502-
emit_user_level_warning(
503-
"dt.dayofyear is deprecated and will be removed in a future "
504-
"version. Use dt.day_of_year instead.",
505-
FutureWarning,
506-
)
507-
return self._date_field("day_of_year", np.int64)
481+
dayofyear = day_of_year
508482

509483
@property
510484
def quarter(self) -> T_DataArray:
@@ -516,15 +490,7 @@ def days_in_month(self) -> T_DataArray:
516490
"""The number of days in the month"""
517491
return self._date_field("days_in_month", np.int64)
518492

519-
@property
520-
def daysinmonth(self) -> T_DataArray:
521-
"""The number of days in the month"""
522-
emit_user_level_warning(
523-
"dt.daysinmonth is deprecated and will be removed in a future "
524-
"version. Use dt.days_in_month instead.",
525-
FutureWarning,
526-
)
527-
return self._date_field("days_in_month", np.int64)
493+
daysinmonth = days_in_month
528494

529495
@property
530496
def season(self) -> T_DataArray:

xarray/tests/test_accessor_dt.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,6 @@ def test_field_access(self, field) -> None:
102102
assert expected.dtype == actual.dtype
103103
assert_identical(expected, actual)
104104

105-
@pytest.mark.parametrize(
106-
("field", "replacement"),
107-
[
108-
("daysinmonth", "days_in_month"),
109-
("dayofweek", "day_of_week"),
110-
("weekday", "day_of_week"),
111-
("dayofyear", "day_of_year"),
112-
],
113-
)
114-
def test_deprecated_field_access(self, field, replacement) -> None:
115-
expected = getattr(self.data.time.dt, replacement)
116-
with pytest.warns(FutureWarning, match=f"{field}.*{replacement}"):
117-
actual = getattr(self.data.time.dt, field)
118-
assert_identical(expected, actual)
119-
120105
def test_total_seconds(self) -> None:
121106
# Subtract a value in the middle of the range to ensure that some values
122107
# are negative

xarray/tests/test_cftimeindex.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,30 +329,18 @@ def test_empty_cftimeindex_field_accessors(field):
329329

330330

331331
@requires_cftime
332-
@pytest.mark.parametrize(
333-
("field", "replacement"), [("day_of_year", None), ("dayofyear", "day_of_year")]
334-
)
335-
def test_cftimeindex_dayofyear_accessor(index, field, replacement):
336-
if replacement is not None:
337-
with pytest.warns(FutureWarning, match=f"{field}.*{replacement}"):
338-
result = getattr(index, field)
339-
else:
340-
result = getattr(index, field)
332+
@pytest.mark.parametrize("field", ["day_of_year", "dayofyear"])
333+
def test_cftimeindex_dayofyear_accessor(index, field):
334+
result = getattr(index, field)
341335
expected = np.array([date.dayofyr for date in index], dtype=np.int64)
342336
assert_array_equal(result, expected)
343337
assert result.dtype == expected.dtype
344338

345339

346340
@requires_cftime
347-
@pytest.mark.parametrize(
348-
("field", "replacement"), [("day_of_week", None), ("dayofweek", "day_of_week")]
349-
)
350-
def test_cftimeindex_dayofweek_accessor(index, field, replacement):
351-
if replacement is not None:
352-
with pytest.warns(FutureWarning, match=f"{field}.*{replacement}"):
353-
result = getattr(index, field)
354-
else:
355-
result = getattr(index, field)
341+
@pytest.mark.parametrize("field", ["day_of_week", "dayofweek"])
342+
def test_cftimeindex_dayofweek_accessor(index, field):
343+
result = getattr(index, field)
356344
expected = np.array([date.dayofwk for date in index], dtype=np.int64)
357345
assert_array_equal(result, expected)
358346
assert result.dtype == expected.dtype

0 commit comments

Comments
 (0)