-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Using agg with groupy, as_index=False still returning group variable as index #25114
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cb1419b
Solving issue 25011
95f8f0b
added test and whatsnew
19a041c
Merge remote-tracking branch 'upstream/master' into Solving_Issue_25011
055cfa7
Minor Changes
ba4ebf7
Test and whatnew entries updated
a54a052
Merge remote-tracking branch 'upstream/master' into Solving_Issue_25011
b922fb4
test changes
0137ff0
Minor changes
8a8ace4
Minor changes
bc3f337
Merge remote-tracking branch 'upstream/master' into Solving_Issue_25011
7f1161c
minor changes
e564129
merge
f963b17
merge master
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,3 +286,46 @@ def test_multi_function_flexible_mix(df): | |
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): | ||
result = grouped.aggregate(d) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_not_as_index_agg_list(): | ||
|
||
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. add the issue number. parameterize on as_index=[True,False] 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. like
|
||
# GH 25011 | ||
# expected behavhior of agg with as_index=True | ||
as_index = False | ||
array = [[3, 1, 2], | ||
[3, 3, 4], | ||
[4, 5, 6], | ||
[4, 7, 8]] | ||
df = pd.DataFrame(array, columns=['shouldnt_be_index', 'A', 'B']) | ||
groupby = df.groupby('shouldnt_be_index', as_index=as_index) | ||
result = groupby.agg(['min', 'max']) | ||
|
||
array2 = [[3, 1, 3, 2, 4], | ||
[4, 5, 7, 6, 8]] | ||
columns = pd.MultiIndex(levels=[['A', 'B', 'shouldnt_be_index'], | ||
['min', 'max', '']], | ||
codes=[[2, 0, 0, 1, 1], [2, 0, 1, 0, 1]]) | ||
expected = pd.DataFrame(array2, columns=columns) | ||
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
# expected behavhior of agg with as_index=True | ||
as_index = True | ||
array = [[3, 1, 2], | ||
[3, 3, 4], | ||
[4, 5, 6], | ||
[4, 7, 8]] | ||
df = pd.DataFrame(array, columns=['should_be_index', 'A', 'B']) | ||
groupby = df.groupby('should_be_index', as_index=as_index) | ||
result = groupby.agg(['min', 'max']) | ||
|
||
array2 = [[1, 3, 2, 4], | ||
[5, 7, 6, 8]] | ||
columns = pd.MultiIndex(levels=[['A', 'B'], | ||
['min', 'max']], | ||
codes=[[0, 0, 1, 1], [0, 1, 0, 1]]) | ||
index = pd.Series([3, 4], name='should_be_index') | ||
expected = pd.DataFrame(array2, columns=columns, index=index) | ||
|
||
tm.assert_frame_equal(result, expected) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Bug in ::meth:`pandas.core.groupby.GroupBy.agg
when passing
as_index=False``, returning an additional column.