Skip to content

Commit c335941

Browse files
committed
Silence more warnings
1 parent 44e5a41 commit c335941

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

xarray/tests/test_computation.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ def test_apply_identity() -> None:
118118
assert_identical(variable, apply_identity(variable))
119119
assert_identical(data_array, apply_identity(data_array))
120120
assert_identical(data_array, apply_identity(data_array.groupby("x")))
121+
assert_identical(data_array, apply_identity(data_array.groupby("x", squeeze=False)))
121122
assert_identical(dataset, apply_identity(dataset))
122123
assert_identical(dataset, apply_identity(dataset.groupby("x")))
124+
assert_identical(dataset, apply_identity(dataset.groupby("x", squeeze=False)))
123125

124126

125127
def add(a, b):
@@ -519,8 +521,10 @@ def func(x):
519521
assert_identical(stacked_variable, stack_negative(variable))
520522
assert_identical(stacked_data_array, stack_negative(data_array))
521523
assert_identical(stacked_dataset, stack_negative(dataset))
522-
assert_identical(stacked_data_array, stack_negative(data_array.groupby("x")))
523-
assert_identical(stacked_dataset, stack_negative(dataset.groupby("x")))
524+
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
525+
assert_identical(stacked_data_array, stack_negative(data_array.groupby("x")))
526+
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
527+
assert_identical(stacked_dataset, stack_negative(dataset.groupby("x")))
524528

525529
def original_and_stack_negative(obj):
526530
def func(x):
@@ -547,11 +551,13 @@ def func(x):
547551
assert_identical(dataset, out0)
548552
assert_identical(stacked_dataset, out1)
549553

550-
out0, out1 = original_and_stack_negative(data_array.groupby("x"))
554+
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
555+
out0, out1 = original_and_stack_negative(data_array.groupby("x"))
551556
assert_identical(data_array, out0)
552557
assert_identical(stacked_data_array, out1)
553558

554-
out0, out1 = original_and_stack_negative(dataset.groupby("x"))
559+
with pytest.warns(UserWarning, match="The `squeeze` kwarg"):
560+
out0, out1 = original_and_stack_negative(dataset.groupby("x"))
555561
assert_identical(dataset, out0)
556562
assert_identical(stacked_dataset, out1)
557563

xarray/tests/test_concat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_concat_merge_variables_present_in_some_datasets(self, data) -> None:
494494

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

510510
actual = concat(datasets, data[dim], coords=coords)
511511
if coords == "all":
@@ -1000,7 +1000,7 @@ def test_concat(self) -> None:
10001000
actual = concat([foo, bar], "w")
10011001
assert_equal(expected, actual)
10021002
# from iteration:
1003-
grouped = [g for _, g in foo.groupby("x")]
1003+
grouped = [g.squeeze() for _, g in foo.groupby("x", squeeze=False)]
10041004
stacked = concat(grouped, ds["x"])
10051005
assert_identical(foo, stacked)
10061006
# with an index as the 'dim' argument

0 commit comments

Comments
 (0)