Skip to content

BUG: describe not returning ArrowDtype #52470

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

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Fixed regressions
Bug fixes
~~~~~~~~~
- Fixed bug in :func:`merge` when merging with ``ArrowDtype`` one one and a NumPy dtype on the other side (:issue:`52406`)
- Bug in :meth:`Series.describe` not returning :class:`ArrowDtype` with ``pyarrow.float64`` type with numeric data (:issue:`52427`)

.. ---------------------------------------------------------------------------
.. _whatsnew_201.other:
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/methods/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
is_timedelta64_dtype,
)

from pandas.core.arrays.arrow.dtype import ArrowDtype
from pandas.core.arrays.floating import Float64Dtype
from pandas.core.reshape.concat import concat

Expand Down Expand Up @@ -229,7 +230,12 @@ def describe_numeric_1d(series: Series, percentiles: Sequence[float]) -> Series:
# GH#48340 - always return float on non-complex numeric data
dtype: DtypeObj | None
if is_extension_array_dtype(series.dtype):
dtype = Float64Dtype()
if isinstance(series.dtype, ArrowDtype):
import pyarrow as pa

dtype = ArrowDtype(pa.float64())
else:
dtype = Float64Dtype()
elif is_numeric_dtype(series.dtype) and not is_complex_dtype(series.dtype):
dtype = np.dtype("float")
else:
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2387,3 +2387,16 @@ def test_setitem_boolean_replace_with_mask_segfault():
expected = arr.copy()
arr[np.zeros((N,), dtype=np.bool_)] = False
assert arr._pa_array == expected._pa_array


@pytest.mark.parametrize("pa_type", tm.ALL_INT_PYARROW_DTYPES + tm.FLOAT_PYARROW_DTYPES)
def test_describe_numeric_data(pa_type):
# GH 52470
data = pd.Series([1, 2, 3], dtype=ArrowDtype(pa_type))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add gh ref?

result = data.describe()
expected = pd.Series(
[3, 2, 1, 1, 1.5, 2.0, 2.5, 3],
dtype=ArrowDtype(pa.float64()),
index=["count", "mean", "std", "min", "25%", "50%", "75%", "max"],
)
tm.assert_series_equal(result, expected)