Skip to content

Commit 2a6368e

Browse files
authored
BUG: floordiv fix for large values (#56647)
1 parent 62dbbe6 commit 2a6368e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ Timezones
727727
Numeric
728728
^^^^^^^
729729
- Bug in :func:`read_csv` with ``engine="pyarrow"`` causing rounding errors for large integers (:issue:`52505`)
730+
- Bug in :meth:`Series.__floordiv__` for :class:`ArrowDtype` with integral dtypes raising for large values (:issue:`56645`)
730731
- Bug in :meth:`Series.pow` not filling missing values correctly (:issue:`55512`)
731732

732733
Conversion

pandas/core/arrays/arrow/array.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ def cast_for_truediv(
114114
if pa.types.is_integer(arrow_array.type) and pa.types.is_integer(
115115
pa_object.type
116116
):
117-
return arrow_array.cast(pa.float64())
117+
# https://github.com/apache/arrow/issues/35563
118+
# Arrow does not allow safe casting large integral values to float64.
119+
# Intentionally not using arrow_array.cast because it could be a scalar
120+
# value in reflected case, and safe=False only added to
121+
# scalar cast in pyarrow 13.
122+
return pc.cast(arrow_array, pa.float64(), safe=False)
118123
return arrow_array
119124

120125
def floordiv_compat(

pandas/tests/extension/test_arrow.py

+8
Original file line numberDiff line numberDiff line change
@@ -3133,6 +3133,14 @@ def test_arrow_floordiv():
31333133
tm.assert_series_equal(result, expected)
31343134

31353135

3136+
def test_arrow_floordiv_large_values():
3137+
# GH 55561
3138+
a = pd.Series([1425801600000000000], dtype="int64[pyarrow]")
3139+
expected = pd.Series([1425801600000], dtype="int64[pyarrow]")
3140+
result = a // 1_000_000
3141+
tm.assert_series_equal(result, expected)
3142+
3143+
31363144
def test_string_to_datetime_parsing_cast():
31373145
# GH 56266
31383146
string_dates = ["2020-01-01 04:30:00", "2020-01-02 00:00:00", "2020-01-03 00:00:00"]

0 commit comments

Comments
 (0)