-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[ArrowStringArray] PERF: use pa.compute.match_substring_regex for str.fullmatch if available #41332
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
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
70799c0
wip
simonjayhawkins 206a69a
Merge remote-tracking branch 'upstream/master' into _str_fullmatch
simonjayhawkins 70a1845
update to use pa_version_under
simonjayhawkins cc0ba08
Merge remote-tracking branch 'upstream/master' into _str_fullmatch
simonjayhawkins 7504466
undo changes to annotations
simonjayhawkins 1bdd53c
black
simonjayhawkins b4a426d
fix docstring validation
simonjayhawkins 4894fcf
more tests
simonjayhawkins 5176d35
asv
simonjayhawkins 0fbd3cc
Merge remote-tracking branch 'upstream/master' into _str_fullmatch
simonjayhawkins 0ef9d27
typo
simonjayhawkins 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -819,33 +819,40 @@ def _str_contains(self, pat, case=True, flags=0, na=np.nan, regex: bool = True): | |
result[isna(result)] = bool(na) | ||
return result | ||
|
||
def _str_startswith(self, pat, na=None): | ||
def _str_startswith(self, pat: str, na=None): | ||
if pa_version_under4p0: | ||
return super()._str_startswith(pat, na) | ||
|
||
result = pc.match_substring_regex(self._data, "^" + re.escape(pat)) | ||
result = BooleanDtype().__from_arrow__(result) | ||
if not isna(na): | ||
result[isna(result)] = bool(na) | ||
return result | ||
pat = "^" + re.escape(pat) | ||
return self._str_contains(pat, na=na, regex=True) | ||
|
||
def _str_endswith(self, pat, na=None): | ||
def _str_endswith(self, pat: str, na=None): | ||
if pa_version_under4p0: | ||
return super()._str_endswith(pat, na) | ||
|
||
result = pc.match_substring_regex(self._data, re.escape(pat) + "$") | ||
result = BooleanDtype().__from_arrow__(result) | ||
if not isna(na): | ||
result[isna(result)] = bool(na) | ||
return result | ||
pat = re.escape(pat) + "$" | ||
return self._str_contains(pat, na=na, regex=True) | ||
|
||
def _str_match( | ||
self, pat: str, case: bool = True, flags: int = 0, na: Scalar = None | ||
): | ||
if pa_version_under4p0: | ||
return super()._str_match(pat, case, flags, na) | ||
|
||
if not pat.startswith("^"): | ||
pat = "^" + pat | ||
return self._str_contains(pat, case, flags, na, regex=True) | ||
|
||
def _str_fullmatch( | ||
self, pat: str, case: bool = True, flags: int = 0, na: Scalar = None | ||
): | ||
if pa_version_under4p0: | ||
return super()._str_fullmatch(pat, case, flags, na) | ||
|
||
if not pat.endswith("$") or pat.endswith("//$"): | ||
pat = pat + "$" | ||
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. we probably don't need the check but maybe faster... will need to check. |
||
return self._str_match(pat, case, flags, na) | ||
|
||
def _str_isalnum(self): | ||
result = pc.utf8_is_alnum(self._data) | ||
return BooleanDtype().__from_arrow__(result) | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
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.
this may be quicker if using the fallback.... will need to check.
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.
broken this change off into #41487, slighter quicker than master, to bring the perf for object fallback back to before the pyarrow native implementation was added