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