Skip to content

remove warning and raise error when dataset constructor is called wit… #1539

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

Merged
merged 3 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ 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 <https://github.com/jhamman>`_.

Enhancements
~~~~~~~~~~~~

Expand Down
18 changes: 9 additions & 9 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down