Skip to content

BUG: fix np.isnan raising TypeError on pyarrow dtypes (GH#62506)#65041

Draft
jbrockmendel wants to merge 3 commits intopandas-dev:mainfrom
jbrockmendel:bug-62506
Draft

BUG: fix np.isnan raising TypeError on pyarrow dtypes (GH#62506)#65041
jbrockmendel wants to merge 3 commits intopandas-dev:mainfrom
jbrockmendel:bug-62506

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • When future.distinguish_nan_and_na is True, np.isnan on pyarrow-backed Series/Index raises TypeError because the default ufunc path converts to an object-dtype numpy array
  • Intercept np.isnan in ArrowExtensionArray.__array_ufunc__ and use pc.is_nan for numeric pyarrow types, which correctly identifies NaN and propagates NA
  • Non-numeric types fall through to the default path, mirroring numpy behavior

closes #62506

Test plan

  • New test test_np_isnan_pyarrow covering both using_nan_is_na parametrizations
  • All existing ufunc and isnan tests pass
  • Full test_arrow.py suite passes

🤖 Generated with Claude Code

Copy link
Copy Markdown
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

As mentioned on the issue, it is not just an issue with np.isnan, but with most numeric ufuncs. So I think we should solve this more generally

@jbrockmendel
Copy link
Copy Markdown
Member Author

As mentioned on the issue, it is not just an issue with np.isnan, but with most numeric ufuncs. So I think we should solve this more generally

Will give it a try.

jbrockmendel and others added 2 commits April 3, 2026 08:47
…guish_nan_and_na (pandas-dev#62506)

When distinguish_nan_and_na is True, the default ufunc path converts
pyarrow arrays to object-dtype numpy arrays, which most ufuncs can't
handle. Fix by converting with na_value=np.nan (producing float arrays)
and re-masking NA positions in the result.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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: np.isnan raises on pyarrow dtypes

2 participants