From d1260443d065c3f2ec3f8eb3d999c59a695b35a2 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Sun, 8 Sep 2019 18:58:15 -0400 Subject: [PATCH] Remove some deprecations (#3292) * remove some deprecations * whatsnew --- doc/whats-new.rst | 7 +++++++ xarray/__init__.py | 2 +- xarray/core/alignment.py | 21 ++------------------- xarray/core/dataarray.py | 12 +++--------- xarray/core/variable.py | 10 ---------- xarray/tests/test_dataarray.py | 12 ++++-------- xarray/tests/test_dataset.py | 6 ++---- 7 files changed, 19 insertions(+), 51 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 61a1fa59388..e65f052ca8c 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -49,6 +49,13 @@ Breaking changes crash in a later release. (:issue:`3250`) by `Guido Imperiale `_. +- :py:meth:`~Dataset.to_dataset` requires ``name`` to be passed as a kwarg (previously ambiguous + positional arguments were deprecated) +- Reindexing with variables of a different dimension now raise an error (previously deprecated) +- :py:func:`~xarray.broadcast_array` is removed (previously deprecated in favor of + :py:func:`~xarray.broadcast`) +- :py:meth:`~Variable.expand_dims` is removed (previously deprecated in favor of + :py:meth:`~Variable.set_dims`) New functions/methods ~~~~~~~~~~~~~~~~~~~~~ diff --git a/xarray/__init__.py b/xarray/__init__.py index a3df034f7c7..cdca708e28c 100644 --- a/xarray/__init__.py +++ b/xarray/__init__.py @@ -6,7 +6,7 @@ __version__ = get_versions()["version"] del get_versions -from .core.alignment import align, broadcast, broadcast_arrays +from .core.alignment import align, broadcast from .core.common import full_like, zeros_like, ones_like from .core.concat import concat from .core.combine import combine_by_coords, combine_nested, auto_combine diff --git a/xarray/core/alignment.py b/xarray/core/alignment.py index 9aeef63e891..d63718500bc 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -1,6 +1,5 @@ import functools import operator -import warnings from collections import OrderedDict, defaultdict from contextlib import suppress from typing import TYPE_CHECKING, Any, Dict, Hashable, Mapping, Optional, Tuple, Union @@ -387,14 +386,9 @@ def reindex_variables( for dim, indexer in indexers.items(): if isinstance(indexer, DataArray) and indexer.dims != (dim,): - warnings.warn( + raise ValueError( "Indexer has dimensions {:s} that are different " - "from that to be indexed along {:s}. " - "This will behave differently in the future.".format( - str(indexer.dims), dim - ), - FutureWarning, - stacklevel=3, + "from that to be indexed along {:s}".format(str(indexer.dims), dim) ) target = new_indexes[dim] = utils.safe_cast_to_index(indexers[dim]) @@ -592,14 +586,3 @@ def broadcast(*args, exclude=None): result.append(_broadcast_helper(arg, exclude, dims_map, common_coords)) return tuple(result) - - -def broadcast_arrays(*args): - import warnings - - warnings.warn( - "xarray.broadcast_arrays is deprecated: use " "xarray.broadcast instead", - DeprecationWarning, - stacklevel=2, - ) - return broadcast(*args) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 8660fa952b1..a3655e2c4b2 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -471,7 +471,7 @@ def _to_dataset_whole( dataset = Dataset._from_vars_and_coord_names(variables, coord_names) return dataset - def to_dataset(self, dim: Hashable = None, name: Hashable = None) -> Dataset: + def to_dataset(self, dim: Hashable = None, *, name: Hashable = None) -> Dataset: """Convert a DataArray to a Dataset. Parameters @@ -489,15 +489,9 @@ def to_dataset(self, dim: Hashable = None, name: Hashable = None) -> Dataset: dataset : Dataset """ if dim is not None and dim not in self.dims: - warnings.warn( - "the order of the arguments on DataArray.to_dataset " - "has changed; you now need to supply ``name`` as " - "a keyword argument", - FutureWarning, - stacklevel=2, + raise TypeError( + "{} is not a dim. If supplying a ``name``, pass as a kwarg.".format(dim) ) - name = dim - dim = None if dim is not None: if name is not None: diff --git a/xarray/core/variable.py b/xarray/core/variable.py index ac4f7052f14..2e9906ce5ae 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1226,16 +1226,6 @@ def transpose(self, *dims) -> "Variable": def T(self) -> "Variable": return self.transpose() - def expand_dims(self, *args): - import warnings - - warnings.warn( - "Variable.expand_dims is deprecated: use " "Variable.set_dims instead", - DeprecationWarning, - stacklevel=2, - ) - return self.expand_dims(*args) - def set_dims(self, dims, shape=None): """Return a new variable with given set of dimensions. This method might be used to attach new dimension(s) to variable. diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 27e6ab92f71..8c01ef9a68c 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -1408,13 +1408,11 @@ def test_reindex_like_no_index(self): with raises_regex(ValueError, "different size for unlabeled"): foo.reindex_like(bar) - @pytest.mark.filterwarnings("ignore:Indexer has dimensions") def test_reindex_regressions(self): - # regression test for #279 - expected = DataArray(np.random.randn(5), coords=[("time", range(5))]) + da = DataArray(np.random.randn(5), coords=[("time", range(5))]) time2 = DataArray(np.arange(5), dims="time2") - actual = expected.reindex(time=time2) - assert_identical(actual, expected) + with pytest.raises(ValueError): + da.reindex(time=time2) # regression test for #736, reindex can not change complex nums dtype x = np.array([1, 2, 3], dtype=np.complex) @@ -3685,10 +3683,8 @@ def test_to_dataset_whole(self): expected = Dataset({"foo": ("x", [1, 2])}) assert_identical(expected, actual) - expected = Dataset({"bar": ("x", [1, 2])}) - with pytest.warns(FutureWarning): + with pytest.raises(TypeError): actual = named.to_dataset("bar") - assert_identical(expected, actual) def test_to_dataset_split(self): array = DataArray([1, 2, 3], coords=[("x", list("abc"))], attrs={"a": 1}) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index d9f0284969e..814fc31d734 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -1689,9 +1689,8 @@ def test_reindex(self): # regression test for #279 expected = Dataset({"x": ("time", np.random.randn(5))}, {"time": range(5)}) time2 = DataArray(np.arange(5), dims="time2") - with pytest.warns(FutureWarning): + with pytest.raises(ValueError): actual = expected.reindex(time=time2) - assert_identical(actual, expected) # another regression test ds = Dataset( @@ -1707,11 +1706,10 @@ def test_reindex(self): def test_reindex_warning(self): data = create_test_data() - with pytest.warns(FutureWarning) as ws: + with pytest.raises(ValueError): # DataArray with different dimension raises Future warning ind = xr.DataArray([0.0, 1.0], dims=["new_dim"], name="ind") data.reindex(dim2=ind) - assert any(["Indexer has dimensions " in str(w.message) for w in ws]) # Should not warn ind = xr.DataArray([0.0, 1.0], dims=["dim2"], name="ind")