-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: __from_arrow__ not respecting explicit dtype #52547
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
Conversation
@@ -1739,6 +1739,21 @@ def test_setitem_invalid_dtype(data): | |||
data[:] = fill_value | |||
|
|||
|
|||
@pytest.mark.skipif(pa_version_under8p0, reason="returns object with 7.0") | |||
def test_from_arrow_respecting_given_dtype(): |
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.
Could you add a test for an invalid/unsafe cast as well?
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.
added a test
pandas/core/arrays/arrow/dtype.py
Outdated
@@ -319,4 +320,5 @@ def __from_arrow__(self, array: pa.Array | pa.ChunkedArray): | |||
Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray. | |||
""" | |||
array_class = self.construct_array_type() | |||
return array_class(array) | |||
arr = pc.cast(array, self.pyarrow_dtype, safe=True) |
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.
Nit: Could just do array.cast(self.pyarrow_dtype, safe=True)
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.
changed
Thanks @phofl |
…g explicit dtype) (#52584) Backport PR #52547: BUG: __from_arrow__ not respecting explicit dtype Co-authored-by: Patrick Hoefler <[email protected]>
__from_arrow__
ignores its dtype but converts data to its mapped ArrowDtype #52533 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.cc @mroeschke thoughts?