Skip to content

Commit beea37e

Browse files
dcheriankeewis
andauthored
Fix some warnings (#3864)
* Fix some warnings * Update xarray/backends/api.py Co-Authored-By: keewis <[email protected]> * fix test Co-authored-by: keewis <[email protected]>
1 parent df614b9 commit beea37e

10 files changed

+32
-24
lines changed

xarray/backends/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def check_dtype(var):
12531253
if (
12541254
not np.issubdtype(var.dtype, np.number)
12551255
and not np.issubdtype(var.dtype, np.datetime64)
1256-
and not np.issubdtype(var.dtype, np.bool)
1256+
and not np.issubdtype(var.dtype, np.bool_)
12571257
and not coding.strings.is_unicode_dtype(var.dtype)
12581258
and not var.dtype == object
12591259
):

xarray/tests/test_accessor_dt.py

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def test_field_access(data, field):
347347

348348

349349
@requires_cftime
350+
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
350351
def test_cftime_strftime_access(data):
351352
""" compare cftime formatting against datetime formatting """
352353
date_format = "%Y%m%d%H"

xarray/tests/test_backends.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -1921,33 +1921,36 @@ def test_to_zarr_append_compute_false_roundtrip(self):
19211921
ds, ds_to_append, _ = create_append_test_data()
19221922
ds, ds_to_append = ds.chunk(), ds_to_append.chunk()
19231923

1924-
with self.create_zarr_target() as store:
1925-
delayed_obj = self.save(ds, store, compute=False, mode="w")
1926-
assert isinstance(delayed_obj, Delayed)
1924+
with pytest.warns(SerializationWarning):
1925+
with self.create_zarr_target() as store:
1926+
delayed_obj = self.save(ds, store, compute=False, mode="w")
1927+
assert isinstance(delayed_obj, Delayed)
1928+
1929+
with pytest.raises(AssertionError):
1930+
with self.open(store) as actual:
1931+
assert_identical(ds, actual)
1932+
1933+
delayed_obj.compute()
19271934

1928-
with pytest.raises(AssertionError):
19291935
with self.open(store) as actual:
19301936
assert_identical(ds, actual)
19311937

1932-
delayed_obj.compute()
1938+
delayed_obj = self.save(
1939+
ds_to_append, store, compute=False, append_dim="time"
1940+
)
1941+
assert isinstance(delayed_obj, Delayed)
19331942

1934-
with self.open(store) as actual:
1935-
assert_identical(ds, actual)
1943+
with pytest.raises(AssertionError):
1944+
with self.open(store) as actual:
1945+
assert_identical(
1946+
xr.concat([ds, ds_to_append], dim="time"), actual
1947+
)
19361948

1937-
delayed_obj = self.save(
1938-
ds_to_append, store, compute=False, append_dim="time"
1939-
)
1940-
assert isinstance(delayed_obj, Delayed)
1949+
delayed_obj.compute()
19411950

1942-
with pytest.raises(AssertionError):
19431951
with self.open(store) as actual:
19441952
assert_identical(xr.concat([ds, ds_to_append], dim="time"), actual)
19451953

1946-
delayed_obj.compute()
1947-
1948-
with self.open(store) as actual:
1949-
assert_identical(xr.concat([ds, ds_to_append], dim="time"), actual)
1950-
19511954
def test_encoding_chunksizes(self):
19521955
# regression test for GH2278
19531956
# see also test_encoding_chunksizes_unlimited
@@ -3519,6 +3522,7 @@ def test_uamiv_format_mfread(self):
35193522
["example.uamiv", "example.uamiv"],
35203523
engine="pseudonetcdf",
35213524
concat_dim="TSTEP",
3525+
combine="nested",
35223526
backend_kwargs={"format": "uamiv"},
35233527
)
35243528

xarray/tests/test_concat.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def test_concat_compat():
4040
assert_equal(ds2.no_x_y, result.no_x_y.transpose())
4141

4242
for var in ["has_x", "no_x_y"]:
43-
assert "y" not in result[var]
44-
43+
assert "y" not in result[var].dims and "y" not in result[var].coords
4544
with raises_regex(ValueError, "coordinates in some datasets but not others"):
4645
concat([ds1, ds2], dim="q")
4746
with raises_regex(ValueError, "'q' is not present in all datasets"):

xarray/tests/test_dask.py

+1
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ def test_normalize_token_with_backend(map_ds):
13441344
map_ds.to_netcdf(tmp_file)
13451345
read = xr.open_dataset(tmp_file)
13461346
assert not dask.base.tokenize(map_ds) == dask.base.tokenize(read)
1347+
read.close()
13471348

13481349

13491350
@pytest.mark.parametrize(

xarray/tests/test_dataarray.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ def test_stack_unstack(self):
20352035
codes=[[], []],
20362036
names=["x", "y"],
20372037
)
2038-
pd.util.testing.assert_index_equal(a, b)
2038+
pd.testing.assert_index_equal(a, b)
20392039

20402040
actual = orig.stack(z=["x", "y"]).unstack("z").drop_vars(["x", "y"])
20412041
assert_identical(orig, actual)
@@ -3488,7 +3488,7 @@ def test_from_series_sparse(self):
34883488

34893489
def test_to_and_from_empty_series(self):
34903490
# GH697
3491-
expected = pd.Series([])
3491+
expected = pd.Series([], dtype=np.float64)
34923492
da = DataArray.from_series(expected)
34933493
assert len(da) == 0
34943494
actual = da.to_series()

xarray/tests/test_dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6042,7 +6042,7 @@ def test_integrate(dask):
60426042
actual = da.integrate("x")
60436043
# coordinate that contains x should be dropped.
60446044
expected_x = xr.DataArray(
6045-
np.trapz(da, da["x"], axis=0),
6045+
np.trapz(da.compute(), da["x"], axis=0),
60466046
dims=["y"],
60476047
coords={k: v for k, v in da.coords.items() if "x" not in v.dims},
60486048
)

xarray/tests/test_duck_array_ops.py

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def assert_dask_array(da, dask):
279279

280280

281281
@arm_xfail
282+
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
282283
@pytest.mark.parametrize("dask", [False, True] if has_dask else [False])
283284
def test_datetime_mean(dask):
284285
# Note: only testing numpy, as dask is broken upstream

xarray/tests/test_groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ def test_groupby_drops_nans():
447447

448448
# reduction operation along a different dimension
449449
actual = grouped.mean("time")
450-
expected = ds.mean("time").where(ds.id.notnull())
450+
with pytest.warns(RuntimeWarning): # mean of empty slice
451+
expected = ds.mean("time").where(ds.id.notnull())
451452
assert_identical(actual, expected)
452453

453454
# NaN in non-dimensional coordinate

xarray/tests/test_plot.py

+1
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,7 @@ def test_can_set_vmin_vmax(self):
17491749
assert np.allclose(expected, clim)
17501750

17511751
@pytest.mark.slow
1752+
@pytest.mark.filterwarnings("ignore")
17521753
def test_can_set_norm(self):
17531754
norm = mpl.colors.SymLogNorm(0.1)
17541755
self.g.map_dataarray(xplt.imshow, "x", "y", norm=norm)

0 commit comments

Comments
 (0)