BUG: Error writing DataFrame with categorical type column and "Int" data to a CSV file ("int" works of course) #46812
Labels
Bug
Categorical
Categorical Data Type
IO CSV
read_csv, to_csv
NA - MaskedArrays
Related to pd.NA and nullable extension arrays
Regression
Functionality that used to work in a prior pandas version
Milestone
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
Issue Description
This Bug is similar to: #46297. Executing the example above produces the following error in pandas 1.4.2 (this code example works fine on older pandas versions, e.g. 1.2.4). The problem occurs when saving a dataframe to a .csv when the categorical type is set over a nan supported "Int" dtype (note not a default "int" dtype).
Expected Behavior
I'd expect the above example to write a dataframe to a .csv as in older pandas versions instead of ending in an error traceback.
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United States.1252
pandas : 1.4.2
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : 0.29.21
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
brotli :
fastparquet : None
fsspec : 0.8.3
gcsfs : None
markupsafe : 1.1.1
matplotlib : 3.3.2
numba : 0.51.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
snappy : None
sqlalchemy : 1.3.20
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
zstandard : None
The text was updated successfully, but these errors were encountered: