@@ -116,8 +116,9 @@ def f(x, q=None, axis=0):
116
116
expected_seq = df_grouped .quantile ([0.4 , 0.8 ])
117
117
if not as_index :
118
118
# apply treats the op as a transform; .quantile knows it's a reduction
119
- apply_result = apply_result .reset_index ()
120
- apply_result ["level_0" ] = [1 , 1 , 2 , 2 ]
119
+ apply_result .index = range (4 )
120
+ apply_result .insert (loc = 0 , column = "level_0" , value = [1 , 1 , 2 , 2 ])
121
+ apply_result .insert (loc = 1 , column = "level_1" , value = [0.4 , 0.8 , 0.4 , 0.8 ])
121
122
tm .assert_frame_equal (apply_result , expected_seq , check_names = False )
122
123
123
124
agg_result = df_grouped .agg (f , q = 80 )
@@ -522,13 +523,7 @@ def test_as_index_select_column():
522
523
result = df .groupby ("A" , as_index = False , group_keys = True )["B" ].apply (
523
524
lambda x : x .cumsum ()
524
525
)
525
- expected = Series (
526
- [2 , 6 , 6 ],
527
- name = "B" ,
528
- index = MultiIndex (
529
- levels = [RangeIndex (2 ), RangeIndex (3 )], codes = [[0 , 0 , 1 ], [0 , 1 , 2 ]]
530
- ),
531
- )
526
+ expected = Series ([2 , 6 , 6 ], name = "B" , index = range (3 ))
532
527
tm .assert_series_equal (result , expected )
533
528
534
529
0 commit comments