Skip to content

Commit 0c534b0

Browse files
TimoRothshoyer
authored andcommitted
Don't use deprecated np.asscalar() (#2800)
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.
1 parent c33dab2 commit 0c534b0

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

xarray/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def from_iris(cube):
247247
if coord_dims:
248248
coords[_name(coord)] = (coord_dims, coord.points, coord_attrs)
249249
else:
250-
coords[_name(coord)] = ((), np.asscalar(coord.points), coord_attrs)
250+
coords[_name(coord)] = ((), coord.points.item(), coord_attrs)
251251

252252
array_attrs = _iris_obj_to_attrs(cube)
253253
cell_methods = _iris_cell_methods_to_str(cube.cell_methods)

xarray/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def decode_numpy_dict_values(attrs):
550550
if isinstance(v, np.ndarray):
551551
attrs[k] = v.tolist()
552552
elif isinstance(v, np.generic):
553-
attrs[k] = np.asscalar(v)
553+
attrs[k] = v.item()
554554
return attrs
555555

556556

xarray/tests/test_dataarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2963,7 +2963,7 @@ def test_to_dict_with_numpy_attrs(self):
29632963
'maintainer': 'bar'}
29642964
da = DataArray(x, {'t': t, 'lat': lat}, dims=['t', 'lat'],
29652965
attrs=attrs)
2966-
expected_attrs = {'created': np.asscalar(attrs['created']),
2966+
expected_attrs = {'created': attrs['created'].item(),
29672967
'coords': attrs['coords'].tolist(),
29682968
'maintainer': 'bar'}
29692969
actual = da.to_dict()

xarray/tests/test_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ def test_to_dict_with_numpy_attrs(self):
31523152
ds = Dataset(OrderedDict([('a', ('t', x, attrs)),
31533153
('b', ('t', y, attrs)),
31543154
('t', ('t', t))]))
3155-
expected_attrs = {'created': np.asscalar(attrs['created']),
3155+
expected_attrs = {'created': attrs['created'].item(),
31563156
'coords': attrs['coords'].tolist(),
31573157
'maintainer': 'bar'}
31583158
actual = ds.to_dict()

0 commit comments

Comments
 (0)