-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat(python): Allow mapping as syntactic sugar in str.replace_many
#18214
Conversation
Returns | ||
------- | ||
DataFrame | ||
|
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.
Drive by: Returns section is not consistent with other DataFrame methods and LazyFrame.join
docstring. Is also already covered by type hint.
|
||
This version determines if any of the patterns find a match. | ||
Determines if any of the patterns are contained in the string. |
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.
It is not clear what is being compared against "this version". Also updated to be a bit more explicit.
) | ||
|
||
|
||
def test_replace_many_invalid_inputs() -> None: |
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 could alternatively be moved to py-polars/tests/unit/test_errors.py
if so desired.
_reserved_namespaces: set[str] = reduce( | ||
or_, | ||
(cls._accessors for cls in (pl.DataFrame, pl.Expr, pl.LazyFrame, pl.Series)), | ||
_reserved_namespaces: set[str] = set.union( | ||
*(cls._accessors for cls in (pl.DataFrame, pl.Expr, pl.LazyFrame, pl.Series)) | ||
) |
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.
Drive by: intent is clearer IMO and removes the need for two imports
This comment was marked as resolved.
This comment was marked as resolved.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #18214 +/- ##
==========================================
- Coverage 80.30% 79.84% -0.47%
==========================================
Files 1498 1496 -2
Lines 198751 200345 +1594
Branches 2833 2844 +11
==========================================
+ Hits 159598 159956 +358
- Misses 38626 39864 +1238
+ Partials 527 525 -2 ☔ View full report in Codecov by Sentry. |
Hi @ritchie46 @alexander-beedie @MarcoGorelli Cheers |
Closes #17220
Functionality and implementation is most similar to
Expr.replace
, but avoids the issue raised in #18185Also makes a few other minor changes in support:
str.replace_many
to take a dictionary that defines a replacement mapping. #17220 (comment)As a heads up, this feature does now result in a different error message (but the same type) when
replace_many
is called with a single (non-mapping) argument.