Skip to content
forked from pydata/xarray

Commit

Permalink
Silence more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Dec 22, 2023
1 parent 44e5a41 commit dd6ea53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
14 changes: 10 additions & 4 deletions xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ def test_apply_identity() -> None:
assert_identical(variable, apply_identity(variable))
assert_identical(data_array, apply_identity(data_array))
assert_identical(data_array, apply_identity(data_array.groupby("x")))
assert_identical(data_array, apply_identity(data_array.groupby("x", squeeze=False)))
assert_identical(dataset, apply_identity(dataset))
assert_identical(dataset, apply_identity(dataset.groupby("x")))
assert_identical(dataset, apply_identity(dataset.groupby("x", squeeze=False)))


def add(a, b):
Expand Down Expand Up @@ -519,8 +521,10 @@ def func(x):
assert_identical(stacked_variable, stack_negative(variable))
assert_identical(stacked_data_array, stack_negative(data_array))
assert_identical(stacked_dataset, stack_negative(dataset))
assert_identical(stacked_data_array, stack_negative(data_array.groupby("x")))
assert_identical(stacked_dataset, stack_negative(dataset.groupby("x")))
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
assert_identical(stacked_data_array, stack_negative(data_array.groupby("x")))
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
assert_identical(stacked_dataset, stack_negative(dataset.groupby("x")))

def original_and_stack_negative(obj):
def func(x):
Expand All @@ -547,11 +551,13 @@ def func(x):
assert_identical(dataset, out0)
assert_identical(stacked_dataset, out1)

out0, out1 = original_and_stack_negative(data_array.groupby("x"))
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
out0, out1 = original_and_stack_negative(data_array.groupby("x"))
assert_identical(data_array, out0)
assert_identical(stacked_data_array, out1)

out0, out1 = original_and_stack_negative(dataset.groupby("x"))
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
out0, out1 = original_and_stack_negative(dataset.groupby("x"))
assert_identical(dataset, out0)
assert_identical(stacked_dataset, out1)

Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def test_concat_merge_variables_present_in_some_datasets(self, data) -> None:

def test_concat_2(self, data) -> None:
dim = "dim2"
datasets = [g for _, g in data.groupby(dim, squeeze=True)]
datasets = [g.squeeze(dim) for _, g in data.groupby(dim, squeeze=False)]
concat_over = [k for k, v in data.coords.items() if dim in v.dims and k != dim]
actual = concat(datasets, data[dim], coords=concat_over)
assert_identical(data, self.rectify_dim_order(data, actual))
Expand All @@ -505,7 +505,7 @@ def test_concat_coords_kwarg(self, data, dim, coords) -> None:
data = data.copy(deep=True)
# make sure the coords argument behaves as expected
data.coords["extra"] = ("dim4", np.arange(3))
datasets = [g for _, g in data.groupby(dim, squeeze=True)]
datasets = [g.squeeze() for _, g in data.groupby(dim, squeeze=False)]

actual = concat(datasets, data[dim], coords=coords)
if coords == "all":
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def test_concat(self) -> None:
actual = concat([foo, bar], "w")
assert_equal(expected, actual)
# from iteration:
grouped = [g for _, g in foo.groupby("x")]
grouped = [g.squeeze() for _, g in foo.groupby("x", squeeze=False)]
stacked = concat(grouped, ds["x"])
assert_identical(foo, stacked)
# with an index as the 'dim' argument
Expand Down
7 changes: 3 additions & 4 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,10 +1475,9 @@ def test_groupby_restore_coord_dims(self):
("a", ("a", "y")),
("b", ("x", "b")),
]:
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
result = array.groupby(by, restore_coord_dims=True).map(
lambda x: x.squeeze()
)["c"]
result = array.groupby(by, squeeze=False, restore_coord_dims=True).map(
lambda x: x.squeeze()
)["c"]
assert result.dims == expected_dims

def test_groupby_first_and_last(self):
Expand Down

0 comments on commit dd6ea53

Please sign in to comment.