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

Fix some warnings #3864

Merged
merged 3 commits into from
Mar 19, 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
2 changes: 1 addition & 1 deletion xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def check_dtype(var):
if (
not np.issubdtype(var.dtype, np.number)
and not np.issubdtype(var.dtype, np.datetime64)
and not np.issubdtype(var.dtype, np.bool)
and not np.issubdtype(var.dtype, np.bool_)
and not coding.strings.is_unicode_dtype(var.dtype)
and not var.dtype == object
):
Expand Down
1 change: 1 addition & 0 deletions xarray/tests/test_accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def test_field_access(data, field):


@requires_cftime
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
def test_cftime_strftime_access(data):
""" compare cftime formatting against datetime formatting """
date_format = "%Y%m%d%H"
Expand Down
38 changes: 21 additions & 17 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,33 +1921,36 @@ def test_to_zarr_append_compute_false_roundtrip(self):
ds, ds_to_append, _ = create_append_test_data()
ds, ds_to_append = ds.chunk(), ds_to_append.chunk()

with self.create_zarr_target() as store:
delayed_obj = self.save(ds, store, compute=False, mode="w")
assert isinstance(delayed_obj, Delayed)
with pytest.warns(SerializationWarning):
with self.create_zarr_target() as store:
delayed_obj = self.save(ds, store, compute=False, mode="w")
assert isinstance(delayed_obj, Delayed)

with pytest.raises(AssertionError):
with self.open(store) as actual:
assert_identical(ds, actual)

delayed_obj.compute()

with pytest.raises(AssertionError):
with self.open(store) as actual:
assert_identical(ds, actual)

delayed_obj.compute()
delayed_obj = self.save(
ds_to_append, store, compute=False, append_dim="time"
)
assert isinstance(delayed_obj, Delayed)

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

delayed_obj = self.save(
ds_to_append, store, compute=False, append_dim="time"
)
assert isinstance(delayed_obj, Delayed)
delayed_obj.compute()

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

delayed_obj.compute()

with self.open(store) as actual:
assert_identical(xr.concat([ds, ds_to_append], dim="time"), actual)

def test_encoding_chunksizes(self):
# regression test for GH2278
# see also test_encoding_chunksizes_unlimited
Expand Down Expand Up @@ -3519,6 +3522,7 @@ def test_uamiv_format_mfread(self):
["example.uamiv", "example.uamiv"],
engine="pseudonetcdf",
concat_dim="TSTEP",
combine="nested",
backend_kwargs={"format": "uamiv"},
)

Expand Down
3 changes: 1 addition & 2 deletions xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def test_concat_compat():
assert_equal(ds2.no_x_y, result.no_x_y.transpose())

for var in ["has_x", "no_x_y"]:
assert "y" not in result[var]

assert "y" not in result[var].dims and "y" not in result[var].coords
with raises_regex(ValueError, "coordinates in some datasets but not others"):
concat([ds1, ds2], dim="q")
with raises_regex(ValueError, "'q' is not present in all datasets"):
Expand Down
1 change: 1 addition & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ def test_normalize_token_with_backend(map_ds):
map_ds.to_netcdf(tmp_file)
read = xr.open_dataset(tmp_file)
assert not dask.base.tokenize(map_ds) == dask.base.tokenize(read)
read.close()


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ def test_stack_unstack(self):
codes=[[], []],
names=["x", "y"],
)
pd.util.testing.assert_index_equal(a, b)
pd.testing.assert_index_equal(a, b)

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

def test_to_and_from_empty_series(self):
# GH697
expected = pd.Series([])
expected = pd.Series([], dtype=np.float64)
da = DataArray.from_series(expected)
assert len(da) == 0
actual = da.to_series()
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6031,7 +6031,7 @@ def test_integrate(dask):
actual = da.integrate("x")
# coordinate that contains x should be dropped.
expected_x = xr.DataArray(
np.trapz(da, da["x"], axis=0),
np.trapz(da.compute(), da["x"], axis=0),
dims=["y"],
coords={k: v for k, v in da.coords.items() if "x" not in v.dims},
)
Expand Down
1 change: 1 addition & 0 deletions xarray/tests/test_duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def assert_dask_array(da, dask):


@arm_xfail
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
@pytest.mark.parametrize("dask", [False, True] if has_dask else [False])
def test_datetime_mean(dask):
# Note: only testing numpy, as dask is broken upstream
Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ def test_groupby_drops_nans():

# reduction operation along a different dimension
actual = grouped.mean("time")
expected = ds.mean("time").where(ds.id.notnull())
with pytest.warns(RuntimeWarning): # mean of empty slice
expected = ds.mean("time").where(ds.id.notnull())
assert_identical(actual, expected)

# NaN in non-dimensional coordinate
Expand Down
1 change: 1 addition & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,7 @@ def test_can_set_vmin_vmax(self):
assert np.allclose(expected, clim)

@pytest.mark.slow
@pytest.mark.filterwarnings("ignore")
def test_can_set_norm(self):
norm = mpl.colors.SymLogNorm(0.1)
self.g.map_dataarray(xplt.imshow, "x", "y", norm=norm)
Expand Down