@@ -107,47 +107,36 @@ def test_groupby_input_mutation():
107
107
assert_identical (array , array_copy ) # should not modify inputs
108
108
109
109
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 ]))
136
120
assert_identical (expected , actual )
137
121
138
122
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 ):
142
131
def func (group ):
143
132
if group .sizes ["x" ] == 1 :
144
133
result = group .isel (x = [0 , 0 ])
145
134
else :
146
135
result = group .isel (x = [0 ])
147
136
return result
148
137
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 )
151
140
assert_identical (expected , actual )
152
141
153
142
0 commit comments