From eeb3de942fcd285924b80fd2581f97e7e00d3476 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Tue, 5 Mar 2019 13:44:36 +0100 Subject: [PATCH] Don't use deprecated np.asscalar() 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. --- xarray/convert.py | 2 +- xarray/core/utils.py | 2 +- xarray/tests/test_dataarray.py | 2 +- xarray/tests/test_dataset.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/convert.py b/xarray/convert.py index efcdd079a9f..b8c0c2a7eca 100644 --- a/xarray/convert.py +++ b/xarray/convert.py @@ -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) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 053a45f01cb..fd1330a4e1f 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -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 diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 09c0f003888..ab05f19dbbe 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -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() diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 7063e217ac2..d130363a7c0 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -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()