-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REGR: .describe on unsigned dtypes results in object #48473
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
d907794
97e6cdd
ff4a95f
60a9b6c
359cfd7
21b839d
3e3aa9f
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 |
---|---|---|
|
@@ -240,7 +240,12 @@ def describe_numeric_1d(series: Series, percentiles: Sequence[float]) -> Series: | |
+ series.quantile(percentiles).tolist() | ||
+ [series.max()] | ||
) | ||
return Series(d, index=stat_index, name=series.name) | ||
|
||
result = Series(d, index=stat_index, name=series.name) | ||
if isinstance(d[1], float): | ||
# GH#48340 - don't rely on inference, always return float on numeric data | ||
result = result.astype(float) | ||
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. Nit: Can we just set dtype=... when creating the Series? |
||
return result | ||
|
||
|
||
def describe_categorical_1d( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from pandas import ( | ||
Period, | ||
|
@@ -149,3 +150,25 @@ def test_datetime_is_numeric_includes_datetime(self): | |
index=["count", "mean", "min", "25%", "50%", "75%", "max"], | ||
) | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"dtype", ["int32", "int64", "uint32", "uint64", "float32", "float64"] | ||
) | ||
def test_numeric_result_is_float(self, 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. Maybe 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. Thanks - I also tried complex and found this was buggy in that case. Fixed and added all numeric dtypes. |
||
# GH#48340 - describe should always return dtype float on numeric input | ||
ser = Series([0, 1], dtype=dtype) | ||
result = ser.describe() | ||
expected = Series( | ||
[ | ||
2.0, | ||
0.5, | ||
ser.std(), | ||
0, | ||
0.25, | ||
0.5, | ||
0.75, | ||
1.0, | ||
], | ||
index=["count", "mean", "std", "min", "25%", "50%", "75%", "max"], | ||
) | ||
tm.assert_series_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.
Can we determine the target dtype based on the input dtype? Like when we have numeric cast to float, else keep?
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.
Thanks - I was worried about doing this because of object dtype with numeric data, but I see now object dtype takes a different path.