Skip to content

BUG: coerce empty-string IEEE NaN to null for pyarrow floats #66834

Description

@hebian1994

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

from io import StringIO

import pandas as pd

csv = """id,A,B,C
1,1.5,x,1
2,,x,2
3,2.0,x,3
"""

df = pd.read_csv(StringIO(csv), dtype={"A": "double[pyarrow]"}, keep_default_na=False)
df = df[["A", "B", "C"]]
df["A"] = df["A"].fillna(0)
print(df)
print("isna:", pd.isna(df["A"]).tolist())

Issue Description

Bug in Arrow float conversion: empty strings become IEEE NaN, so fillna does not fill them

When converting string data (e.g. CSV empty fields ,,) to a floating PyArrow dtype, empty strings are not NA (pd.isna("") is False). to_numeric turns them into IEEE NaN, and _from_sequence_of_strings builds pa.array(..., mask=isna(strings)) with that mask all-False. The NaN is stored as a value (null_count=0), not a pyarrow null.

Default pandas 3 semantics treat NaN as NA (is_nan_na() is True), but isna / fillna only look at is_null(). Result: fillna(0) is a no-op.

Expected Behavior

Empty CSV fields converted to double[pyarrow] should be pyarrow null (). isna() is True for those rows, and fillna(0) replaces them with 0.0.

Installed Versions

Details

pd.show_versions()

INSTALLED VERSIONS

commit : e68db09
python : 3.13.5
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.26200
machine : AMD64
processor : Intel64 Family 6 Model 151 Stepping 5, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : Chinese (Simplified)_China.936

pandas : 3.0.5
numpy : 2.5.2
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 25.0.0
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

Arrowpyarrow functionalityBug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions