-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
BUG: .describe() doesn't work for EAs #61707 #61760
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
9b3c6ac
3550556
22f12fc
b91fa1d
9dcce63
391107a
51763f9
e5a1c10
2b471c8
0faaf5c
cf1a11c
ebca3c5
b9d5732
be2cb8c
ff8a607
d21ad1a
16fd208
b5e441e
fea4f5b
7c2796d
d1a245c
d5f97ed
f94b430
e635c3e
b876c67
9da2c8f
d785a3d
337d5fe
688e2a0
e1328fc
fd7bfaa
e83b820
da7f2be
4f2aa4d
a2315af
bc6ad14
1d153bb
43711d5
2c89a91
13bba34
598b7d1
88cb152
042ac78
3e9237c
d5eab1b
90b1c5d
6537afe
6fca116
4b18266
6a6a1ba
8de38e8
9edf890
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
) | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
cast, | ||
) | ||
|
||
|
@@ -215,6 +216,14 @@ def reorder_columns(ldesc: Sequence[Series]) -> list[Hashable]: | |
return names | ||
|
||
|
||
def has_multiple_internal_dtypes(d: list[Any]) -> bool: | ||
"""Check if the sequence has multiple internal dtypes.""" | ||
if not d: | ||
return False | ||
|
||
return any(type(item) != type(d[0]) for item in d) | ||
|
||
|
||
def describe_numeric_1d(series: Series, percentiles: Sequence[float]) -> Series: | ||
"""Describe series containing numerical data. | ||
|
||
|
@@ -251,6 +260,10 @@ def describe_numeric_1d(series: Series, percentiles: Sequence[float]) -> Series: | |
import pyarrow as pa | ||
|
||
dtype = ArrowDtype(pa.float64()) | ||
elif has_multiple_internal_dtypes(d): | ||
# GH61707: describe() doesn't work on EAs | ||
# with multiple internal dtypes, so return object dtype | ||
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. is the relevant characteristic "multiple internal dtypes" or "entries that cant be cast to Float64"? 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. latter makes more sense |
||
dtype = None | ||
else: | ||
dtype = Float64Dtype() | ||
elif series.dtype.kind in "iufb": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,32 @@ def test_describe_empty_object(self): | |
assert np.isnan(result.iloc[2]) | ||
assert np.isnan(result.iloc[3]) | ||
|
||
def test_describe_multiple_dtypes(self): | ||
""" | ||
GH61707: describe() doesn't work on EAs which generate | ||
statistics with multiple dtypes. | ||
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 can this be a comment instead of a docstring |
||
""" | ||
from decimal import Decimal | ||
|
||
from pandas.tests.extension.decimal import to_decimal | ||
|
||
s = Series(to_decimal([1, 2.5, 3]), dtype="decimal") | ||
|
||
expected = Series( | ||
[ | ||
3, | ||
Decimal("2.166666666666666666666666667"), | ||
Decimal("0.8498365855987974716713706849"), | ||
Decimal("1"), | ||
Decimal("3"), | ||
], | ||
index=["count", "mean", "std", "min", "max"], | ||
dtype="object", | ||
) | ||
|
||
result = s.describe(percentiles=[]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_describe_with_tz(self, tz_naive_fixture): | ||
# GH 21332 | ||
tz = tz_naive_fixture | ||
|
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 think this can be inlined since it is only used once