Skip to content

Commit 4571d60

Browse files
author
Joe Hamman
authored
remove warning and raise error when dataset constructor is called wit… (#1539)
* remove warning and raise error when dataset constructor is called with coords dict and not dims * remove else clause and improve whats new note
1 parent 0b2424a commit 4571d60

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

doc/whats-new.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ What's New
1515
1616
.. _whats-new.0.9.7:
1717

18-
v0.9.7 (unreleased)
18+
v0.10.0 (unreleased)
1919
-------------------
2020

21+
Breaking changes
22+
~~~~~~~~~~~~~~~~
23+
24+
- Supplying ``coords`` as a dictionary to the ``DataArray`` constructor without
25+
also supplying an explicit ``dims`` argument is no longer supported. This
26+
behavior was deprecated in version 0.9 but is now an error (:issue:`727`).
27+
By `Joe Hamman <https://github.com/jhamman>`_.
2128
Backward Incompatible Changes
2229
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2330

xarray/core/dataarray.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ def _infer_coords_and_dims(shape, coords, dims):
4747
if coords is not None and len(coords) == len(shape):
4848
# try to infer dimensions from coords
4949
if utils.is_dict_like(coords):
50-
warnings.warn('inferring DataArray dimensions from dictionary '
51-
'like ``coords`` has been deprecated. Use an '
52-
'explicit list of ``dims`` instead.',
53-
FutureWarning, stacklevel=3)
54-
dims = list(coords.keys())
55-
else:
56-
for n, (dim, coord) in enumerate(zip(dims, coords)):
57-
coord = as_variable(coord, name=dims[n]).to_index_variable()
58-
dims[n] = coord.name
50+
# deprecated in GH993, removed in GH1539
51+
raise ValueError('inferring DataArray dimensions from '
52+
'dictionary like ``coords`` has been '
53+
'deprecated. Use an explicit list of '
54+
'``dims`` instead.')
55+
for n, (dim, coord) in enumerate(zip(dims, coords)):
56+
coord = as_variable(coord,
57+
name=dims[n]).to_index_variable()
58+
dims[n] = coord.name
5959
dims = tuple(dims)
6060
else:
6161
for d in dims:

xarray/tests/test_dataset.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class Arbitrary(object):
274274
self.assertDatasetIdentical(expected, actual)
275275

276276
def test_constructor_deprecated(self):
277-
with pytest.warns(FutureWarning):
277+
with self.assertRaisesRegexp(ValueError, 'DataArray dimensions'):
278278
DataArray([1, 2, 3], coords={'x': [0, 1, 2]})
279279

280280
def test_constructor_auto_align(self):
@@ -1294,9 +1294,11 @@ def test_align_nocopy(self):
12941294
assert source_ndarray(x['foo'].data) is not source_ndarray(x2['foo'].data)
12951295

12961296
def test_align_indexes(self):
1297-
x = Dataset({'foo': DataArray([1, 2, 3], coords=[('x', [1, 2, 3])])})
1297+
x = Dataset({'foo': DataArray([1, 2, 3], dims='x',
1298+
coords=[('x', [1, 2, 3])])})
12981299
x2, = align(x, indexes={'x': [2, 3, 1]})
1299-
expected_x2 = Dataset({'foo': DataArray([2, 3, 1], coords={'x': [2, 3, 1]})})
1300+
expected_x2 = Dataset({'foo': DataArray([2, 3, 1], dims='x',
1301+
coords={'x': [2, 3, 1]})})
13001302
self.assertDatasetIdentical(expected_x2, x2)
13011303

13021304
def test_align_non_unique(self):

0 commit comments

Comments
 (0)