Skip to content

BUG: fix ArrowExtensionArray construction with NaN in string data#64581

Closed
wavebyrd wants to merge 10000 commits into
pandas-dev:mainfrom
wavebyrd:fix-arrow-string-nan-construction
Closed

BUG: fix ArrowExtensionArray construction with NaN in string data#64581
wavebyrd wants to merge 10000 commits into
pandas-dev:mainfrom
wavebyrd:fix-arrow-string-nan-construction

Conversation

@wavebyrd

Copy link
Copy Markdown

Closes #64578.

_box_pa_array calls np.asarray(value) to build an NA mask, but when the input is a list mixing strings and np.nan, numpy infers a unicode dtype and coerces the nan to the literal string "nan". After that, isna() returns all-False and the NaN is not masked, so pa.array blows up with ArrowTypeError.

Fix: pass dtype=object so the original np.nan stays in place and isna() can see it. This matches what the elif branch right below already does.

Added tests covering single/multiple/all-NaN and large_string.

Loading
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: constructing string ArrowExtensionArray with NaNs fails