Skip to content

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

Open
hebian1994 wants to merge 4 commits into
pandas-dev:mainfrom
hebian1994:fix-pyarrow-empty-string-nan-fillna
Open

BUG: coerce empty-string IEEE NaN to null for pyarrow floats#66836
hebian1994 wants to merge 4 commits into
pandas-dev:mainfrom
hebian1994:fix-pyarrow-empty-string-nan-fillna

Conversation

@hebian1994

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @hebian1994! It's linked to #66834, but that issue isn't assigned to you yet. To make sure two people don't unknowingly work on the same thing, we ask contributors to claim an issue first. Just comment /take on #66834 to claim it, and you're good to go. See the contributing guide for the full flow.

I've closed this PR for now to keep the queue tidy — none of your work is lost. To pick it back up: 1) comment /take on #66834 to claim it, then 2) reopen this PR with the button below. Thanks!

@github-actions github-actions Bot added the Needs Issue Assignment PR whose author is not assigned to a linked issue label Aug 18, 2026
@github-actions github-actions Bot closed this Aug 18, 2026
@rhshadrach rhshadrach reopened this Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @hebian1994! It's linked to #66834, but that issue isn't assigned to you yet. To make sure two people don't unknowingly work on the same thing, we ask contributors to claim an issue first. Just comment /take on #66834 to claim it, and you're good to go. See the contributing guide for the full flow.

I've closed this PR for now to keep the queue tidy — none of your work is lost. To pick it back up: 1) comment /take on #66834 to claim it, then 2) reopen this PR with the button below. Thanks!

@github-actions github-actions Bot closed this Aug 20, 2026
)

Empty CSV fields with keep_default_na=False stored IEEE NaN in double[pyarrow] instead of raising like numpy float64.
@github-actions github-actions Bot removed the Needs Issue Assignment PR whose author is not assigned to a linked issue label Aug 21, 2026

@rhshadrach rhshadrach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I'm seeing this fail on pd.NA

from pandas.core.arrays.arrow.array import ArrowExtensionArray

strings = np.array(["1.5", pd.NA, ""], dtype=object)
ArrowExtensionArray._from_sequence_of_strings(strings, dtype=pd.ArrowDtype(pa.float64()))
# TypeError: boolean value of NA is ambiguous

where it should raise ValueError: could not convert string to float: ''

Can you also add a test with read_csv.

Comment thread pandas/core/arrays/arrow/array.py Outdated
arr = np.asarray(strings, dtype=object)
unmasked_empty = (arr == "") & ~np.asarray(mask, dtype=np.bool_)
if unmasked_empty.any():
raise ValueError("could not convert string to float: ''")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also hit with e.g. int/decimal types too. Can you use pa_type instead.

Comment thread doc/source/whatsnew/v3.1.0.rst Outdated
- Bug in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` with ``method`` in ``"index"``, ``"values"`` or ``"time"`` raising when the index had an :class:`ArrowDtype` timestamp or duration dtype; these now match the equivalent :class:`DatetimeIndex` or :class:`TimedeltaIndex` (:issue:`66338`)
- Bug in :meth:`DataFrame.shift`, :meth:`DataFrame.where`, :meth:`DataFrame.mask`, :meth:`Series.shift`, :meth:`Series.where`, and :meth:`Series.mask` raising an internal ``AssertionError`` for a NumPy bytes dtype instead of upcasting to ``object`` to hold a missing value; item assignment now raises the expected ``TypeError`` for the incompatible value (:issue:`52373`)
- Bug in :meth:`Series.combine_first` crashing when Series names are :class:`Timestamp` objects (:issue:`65333`)
- Bug in :class:`ArrowExtensionArray` where converting empty strings to a floating PyArrow dtype stored IEEE ``NaN`` instead of raising like numpy ``float64`` (e.g. empty CSV fields with ``dtype="double[pyarrow]"`` and ``keep_default_na=False``) (:issue:`66834`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the only place this code is hit is I/O, can you move to the I/O section and make it something like

- :func:`read_csv`, :func:`read_fwf`, and :func:`read_excel` with a numeric :class:`ArrowDtype` (e.g. ``dtype="double[pyarrow]"``) now raise ``ValueError`` for an empty field that is not treated as missing (e.g. with ``keep_default_na=False``), matching the behavior of numpy dtypes such as ``float64``; previously the value was silently stored as ``NaN`` but was not considered missing by :meth:`Series.isna` and :meth:`Series.fillna` (:issue:`66834`)

Move the GH#66834 whatsnew note to I/O to resolve the Missing-section
conflict. Empty-string conversion now skips pd.NA and raises using pa_type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants