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 5 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
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
12 changes: 2 additions & 10 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
keewis marked this conversation as resolved.
Show resolved Hide resolved

Raises
------
ValueError
Expand All @@ -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,
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
2 changes: 1 addition & 1 deletion xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
keewis marked this conversation as resolved.
Show resolved Hide resolved

# fails because of index error
# assert_equal(
Expand Down
27 changes: 0 additions & 27 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading