Skip to content

BUG: pd.concat fails with large index values when using ArrowDtype #58819

Open
@hombit

Description

@hombit

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import numpy as np
import pandas as pd
import pyarrow as pa

index1 = pd.Index((1<<60) + np.arange(100), dtype=pd.ArrowDtype(pa.uint64()))
index2 = index1 + 100
df1 = pd.DataFrame(dict(a=range(100), b=range(100)), index=index1)
df2 = pd.DataFrame(dict(a=range(100), b=range(100)), index=index2)
pd.concat([df1, df2])

Issue Description

When using arrow uint64 dtype for index and index values larger than 2^53 (9007199254740992), pd.concat fails with an ArrowInvalid error like this:

ArrowInvalid: Integer value 1152921504606846976 not in range: 0 to 9007199254740992

It looks like this function is trying to cast index to float64, because 1) 2^52 is float64's fraction length, 2) because the same error occurs when I'm trying to do it this:

import pyarrow as pa

pa.scalar(1152921504606846976, type=pa.uint64()).cast(pa.float64())

Expected Behavior

pd.concat doesn't try to cast integer index to floats and works as expected

Installed Versions

commit : 3b48b17
python : 3.12.3.final.0
python-bits : 64
OS : Darwin
OS-release : 23.4.0
Version : Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 3.0.0.dev0+1023.g3b48b17e52
numpy : 2.1.0.dev0+git20240503.53cfea9
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : None
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.24.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pyarrow : 16.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugDtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions