Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecations scheduled for 0.19 #5630

Merged
merged 13 commits into from
Jul 23, 2021
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
4 changes: 0 additions & 4 deletions doc/api-hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ 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`)

Bug fixes
~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def _combine_single_variable_hypercube(
return concatenated


# TODO remove empty list default param after version 0.19, see PR4696
keewis marked this conversation as resolved.
Show resolved Hide resolved
# TODO remove empty list default param after version 0.21, see PR4696
def combine_by_coords(
data_objects=[],
compat="no_conflicts",
Expand Down Expand Up @@ -849,11 +849,11 @@ 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
# TODO remove after version 0.21, 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."
" From 0.21 on passing a value for datasets will raise an error."
)
data_objects = datasets

Expand Down
7 changes: 1 addition & 6 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
"""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -940,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,
):
"""
Expand Down Expand Up @@ -1009,7 +1005,6 @@ def coarsen(
boundary=boundary,
side=side,
coord_func=coord_func,
keep_attrs=keep_attrs,
)

def resample(
Expand Down
19 changes: 0 additions & 19 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4161,6 +4161,7 @@ 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.
For a non-inplace version, see :py:meth:`Dataset.merge`.

Parameters
----------
Expand All @@ -4179,7 +4180,7 @@ def update(self, other: "CoercibleMapping") -> "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.
It is deprecated since version 0.17 and scheduled to be removed in 0.21.

Raises
------
Expand All @@ -4190,6 +4191,7 @@ def update(self, other: "CoercibleMapping") -> "Dataset":
See Also
--------
Dataset.assign
Dataset.merge
"""
merge_result = dataset_update_method(self, other)
return self._replace(inplace=True, **merge_result._asdict())
Expand Down Expand Up @@ -4263,6 +4265,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(
Expand Down
57 changes: 10 additions & 47 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -188,23 +179,16 @@ 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


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
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -768,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.

Expand All @@ -799,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(
Expand All @@ -823,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

Expand Down
11 changes: 3 additions & 8 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 0 additions & 58 deletions xarray/tests/test_coarsen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"))
Expand Down
Loading