Skip to content

Commit

Permalink
BUG: ArrowExtensionArray(temporal).quantile raising for non-round res…
Browse files Browse the repository at this point in the history
…ults (#52678)

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

* whatsnew
  • Loading branch information
lukemanley committed Apr 17, 2023
1 parent 59024bd commit 35a121e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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 @@ -388,6 +388,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

0 comments on commit 35a121e

Please sign in to comment.