Skip to content

Commit b77f0c9

Browse files
committed
cleanup tests
1 parent 394c46e commit b77f0c9

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

xarray/tests/test_groupby.py

+20-31
Original file line numberDiff line numberDiff line change
@@ -107,47 +107,36 @@ def test_groupby_input_mutation():
107107
assert_identical(array, array_copy) # should not modify inputs
108108

109109

110-
def test_da_groupby_map_shrink_groups():
111-
array = xr.DataArray([1, 2, 3, 4, 5, 6], [("x", [1, 1, 1, 2, 2, 2])])
112-
expected = array.isel(x=[0, 1, 3, 4])
113-
actual = array.groupby("x").map(lambda f: f.isel(x=[0, 1]))
114-
assert_identical(expected, actual)
115-
116-
117-
def test_ds_groupby_map_shrink_groups():
118-
dataset = xr.Dataset({"foo": ("x", [1, 2, 3, 4, 5, 6])}, {"x": [1, 1, 1, 2, 2, 2]})
119-
expected = dataset.isel(x=[0, 1, 3, 4])
120-
actual = dataset.groupby("x").map(lambda f: f.isel(x=[0, 1]))
121-
assert_identical(expected, actual)
122-
123-
124-
def test_da_groupby_map_change_group_size():
125-
array = xr.DataArray([1, 2, 3], [("x", [1, 2, 2])])
126-
127-
def func(group):
128-
if group.sizes["x"] == 1:
129-
result = group.isel(x=[0, 0])
130-
else:
131-
result = group.isel(x=[0])
132-
return result
133-
134-
expected = array.isel(x=[0, 0, 1])
135-
actual = array.groupby("x").map(func)
110+
@pytest.mark.parametrize(
111+
"obj",
112+
[
113+
xr.DataArray([1, 2, 3, 4, 5, 6], [("x", [1, 1, 1, 2, 2, 2])]),
114+
xr.Dataset({"foo": ("x", [1, 2, 3, 4, 5, 6])}, {"x": [1, 1, 1, 2, 2, 2]}),
115+
],
116+
)
117+
def test_groupby_map_shrink_groups(obj):
118+
expected = obj.isel(x=[0, 1, 3, 4])
119+
actual = obj.groupby("x").map(lambda f: f.isel(x=[0, 1]))
136120
assert_identical(expected, actual)
137121

138122

139-
def test_ds_groupby_map_change_group_size():
140-
dataset = xr.Dataset({"foo": ("x", [1, 2, 3])}, {"x": [1, 2, 2]})
141-
123+
@pytest.mark.parametrize(
124+
"obj",
125+
[
126+
xr.DataArray([1, 2, 3], [("x", [1, 2, 2])]),
127+
xr.Dataset({"foo": ("x", [1, 2, 3])}, {"x": [1, 2, 2]}),
128+
],
129+
)
130+
def test_ds_groupby_map_change_group_size(obj):
142131
def func(group):
143132
if group.sizes["x"] == 1:
144133
result = group.isel(x=[0, 0])
145134
else:
146135
result = group.isel(x=[0])
147136
return result
148137

149-
expected = dataset.isel(x=[0, 0, 1])
150-
actual = dataset.groupby("x").map(func)
138+
expected = obj.isel(x=[0, 0, 1])
139+
actual = obj.groupby("x").map(func)
151140
assert_identical(expected, actual)
152141

153142

0 commit comments

Comments
 (0)