Skip to content

Commit

Permalink
Don't use deprecated np.asscalar() (pydata#2800)
Browse files Browse the repository at this point in the history
It got deprecated in numpy 1.16 and throws a ton of warnings due to
that.
All the function does is returning .item() anyway, which is why it got
deprecated.
  • Loading branch information
TimoRoth authored and pletchm committed Mar 21, 2019
1 parent b393754 commit 872b49c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion xarray/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def from_iris(cube):
if coord_dims:
coords[_name(coord)] = (coord_dims, coord.points, coord_attrs)
else:
coords[_name(coord)] = ((), np.asscalar(coord.points), coord_attrs)
coords[_name(coord)] = ((), coord.points.item(), coord_attrs)

array_attrs = _iris_obj_to_attrs(cube)
cell_methods = _iris_cell_methods_to_str(cube.cell_methods)
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def decode_numpy_dict_values(attrs):
if isinstance(v, np.ndarray):
attrs[k] = v.tolist()
elif isinstance(v, np.generic):
attrs[k] = np.asscalar(v)
attrs[k] = v.item()
return attrs


Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,7 @@ def test_to_dict_with_numpy_attrs(self):
'maintainer': 'bar'}
da = DataArray(x, {'t': t, 'lat': lat}, dims=['t', 'lat'],
attrs=attrs)
expected_attrs = {'created': np.asscalar(attrs['created']),
expected_attrs = {'created': attrs['created'].item(),
'coords': attrs['coords'].tolist(),
'maintainer': 'bar'}
actual = da.to_dict()
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3152,7 +3152,7 @@ def test_to_dict_with_numpy_attrs(self):
ds = Dataset(OrderedDict([('a', ('t', x, attrs)),
('b', ('t', y, attrs)),
('t', ('t', t))]))
expected_attrs = {'created': np.asscalar(attrs['created']),
expected_attrs = {'created': attrs['created'].item(),
'coords': attrs['coords'].tolist(),
'maintainer': 'bar'}
actual = ds.to_dict()
Expand Down

0 comments on commit 872b49c

Please sign in to comment.