Skip to content

Commit 1be0cd6

Browse files
Backport PR #55562 on branch 2.1.x (Floordiv fix for pyarrow dtypes) (#55578)
Backport PR #55562: Floordiv fix for pyarrow dtypes Co-authored-by: rohanjain101 <[email protected]>
1 parent 622a42f commit 1be0cd6

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
@@ -27,9 +27,9 @@ Bug fixes
2727
- Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`)
2828
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
2929
- Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`)
30+
- Fixed bug in :meth:`Series.floordiv` for :class:`ArrowDtype` (:issue:`55561`)
3031
- Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`55362`)
3132
- Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`)
32-
-
3333

3434
.. ---------------------------------------------------------------------------
3535
.. _whatsnew_212.other:

pandas/core/arrays/arrow/array.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def floordiv_compat(
116116
) -> pa.ChunkedArray:
117117
# Ensure int // int -> int mirroring Python/Numpy behavior
118118
# as pc.floor(pc.divide_checked(int, int)) -> float
119-
result = pc.floor(pc.divide(left, right))
119+
converted_left = cast_for_truediv(left, right)
120+
result = pc.floor(pc.divide(converted_left, right))
120121
if pa.types.is_integer(left.type) and pa.types.is_integer(right.type):
121122
result = result.cast(left.type)
122123
return result

pandas/tests/extension/test_arrow.py

+9
Original file line numberDiff line numberDiff line change
@@ -3091,3 +3091,12 @@ def test_factorize_chunked_dictionary():
30913091
exp_uniques = pd.Index(ArrowExtensionArray(pa_array.combine_chunks()))
30923092
tm.assert_numpy_array_equal(res_indices, exp_indicies)
30933093
tm.assert_index_equal(res_uniques, exp_uniques)
3094+
3095+
3096+
def test_arrow_floordiv():
3097+
# GH 55561
3098+
a = pd.Series([-7], dtype="int64[pyarrow]")
3099+
b = pd.Series([4], dtype="int64[pyarrow]")
3100+
expected = pd.Series([-2], dtype="int64[pyarrow]")
3101+
result = a // b
3102+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)