diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 306e98a4f34..d74ebc05391 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -15,9 +15,16 @@ What's New .. _whats-new.0.9.7: -v0.9.7 (unreleased) +v0.10.0 (unreleased) ------------------- +Breaking changes +~~~~~~~~~~~~~~~~ + +- Supplying ``coords`` as a dictionary to the ``DataArray`` constructor without + also supplying an explicit ``dims`` argument is no longer supported. This + behavior was deprecated in version 0.9 but is now an error (:issue:`727`). + By `Joe Hamman `_. Backward Incompatible Changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 6b4d28e1006..3f0fa85ba10 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -47,15 +47,15 @@ def _infer_coords_and_dims(shape, coords, dims): if coords is not None and len(coords) == len(shape): # try to infer dimensions from coords if utils.is_dict_like(coords): - warnings.warn('inferring DataArray dimensions from dictionary ' - 'like ``coords`` has been deprecated. Use an ' - 'explicit list of ``dims`` instead.', - FutureWarning, stacklevel=3) - dims = list(coords.keys()) - else: - for n, (dim, coord) in enumerate(zip(dims, coords)): - coord = as_variable(coord, name=dims[n]).to_index_variable() - dims[n] = coord.name + # deprecated in GH993, removed in GH1539 + raise ValueError('inferring DataArray dimensions from ' + 'dictionary like ``coords`` has been ' + 'deprecated. Use an explicit list of ' + '``dims`` instead.') + for n, (dim, coord) in enumerate(zip(dims, coords)): + coord = as_variable(coord, + name=dims[n]).to_index_variable() + dims[n] = coord.name dims = tuple(dims) else: for d in dims: diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index bfc98cd12b1..b17aab47c12 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -274,7 +274,7 @@ class Arbitrary(object): self.assertDatasetIdentical(expected, actual) def test_constructor_deprecated(self): - with pytest.warns(FutureWarning): + with self.assertRaisesRegexp(ValueError, 'DataArray dimensions'): DataArray([1, 2, 3], coords={'x': [0, 1, 2]}) def test_constructor_auto_align(self): @@ -1294,9 +1294,11 @@ def test_align_nocopy(self): assert source_ndarray(x['foo'].data) is not source_ndarray(x2['foo'].data) def test_align_indexes(self): - x = Dataset({'foo': DataArray([1, 2, 3], coords=[('x', [1, 2, 3])])}) + x = Dataset({'foo': DataArray([1, 2, 3], dims='x', + coords=[('x', [1, 2, 3])])}) x2, = align(x, indexes={'x': [2, 3, 1]}) - expected_x2 = Dataset({'foo': DataArray([2, 3, 1], coords={'x': [2, 3, 1]})}) + expected_x2 = Dataset({'foo': DataArray([2, 3, 1], dims='x', + coords={'x': [2, 3, 1]})}) self.assertDatasetIdentical(expected_x2, x2) def test_align_non_unique(self):