Skip to content

Commit 2a8cd3b

Browse files
authored
use builtin python types instead of the numpy alias (#4170)
* replace np.bool with the python type * replace np.int with the python type * replace np.complex with the builtin python type * replace np.float with the builtin python type
1 parent b9e6a36 commit 2a8cd3b

10 files changed

+18
-20
lines changed

xarray/coding/times.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def decode_cf_datetime(num_dates, units, calendar=None, use_cftime=None):
158158
dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)
159159
except (KeyError, OutOfBoundsDatetime, OverflowError):
160160
dates = _decode_datetime_with_cftime(
161-
flat_num_dates.astype(np.float), units, calendar
161+
flat_num_dates.astype(float), units, calendar
162162
)
163163

164164
if (
@@ -179,7 +179,7 @@ def decode_cf_datetime(num_dates, units, calendar=None, use_cftime=None):
179179
dates = cftime_to_nptime(dates)
180180
elif use_cftime:
181181
dates = _decode_datetime_with_cftime(
182-
flat_num_dates.astype(np.float), units, calendar
182+
flat_num_dates.astype(float), units, calendar
183183
)
184184
else:
185185
dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)

xarray/conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def maybe_default_fill_value(var):
116116

117117
def maybe_encode_bools(var):
118118
if (
119-
(var.dtype == np.bool)
119+
(var.dtype == bool)
120120
and ("dtype" not in var.encoding)
121121
and ("dtype" not in var.attrs)
122122
):

xarray/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ def zeros_like(other, dtype: DTypeLike = None):
14811481
* lat (lat) int64 1 2
14821482
* lon (lon) int64 0 1 2
14831483
1484-
>>> xr.zeros_like(x, dtype=np.float)
1484+
>>> xr.zeros_like(x, dtype=float)
14851485
<xarray.DataArray (lat: 2, lon: 3)>
14861486
array([[0., 0., 0.],
14871487
[0., 0., 0.]])

xarray/core/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def format_item(x, timedelta_format=None, quote_strings=True):
140140
return format_timedelta(x, timedelta_format=timedelta_format)
141141
elif isinstance(x, (str, bytes)):
142142
return repr(x) if quote_strings else x
143-
elif isinstance(x, (float, np.float)):
143+
elif isinstance(x, (float, np.float_)):
144144
return f"{x:.4}"
145145
else:
146146
return str(x)

xarray/tests/test_backends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ def test_roundtrip_endian(self):
885885
"x": np.arange(3, 10, dtype=">i2"),
886886
"y": np.arange(3, 20, dtype="<i4"),
887887
"z": np.arange(3, 30, dtype="=i8"),
888-
"w": ("x", np.arange(3, 10, dtype=np.float)),
888+
"w": ("x", np.arange(3, 10, dtype=float)),
889889
}
890890
)
891891

xarray/tests/test_conventions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ class TestBoolTypeArray:
3232
def test_booltype_array(self):
3333
x = np.array([1, 0, 1, 1, 0], dtype="i1")
3434
bx = conventions.BoolTypeArray(x)
35-
assert bx.dtype == np.bool
36-
assert_array_equal(
37-
bx, np.array([True, False, True, True, False], dtype=np.bool)
38-
)
35+
assert bx.dtype == bool
36+
assert_array_equal(bx, np.array([True, False, True, True, False], dtype=bool))
3937

4038

4139
class TestNativeEndiannessArray:

xarray/tests/test_dataarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ def test_reindex_regressions(self):
15031503
da.reindex(time=time2)
15041504

15051505
# regression test for #736, reindex can not change complex nums dtype
1506-
x = np.array([1, 2, 3], dtype=np.complex)
1506+
x = np.array([1, 2, 3], dtype=complex)
15071507
x = DataArray(x, coords=[[0.1, 0.2, 0.3]])
15081508
y = DataArray([2, 5, 6, 7, 8], coords=[[-1.1, 0.21, 0.31, 0.41, 0.51]])
15091509
re_dtype = x.reindex_like(y, method="pad").dtype

xarray/tests/test_dataset.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def create_append_test_data(seed=None):
9898
datetime_var_to_append = np.array(
9999
["2019-01-04", "2019-01-05"], dtype="datetime64[s]"
100100
)
101-
bool_var = np.array([True, False, True], dtype=np.bool)
102-
bool_var_to_append = np.array([False, True], dtype=np.bool)
101+
bool_var = np.array([True, False, True], dtype=bool)
102+
bool_var_to_append = np.array([False, True], dtype=bool)
103103

104104
ds = xr.Dataset(
105105
data_vars={
@@ -2943,12 +2943,12 @@ def test_unstack_fill_value(self):
29432943
ds = ds.isel(x=[0, 2, 3, 4]).set_index(index=["x", "y"])
29442944
# test fill_value
29452945
actual = ds.unstack("index", fill_value=-1)
2946-
expected = ds.unstack("index").fillna(-1).astype(np.int)
2947-
assert actual["var"].dtype == np.int
2946+
expected = ds.unstack("index").fillna(-1).astype(int)
2947+
assert actual["var"].dtype == int
29482948
assert_equal(actual, expected)
29492949

29502950
actual = ds["var"].unstack("index", fill_value=-1)
2951-
expected = ds["var"].unstack("index").fillna(-1).astype(np.int)
2951+
expected = ds["var"].unstack("index").fillna(-1).astype(int)
29522952
assert actual.equals(expected)
29532953

29542954
@requires_sparse

xarray/tests/test_dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
@pytest.mark.parametrize(
88
"args, expected",
99
[
10-
([np.bool], np.bool),
11-
([np.bool, np.string_], np.object_),
10+
([bool], bool),
11+
([bool, np.string_], np.object_),
1212
([np.float32, np.float64], np.float64),
1313
([np.float32, np.string_], np.object_),
1414
([np.unicode_, np.int64], np.object_),

xarray/tests/test_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def test1d(self):
149149
(self.darray[:, 0, 0] + 1j).plot()
150150

151151
def test_1d_bool(self):
152-
xr.ones_like(self.darray[:, 0, 0], dtype=np.bool).plot()
152+
xr.ones_like(self.darray[:, 0, 0], dtype=bool).plot()
153153

154154
def test_1d_x_y_kw(self):
155155
z = np.arange(10)
@@ -1037,7 +1037,7 @@ def test_1d_raises_valueerror(self):
10371037
self.plotfunc(self.darray[0, :])
10381038

10391039
def test_bool(self):
1040-
xr.ones_like(self.darray, dtype=np.bool).plot()
1040+
xr.ones_like(self.darray, dtype=bool).plot()
10411041

10421042
def test_complex_raises_typeerror(self):
10431043
with raises_regex(TypeError, "complex128"):

0 commit comments

Comments
 (0)