-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
add test cases for GroupBy.apply trivial cases #20081
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 2 commits
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 |
---|---|---|
|
@@ -233,6 +233,39 @@ def test_apply_issues(self): | |
lambda x: x['time'][x['value'].idxmax()]) | ||
assert_series_equal(result, expected) | ||
|
||
def test_apply_trivial(self): | ||
# GH 20066 | ||
def gen_one_df(start=0): | ||
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. you dont need a function for this, just create the dataframe directly 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. done in my last commit. |
||
df_this = pd.DataFrame({'key': ['a', 'a', 'b', 'b', 'a'], | ||
'data': [1.0, 2.0, 3.0, 4.0, 5.0]}, | ||
columns=['key', 'data'])[start:] | ||
return df_this | ||
|
||
df = gen_one_df() | ||
expected = pd.concat([gen_one_df(1), gen_one_df(1)], | ||
axis=1, keys=['float64', 'object']) | ||
result = df.groupby([str(x) for x in df.dtypes], | ||
axis=1).apply(lambda x: gen_one_df(1)) | ||
|
||
assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.xfail(reason="didn't work yet") | ||
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 mark the issue and provide some more explanation 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. done in my last commit. |
||
def test_apply_trivial_fail(self): | ||
# GH 20066 | ||
def gen_one_df(start=0): | ||
df_this = pd.DataFrame({'key': ['a', 'a', 'b', 'b', 'a'], | ||
'data': [1.0, 2.0, 3.0, 4.0, 5.0]}, | ||
columns=['key', 'data'])[start:] | ||
return df_this | ||
|
||
df = gen_one_df() | ||
expected = pd.concat([gen_one_df(), gen_one_df()], | ||
axis=1, keys=['float64', 'object']) | ||
result = df.groupby([str(x) for x in df.dtypes], | ||
axis=1).apply(lambda x: gen_one_df()) | ||
|
||
assert_frame_equal(result, expected) | ||
|
||
def test_time_field_bug(self): | ||
# Test a fix for the following error related to GH issue 11324 When | ||
# non-key fields in a group-by dataframe contained time-based fields | ||
|
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 you provide a 1-line comment
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.
done in my last commit.