Skip to content

Commit d126044

Browse files
max-sixtyshoyer
authored andcommitted
Remove some deprecations (#3292)
* remove some deprecations * whatsnew
1 parent 0a046db commit d126044

File tree

7 files changed

+19
-51
lines changed

7 files changed

+19
-51
lines changed

doc/whats-new.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ Breaking changes
4949
crash in a later release.
5050

5151
(:issue:`3250`) by `Guido Imperiale <https://github.com/crusaderky>`_.
52+
- :py:meth:`~Dataset.to_dataset` requires ``name`` to be passed as a kwarg (previously ambiguous
53+
positional arguments were deprecated)
54+
- Reindexing with variables of a different dimension now raise an error (previously deprecated)
55+
- :py:func:`~xarray.broadcast_array` is removed (previously deprecated in favor of
56+
:py:func:`~xarray.broadcast`)
57+
- :py:meth:`~Variable.expand_dims` is removed (previously deprecated in favor of
58+
:py:meth:`~Variable.set_dims`)
5259

5360
New functions/methods
5461
~~~~~~~~~~~~~~~~~~~~~

xarray/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__version__ = get_versions()["version"]
77
del get_versions
88

9-
from .core.alignment import align, broadcast, broadcast_arrays
9+
from .core.alignment import align, broadcast
1010
from .core.common import full_like, zeros_like, ones_like
1111
from .core.concat import concat
1212
from .core.combine import combine_by_coords, combine_nested, auto_combine

xarray/core/alignment.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import functools
22
import operator
3-
import warnings
43
from collections import OrderedDict, defaultdict
54
from contextlib import suppress
65
from typing import TYPE_CHECKING, Any, Dict, Hashable, Mapping, Optional, Tuple, Union
@@ -387,14 +386,9 @@ def reindex_variables(
387386

388387
for dim, indexer in indexers.items():
389388
if isinstance(indexer, DataArray) and indexer.dims != (dim,):
390-
warnings.warn(
389+
raise ValueError(
391390
"Indexer has dimensions {:s} that are different "
392-
"from that to be indexed along {:s}. "
393-
"This will behave differently in the future.".format(
394-
str(indexer.dims), dim
395-
),
396-
FutureWarning,
397-
stacklevel=3,
391+
"from that to be indexed along {:s}".format(str(indexer.dims), dim)
398392
)
399393

400394
target = new_indexes[dim] = utils.safe_cast_to_index(indexers[dim])
@@ -592,14 +586,3 @@ def broadcast(*args, exclude=None):
592586
result.append(_broadcast_helper(arg, exclude, dims_map, common_coords))
593587

594588
return tuple(result)
595-
596-
597-
def broadcast_arrays(*args):
598-
import warnings
599-
600-
warnings.warn(
601-
"xarray.broadcast_arrays is deprecated: use " "xarray.broadcast instead",
602-
DeprecationWarning,
603-
stacklevel=2,
604-
)
605-
return broadcast(*args)

xarray/core/dataarray.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def _to_dataset_whole(
471471
dataset = Dataset._from_vars_and_coord_names(variables, coord_names)
472472
return dataset
473473

474-
def to_dataset(self, dim: Hashable = None, name: Hashable = None) -> Dataset:
474+
def to_dataset(self, dim: Hashable = None, *, name: Hashable = None) -> Dataset:
475475
"""Convert a DataArray to a Dataset.
476476
477477
Parameters
@@ -489,15 +489,9 @@ def to_dataset(self, dim: Hashable = None, name: Hashable = None) -> Dataset:
489489
dataset : Dataset
490490
"""
491491
if dim is not None and dim not in self.dims:
492-
warnings.warn(
493-
"the order of the arguments on DataArray.to_dataset "
494-
"has changed; you now need to supply ``name`` as "
495-
"a keyword argument",
496-
FutureWarning,
497-
stacklevel=2,
492+
raise TypeError(
493+
"{} is not a dim. If supplying a ``name``, pass as a kwarg.".format(dim)
498494
)
499-
name = dim
500-
dim = None
501495

502496
if dim is not None:
503497
if name is not None:

xarray/core/variable.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,16 +1226,6 @@ def transpose(self, *dims) -> "Variable":
12261226
def T(self) -> "Variable":
12271227
return self.transpose()
12281228

1229-
def expand_dims(self, *args):
1230-
import warnings
1231-
1232-
warnings.warn(
1233-
"Variable.expand_dims is deprecated: use " "Variable.set_dims instead",
1234-
DeprecationWarning,
1235-
stacklevel=2,
1236-
)
1237-
return self.expand_dims(*args)
1238-
12391229
def set_dims(self, dims, shape=None):
12401230
"""Return a new variable with given set of dimensions.
12411231
This method might be used to attach new dimension(s) to variable.

xarray/tests/test_dataarray.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,13 +1408,11 @@ def test_reindex_like_no_index(self):
14081408
with raises_regex(ValueError, "different size for unlabeled"):
14091409
foo.reindex_like(bar)
14101410

1411-
@pytest.mark.filterwarnings("ignore:Indexer has dimensions")
14121411
def test_reindex_regressions(self):
1413-
# regression test for #279
1414-
expected = DataArray(np.random.randn(5), coords=[("time", range(5))])
1412+
da = DataArray(np.random.randn(5), coords=[("time", range(5))])
14151413
time2 = DataArray(np.arange(5), dims="time2")
1416-
actual = expected.reindex(time=time2)
1417-
assert_identical(actual, expected)
1414+
with pytest.raises(ValueError):
1415+
da.reindex(time=time2)
14181416

14191417
# regression test for #736, reindex can not change complex nums dtype
14201418
x = np.array([1, 2, 3], dtype=np.complex)
@@ -3685,10 +3683,8 @@ def test_to_dataset_whole(self):
36853683
expected = Dataset({"foo": ("x", [1, 2])})
36863684
assert_identical(expected, actual)
36873685

3688-
expected = Dataset({"bar": ("x", [1, 2])})
3689-
with pytest.warns(FutureWarning):
3686+
with pytest.raises(TypeError):
36903687
actual = named.to_dataset("bar")
3691-
assert_identical(expected, actual)
36923688

36933689
def test_to_dataset_split(self):
36943690
array = DataArray([1, 2, 3], coords=[("x", list("abc"))], attrs={"a": 1})

xarray/tests/test_dataset.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,9 +1689,8 @@ def test_reindex(self):
16891689
# regression test for #279
16901690
expected = Dataset({"x": ("time", np.random.randn(5))}, {"time": range(5)})
16911691
time2 = DataArray(np.arange(5), dims="time2")
1692-
with pytest.warns(FutureWarning):
1692+
with pytest.raises(ValueError):
16931693
actual = expected.reindex(time=time2)
1694-
assert_identical(actual, expected)
16951694

16961695
# another regression test
16971696
ds = Dataset(
@@ -1707,11 +1706,10 @@ def test_reindex(self):
17071706
def test_reindex_warning(self):
17081707
data = create_test_data()
17091708

1710-
with pytest.warns(FutureWarning) as ws:
1709+
with pytest.raises(ValueError):
17111710
# DataArray with different dimension raises Future warning
17121711
ind = xr.DataArray([0.0, 1.0], dims=["new_dim"], name="ind")
17131712
data.reindex(dim2=ind)
1714-
assert any(["Indexer has dimensions " in str(w.message) for w in ws])
17151713

17161714
# Should not warn
17171715
ind = xr.DataArray([0.0, 1.0], dims=["dim2"], name="ind")

0 commit comments

Comments
 (0)