-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-49002: [Python] Fix array.to_pandas string type conversion for arrays with None #49247
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2308,6 +2308,13 @@ cdef _array_like_to_pandas(obj, options, types_mapper): | |||||
| dtype = "object" | ||||||
| elif types_mapper: | ||||||
| dtype = types_mapper(original_type) | ||||||
| elif _pandas_api.uses_string_dtype() and ( | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
like we do in the other place with this logic (which Raul quoted), only that you will have to get the option value out of the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, will do! |
||||||
| original_type.id == _Type_STRING or | ||||||
| original_type.id == _Type_LARGE_STRING or | ||||||
| original_type.id == _Type_STRING_VIEW | ||||||
| ): | ||||||
| # for pandas 3.0+, use pandas' new default string dtype | ||||||
| dtype = _pandas_api.pd.StringDtype(na_value=np.nan) | ||||||
| else: | ||||||
| dtype = None | ||||||
|
|
||||||
|
|
||||||
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 it would be better to move this check a bit more above, together with the if/elif block checking for types_mapper. Because then we get to
if hasattr(dtype, '__from_arrow__'):and will avoid actually converting the pyarrow memory to an numpy object-dtype array of stringsThere 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.
Yes, that was my first idea but didn't think it well through before changing to what I have now. The thing is that I have hit this line https://github.com/AlenkaF/arrow/blob/6f1fda5ef1cfe7ee40ccd1ddefc3861c2718d920/python/pyarrow/array.pxi#L2319
and then the change of the dtype got reverted to
None.Will try putting the whole if/elif block further back, as suggested (if I do not break something else).