Skip to content

ENH: Implement str.extract for ArrowDtype #56334

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
Dec 5, 2023

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke added Strings String extension data type and string data Arrow pyarrow functionality labels Dec 5, 2023
@mroeschke mroeschke added this to the 2.2 milestone Dec 5, 2023
)
tm.assert_frame_equal(result, expected)

result = ser.str.extract(r"[ab](?P<digit>\d)", expand=False)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add coverage for when there are multiple groups and expand=False?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I parametrized the above test with expand=

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the expand=False case only produce a series?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily:

https://pandas.pydata.org/docs/reference/api/pandas.Series.str.extract.html

If True, return DataFrame with one column per capture group. If False, return a Series/Index if there is one capture group or DataFrame if there are multiple capture groups.

Copy link
Member

Choose a reason for hiding this comment

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

Ah OK - sorry I misremembered how that works. I was somewhat expecting expand=False here to just return the struct array

Copy link
Member

Choose a reason for hiding this comment

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

FWIW I'm OK with this now too as it is definitely consistent with our current API. There may be a future where we actuallly want it to return a pyarrow struct but can always come back and do that later

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 agreed. For arrow types, I think in the future expand=False should return a struct typed Series

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

thx

@phofl phofl merged commit df7498f into pandas-dev:main Dec 5, 2023
@mroeschke mroeschke deleted the enh/str_extract branch December 5, 2023 23:36
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.

BUG: str.extract Method Not Implemented for pd.ArrowDtype(pa.string())
3 participants