File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -491,6 +491,26 @@ def test_apply_with_duplicated_non_sorted_axis(test_series):
491
491
tm .assert_frame_equal (result , expected )
492
492
493
493
494
+ def test_apply_reindex_values ():
495
+ # GH: 26209
496
+ # reindexing from a single column of a groupby object with duplicate indices caused
497
+ # a ValueError (cannot reindex from duplicate axis) in 0.24.2, the problem was
498
+ # solved in #30679
499
+ values = [1 , 2 , 3 , 4 ]
500
+ indices = [1 , 1 , 2 , 2 ]
501
+ df = pd .DataFrame (
502
+ {"group" : ["Group1" , "Group2" ] * 2 , "value" : values }, index = indices
503
+ )
504
+ expected = pd .Series (values , index = indices , name = "value" )
505
+
506
+ def reindex_helper (x ):
507
+ return x .reindex (np .arange (x .index .min (), x .index .max () + 1 ))
508
+
509
+ # the following group by raised a ValueError
510
+ result = df .groupby ("group" ).value .apply (reindex_helper )
511
+ tm .assert_series_equal (expected , result )
512
+
513
+
494
514
def test_apply_corner_cases ():
495
515
# #535, can't use sliding iterator
496
516
You can’t perform that action at this time.
0 commit comments