Skip to content

BUG: DataFrame.convert_dtype(convert_integer=True) with int64_t limits throws Warning #58485

Open
@Tishj

Description

@Tishj

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 pandas as pd
import pyarrow as pa

print(pd.__version__)
print(pa.__version__)

df = pd.DataFrame({
	'a': [-9223372036854775808, 4611686018427387904, 9223372036854775807, None],
	'b': [-9223372036854775808, 4611686018427387904, 9223372036854775807, None],
	'c': [-9223372036854775808, 4611686018427387904, 9223372036854775807, None],
})

pa_df = df.convert_dtypes(dtype_backend='pyarrow')
print(pa_df)
2.2.2
16.0.0
/Users/User/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pandas/core/dtypes/cast.py:1057: RuntimeWarning: invalid value encountered in cast
  if (arr.astype(int) == arr).all():
/Users/User/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pandas/core/dtypes/cast.py:1081: RuntimeWarning: invalid value encountered in cast
  if (arr.astype(int) == arr).all():
                      a                     b                     c
0  -9223372036854775808  -9223372036854775808  -9223372036854775808
1   4611686018427387904   4611686018427387904   4611686018427387904
2   9223372036854775807   9223372036854775807   9223372036854775807
3                  <NA>                  <NA>                  <NA>

Issue Description

Throwing a warning when converting

Expected Behavior

It should not throw a warning, it looks like the conversion happens successfully in spite of the warning.

Installed Versions

commit : d9cdd2e python : 3.12.1.final.0 python-bits : 64 OS : Darwin OS-release : 23.1.0 Version : Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.5.1
pip : 23.2.1
Cython : None
pytest : 8.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.3.1
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 16.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 2.0.29
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsWarningsWarnings that appear or should be added to pandas

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions