Skip to content

fix and supress some test warnings #10104

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

Merged
merged 3 commits into from
Mar 7, 2025
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: 2 additions & 0 deletions xarray/tests/test_array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def test_aggregation_skipna(arrays) -> None:
assert_equal(actual, expected)


# casting nan warns
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast")
def test_astype(arrays) -> None:
np_arr, xp_arr = arrays
expected = np_arr.astype(np.int64)
Expand Down
11 changes: 6 additions & 5 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4185,7 +4185,7 @@ def test_phony_dims_warning(self) -> None:
fx.create_dataset(k, data=v)
with pytest.warns(UserWarning, match="The 'phony_dims' kwarg"):
with xr.open_dataset(tmp_file, engine="h5netcdf", group="bar") as ds:
assert ds.dims == {
assert ds.sizes == {
"phony_dim_0": 5,
"phony_dim_1": 5,
"phony_dim_2": 5,
Expand Down Expand Up @@ -4300,7 +4300,8 @@ def test_open_fileobj(self) -> None:
# `raises_regex`?). Ref https://github.com/pydata/xarray/pull/5191
with open(tmp_file, "rb") as f:
f.seek(8)
open_dataset(f)
with open_dataset(f): # ensure file gets closed
pass


@requires_h5netcdf
Expand Down Expand Up @@ -6587,11 +6588,11 @@ def test_h5netcdf_storage_options() -> None:
ds2.to_netcdf(f2, engine="h5netcdf")

files = [f"file://{f}" for f in [f1, f2]]
ds = xr.open_mfdataset(
with xr.open_mfdataset(
files,
engine="h5netcdf",
concat_dim="time",
combine="nested",
storage_options={"skip_instance_cache": False},
)
assert_identical(xr.concat([ds1, ds2], dim="time"), ds)
) as ds:
assert_identical(xr.concat([ds1, ds2], dim="time"), ds)
7 changes: 4 additions & 3 deletions xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ def test_apply_groupby_add() -> None:
add(data_array.groupby("y"), data_array.groupby("x"))


@pytest.mark.filterwarnings("ignore:Duplicate dimension names present")
def test_unified_dim_sizes() -> None:
assert unified_dim_sizes([xr.Variable((), 0)]) == {}
assert unified_dim_sizes([xr.Variable("x", [1]), xr.Variable("x", [1])]) == {"x": 1}
Expand All @@ -646,9 +647,9 @@ def test_unified_dim_sizes() -> None:
exclude_dims={"z"},
) == {"x": 1, "y": 2}

# duplicate dimensions
with pytest.raises(ValueError):
unified_dim_sizes([xr.Variable(("x", "x"), [[1]])])
with pytest.raises(ValueError, match="broadcasting cannot handle"):
with pytest.warns(UserWarning, match="Duplicate dimension names"):
unified_dim_sizes([xr.Variable(("x", "x"), [[1]])])

# mismatched lengths
with pytest.raises(ValueError):
Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6007,6 +6007,8 @@ def test_dataset_number_math(self) -> None:
actual += 0
assert_identical(ds, actual)

# casting nan warns
@pytest.mark.filterwarnings("ignore:invalid value encountered in cast")
def test_unary_ops(self) -> None:
ds = self.make_example_math_dataset()

Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,8 @@ def test_from_sparse(self, Var):
import sparse

arr = np.diagflat([1, 2, 3])
sparr = sparse.COO(coords=[[0, 1, 2], [0, 1, 2]], data=[1, 2, 3])
coords = np.array([[0, 1, 2], [0, 1, 2]])
sparr = sparse.COO(coords=coords, data=[1, 2, 3], shape=(3, 3))
v = Variable(["x", "y"], sparr)

assert_identical(v.as_numpy(), Variable(["x", "y"], arr))
Expand Down
Loading