Skip to content

Commit

Permalink
use builtin python types instead of the numpy alias (#4170)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
keewis authored Jun 22, 2020
1 parent b9e6a36 commit 2a8cd3b
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions xarray/coding/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion xarray/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
):
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<xarray.DataArray (lat: 2, lon: 3)>
array([[0., 0., 0.],
[0., 0., 0.]])
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def test_roundtrip_endian(self):
"x": np.arange(3, 10, dtype=">i2"),
"y": np.arange(3, 20, dtype="<i4"),
"z": np.arange(3, 30, dtype="=i8"),
"w": ("x", np.arange(3, 10, dtype=np.float)),
"w": ("x", np.arange(3, 10, dtype=float)),
}
)

Expand Down
6 changes: 2 additions & 4 deletions xarray/tests/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@ -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
Expand Down
10 changes: 5 additions & 5 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_),
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 2a8cd3b

Please sign in to comment.