Skip to content

Commit 35a121e

Browse files
authored
BUG: ArrowExtensionArray(temporal).quantile raising for non-round results (#52678)
* BUG: ArrowExtensionArray(temporal).quantile raising for non-round results * whatsnew
1 parent 59024bd commit 35a121e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ Sparse
388388

389389
ExtensionArray
390390
^^^^^^^^^^^^^^
391+
- Bug in :meth:`Series.quantile` for pyarrow temporal types raising ArrowInvalid (:issue:`52678`)
391392
- Bug in :meth:`Series.rank` returning wrong order for small values with ``Float64`` dtype (:issue:`52471`)
392393
- 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`)
393394
-

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,8 @@ def _quantile(self, qs: npt.NDArray[np.float64], interpolation: str) -> Self:
14951495
result = pc.quantile(data, q=qs, interpolation=interpolation)
14961496

14971497
if pa.types.is_temporal(pa_dtype):
1498+
if pa.types.is_floating(result.type):
1499+
result = pc.floor(result)
14981500
nbits = pa_dtype.bit_width
14991501
if nbits == 32:
15001502
result = result.cast(pa.int32())

pandas/tests/extension/test_arrow.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,3 +2488,15 @@ def test_describe_numeric_data(pa_type):
24882488
index=["count", "mean", "std", "min", "25%", "50%", "75%", "max"],
24892489
)
24902490
tm.assert_series_equal(result, expected)
2491+
2492+
2493+
@pytest.mark.parametrize(
2494+
"pa_type", tm.DATETIME_PYARROW_DTYPES + tm.TIMEDELTA_PYARROW_DTYPES
2495+
)
2496+
def test_quantile_temporal(pa_type):
2497+
# GH52678
2498+
data = [1, 2, 3]
2499+
ser = pd.Series(data, dtype=ArrowDtype(pa_type))
2500+
result = ser.quantile(0.1)
2501+
expected = ser[0]
2502+
assert result == expected

0 commit comments

Comments
 (0)