Skip to content

BUG: [REGRESSION] to_csv cannot handle FloatingArrays with np.nan, even with distinguish_nan_and_na=True #65227

@carlocastoldi

Description

@carlocastoldi

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

s = pd.Series((1, pd.NA, 0), index=["a","b","c"], dtype=pd.Float64Dtype(), name="x")
with pd.option_context("future.distinguish_nan_and_na", True):
    s = s/s # creates a series with both NA and NaN
    print(s.to_csv(sep=",", mode="w"))

Issue Description

The above code raises the following error:

ArrowTypeError: Expected bytes, got a 'numpy.float64' object

A similar code, worked as expected with Pandas<3 (i.e. pandas=2.3.2, with PyArrow=21.0.0 just like for pandas3):

import pandas as pd

s = pd.Series((1, pd.NA, 0), index=["a","b","c"], dtype=pd.Float64Dtype(), name="x")
s = s/s # creates a series with both NA and NaN
print(s.to_csv(sep=",", mode="w"))

prints:

,x
a,1.0
b,
c,nan

Expected Behavior

I would expect to have the same behaviour as Pandas2. Even more so if distinguish_nan_and_na=True.

Note that Pandas2 distinguished between NA and NaN (i.e. empty string vs "nan" string)

Installed Versions

Details

INSTALLED VERSIONS

commit : ab90747
python : 3.13.13
python-bits : 64
OS : Linux
OS-release : 6.17.0-20-generic
Version : #20~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 01:28:37 UTC 2
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 3.0.2
numpy : 2.4.4
dateutil : 2.9.0.post0
pip : 26.0.1
Cython : None
sphinx : None
IPython : 9.5.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.5
bottleneck : None
fastparquet : None
fsspec : 2025.7.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.6
numba : 0.65.0
numexpr : 2.11.0
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 21.0.0
pyiceberg : None
pyreadstat : None
pytest : 8.4.1
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : 1.16.1
sqlalchemy : None
tables : 3.10.2
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO CSVread_csv, to_csvNA - MaskedArraysRelated to pd.NA and nullable extension arrays

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions