Skip to content

ENH: allow opt-in to inferring pyarrow strings #54430

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 7 commits into from
Aug 9, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Aug 5, 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.

This is a simple opt-in for now without warning by default. Can adjust this for 2.2

cc @jbrockmendel

{"a": ["a", "b"]}, dtype="object", columns=Index(["a"], dtype=dtype)
)
with pd.option_context("future.infer_string", True):
df = DataFrame({"a": ["a", "b"]}, dtype="object")
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a case with null/nan/None in it?

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, needed a fix...

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Have we considered naming the option infer_pyarrow_string instead of infer_string?

y,2"""
parser = all_parsers
if parser.engine == "pyarrow":
pytest.skip("TODO: Follow up")
Copy link
Member

Choose a reason for hiding this comment

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

Did we ever discuss pyarrow backed engines returning pyarrow types by default? I think from a user perspective it is less than ideal to have to specify both this option and the dtype backend for any pyarrow backed IO methods

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's move this discussion to Basel, but there is an issue about this: #51846

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 link the GH issue in this skip message?

Copy link
Member Author

Choose a reason for hiding this comment

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

#54431 already addresses this

@phofl
Copy link
Member Author

phofl commented Aug 7, 2023

cc @jbrockmendel thoughts about the option name?

@jbrockmendel
Copy link
Member

thoughts about the option name?

I think future.infer_string is reasonable

@mroeschke mroeschke added Strings String extension data type and string data Arrow pyarrow functionality labels Aug 7, 2023
phofl and others added 2 commits August 7, 2023 18:54
import pyarrow as pa

pa_dtype = pa.string()
dtype = ArrowDtype(pa_dtype)
Copy link
Member

Choose a reason for hiding this comment

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

are there any tests that hit this?

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 one

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Could use some documentation in the whatsnew otherwise looks good

@phofl
Copy link
Member Author

phofl commented Aug 9, 2023

I’ll add this With the general arrow announcement

@mroeschke mroeschke added this to the 2.1 milestone Aug 9, 2023
@mroeschke mroeschke merged commit 79ce72b into pandas-dev:main Aug 9, 2023
@mroeschke
Copy link
Member

Thanks @phofl

mroeschke added a commit to mroeschke/pandas that referenced this pull request Aug 18, 2023
* ENH: allow opt-in to inferring pyarrow strings

* Remove comments and add tests

* Add json tests

* Update

* Update pandas/_libs/lib.pyx

Co-authored-by: Matthew Roeschke <[email protected]>

* Update

* Add test

---------

Co-authored-by: Brock <[email protected]>
Co-authored-by: Matthew Roeschke <[email protected]>
@phofl phofl deleted the arrow_strings branch September 30, 2023 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants