-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: _wrap_applied_output #35412
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
CLN: _wrap_applied_output #35412
Changes from 1 commit
aa02b83
21e1fca
0e16de3
bb032ea
059405c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -868,13 +868,15 @@ def test_apply_multi_level_name(category): | |
b = [1, 2] * 5 | ||
if category: | ||
b = pd.Categorical(b, categories=[1, 2, 3]) | ||
expected_index = pd.CategoricalIndex([1, 2], categories=[1, 2, 3], name="B") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an open issue for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe so. There is only one issue tagged with categorical, groupby, and apply which is not relevant. I also took a look through those tagged as categorical and groupby and didn't see anything either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a whatsnew for this? Something along the lines of |
||
else: | ||
expected_index = pd.Index([1, 2], name="B") | ||
df = pd.DataFrame( | ||
{"A": np.arange(10), "B": b, "C": list(range(10)), "D": list(range(10))} | ||
).set_index(["A", "B"]) | ||
result = df.groupby("B").apply(lambda x: x.sum()) | ||
expected = pd.DataFrame( | ||
{"C": [20, 25], "D": [20, 25]}, index=pd.Index([1, 2], name="B") | ||
) | ||
|
||
expected = pd.DataFrame({"C": [20, 25], "D": [20, 25]}, index=expected_index) | ||
tm.assert_frame_equal(result, expected) | ||
assert df.index.names == ["A", "B"] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be an else statement? Or are there more types we handle than these + NDFrame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're suggesting something like:
The reason I have opted not to do this is that the if-block is exceedingly long, whereas the else-block is quite short. Doing it this way would result in a more nested rather than flat structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack - sorry, I see what you're saying now. Ignore my previous response, will investigate.