Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
hombit opened this issue May 24, 2024 · 1 comment
Open
3 tasks done

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

hombit opened this issue May 24, 2024 · 1 comment
Labels
Arrow pyarrow functionality Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@hombit
Copy link
Contributor

hombit commented May 24, 2024

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

@hombit hombit added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 24, 2024
@mroeschke mroeschke added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Arrow pyarrow functionality Dtype Conversions Unexpected or buggy dtype conversions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 8, 2024
@mroeschke
Copy link
Member

Thanks for the report. Looks like the concat type is determined by numpy types using _get_result_dtype, and then when casting, pyarrow.cast defaults to safe=True as opposed to numpy casting which allows uint64 to float64

Then again, there is an idea to only allow safe casting generally #45588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants