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: read_parquet converts all digits strings to int #58771

Closed
3 tasks done
tfardet opened this issue May 18, 2024 · 2 comments
Closed
3 tasks done

BUG: read_parquet converts all digits strings to int #58771

tfardet opened this issue May 18, 2024 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@tfardet
Copy link

tfardet commented May 18, 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

df = pd.DataFrame({"a": ["a", "b", "c"], "b": ["1", "2", "3"]})
df.to_parquet("df.parquet")
df2 = pd.read_parquet("df.parquet")
"1" in df2.b  # returns False
1 in df2.b  # returns True

from pyarrow.parquet import read_table
read_table("df.parquet")  # returns the proper string types

Issue Description

Reading parquet files converts all-digit strings to integers despite pyarrow properly returning the string type of the column.

Potentially related to #31821

Expected Behavior

The column is properly typed as strings

Installed Versions

commit : a3e751c
python : 3.12.3.final.0
python-bits : 64
OS : Linux
OS-release : 6.8.9-300.fc40.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Thu May 2 18:59:06 UTC 2024
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : fr_FR.UTF-8
LOCALE : fr_FR.UTF-8

pandas : 3.0.0.dev0+991.ga3e751c6b
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.3.2
Cython : 3.0.10
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.0
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 : 4.12.3
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.4
numba : None
numexpr : None
odfpy : None
openpyxl : None
pyarrow : 16.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.0
sqlalchemy : None
tables : None
tabulate : None
xarray : 2024.3.0
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@tfardet tfardet added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 18, 2024
@Aloqeely
Copy link
Member

Thanks for the report. read_parquet does preserve the numbers as strings, it's just that the in operator checks for the items in the index rather than the Series data. You can instead use the in operator on Series.values to see if an item exists in the Series data, e.g.

"1" in df2.b.values  # True

@tfardet
Copy link
Author

tfardet commented May 18, 2024

Ah, I see, sorry, I did not realize this was how Series worked.
Closing!

@tfardet tfardet closed this as completed May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants