Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use builtin python types instead of the numpy alias #4170

Merged
merged 4 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_)):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might change this to just

Suggested change
elif isinstance(x, (float, np.float_)):
elif isinstance(x, float):

since

In [1]: import numpy as np 
   ...:  
   ...: a = np.float64(0) 
   ...: a.dtype == float, isinstance(a, float)
Out[1]: (True, True)

but I'm not sure if this also works with the minimum supported numpy version (1.15 / 1.16)

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