-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: Ensure "string[pyarrow]" type is preserved when calling extractall #55534
Merged
mroeschke
merged 8 commits into
pandas-dev:main
from
ABizzinotto:BUG-53846-extractall-with-arrow-returns-object-dtype
Oct 19, 2023
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bb01589
Ensure "string[pyarrow]" type is preserved when calling extractall
ABizzinotto e5ef14b
Add whatsnew note
ABizzinotto ee33c4e
Add test and fix whatsnew entry
ABizzinotto 55e8a0d
Merge branch 'main' into BUG-53846-extractall-with-arrow-returns-obje…
ABizzinotto 03ed4a1
Fix test case and move import
ABizzinotto 35aa528
Add pyarrow requirement to actions
ABizzinotto 27cf36d
Add pyarrow requirement as importorskip
ABizzinotto e342d86
Merge branch 'main' into BUG-53846-extractall-with-arrow-returns-obje…
ABizzinotto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import re | ||
|
||
import numpy as np | ||
import pyarrow as pa | ||
import pytest | ||
|
||
from pandas import ( | ||
|
@@ -11,6 +12,7 @@ | |
Series, | ||
_testing as tm, | ||
) | ||
from pandas.core.dtypes.dtypes import ArrowDtype | ||
|
||
|
||
def test_extract_expand_kwarg_wrong_type_raises(any_string_dtype): | ||
|
@@ -706,3 +708,18 @@ def test_extractall_same_as_extract_subject_index(any_string_dtype): | |
has_match_index = s.str.extractall(pattern_one_noname) | ||
no_match_index = has_match_index.xs(0, level="match") | ||
tm.assert_frame_equal(extract_one_noname, no_match_index) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data, expected_dtype", | ||
[ | ||
(Series(["abc", "ab"], dtype=ArrowDtype(pa.string())), "string[pyarrow]"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just test this case since I think the other cases are tested |
||
(Series(["abc", "ab"], dtype="string"), "string[python]"), | ||
(Series(["abc", "ab"]), "object"), | ||
] | ||
) | ||
def test_extractall_preserves_dtype(data, expected_dtype): | ||
# Ensure that when extractall is called on a series with specific dtypes set, that | ||
# the dtype is preserved in the resulting DataFrame's column. | ||
result = data.str.extractall("(ab)") | ||
assert result.dtypes[0] == expected_dtype |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You'll need to import this in
test_extractall_preserves_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.
@mroeschke thanks, moved the import. I also added the requirement to the
pypy
andnumpydev
actions yaml files but some tests are still failing, so before making any additional changes, I thought I'd ask what else might need to be changed so ci can run. Looks like themeta.yaml
file needs it added as a requirement 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.
Instead of adding pyarrow to the dependency files you can structure the test like
So the test will be skipped if pyarrow is not installed or you will have pyarrow accessible as
pa
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.
Ah, fair enough 👍 Thank you. There's still one spec failing but it's also failing in main, it's due to a Numpy deprecation warning as far as I can tell.