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 some deprecations #3292

Merged
merged 3 commits into from
Sep 8, 2019
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
7 changes: 7 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ Breaking changes
crash in a later release.

(:issue:`3250`) by `Guido Imperiale <https://github.com/crusaderky>`_.
- :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
~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 2 additions & 19 deletions xarray/core/alignment.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
12 changes: 3 additions & 9 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 0 additions & 10 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 4 additions & 8 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
6 changes: 2 additions & 4 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand Down