@@ -171,52 +171,30 @@ def test_grouper_dropna_propagation(dropna):
171
171
172
172
173
173
@pytest .mark .parametrize (
174
- "dropna,input_index,expected_data,expected_index " ,
174
+ "index " ,
175
175
[
176
- (True , pd .RangeIndex (0 , 4 ), {"B" : [2 , 2 , 1 ]}, pd .RangeIndex (0 , 3 )),
177
- (True , list ("abcd" ), {"B" : [2 , 2 , 1 ]}, list ("abc" )),
178
- (
179
- True ,
180
- pd .MultiIndex .from_tuples (
181
- [(1 , "R" ), (1 , "B" ), (2 , "R" ), (2 , "B" )], names = ["num" , "col" ]
182
- ),
183
- {"B" : [2 , 2 , 1 ]},
184
- pd .MultiIndex .from_tuples (
185
- [(1 , "R" ), (1 , "B" ), (2 , "R" )], names = ["num" , "col" ]
186
- ),
187
- ),
188
- (False , pd .RangeIndex (0 , 4 ), {"B" : [2 , 2 , 1 , 1 ]}, pd .RangeIndex (0 , 4 )),
189
- (False , list ("abcd" ), {"B" : [2 , 2 , 1 , 1 ]}, list ("abcd" )),
190
- (
191
- False ,
192
- pd .MultiIndex .from_tuples (
193
- [(1 , "R" ), (1 , "B" ), (2 , "R" ), (2 , "B" )], names = ["num" , "col" ]
194
- ),
195
- {"B" : [2 , 2 , 1 , 1 ]},
196
- pd .MultiIndex .from_tuples (
197
- [(1 , "R" ), (1 , "B" ), (2 , "R" ), (2 , "B" )], names = ["num" , "col" ]
198
- ),
199
- ),
176
+ pd .RangeIndex (0 , 4 ),
177
+ list ("abcd" ),
178
+ pd .MultiIndex .from_product ([(1 , 2 ), ("R" , "B" )], names = ["num" , "col" ]),
200
179
],
201
180
)
202
- def test_groupby_dataframe_slice_then_transform (
203
- dropna , input_index , expected_data , expected_index
204
- ):
181
+ def test_groupby_dataframe_slice_then_transform (dropna , index ):
205
182
# GH35014 & GH35612
183
+ expected_data = {"B" : [2 , 2 , 1 , np .nan if dropna else 1 ]}
206
184
207
- df = pd .DataFrame ({"A" : [0 , 0 , 1 , None ], "B" : [1 , 2 , 3 , None ]}, index = input_index )
185
+ df = pd .DataFrame ({"A" : [0 , 0 , 1 , None ], "B" : [1 , 2 , 3 , None ]}, index = index )
208
186
gb = df .groupby ("A" , dropna = dropna )
209
187
210
188
result = gb .transform (len )
211
- expected = pd .DataFrame (expected_data , index = expected_index )
189
+ expected = pd .DataFrame (expected_data , index = index )
212
190
tm .assert_frame_equal (result , expected )
213
191
214
192
result = gb [["B" ]].transform (len )
215
- expected = pd .DataFrame (expected_data , index = expected_index )
193
+ expected = pd .DataFrame (expected_data , index = index )
216
194
tm .assert_frame_equal (result , expected )
217
195
218
196
result = gb ["B" ].transform (len )
219
- expected = pd .Series (expected_data ["B" ], index = expected_index , name = "B" )
197
+ expected = pd .Series (expected_data ["B" ], index = index , name = "B" )
220
198
tm .assert_series_equal (result , expected )
221
199
222
200
0 commit comments