Skip to content

Commit 864596b

Browse files
rohanjain101Rohan Jainmroeschke
authored
Floordiv fix for pyarrow dtypes (#55562)
* floordiv fix * docs * docs * try fix * revert * precommit * Update doc/source/whatsnew/v2.1.2.rst Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Rohan Jain <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent a9fce50 commit 864596b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v2.1.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Bug fixes
2929
- Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`)
3030
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
3131
- Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`)
32+
- Fixed bug in :meth:`Series.floordiv` for :class:`ArrowDtype` (:issue:`55561`)
3233
- Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`55362`)
3334
- Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`)
34-
-
3535

3636
.. ---------------------------------------------------------------------------
3737
.. _whatsnew_212.other:

pandas/core/arrays/arrow/array.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def floordiv_compat(
119119
) -> pa.ChunkedArray:
120120
# Ensure int // int -> int mirroring Python/Numpy behavior
121121
# as pc.floor(pc.divide_checked(int, int)) -> float
122-
result = pc.floor(pc.divide(left, right))
122+
converted_left = cast_for_truediv(left, right)
123+
result = pc.floor(pc.divide(converted_left, right))
123124
if pa.types.is_integer(left.type) and pa.types.is_integer(right.type):
124125
result = result.cast(left.type)
125126
return result

pandas/tests/extension/test_arrow.py

+9
Original file line numberDiff line numberDiff line change
@@ -3046,3 +3046,12 @@ def test_factorize_chunked_dictionary():
30463046
exp_uniques = pd.Index(ArrowExtensionArray(pa_array.combine_chunks()))
30473047
tm.assert_numpy_array_equal(res_indices, exp_indicies)
30483048
tm.assert_index_equal(res_uniques, exp_uniques)
3049+
3050+
3051+
def test_arrow_floordiv():
3052+
# GH 55561
3053+
a = pd.Series([-7], dtype="int64[pyarrow]")
3054+
b = pd.Series([4], dtype="int64[pyarrow]")
3055+
expected = pd.Series([-2], dtype="int64[pyarrow]")
3056+
result = a // b
3057+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)