From 8aacaf5a80adc8994e33af429e2c721f20168d0f Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 00:33:29 +0200 Subject: [PATCH 01/13] remove the deprecated dim kwarg for DataArray.integrate --- xarray/core/dataarray.py | 19 ------------------- xarray/tests/test_dataset.py | 3 --- 2 files changed, 22 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index b4d553c235a..7214d55d43a 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -3540,8 +3540,6 @@ def integrate( self, coord: Union[Hashable, Sequence[Hashable]] = None, datetime_unit: str = None, - *, - dim: Union[Hashable, Sequence[Hashable]] = None, ) -> "DataArray": """Integrate along the given coordinate using the trapezoidal rule. @@ -3553,8 +3551,6 @@ def integrate( ---------- coord : hashable, or sequence of hashable Coordinate(s) used for the integration. - dim : hashable, or sequence of hashable - Coordinate(s) used for the integration. datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ 'ps', 'fs', 'as'}, optional Specify the unit if a datetime coordinate is used. @@ -3591,21 +3587,6 @@ def integrate( array([5.4, 6.6, 7.8]) Dimensions without coordinates: y """ - if dim is not None and coord is not None: - raise ValueError( - "Cannot pass both 'dim' and 'coord'. Please pass only 'coord' instead." - ) - - if dim is not None and coord is None: - coord = dim - msg = ( - "The `dim` keyword argument to `DataArray.integrate` is " - "being replaced with `coord`, for consistency with " - "`Dataset.integrate`. Please pass `coord` instead." - " `dim` will be removed in version 0.19.0." - ) - warnings.warn(msg, FutureWarning, stacklevel=2) - ds = self._to_temp_dataset().integrate(coord, datetime_unit) return self._from_temp_dataset(ds) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index b08ce9ea730..c9d4c2b79b9 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -6580,9 +6580,6 @@ def test_integrate(dask): with pytest.raises(ValueError): da.integrate("x2d") - with pytest.warns(FutureWarning): - da.integrate(dim="x") - @requires_scipy @pytest.mark.parametrize("dask", [True, False]) From dda0280a6ddb22307f590b16fdde78a48457302f Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 00:39:52 +0200 Subject: [PATCH 02/13] remove the deprecated keep_attrs kwarg to .rolling --- xarray/core/common.py | 5 +---- xarray/core/rolling.py | 34 ++++++++------------------------- xarray/tests/test_dataarray.py | 27 -------------------------- xarray/tests/test_dataset.py | 35 ---------------------------------- 4 files changed, 9 insertions(+), 92 deletions(-) diff --git a/xarray/core/common.py b/xarray/core/common.py index 7b6e9198b43..9dab0a32a89 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -821,7 +821,6 @@ def rolling( dim: Mapping[Hashable, int] = None, min_periods: int = None, center: Union[bool, Mapping[Hashable, bool]] = False, - keep_attrs: bool = None, **window_kwargs: int, ): """ @@ -889,9 +888,7 @@ def rolling( """ dim = either_dict_or_kwargs(dim, window_kwargs, "rolling") - return self._rolling_cls( - self, dim, min_periods=min_periods, center=center, keep_attrs=keep_attrs - ) + return self._rolling_cls(self, dim, min_periods=min_periods, center=center) def rolling_exp( self, diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index b87dcda24b0..9aab904b1f6 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -48,10 +48,10 @@ class Rolling: xarray.DataArray.rolling """ - __slots__ = ("obj", "window", "min_periods", "center", "dim", "keep_attrs") - _attributes = ("window", "min_periods", "center", "dim", "keep_attrs") + __slots__ = ("obj", "window", "min_periods", "center", "dim") + _attributes = ("window", "min_periods", "center", "dim") - def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None): + def __init__(self, obj, windows, min_periods=None, center=False): """ Moving window object. @@ -89,15 +89,6 @@ def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None self.min_periods = np.prod(self.window) if min_periods is None else min_periods - if keep_attrs is not None: - warnings.warn( - "Passing ``keep_attrs`` to ``rolling`` is deprecated and will raise an" - " error in xarray 0.18. Please pass ``keep_attrs`` directly to the" - " applied function. Note that keep_attrs is now True per default.", - FutureWarning, - ) - self.keep_attrs = keep_attrs - def __repr__(self): """provide a nice str repr of our rolling object""" @@ -188,15 +179,8 @@ def _mapping_to_list( ) def _get_keep_attrs(self, keep_attrs): - if keep_attrs is None: - # TODO: uncomment the next line and remove the others after the deprecation - # keep_attrs = _get_keep_attrs(default=True) - - if self.keep_attrs is None: - keep_attrs = _get_keep_attrs(default=True) - else: - keep_attrs = self.keep_attrs + keep_attrs = _get_keep_attrs(default=True) return keep_attrs @@ -204,7 +188,7 @@ def _get_keep_attrs(self, keep_attrs): class DataArrayRolling(Rolling): __slots__ = ("window_labels",) - def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None): + def __init__(self, obj, windows, min_periods=None, center=False): """ Moving window object for DataArray. 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 xarray.Dataset.rolling xarray.Dataset.groupby """ - super().__init__( - obj, windows, min_periods=min_periods, center=center, keep_attrs=keep_attrs - ) + super().__init__(obj, windows, min_periods=min_periods, center=center) # TODO legacy attribute self.window_labels = self.obj[self.dim[0]] @@ -561,7 +543,7 @@ def _numpy_or_bottleneck_reduce( class DatasetRolling(Rolling): __slots__ = ("rollings",) - def __init__(self, obj, windows, min_periods=None, center=False, keep_attrs=None): + def __init__(self, obj, windows, min_periods=None, center=False): """ Moving window object for Dataset. 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 xarray.Dataset.groupby xarray.DataArray.groupby """ - super().__init__(obj, windows, min_periods, center, keep_attrs) + super().__init__(obj, windows, min_periods, center) if any(d not in self.obj.dims for d in self.dim): raise KeyError(self.dim) # Keep each Rolling object as a dictionary diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index b9f04085935..27cdf3739ba 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -6865,33 +6865,6 @@ def test_rolling_keep_attrs(funcname, argument): assert result.name == "name" -def test_rolling_keep_attrs_deprecated(): - attrs_da = {"da_attr": "test"} - - data = np.linspace(10, 15, 100) - coords = np.linspace(1, 10, 100) - - da = DataArray(data, dims=("coord"), coords={"coord": coords}, attrs=attrs_da) - - # deprecated option - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``rolling`` is deprecated" - ): - result = da.rolling(dim={"coord": 5}, keep_attrs=False).construct("window_dim") - - assert result.attrs == {} - - # the keep_attrs in the reduction function takes precedence - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``rolling`` is deprecated" - ): - result = da.rolling(dim={"coord": 5}, keep_attrs=True).construct( - "window_dim", keep_attrs=False - ) - - assert result.attrs == {} - - def test_raise_no_warning_for_nan_in_binary_ops(): with pytest.warns(None) as record: xr.DataArray([1, 2, np.NaN]) > 0 diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index c9d4c2b79b9..7ee80c0e8f6 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -6100,41 +6100,6 @@ def test_rolling_keep_attrs(funcname, argument): assert result.da_not_rolled.name == "da_not_rolled" -def test_rolling_keep_attrs_deprecated(): - global_attrs = {"units": "test", "long_name": "testing"} - attrs_da = {"da_attr": "test"} - - data = np.linspace(10, 15, 100) - coords = np.linspace(1, 10, 100) - - ds = Dataset( - data_vars={"da": ("coord", data)}, - coords={"coord": coords}, - attrs=global_attrs, - ) - ds.da.attrs = attrs_da - - # deprecated option - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``rolling`` is deprecated" - ): - result = ds.rolling(dim={"coord": 5}, keep_attrs=False).construct("window_dim") - - assert result.attrs == {} - assert result.da.attrs == {} - - # the keep_attrs in the reduction function takes precedence - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``rolling`` is deprecated" - ): - result = ds.rolling(dim={"coord": 5}, keep_attrs=True).construct( - "window_dim", keep_attrs=False - ) - - assert result.attrs == {} - assert result.da.attrs == {} - - def test_rolling_properties(ds): # catching invalid args with pytest.raises(ValueError, match="window must be > 0"): From 986b8fdeec1848dba222ef7e61b673ecb4f28858 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 00:44:58 +0200 Subject: [PATCH 03/13] remove the keep_attrs kwarg to .coarsen --- xarray/core/common.py | 2 -- xarray/core/rolling.py | 23 ++------------ xarray/tests/test_coarsen.py | 58 ------------------------------------ 3 files changed, 2 insertions(+), 81 deletions(-) diff --git a/xarray/core/common.py b/xarray/core/common.py index 9dab0a32a89..ab822f576d3 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -937,7 +937,6 @@ def coarsen( boundary: str = "exact", side: Union[str, Mapping[Hashable, str]] = "left", coord_func: str = "mean", - keep_attrs: bool = None, **window_kwargs: int, ): """ @@ -1006,7 +1005,6 @@ def coarsen( boundary=boundary, side=side, coord_func=coord_func, - keep_attrs=keep_attrs, ) def resample( diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index 9aab904b1f6..04052510f5d 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -750,11 +750,10 @@ class Coarsen(CoarsenArithmetic): "windows", "side", "trim_excess", - "keep_attrs", ) _attributes = ("windows", "side", "trim_excess") - def __init__(self, obj, windows, boundary, side, coord_func, keep_attrs): + def __init__(self, obj, windows, boundary, side, coord_func): """ Moving window object. @@ -781,17 +780,6 @@ def __init__(self, obj, windows, boundary, side, coord_func, keep_attrs): self.side = side self.boundary = boundary - if keep_attrs is not None: - warnings.warn( - "Passing ``keep_attrs`` to ``coarsen`` is deprecated and will raise an" - " error in xarray 0.19. Please pass ``keep_attrs`` directly to the" - " applied function, i.e. use ``ds.coarsen(...).mean(keep_attrs=False)``" - " instead of ``ds.coarsen(..., keep_attrs=False).mean()``" - " Note that keep_attrs is now True per default.", - FutureWarning, - ) - self.keep_attrs = keep_attrs - absent_dims = [dim for dim in windows.keys() if dim not in self.obj.dims] if absent_dims: raise ValueError( @@ -805,15 +793,8 @@ def __init__(self, obj, windows, boundary, side, coord_func, keep_attrs): self.coord_func = coord_func def _get_keep_attrs(self, keep_attrs): - if keep_attrs is None: - # TODO: uncomment the next line and remove the others after the deprecation - # keep_attrs = _get_keep_attrs(default=True) - - if self.keep_attrs is None: - keep_attrs = _get_keep_attrs(default=True) - else: - keep_attrs = self.keep_attrs + keep_attrs = _get_keep_attrs(default=True) return keep_attrs diff --git a/xarray/tests/test_coarsen.py b/xarray/tests/test_coarsen.py index 503c742252a..278a961166f 100644 --- a/xarray/tests/test_coarsen.py +++ b/xarray/tests/test_coarsen.py @@ -153,39 +153,6 @@ def test_coarsen_keep_attrs(funcname, argument): assert result.da_not_coarsend.name == "da_not_coarsend" -def test_coarsen_keep_attrs_deprecated(): - global_attrs = {"units": "test", "long_name": "testing"} - attrs_da = {"da_attr": "test"} - - data = np.linspace(10, 15, 100) - coords = np.linspace(1, 10, 100) - - ds = Dataset( - data_vars={"da": ("coord", data)}, - coords={"coord": coords}, - attrs=global_attrs, - ) - ds.da.attrs = attrs_da - - # deprecated option - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated" - ): - result = ds.coarsen(dim={"coord": 5}, keep_attrs=False).mean() - - assert result.attrs == {} - assert result.da.attrs == {} - - # the keep_attrs in the reduction function takes precedence - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated" - ): - result = ds.coarsen(dim={"coord": 5}, keep_attrs=True).mean(keep_attrs=False) - - assert result.attrs == {} - assert result.da.attrs == {} - - @pytest.mark.slow @pytest.mark.parametrize("ds", (1, 2), indirect=True) @pytest.mark.parametrize("window", (1, 2, 3, 4)) @@ -267,31 +234,6 @@ def test_coarsen_da_keep_attrs(funcname, argument): assert result.name == "name" -def test_coarsen_da_keep_attrs_deprecated(): - attrs_da = {"da_attr": "test"} - - data = np.linspace(10, 15, 100) - coords = np.linspace(1, 10, 100) - - da = DataArray(data, dims=("coord"), coords={"coord": coords}, attrs=attrs_da) - - # deprecated option - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated" - ): - result = da.coarsen(dim={"coord": 5}, keep_attrs=False).mean() - - assert result.attrs == {} - - # the keep_attrs in the reduction function takes precedence - with pytest.warns( - FutureWarning, match="Passing ``keep_attrs`` to ``coarsen`` is deprecated" - ): - result = da.coarsen(dim={"coord": 5}, keep_attrs=True).mean(keep_attrs=False) - - assert result.attrs == {} - - @pytest.mark.parametrize("da", (1, 2), indirect=True) @pytest.mark.parametrize("window", (1, 2, 3, 4)) @pytest.mark.parametrize("name", ("sum", "mean", "std", "max")) From c6b33e625c9b1d4a9a3a074022dabfb2dfc1ec8b Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 00:48:45 +0200 Subject: [PATCH 04/13] raise a TypeError when passing DataArray to Variable --- xarray/core/variable.py | 11 +++-------- xarray/tests/test_variable.py | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index ace09c6f482..22225a4f57b 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -116,14 +116,9 @@ def as_variable(obj, name=None) -> "Union[Variable, IndexVariable]": obj = obj.copy(deep=False) elif isinstance(obj, tuple): if isinstance(obj[1], DataArray): - # TODO: change into TypeError - warnings.warn( - ( - "Using a DataArray object to construct a variable is" - " ambiguous, please extract the data using the .data property." - " This will raise a TypeError in 0.19.0." - ), - DeprecationWarning, + raise TypeError( + "Using a DataArray object to construct a variable is" + " ambiguous, please extract the data using the .data property." ) try: obj = Variable(*obj) diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index 1e0dff45dd2..d92f6b2dd78 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -1160,7 +1160,7 @@ def test_as_variable(self): td = np.array([timedelta(days=x) for x in range(10)]) assert as_variable(td, "time").dtype.kind == "m" - with pytest.warns(DeprecationWarning): + with pytest.raises(TypeError): as_variable(("x", DataArray([]))) def test_repr(self): From 5cc85c8d3658ed55cad98fe79519824f68cfe76e Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 00:53:08 +0200 Subject: [PATCH 05/13] remove the deprecated return value of Dataset.update --- xarray/core/dataset.py | 12 ++---------- xarray/tests/test_dask.py | 2 +- xarray/tests/test_dataset.py | 6 +++--- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 13da8cfad03..8604b031039 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -4157,7 +4157,7 @@ def unstack( result = result._unstack_once(dim, fill_value) return result - def update(self, other: "CoercibleMapping") -> "Dataset": + def update(self, other: "CoercibleMapping") -> None: """Update this dataset's variables with those from another dataset. Just like :py:meth:`dict.update` this is a in-place operation. @@ -4173,14 +4173,6 @@ def update(self, other: "CoercibleMapping") -> "Dataset": - mapping {var name: (dimension name, array-like)} - mapping {var name: (tuple of dimension names, array-like)} - Returns - ------- - updated : Dataset - Updated dataset. Note that since the update is in-place this is the input - dataset. - - It is deprecated since version 0.17 and scheduled to be removed in 0.19. - Raises ------ ValueError @@ -4192,7 +4184,7 @@ def update(self, other: "CoercibleMapping") -> "Dataset": Dataset.assign """ merge_result = dataset_update_method(self, other) - return self._replace(inplace=True, **merge_result._asdict()) + self._replace(inplace=True, **merge_result._asdict()) def merge( self, diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index f790587efa9..d52fe0875fe 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -1619,7 +1619,7 @@ def test_more_transforms_pass_lazy_array_equiv(map_da, map_ds): assert_equal(xr.broadcast(map_ds.cxy, map_ds.cxy)[0], map_ds.cxy) assert_equal(map_ds.map(lambda x: x), map_ds) assert_equal(map_ds.set_coords("a").reset_coords("a"), map_ds) - assert_equal(map_ds.update({"a": map_ds.a}), map_ds) + assert_equal(map_ds.assign({"a": map_ds.a}), map_ds) # fails because of index error # assert_equal( diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 7ee80c0e8f6..7d44544aa49 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -3191,13 +3191,13 @@ def test_update(self): data = create_test_data(seed=0) expected = data.copy() var2 = Variable("dim1", np.arange(8)) - actual = data.update({"var2": var2}) + actual = data + actual.update({"var2": var2}) expected["var2"] = var2 assert_identical(expected, actual) actual = data.copy() - actual_result = actual.update(data) - assert actual_result is actual + actual.update(data) assert_identical(expected, actual) other = Dataset(attrs={"new": "attr"}) From 85f5d2c25f4c4a0e0ac9aa75a8c31a2cd60f3033 Mon Sep 17 00:00:00 2001 From: Thomas Nicholas Date: Thu, 22 Jul 2021 21:07:32 -0400 Subject: [PATCH 06/13] remove the outdated datasets argument to combine_by_coords --- xarray/core/combine.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/xarray/core/combine.py b/xarray/core/combine.py index de6d16ef5c3..3ed2a3e9f97 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -635,16 +635,14 @@ def _combine_single_variable_hypercube( return concatenated -# TODO remove empty list default param after version 0.19, see PR4696 def combine_by_coords( - data_objects=[], + data_objects, compat="no_conflicts", data_vars="all", coords="different", fill_value=dtypes.NA, join="outer", combine_attrs="no_conflicts", - datasets=None, ): """ Attempt to auto-magically combine the given datasets (or data arrays) @@ -849,14 +847,6 @@ def combine_by_coords( precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.5684 0.01879 0.6176 """ - # TODO remove after version 0.19, see PR4696 - if datasets is not None: - warnings.warn( - "The datasets argument has been renamed to `data_objects`." - " In future passing a value for datasets will raise an error." - ) - data_objects = datasets - if not data_objects: return Dataset() From a1d576d5a277c9fa3e440beedf39ef22cbe8aacb Mon Sep 17 00:00:00 2001 From: Thomas Nicholas Date: Thu, 22 Jul 2021 21:19:30 -0400 Subject: [PATCH 07/13] fixed linting for combine_by_coords deprecation --- xarray/core/combine.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 3ed2a3e9f97..85b58d7ee27 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -1,5 +1,4 @@ import itertools -import warnings from collections import Counter import pandas as pd From c245cacd2a4911993c1950b0701fbcbac3d1d4eb Mon Sep 17 00:00:00 2001 From: Thomas Nicholas Date: Thu, 22 Jul 2021 21:20:02 -0400 Subject: [PATCH 08/13] all deprecations in the what's new --- doc/whats-new.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 0053824c87b..6344bc86d6c 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -70,6 +70,13 @@ Breaking changes Deprecations ~~~~~~~~~~~~ +- Removed the deprecated ``dim`` kwarg to :py:func:`DataArray.integrate` (:pull:`5630`) +- Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.rolling` (:pull:`5630`) +- Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.coarsen` (:pull:`5630`) +- Completed deprecation of passing an ``xarray.DataArray`` to :py:func:`Variable` - will now raise a ``TypeError`` (:pull:`5630`) +- Removed the deprecated return value of :py:func:`Dataset.update` (:pull:`5630`) +- Removed the deprecated lock kwarg to :py:func:`DataArray.open_dataset` (:pull:`5630`) +- Removed the deprecated datasets argument to :py:func:`combine_by_coords` (:pull:`5630`) Bug fixes ~~~~~~~~~ From 65999558078f0e02abc077725fe831a8186111e0 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 13:44:42 +0200 Subject: [PATCH 09/13] remove the documentation pages for the removed attributes [skip-ci] --- doc/api-hidden.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/api-hidden.rst b/doc/api-hidden.rst index 076b0eb452a..fc27d9c3fe8 100644 --- a/doc/api-hidden.rst +++ b/doc/api-hidden.rst @@ -54,7 +54,6 @@ core.rolling.DatasetCoarsen.var core.rolling.DatasetCoarsen.boundary core.rolling.DatasetCoarsen.coord_func - core.rolling.DatasetCoarsen.keep_attrs core.rolling.DatasetCoarsen.obj core.rolling.DatasetCoarsen.side core.rolling.DatasetCoarsen.trim_excess @@ -120,7 +119,6 @@ core.rolling.DatasetRolling.var core.rolling.DatasetRolling.center core.rolling.DatasetRolling.dim - core.rolling.DatasetRolling.keep_attrs core.rolling.DatasetRolling.min_periods core.rolling.DatasetRolling.obj core.rolling.DatasetRolling.rollings @@ -199,7 +197,6 @@ core.rolling.DataArrayCoarsen.var core.rolling.DataArrayCoarsen.boundary core.rolling.DataArrayCoarsen.coord_func - core.rolling.DataArrayCoarsen.keep_attrs core.rolling.DataArrayCoarsen.obj core.rolling.DataArrayCoarsen.side core.rolling.DataArrayCoarsen.trim_excess @@ -263,7 +260,6 @@ core.rolling.DataArrayRolling.var core.rolling.DataArrayRolling.center core.rolling.DataArrayRolling.dim - core.rolling.DataArrayRolling.keep_attrs core.rolling.DataArrayRolling.min_periods core.rolling.DataArrayRolling.obj core.rolling.DataArrayRolling.window From 132a8b892b7de3bdf98734a911214e1fc36f5620 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 18:41:29 +0200 Subject: [PATCH 10/13] Undo the deprecation and schedule the removal for 0.21 This reverts commit 85f5d2c25f4c4a0e0ac9aa75a8c31a2cd60f3033. --- xarray/core/combine.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 85b58d7ee27..be9c2992832 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -1,4 +1,5 @@ import itertools +import warnings from collections import Counter import pandas as pd @@ -634,14 +635,16 @@ def _combine_single_variable_hypercube( return concatenated +# TODO remove empty list default param after version 0.21, see PR4696 def combine_by_coords( - data_objects, + data_objects=[], compat="no_conflicts", data_vars="all", coords="different", fill_value=dtypes.NA, join="outer", combine_attrs="no_conflicts", + datasets=None, ): """ Attempt to auto-magically combine the given datasets (or data arrays) @@ -846,6 +849,14 @@ def combine_by_coords( precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.5684 0.01879 0.6176 """ + # TODO remove after version 0.21, see PR4696 + if datasets is not None: + warnings.warn( + "The datasets argument has been renamed to `data_objects`." + " From 0.21 on passing a value for datasets will raise an error." + ) + data_objects = datasets + if not data_objects: return Dataset() From 2d0ef4cf181b94c0ec4a2832810c53b87d47d6c7 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 18:43:07 +0200 Subject: [PATCH 11/13] update whats-new.rst --- doc/whats-new.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 6344bc86d6c..780045973de 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -75,8 +75,6 @@ Deprecations - Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.coarsen` (:pull:`5630`) - Completed deprecation of passing an ``xarray.DataArray`` to :py:func:`Variable` - will now raise a ``TypeError`` (:pull:`5630`) - Removed the deprecated return value of :py:func:`Dataset.update` (:pull:`5630`) -- Removed the deprecated lock kwarg to :py:func:`DataArray.open_dataset` (:pull:`5630`) -- Removed the deprecated datasets argument to :py:func:`combine_by_coords` (:pull:`5630`) Bug fixes ~~~~~~~~~ From efc82d392c1c859704af042a5a5d9eb72be011ad Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 18:46:38 +0200 Subject: [PATCH 12/13] point to Dataset.merge [skip-ci] --- xarray/core/dataset.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 8604b031039..79b2a0cd2a9 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -4161,6 +4161,7 @@ def update(self, other: "CoercibleMapping") -> None: """Update this dataset's variables with those from another dataset. Just like :py:meth:`dict.update` this is a in-place operation. + For a non-inplace version, see :py:meth:`Dataset.merge`. Parameters ---------- @@ -4182,6 +4183,7 @@ def update(self, other: "CoercibleMapping") -> None: See Also -------- Dataset.assign + Dataset.merge """ merge_result = dataset_update_method(self, other) self._replace(inplace=True, **merge_result._asdict()) @@ -4255,6 +4257,10 @@ def merge( ------ MergeError If any variables conflict (see ``compat``). + + See Also + -------- + Dataset.update """ other = other.to_dataset() if isinstance(other, xr.DataArray) else other merge_result = dataset_merge_method( From b4252cc006655f559b5fc27014bded01fc8232a8 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 23 Jul 2021 20:45:35 +0200 Subject: [PATCH 13/13] Undo the removal of the update return value and update the scheduled version --- doc/whats-new.rst | 1 - xarray/core/dataset.py | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 780045973de..7b24611d190 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -74,7 +74,6 @@ Deprecations - Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.rolling` (:pull:`5630`) - Removed the deprecated ``keep_attrs`` kwarg to :py:func:`DataArray.coarsen` (:pull:`5630`) - Completed deprecation of passing an ``xarray.DataArray`` to :py:func:`Variable` - will now raise a ``TypeError`` (:pull:`5630`) -- Removed the deprecated return value of :py:func:`Dataset.update` (:pull:`5630`) Bug fixes ~~~~~~~~~ diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 79b2a0cd2a9..7b7a4fcf51f 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -4157,7 +4157,7 @@ def unstack( result = result._unstack_once(dim, fill_value) return result - def update(self, other: "CoercibleMapping") -> None: + def update(self, other: "CoercibleMapping") -> "Dataset": """Update this dataset's variables with those from another dataset. Just like :py:meth:`dict.update` this is a in-place operation. @@ -4174,6 +4174,14 @@ def update(self, other: "CoercibleMapping") -> None: - mapping {var name: (dimension name, array-like)} - mapping {var name: (tuple of dimension names, array-like)} + Returns + ------- + updated : Dataset + Updated dataset. Note that since the update is in-place this is the input + dataset. + + It is deprecated since version 0.17 and scheduled to be removed in 0.21. + Raises ------ ValueError @@ -4186,7 +4194,7 @@ def update(self, other: "CoercibleMapping") -> None: Dataset.merge """ merge_result = dataset_update_method(self, other) - self._replace(inplace=True, **merge_result._asdict()) + return self._replace(inplace=True, **merge_result._asdict()) def merge( self,