Skip to content

TST: groupby-reindex on DTI #33638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,3 +901,17 @@ def fn(x):
name="col2",
)
tm.assert_series_equal(result, expected)


def test_apply_reindex_values():
# GH: 26209
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few words about what the bug was would be hepful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

values = [1, 2, 3, 4]
indices = [1, 1, 2, 2]
df = pd.DataFrame(
{"group": ["Group1", "Group2"] * 2, "value": values}, index=indices
)
srs_exp = pd.Series(values, index=indices, name="value")
srs_grouped = df.groupby("group").value.apply(
lambda x: x.reindex(np.arange(x.index.min(), x.index.max() + 1))
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theres a lot going on here. can you break this up into multiple lines and comment on which one used to be a problem

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a seperate apply function and gave a little bit more background in the comments. Let me know if there is still somthing missing

tm.assert_series_equal(srs_exp, srs_grouped)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you call these expected and result

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done