-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix DateFrameGroupBy.mean error for Int64 dtype #32223
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 18 commits
225ad43
fc683e1
dec6560
60c3ccb
c5bd077
780c4cd
6d4a94b
651de5e
a237581
3d0477d
0c7a802
967df57
c60dbcb
e94c9db
bcf9867
9a04125
66fa0de
45d7888
3dadd53
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 |
---|---|---|
|
@@ -1605,3 +1605,36 @@ def test_groupby_mean_no_overflow(): | |
} | ||
) | ||
assert df.groupby("user")["connections"].mean()["A"] == 3689348814740003840 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"values", | ||
[ | ||
{ | ||
"a": [1, 1, 1, 2, 2, 2, 3, 3, 3], | ||
"b": [1, pd.NA, 2, 1, pd.NA, 2, 1, pd.NA, 2], | ||
}, | ||
{"a": [1, 1, 2, 2, 3, 3], "b": [1, 2, 1, 2, 1, 2]}, | ||
], | ||
) | ||
@pytest.mark.parametrize("function", ["mean", "median", "var"]) | ||
@pytest.mark.parametrize("use_agg", [True, False]) | ||
def test_apply_to_nullable_integer_returns_float(values, function, use_agg): | ||
# https://github.com/pandas-dev/pandas/issues/32219 | ||
output = 0.5 if function == "var" else 1.5 | ||
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. move the expected to the top. |
||
arr = np.array([output] * 3, dtype=float) | ||
idx = pd.Index([1, 2, 3], dtype=object, name="a") | ||
expected = pd.DataFrame({"b": arr}, index=idx) | ||
|
||
groups = pd.DataFrame(values, dtype="Int64").groupby("a") | ||
|
||
if use_agg: | ||
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 don't need to parameterize on use_agg; just test all 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. @jreback Updated and green |
||
result = groups.agg(function) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = groups.agg([function]) | ||
expected.columns = MultiIndex.from_tuples([("b", function)]) | ||
tm.assert_frame_equal(result, expected) | ||
else: | ||
result = getattr(groups, function)() | ||
tm.assert_frame_equal(result, expected) |
Uh oh!
There was an error while loading. Please reload this page.