-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: ArrowExtensionArray.to_numpy avoid object dtype when na_value provided #54843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: ArrowExtensionArray.to_numpy avoid object dtype when na_value provided #54843
Conversation
lukemanley
commented
Aug 29, 2023
- closes BUG: avoid conversion to object dtype in to_numpy for Arrow dtype and with dtype-compatible fill value #54808
- Tests added and passed if fixing a bug or adding a new feature
- All code checks passed.
- Added type annotations to new arguments/methods/functions.
pandas/core/arrays/arrow/array.py
Outdated
result[self.isna()] = na_value | ||
else: | ||
if dtype is None: | ||
empty = data._pa_array[:0].to_numpy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think data.dtype.empty._pa_array
would be a "nicer" way to get an empty example to use in can_hold_element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, thanks. updated
pandas/core/arrays/arrow/array.py
Outdated
if data._hasna: | ||
result[data.isna()] = na_value | ||
elif pa.types.is_null(pa_type): | ||
if dtype is not None and dtype.kind != "O" and isna(na_value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to skip object here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it, not needed
Thanks @lukemanley |
…ovided (pandas-dev#54843) * ENH: ArrowExtensionArray.to_numpy to avoid object dtype when na_value provided * refactor * cleanup * mypy * fix