From f7998d1571d7874f334cbb1276bb30ed7f68662a Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 22 Jun 2020 23:32:20 +0200 Subject: [PATCH 1/4] replace np.bool with the python type --- xarray/conventions.py | 2 +- xarray/tests/test_conventions.py | 6 ++---- xarray/tests/test_dataset.py | 4 ++-- xarray/tests/test_dtypes.py | 4 ++-- xarray/tests/test_plot.py | 4 ++-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/xarray/conventions.py b/xarray/conventions.py index 588fcea71a3..fc0572944f3 100644 --- a/xarray/conventions.py +++ b/xarray/conventions.py @@ -116,7 +116,7 @@ def maybe_default_fill_value(var): def maybe_encode_bools(var): if ( - (var.dtype == np.bool) + (var.dtype == bool) and ("dtype" not in var.encoding) and ("dtype" not in var.attrs) ): diff --git a/xarray/tests/test_conventions.py b/xarray/tests/test_conventions.py index a5f4324d182..f7b113d0110 100644 --- a/xarray/tests/test_conventions.py +++ b/xarray/tests/test_conventions.py @@ -32,10 +32,8 @@ class TestBoolTypeArray: def test_booltype_array(self): x = np.array([1, 0, 1, 1, 0], dtype="i1") bx = conventions.BoolTypeArray(x) - assert bx.dtype == np.bool - assert_array_equal( - bx, np.array([True, False, True, True, False], dtype=np.bool) - ) + assert bx.dtype == bool + assert_array_equal(bx, np.array([True, False, True, True, False], dtype=bool)) class TestNativeEndiannessArray: diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index fd04c8a7f64..3bc20173d00 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -98,8 +98,8 @@ def create_append_test_data(seed=None): datetime_var_to_append = np.array( ["2019-01-04", "2019-01-05"], dtype="datetime64[s]" ) - bool_var = np.array([True, False, True], dtype=np.bool) - bool_var_to_append = np.array([False, True], dtype=np.bool) + bool_var = np.array([True, False, True], dtype=bool) + bool_var_to_append = np.array([False, True], dtype=bool) ds = xr.Dataset( data_vars={ diff --git a/xarray/tests/test_dtypes.py b/xarray/tests/test_dtypes.py index 1f3aee84979..5ad1a6355e6 100644 --- a/xarray/tests/test_dtypes.py +++ b/xarray/tests/test_dtypes.py @@ -7,8 +7,8 @@ @pytest.mark.parametrize( "args, expected", [ - ([np.bool], np.bool), - ([np.bool, np.string_], np.object_), + ([bool], bool), + ([bool, np.string_], np.object_), ([np.float32, np.float64], np.float64), ([np.float32, np.string_], np.object_), ([np.unicode_, np.int64], np.object_), diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index c26d105a713..938f403e01b 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -149,7 +149,7 @@ def test1d(self): (self.darray[:, 0, 0] + 1j).plot() def test_1d_bool(self): - xr.ones_like(self.darray[:, 0, 0], dtype=np.bool).plot() + xr.ones_like(self.darray[:, 0, 0], dtype=bool).plot() def test_1d_x_y_kw(self): z = np.arange(10) @@ -1037,7 +1037,7 @@ def test_1d_raises_valueerror(self): self.plotfunc(self.darray[0, :]) def test_bool(self): - xr.ones_like(self.darray, dtype=np.bool).plot() + xr.ones_like(self.darray, dtype=bool).plot() def test_complex_raises_typeerror(self): with raises_regex(TypeError, "complex128"): From 12c37c6d8d3c52bfea1dff7f34cb1e15cae64954 Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 22 Jun 2020 23:33:52 +0200 Subject: [PATCH 2/4] replace np.int with the python type --- xarray/tests/test_dataset.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 3bc20173d00..9c8d40724da 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -2943,12 +2943,12 @@ def test_unstack_fill_value(self): ds = ds.isel(x=[0, 2, 3, 4]).set_index(index=["x", "y"]) # test fill_value actual = ds.unstack("index", fill_value=-1) - expected = ds.unstack("index").fillna(-1).astype(np.int) - assert actual["var"].dtype == np.int + expected = ds.unstack("index").fillna(-1).astype(int) + assert actual["var"].dtype == int assert_equal(actual, expected) actual = ds["var"].unstack("index", fill_value=-1) - expected = ds["var"].unstack("index").fillna(-1).astype(np.int) + expected = ds["var"].unstack("index").fillna(-1).astype(int) assert actual.equals(expected) @requires_sparse From 38d4184d89ffce10fc235ab0aeb92c19ec2e24b1 Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 22 Jun 2020 23:35:19 +0200 Subject: [PATCH 3/4] replace np.complex with the builtin python type --- xarray/tests/test_dataarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 95f0ad9f612..36bee63bf3b 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -1503,7 +1503,7 @@ def test_reindex_regressions(self): da.reindex(time=time2) # regression test for #736, reindex can not change complex nums dtype - x = np.array([1, 2, 3], dtype=np.complex) + x = np.array([1, 2, 3], dtype=complex) x = DataArray(x, coords=[[0.1, 0.2, 0.3]]) y = DataArray([2, 5, 6, 7, 8], coords=[[-1.1, 0.21, 0.31, 0.41, 0.51]]) re_dtype = x.reindex_like(y, method="pad").dtype From ea8d8b92cacb80e85ded72b25b121941866333fe Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 22 Jun 2020 23:38:10 +0200 Subject: [PATCH 4/4] replace np.float with the builtin python type --- xarray/coding/times.py | 4 ++-- xarray/core/common.py | 2 +- xarray/core/formatting.py | 2 +- xarray/tests/test_backends.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xarray/coding/times.py b/xarray/coding/times.py index dafa8ca03b1..77b2d2c7937 100644 --- a/xarray/coding/times.py +++ b/xarray/coding/times.py @@ -158,7 +158,7 @@ def decode_cf_datetime(num_dates, units, calendar=None, use_cftime=None): dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar) except (KeyError, OutOfBoundsDatetime, OverflowError): dates = _decode_datetime_with_cftime( - flat_num_dates.astype(np.float), units, calendar + flat_num_dates.astype(float), units, calendar ) if ( @@ -179,7 +179,7 @@ def decode_cf_datetime(num_dates, units, calendar=None, use_cftime=None): dates = cftime_to_nptime(dates) elif use_cftime: dates = _decode_datetime_with_cftime( - flat_num_dates.astype(np.float), units, calendar + flat_num_dates.astype(float), units, calendar ) else: dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar) diff --git a/xarray/core/common.py b/xarray/core/common.py index e343f342040..f759f4c32dd 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -1481,7 +1481,7 @@ def zeros_like(other, dtype: DTypeLike = None): * lat (lat) int64 1 2 * lon (lon) int64 0 1 2 - >>> xr.zeros_like(x, dtype=np.float) + >>> xr.zeros_like(x, dtype=float) array([[0., 0., 0.], [0., 0., 0.]]) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index bd9576a4440..3a9dd772a9f 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -140,7 +140,7 @@ def format_item(x, timedelta_format=None, quote_strings=True): return format_timedelta(x, timedelta_format=timedelta_format) elif isinstance(x, (str, bytes)): return repr(x) if quote_strings else x - elif isinstance(x, (float, np.float)): + elif isinstance(x, (float, np.float_)): return f"{x:.4}" else: return str(x) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 3642c1eb9b7..177435fa864 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -885,7 +885,7 @@ def test_roundtrip_endian(self): "x": np.arange(3, 10, dtype=">i2"), "y": np.arange(3, 20, dtype="