Skip to content

BUG: astype() unexpected mutation of values #58907

Closed
@hajes

Description

@hajes

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

the whole df usually has got >10 rows x 49 columns

`df = pd.DataFrame.from_dict(dictionary)`
`df = df.astype(DF_DTYPES)` where this particular column is defined `{'is_inco_oper': int}`

Issue Description

original df is int64 converted to int32, and values are mutated in row 7-9

0     170914000
1      63275000
2     248049000
3     746273000
4    1067817000
5    1022510000
6    1218091000
7    3415195000
8    3669382000
9    2531232000
Name: is_inco_oper, dtype: int64
0     170914000
1      63275000
2     248049000
3     746273000
4    1067817000
5    1022510000
6    1218091000
7    -879772296
8    -625585296
9   -1763735296
Name: is_inco_oper, dtype: int32

Expected Behavior

keep the original values

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.12.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : AMD64 Family 25 Model 33 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Switzerland.1252

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 70.0.0
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 : 3.1.3
IPython : 8.24.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.4
numba : 0.59.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions