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: conversion from Int64 to string introduces decimals in Pandas 2.2.0 #57418

Closed
2 of 3 tasks
mplatzer opened this issue Feb 14, 2024 · 7 comments · Fixed by #57489
Closed
2 of 3 tasks

BUG: conversion from Int64 to string introduces decimals in Pandas 2.2.0 #57418

mplatzer opened this issue Feb 14, 2024 · 7 comments · Fixed by #57489
Labels
Arrow pyarrow functionality Bug Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@mplatzer
Copy link

mplatzer commented Feb 14, 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 pandas as pd
pd.Series([12, pd.NA], dtype="Int64[pyarrow]").astype("string[pyarrow]")

yields

0    12.0
1    <NA>
dtype: string

Issue Description

Converting from Int64[pyarrow] to string[pyarrow] introduces float notation, if NAs are present. I.e. 12 will be converted to "12.0". This bug got introduced in Pandas 2.2.0, is still present on Pandas 2.2.x branch, but is not present on Pandas main branch.

Expected Behavior

import pandas as pd
x = pd.Series([12, pd.NA], dtype="Int64[pyarrow]").astype("string[pyarrow]")
assert x[0] == "12"

Installed Versions

INSTALLED VERSIONS

commit : fd3f571
python : 3.11.7.final.0
python-bits : 64
OS : Darwin
OS-release : 23.2.0
Version : Darwin Kernel Version 23.2.0: Wed Nov 15 21:59:33 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.0.3
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 : None
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 : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.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

@mplatzer mplatzer added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 14, 2024
@rhshadrach
Copy link
Member

Thanks for the report. @mplatzer - can you give this issue a meaningful title? Currently it is BUG:.

@mplatzer mplatzer changed the title BUG: BUG: conversion from Int64 to string introduces now decimals in Pandas 2.2.0 Feb 14, 2024
@mplatzer
Copy link
Author

@rhshadrach sorry, my bad, I've overlooked that. A meaningful title has now been added.

@mplatzer mplatzer changed the title BUG: conversion from Int64 to string introduces now decimals in Pandas 2.2.0 BUG: conversion from Int64 to string introduces decimals in Pandas 2.2.0 Feb 14, 2024
@rhshadrach
Copy link
Member

Confirmed on main. Further investigations and PRs to fix are welcome.

@rhshadrach rhshadrach added Dtype Conversions Unexpected or buggy dtype conversions Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 15, 2024
@mplatzer
Copy link
Author

I suspect the issue is related to this change (taken from the 2.2.0 release notes):

integer dtypes with missing values are cast to NumPy float dtypes and NaN is used as missing value indicator
but wouldn't know any further details

@rhshadrach rhshadrach added the Regression Functionality that used to work in a prior pandas version label Feb 15, 2024
@rhshadrach rhshadrach added this to the 2.2.1 milestone Feb 15, 2024
@rhshadrach
Copy link
Member

This bug... is not present on Pandas main branch.

I'm still seeing it on main. Can you recheck, make sure we're seeing the same thing?

@rhshadrach
Copy link
Member

Result of a git bisect:

Author: Patrick Hoefler
Date:   Thu Dec 21 23:15:49 2023 +0100

    Convert ArrowExtensionArray to proper NumPy dtype (#56290)

cc @phofl

@mplatzer
Copy link
Author

yes, you are right, it's still happening for main

>>> import pandas as pd
>>> pd.__version__
'3.0.0.dev0+355.g92a52e231'
>>> pd.Series([12, pd.NA], dtype="Int64[pyarrow]").astype("string[pyarrow]")
0    12.0
1    <NA>

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 Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants