Skip to content

Commit

Permalink
Backport PR #55562 on branch 2.1.x (Floordiv fix for pyarrow dtypes) (#…
Browse files Browse the repository at this point in the history
…55578)

Backport PR #55562: Floordiv fix for pyarrow dtypes

Co-authored-by: rohanjain101 <38412262+rohanjain101@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and rohanjain101 committed Oct 18, 2023
1 parent 622a42f commit 1be0cd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Bug fixes
- Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`)
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
- Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`)
- Fixed bug in :meth:`Series.floordiv` for :class:`ArrowDtype` (:issue:`55561`)
- Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`55362`)
- Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`)
-

.. ---------------------------------------------------------------------------
.. _whatsnew_212.other:
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def floordiv_compat(
) -> pa.ChunkedArray:
# Ensure int // int -> int mirroring Python/Numpy behavior
# as pc.floor(pc.divide_checked(int, int)) -> float
result = pc.floor(pc.divide(left, right))
converted_left = cast_for_truediv(left, right)
result = pc.floor(pc.divide(converted_left, right))
if pa.types.is_integer(left.type) and pa.types.is_integer(right.type):
result = result.cast(left.type)
return result
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3091,3 +3091,12 @@ def test_factorize_chunked_dictionary():
exp_uniques = pd.Index(ArrowExtensionArray(pa_array.combine_chunks()))
tm.assert_numpy_array_equal(res_indices, exp_indicies)
tm.assert_index_equal(res_uniques, exp_uniques)


def test_arrow_floordiv():
# GH 55561
a = pd.Series([-7], dtype="int64[pyarrow]")
b = pd.Series([4], dtype="int64[pyarrow]")
expected = pd.Series([-2], dtype="int64[pyarrow]")
result = a // b
tm.assert_series_equal(result, expected)

0 comments on commit 1be0cd6

Please sign in to comment.