-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fixed issue with mixed type groupby aggregate #17003
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
Changes from 1 commit
4c9e32d
a58de54
dbbb0d4
7b24ee1
a7a20d5
34ca8d8
ba57c26
b634bc9
89c585b
0391dfd
4a2dfba
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 |
---|---|---|
|
@@ -892,3 +892,15 @@ def test_sum_uint64_overflow(self): | |
expected.index.name = 0 | ||
result = df.groupby(0).sum() | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_mixed_type_grouping(self): | ||
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. Refer the issue number beneath the function definition (e.g. "see gh-19616") |
||
X = pd.DataFrame(data=[[[1, 1], [2, 2], [3, 3]], | ||
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. expected = |
||
[[1, 1], [2, 2], [3, 3]]], | ||
columns=['X', 'Y', 'Z'], | ||
index=pd.Index(data=[2, 'g1'], name='grouping')) | ||
|
||
S = pd.DataFrame(data=[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]], | ||
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. df = |
||
columns=list('XYZ'), index=list('qwer')) | ||
S['grouping'] = ['g1', 'g1', 2, 2] | ||
T = S.groupby('grouping').aggregate(lambda x: x.tolist()) | ||
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. result = df.groupby(....) |
||
tm.assert_frame_equal(T, X) | ||
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. tm.assert_frame_equal(result, expected) |
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 would rather
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 tried this change and it caused 4 tests in the full test suite to fail. Those tests were TestDatetimeIndex.test_resample_categorical_data_with_timedeltaindex, TestGroupByAggregate.test_mixed_type_grouping (the test that I wrote), TestGroupBy.test_basic, and test_compressed_urls[python-explicit-gzip-.gz]
Also, I noticed that safe_sort returns all objects as strings, even if the input includes numeric types.
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.
yeah this is an embedded issue with
safe_sort
, fixed here: #17034. you can rebase on top (or wait for me to merge this).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 tried this and it resulted in the same tests failing, not sure what's going on.
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.
did u rebase
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 did 'git pull upstream master'
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.
you need to use
safe_sort
here with the latest changed.git pull upstream origin/master