Skip to content

BUG: ArrowExtensionArray(temporal).quantile raising for non-round results #52678

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 2 commits into from
Apr 17, 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.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ Sparse

ExtensionArray
^^^^^^^^^^^^^^
- Bug in :meth:`Series.quantile` for pyarrow temporal types raising ArrowInvalid (:issue:`52678`)
- Bug in :meth:`Series.rank` returning wrong order for small values with ``Float64`` dtype (:issue:`52471`)
- Bug where the ``__from_arrow__`` method of masked ExtensionDtypes(e.g. :class:`Float64Dtype`, :class:`BooleanDtype`) would not accept pyarrow arrays of type ``pyarrow.null()`` (:issue:`52223`)
-
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@ def _quantile(self, qs: npt.NDArray[np.float64], interpolation: str) -> Self:
result = pc.quantile(data, q=qs, interpolation=interpolation)

if pa.types.is_temporal(pa_dtype):
if pa.types.is_floating(result.type):
result = pc.floor(result)
nbits = pa_dtype.bit_width
if nbits == 32:
result = result.cast(pa.int32())
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2488,3 +2488,15 @@ def test_describe_numeric_data(pa_type):
index=["count", "mean", "std", "min", "25%", "50%", "75%", "max"],
)
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize(
"pa_type", tm.DATETIME_PYARROW_DTYPES + tm.TIMEDELTA_PYARROW_DTYPES
)
def test_quantile_temporal(pa_type):
# GH52678
data = [1, 2, 3]
ser = pd.Series(data, dtype=ArrowDtype(pa_type))
result = ser.quantile(0.1)
expected = ser[0]
assert result == expected