Skip to content

BUG: fix FloatingArray.astype(str) crash with distinguish_nan_and_na=True#65038

Draft
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:bug-61617
Draft

BUG: fix FloatingArray.astype(str) crash with distinguish_nan_and_na=True#65038
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:bug-61617

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • With future.distinguish_nan_and_na=True, FloatingArray.astype(str) (and by extension to_csv) crashed with ArrowTypeError because ensure_string_array left unmasked NaN values as np.nan float objects, which PyArrow rejects at unmasked positions.
  • Pass skipna=False to ensure_string_array in ArrowStringArray._from_sequence so NaN values are converted to the string "nan" rather than left as float objects.

closes #61617

Test plan

  • test_astype_masked_float_with_nan_to_string — verifies FloatingArray.astype("string") with both using_nan_is_na modes
  • test_to_csv_float_ea_nan_distinguish — verifies to_csv on a Float64 column containing both np.nan and pd.NA

🤖 Generated with Claude Code

…True (pandas-dev#61617)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jorisvandenbossche
Copy link
Copy Markdown
Member

Does this also fix #64578?

@jbrockmendel
Copy link
Copy Markdown
Member Author

i dont think so, no

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: numpy_nullable NaNs do not round-trip through CSV

2 participants