Skip to content

Commit 283a19d

Browse files
CloseChoicerhshadrach
authored andcommitted
TST: groupby-reindex on DTI (pandas-dev#33638)
1 parent 9958966 commit 283a19d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/groupby/test_apply.py

+20
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,26 @@ def test_apply_with_duplicated_non_sorted_axis(test_series):
491491
tm.assert_frame_equal(result, expected)
492492

493493

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+
494514
def test_apply_corner_cases():
495515
# #535, can't use sliding iterator
496516

0 commit comments

Comments
 (0)