Skip to content

Commit c5530d5

Browse files
keewisTomNicholas
andauthored
remove deprecations scheduled for 0.19 (#5630)
* remove the deprecated dim kwarg for DataArray.integrate * remove the deprecated keep_attrs kwarg to .rolling * remove the keep_attrs kwarg to .coarsen * raise a TypeError when passing DataArray to Variable * remove the deprecated return value of Dataset.update * remove the outdated datasets argument to combine_by_coords * fixed linting for combine_by_coords deprecation * all deprecations in the what's new * remove the documentation pages for the removed attributes [skip-ci] * Undo the deprecation and schedule the removal for 0.21 This reverts commit 85f5d2c. * update whats-new.rst * point to Dataset.merge [skip-ci] * Undo the removal of the update return value and update the scheduled version Co-authored-by: Thomas Nicholas <[email protected]>
1 parent deaca14 commit c5530d5

File tree

13 files changed

+33
-216
lines changed

13 files changed

+33
-216
lines changed

doc/api-hidden.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
core.rolling.DatasetCoarsen.var
5555
core.rolling.DatasetCoarsen.boundary
5656
core.rolling.DatasetCoarsen.coord_func
57-
core.rolling.DatasetCoarsen.keep_attrs
5857
core.rolling.DatasetCoarsen.obj
5958
core.rolling.DatasetCoarsen.side
6059
core.rolling.DatasetCoarsen.trim_excess
@@ -120,7 +119,6 @@
120119
core.rolling.DatasetRolling.var
121120
core.rolling.DatasetRolling.center
122121
core.rolling.DatasetRolling.dim
123-
core.rolling.DatasetRolling.keep_attrs
124122
core.rolling.DatasetRolling.min_periods
125123
core.rolling.DatasetRolling.obj
126124
core.rolling.DatasetRolling.rollings
@@ -199,7 +197,6 @@
199197
core.rolling.DataArrayCoarsen.var
200198
core.rolling.DataArrayCoarsen.boundary
201199
core.rolling.DataArrayCoarsen.coord_func
202-
core.rolling.DataArrayCoarsen.keep_attrs
203200
core.rolling.DataArrayCoarsen.obj
204201
core.rolling.DataArrayCoarsen.side
205202
core.rolling.DataArrayCoarsen.trim_excess
@@ -263,7 +260,6 @@
263260
core.rolling.DataArrayRolling.var
264261
core.rolling.DataArrayRolling.center
265262
core.rolling.DataArrayRolling.dim
266-
core.rolling.DataArrayRolling.keep_attrs
267263
core.rolling.DataArrayRolling.min_periods
268264
core.rolling.DataArrayRolling.obj
269265
core.rolling.DataArrayRolling.window

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Breaking changes
7777
Deprecations
7878
~~~~~~~~~~~~
7979

80+
- Removed the deprecated ``dim`` kwarg to :py:func:`DataArray.integrate` (:pull:`5630`)
81+
- Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.rolling` (:pull:`5630`)
82+
- Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.coarsen` (:pull:`5630`)
83+
- Completed deprecation of passing an ``xarray.DataArray`` to :py:func:`Variable` - will now raise a ``TypeError`` (:pull:`5630`)
8084

8185
Bug fixes
8286
~~~~~~~~~

xarray/core/combine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def _combine_single_variable_hypercube(
635635
return concatenated
636636

637637

638-
# TODO remove empty list default param after version 0.19, see PR4696
638+
# TODO remove empty list default param after version 0.21, see PR4696
639639
def combine_by_coords(
640640
data_objects=[],
641641
compat="no_conflicts",
@@ -849,11 +849,11 @@ def combine_by_coords(
849849
precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.5684 0.01879 0.6176
850850
"""
851851

852-
# TODO remove after version 0.19, see PR4696
852+
# TODO remove after version 0.21, see PR4696
853853
if datasets is not None:
854854
warnings.warn(
855855
"The datasets argument has been renamed to `data_objects`."
856-
" In future passing a value for datasets will raise an error."
856+
" From 0.21 on passing a value for datasets will raise an error."
857857
)
858858
data_objects = datasets
859859

xarray/core/common.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ def rolling(
821821
dim: Mapping[Hashable, int] = None,
822822
min_periods: int = None,
823823
center: Union[bool, Mapping[Hashable, bool]] = False,
824-
keep_attrs: bool = None,
825824
**window_kwargs: int,
826825
):
827826
"""
@@ -889,9 +888,7 @@ def rolling(
889888
"""
890889

891890
dim = either_dict_or_kwargs(dim, window_kwargs, "rolling")
892-
return self._rolling_cls(
893-
self, dim, min_periods=min_periods, center=center, keep_attrs=keep_attrs
894-
)
891+
return self._rolling_cls(self, dim, min_periods=min_periods, center=center)
895892

896893
def rolling_exp(
897894
self,
@@ -940,7 +937,6 @@ def coarsen(
940937
boundary: str = "exact",
941938
side: Union[str, Mapping[Hashable, str]] = "left",
942939
coord_func: str = "mean",
943-
keep_attrs: bool = None,
944940
**window_kwargs: int,
945941
):
946942
"""
@@ -1009,7 +1005,6 @@ def coarsen(
10091005
boundary=boundary,
10101006
side=side,
10111007
coord_func=coord_func,
1012-
keep_attrs=keep_attrs,
10131008
)
10141009

10151010
def resample(

xarray/core/dataarray.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,8 +3582,6 @@ def integrate(
35823582
self,
35833583
coord: Union[Hashable, Sequence[Hashable]] = None,
35843584
datetime_unit: str = None,
3585-
*,
3586-
dim: Union[Hashable, Sequence[Hashable]] = None,
35873585
) -> "DataArray":
35883586
"""Integrate along the given coordinate using the trapezoidal rule.
35893587
@@ -3595,8 +3593,6 @@ def integrate(
35953593
----------
35963594
coord : hashable, or sequence of hashable
35973595
Coordinate(s) used for the integration.
3598-
dim : hashable, or sequence of hashable
3599-
Coordinate(s) used for the integration.
36003596
datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \
36013597
'ps', 'fs', 'as'}, optional
36023598
Specify the unit if a datetime coordinate is used.
@@ -3633,21 +3629,6 @@ def integrate(
36333629
array([5.4, 6.6, 7.8])
36343630
Dimensions without coordinates: y
36353631
"""
3636-
if dim is not None and coord is not None:
3637-
raise ValueError(
3638-
"Cannot pass both 'dim' and 'coord'. Please pass only 'coord' instead."
3639-
)
3640-
3641-
if dim is not None and coord is None:
3642-
coord = dim
3643-
msg = (
3644-
"The `dim` keyword argument to `DataArray.integrate` is "
3645-
"being replaced with `coord`, for consistency with "
3646-
"`Dataset.integrate`. Please pass `coord` instead."
3647-
" `dim` will be removed in version 0.19.0."
3648-
)
3649-
warnings.warn(msg, FutureWarning, stacklevel=2)
3650-
36513632
ds = self._to_temp_dataset().integrate(coord, datetime_unit)
36523633
return self._from_temp_dataset(ds)
36533634

xarray/core/dataset.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4173,6 +4173,7 @@ def update(self, other: "CoercibleMapping") -> "Dataset":
41734173
"""Update this dataset's variables with those from another dataset.
41744174
41754175
Just like :py:meth:`dict.update` this is a in-place operation.
4176+
For a non-inplace version, see :py:meth:`Dataset.merge`.
41764177
41774178
Parameters
41784179
----------
@@ -4191,7 +4192,7 @@ def update(self, other: "CoercibleMapping") -> "Dataset":
41914192
Updated dataset. Note that since the update is in-place this is the input
41924193
dataset.
41934194
4194-
It is deprecated since version 0.17 and scheduled to be removed in 0.19.
4195+
It is deprecated since version 0.17 and scheduled to be removed in 0.21.
41954196
41964197
Raises
41974198
------
@@ -4202,6 +4203,7 @@ def update(self, other: "CoercibleMapping") -> "Dataset":
42024203
See Also
42034204
--------
42044205
Dataset.assign
4206+
Dataset.merge
42054207
"""
42064208
merge_result = dataset_update_method(self, other)
42074209
return self._replace(inplace=True, **merge_result._asdict())
@@ -4275,6 +4277,10 @@ def merge(
42754277
------
42764278
MergeError
42774279
If any variables conflict (see ``compat``).
4280+
4281+
See Also
4282+
--------
4283+
Dataset.update
42784284
"""
42794285
other = other.to_dataset() if isinstance(other, xr.DataArray) else other
42804286
merge_result = dataset_merge_method(

xarray/core/rolling.py

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class Rolling:
4848
xarray.DataArray.rolling
4949
"""
5050

51-
__slots__ = ("obj", "window", "min_periods", "center", "dim", "keep_attrs")
52-
_attributes = ("window", "min_periods", "center", "dim", "keep_attrs")
51+
__slots__ = ("obj", "window", "min_periods", "center", "dim")
52+
_attributes = ("window", "min_periods", "center", "dim")
5353

54-
def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None):
54+
def __init__(self, obj, windows, min_periods=None, center=False):
5555
"""
5656
Moving window object.
5757
@@ -89,15 +89,6 @@ def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None
8989

9090
self.min_periods = np.prod(self.window) if min_periods is None else min_periods
9191

92-
if keep_attrs is not None:
93-
warnings.warn(
94-
"Passing ``keep_attrs`` to ``rolling`` is deprecated and will raise an"
95-
" error in xarray 0.18. Please pass ``keep_attrs`` directly to the"
96-
" applied function. Note that keep_attrs is now True per default.",
97-
FutureWarning,
98-
)
99-
self.keep_attrs = keep_attrs
100-
10192
def __repr__(self):
10293
"""provide a nice str repr of our rolling object"""
10394

@@ -188,23 +179,16 @@ def _mapping_to_list(
188179
)
189180

190181
def _get_keep_attrs(self, keep_attrs):
191-
192182
if keep_attrs is None:
193-
# TODO: uncomment the next line and remove the others after the deprecation
194-
# keep_attrs = _get_keep_attrs(default=True)
195-
196-
if self.keep_attrs is None:
197-
keep_attrs = _get_keep_attrs(default=True)
198-
else:
199-
keep_attrs = self.keep_attrs
183+
keep_attrs = _get_keep_attrs(default=True)
200184

201185
return keep_attrs
202186

203187

204188
class DataArrayRolling(Rolling):
205189
__slots__ = ("window_labels",)
206190

207-
def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None):
191+
def __init__(self, obj, windows, min_periods=None, center=False):
208192
"""
209193
Moving window object for DataArray.
210194
You should use DataArray.rolling() method to construct this object
@@ -235,9 +219,7 @@ def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None
235219
xarray.Dataset.rolling
236220
xarray.Dataset.groupby
237221
"""
238-
super().__init__(
239-
obj, windows, min_periods=min_periods, center=center, keep_attrs=keep_attrs
240-
)
222+
super().__init__(obj, windows, min_periods=min_periods, center=center)
241223

242224
# TODO legacy attribute
243225
self.window_labels = self.obj[self.dim[0]]
@@ -561,7 +543,7 @@ def _numpy_or_bottleneck_reduce(
561543
class DatasetRolling(Rolling):
562544
__slots__ = ("rollings",)
563545

564-
def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None):
546+
def __init__(self, obj, windows, min_periods=None, center=False):
565547
"""
566548
Moving window object for Dataset.
567549
You should use Dataset.rolling() method to construct this object
@@ -592,7 +574,7 @@ def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None
592574
xarray.Dataset.groupby
593575
xarray.DataArray.groupby
594576
"""
595-
super().__init__(obj, windows, min_periods, center, keep_attrs)
577+
super().__init__(obj, windows, min_periods, center)
596578
if any(d not in self.obj.dims for d in self.dim):
597579
raise KeyError(self.dim)
598580
# Keep each Rolling object as a dictionary
@@ -768,11 +750,10 @@ class Coarsen(CoarsenArithmetic):
768750
"windows",
769751
"side",
770752
"trim_excess",
771-
"keep_attrs",
772753
)
773754
_attributes = ("windows", "side", "trim_excess")
774755

775-
def __init__(self, obj, windows, boundary, side, coord_func, keep_attrs):
756+
def __init__(self, obj, windows, boundary, side, coord_func):
776757
"""
777758
Moving window object.
778759
@@ -799,17 +780,6 @@ def __init__(self, obj, windows, boundary, side, coord_func, keep_attrs):
799780
self.side = side
800781
self.boundary = boundary
801782

802-
if keep_attrs is not None:
803-
warnings.warn(
804-
"Passing ``keep_attrs`` to ``coarsen`` is deprecated and will raise an"
805-
" error in xarray 0.19. Please pass ``keep_attrs`` directly to the"
806-
" applied function, i.e. use ``ds.coarsen(...).mean(keep_attrs=False)``"
807-
" instead of ``ds.coarsen(..., keep_attrs=False).mean()``"
808-
" Note that keep_attrs is now True per default.",
809-
FutureWarning,
810-
)
811-
self.keep_attrs = keep_attrs
812-
813783
absent_dims = [dim for dim in windows.keys() if dim not in self.obj.dims]
814784
if absent_dims:
815785
raise ValueError(
@@ -823,15 +793,8 @@ def __init__(self, obj, windows, boundary, side, coord_func, keep_attrs):
823793
self.coord_func = coord_func
824794

825795
def _get_keep_attrs(self, keep_attrs):
826-
827796
if keep_attrs is None:
828-
# TODO: uncomment the next line and remove the others after the deprecation
829-
# keep_attrs = _get_keep_attrs(default=True)
830-
831-
if self.keep_attrs is None:
832-
keep_attrs = _get_keep_attrs(default=True)
833-
else:
834-
keep_attrs = self.keep_attrs
797+
keep_attrs = _get_keep_attrs(default=True)
835798

836799
return keep_attrs
837800

xarray/core/variable.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,9 @@ def as_variable(obj, name=None) -> "Union[Variable, IndexVariable]":
118118
obj = obj.copy(deep=False)
119119
elif isinstance(obj, tuple):
120120
if isinstance(obj[1], DataArray):
121-
# TODO: change into TypeError
122-
warnings.warn(
123-
(
124-
"Using a DataArray object to construct a variable is"
125-
" ambiguous, please extract the data using the .data property."
126-
" This will raise a TypeError in 0.19.0."
127-
),
128-
DeprecationWarning,
121+
raise TypeError(
122+
"Using a DataArray object to construct a variable is"
123+
" ambiguous, please extract the data using the .data property."
129124
)
130125
try:
131126
obj = Variable(*obj)

xarray/tests/test_coarsen.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -153,39 +153,6 @@ def test_coarsen_keep_attrs(funcname, argument):
153153
assert result.da_not_coarsend.name == "da_not_coarsend"
154154

155155

156-
def test_coarsen_keep_attrs_deprecated():
157-
global_attrs = {"units": "test", "long_name": "testing"}
158-
attrs_da = {"da_attr": "test"}
159-
160-
data = np.linspace(10, 15, 100)
161-
coords = np.linspace(1, 10, 100)
162-
163-
ds = Dataset(
164-
data_vars={"da": ("coord", data)},
165-
coords={"coord": coords},
166-
attrs=global_attrs,
167-
)
168-
ds.da.attrs = attrs_da
169-
170-
# deprecated option
171-
with pytest.warns(
172-
FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated"
173-
):
174-
result = ds.coarsen(dim={"coord": 5}, keep_attrs=False).mean()
175-
176-
assert result.attrs == {}
177-
assert result.da.attrs == {}
178-
179-
# the keep_attrs in the reduction function takes precedence
180-
with pytest.warns(
181-
FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated"
182-
):
183-
result = ds.coarsen(dim={"coord": 5}, keep_attrs=True).mean(keep_attrs=False)
184-
185-
assert result.attrs == {}
186-
assert result.da.attrs == {}
187-
188-
189156
@pytest.mark.slow
190157
@pytest.mark.parametrize("ds", (1, 2), indirect=True)
191158
@pytest.mark.parametrize("window", (1, 2, 3, 4))
@@ -267,31 +234,6 @@ def test_coarsen_da_keep_attrs(funcname, argument):
267234
assert result.name == "name"
268235

269236

270-
def test_coarsen_da_keep_attrs_deprecated():
271-
attrs_da = {"da_attr": "test"}
272-
273-
data = np.linspace(10, 15, 100)
274-
coords = np.linspace(1, 10, 100)
275-
276-
da = DataArray(data, dims=("coord"), coords={"coord": coords}, attrs=attrs_da)
277-
278-
# deprecated option
279-
with pytest.warns(
280-
FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated"
281-
):
282-
result = da.coarsen(dim={"coord": 5}, keep_attrs=False).mean()
283-
284-
assert result.attrs == {}
285-
286-
# the keep_attrs in the reduction function takes precedence
287-
with pytest.warns(
288-
FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated"
289-
):
290-
result = da.coarsen(dim={"coord": 5}, keep_attrs=True).mean(keep_attrs=False)
291-
292-
assert result.attrs == {}
293-
294-
295237
@pytest.mark.parametrize("da", (1, 2), indirect=True)
296238
@pytest.mark.parametrize("window", (1, 2, 3, 4))
297239
@pytest.mark.parametrize("name", ("sum", "mean", "std", "max"))

0 commit comments

Comments
 (0)