-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: GroupBy.quantile fails with pd.NA #43150
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 all commits
b94ee25
5712bf8
105abf4
485402c
e64964f
8a57188
2443008
75aa693
7c15bb2
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 |
---|---|---|
|
@@ -248,6 +248,45 @@ def test_groupby_quantile_skips_invalid_dtype(q): | |
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_groupby_quantile_NA_float(any_float_dtype): | ||
# GH#42849 | ||
df = DataFrame({"x": [1, 1], "y": [0.2, np.nan]}, dtype=any_float_dtype) | ||
result = df.groupby("x")["y"].quantile(0.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. can you do a case with a listlike qs e.g. [0.5, 0.75] 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. added below |
||
expected = pd.Series([0.2], dtype=float, index=[1.0], name="y") | ||
expected.index.name = "x" | ||
tm.assert_series_equal(expected, result) | ||
|
||
result = df.groupby("x")["y"].quantile([0.5, 0.75]) | ||
expected = pd.Series( | ||
[0.2] * 2, | ||
index=pd.MultiIndex.from_product(([1.0], [0.5, 0.75]), names=["x", None]), | ||
name="y", | ||
) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
def test_groupby_quantile_NA_int(any_int_ea_dtype): | ||
# GH#42849 | ||
df = DataFrame({"x": [1, 1], "y": [2, 5]}, dtype=any_int_ea_dtype) | ||
result = df.groupby("x")["y"].quantile(0.5) | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expected = pd.Series([3.5], dtype=float, index=Index([1], name="x"), name="y") | ||
tm.assert_series_equal(expected, result) | ||
|
||
result = df.groupby("x").quantile(0.5) | ||
expected = DataFrame({"y": 3.5}, index=Index([1], name="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. nitpick: clearer to just do |
||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("dtype", ["Float64", "Float32"]) | ||
def test_groupby_quantile_allNA_column(dtype): | ||
# GH#42849 | ||
df = DataFrame({"x": [1, 1], "y": [pd.NA] * 2}, dtype=dtype) | ||
result = df.groupby("x")["y"].quantile(0.5) | ||
expected = pd.Series([np.nan], dtype=float, index=[1.0], name="y") | ||
expected.index.name = "x" | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_groupby_timedelta_quantile(): | ||
# GH: 29485 | ||
df = DataFrame( | ||
|
Uh oh!
There was an error while loading. Please reload this page.