Skip to content

Fix roundtripping with pyarrow schema #54768

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 2 commits into from
Aug 26, 2023
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Aug 26, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • 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.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

that's a regression on main as well, it's currently returning NA

cc @mroeschke

@phofl phofl added the Arrow pyarrow functionality label Aug 26, 2023
@phofl phofl added this to the 2.1 milestone Aug 26, 2023
@phofl phofl requested a review from mroeschke August 26, 2023 11:02
@mroeschke
Copy link
Member

Nice thanks @phofl

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Aug 26, 2023
lithomas1 pushed a commit that referenced this pull request Aug 27, 2023
…hema) (#54773)

Backport PR #54768: Fix roundtripping with pyarrow schema

Co-authored-by: Patrick Hoefler <[email protected]>
Comment on lines +1135 to +1140
path = tmp_path / "decimal.p"
df = pd.DataFrame({"a": [Decimal("123.00")]}, dtype="string[pyarrow]")
df.to_parquet(path, schema=pa.schema([("a", pa.decimal128(5))]))
result = read_parquet(path)
expected = pd.DataFrame({"a": ["123"]}, dtype="string[python]")
tm.assert_frame_equal(result, expected)
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look correct to me? If you specify that the schema should use decimals, it should not come back as string but I would expect object dtype (with decimal.Decimal objects)?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that's because regardless of specifying schema, the original dtype (string) is still stored in the "pandas_metadata", which is used when reading back and converting to pandas (this is something on the pyarrow side, but to be honest this doesn't feel right to me when the user also specifies a schema ..)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this looks buggy, but probably on the arrow side. That said, better strings instead of all NA and we are only restoring the previous behaviour

@phofl phofl deleted the from_arrow branch August 28, 2023 15:24
mroeschke pushed a commit to mroeschke/pandas that referenced this pull request Sep 11, 2023
* Fix roundtripping with pyarrow schema

* Skip for lower versions
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.

3 participants