Skip to content

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

Merged
merged 6 commits into from
Apr 10, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Apr 8, 2023

cc @mroeschke thoughts?

@phofl phofl added the Arrow pyarrow functionality label Apr 8, 2023
@phofl phofl added this to the 2.0.1 milestone Apr 8, 2023
@@ -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():
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

added a test

@@ -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)
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

@mroeschke mroeschke merged commit 0e1c237 into pandas-dev:main Apr 10, 2023
@mroeschke
Copy link
Member

Thanks @phofl

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Apr 10, 2023
mroeschke pushed a commit that referenced this pull request Apr 11, 2023
…g explicit dtype) (#52584)

Backport PR #52547: BUG: __from_arrow__ not respecting explicit dtype

Co-authored-by: Patrick Hoefler <[email protected]>
@phofl phofl deleted the 52533 branch April 11, 2023 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: ArrowDtype __from_arrow__ ignores its dtype but converts data to its mapped ArrowDtype
2 participants