-
Notifications
You must be signed in to change notification settings - Fork 175
feat: Add support for Expr.str.zfill
#2598
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 all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
662f258
get pandas zfill to work
williambdean 153f0f3
add to the api-reference
williambdean 55d77b8
add tests for the zfill
williambdean 7ca9fcb
implement for other backends
williambdean 1aa802d
Merge branch 'main' into zfill
williambdean 4c4c58a
add the series tests
williambdean dda9485
add additional test cases
williambdean 6cdf831
Merge branch 'main' into zfill
williambdean 4c41e24
add additional test cases
williambdean 2e737cc
implement for duckdb
williambdean 4ba6ba4
Merge branch 'main' into zfill
williambdean 0a3914c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 508382c
Merge branch 'zfill' of github.com:williambdean/narwhals into zfill
williambdean 33a2d47
support polars like zfill
williambdean 72ad871
make test cases act like polars
williambdean 0aebf85
implement for ibis
williambdean e5fb6c5
implement for spark_like
williambdean a9a0fba
add attempt at arrow
williambdean edef50a
Merge branch 'main' into zfill
williambdean 71cef5a
add skip reason
williambdean 3b31cf2
Merge branch 'main' into zfill
williambdean 03cbdaf
consolidate on inner function name
williambdean 7ef7e87
add to docstring
williambdean 76373df
feat: Get `pyarrow` working
dangotbanned ebd7c02
fix(typing): `ibis` casts
dangotbanned 0b62377
fix(typing): `pyspark` ignore
dangotbanned 407787c
Merge branch 'main' into zfill
dangotbanned 86d9a59
add dask implementation
williambdean f9ff2d8
Merge branch 'zfill' of github.com:williambdean/narwhals into zfill
williambdean d2bd7a9
add exceptions and skips
williambdean e5434d0
adapt pandas / stdlib zfill behavior for all
williambdean 1319479
Merge branch 'main' into zfill
williambdean 94bbaf9
correct the example in the docstring
williambdean 778017b
Merge branch 'main' into zfill
williambdean 2ad6bc1
Merge branch 'main' into zfill
williambdean f9642f4
Merge branch 'main' into zfill
williambdean 6f0178b
Merge branch 'main' into zfill
williambdean cfee983
Merge branch 'main' into zfill
williambdean 1ba08d9
skip based on pandas version
williambdean cb5bf7c
change the condition
williambdean a626606
add expr_str example as well
williambdean 68288d7
fixing the import
williambdean eafdef5
implement for older polars versions
williambdean aeeb82e
Merge branch 'main' into zfill
williambdean 4d70d6a
Merge branch 'main' into zfill
williambdean d03367c
add skipif for second test :tear:
williambdean 5fcdc69
Merge branch 'main' into zfill
williambdean 0514b6a
fix the doctests
williambdean d717cf3
refactor logic to look like _spark_like
williambdean cb0c30e
pyarrow variable naming, typing and some misc
FBruzzesi 9c97fc3
pyarrow use repeat
FBruzzesi c742332
Merge branch 'main' into zfill
williambdean ea48128
remove warnings
williambdean a2a5eb5
chore(typing): Add missing `zfill`
dangotbanned e63ced7
Update narwhals/_ibis/expr_str.py
williambdean fa5c65b
Update narwhals/_ibis/expr_str.py
williambdean 9aa9eb1
Update narwhals/_arrow/series_str.py
williambdean 4842eb7
perf: Reuse `PolarsExpr` impl in `PolarsSeries`
dangotbanned 13f3b4b
Merge branch 'main' into zfill
dangotbanned 8d9e546
use xfail instead
williambdean 622c768
rename helper function
williambdean 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,5 +18,6 @@ | |
| - to_datetime | ||
| - to_lowercase | ||
| - to_uppercase | ||
| - zfill | ||
| show_source: false | ||
| show_bases: false | ||
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 |
|---|---|---|
|
|
@@ -18,5 +18,6 @@ | |
| - to_datetime | ||
| - to_lowercase | ||
| - to_uppercase | ||
| - zfill | ||
| show_source: false | ||
| show_bases: false | ||
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
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
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
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
williambdean marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| import narwhals as nw | ||
| from tests.utils import PANDAS_VERSION, Constructor, ConstructorEager, assert_equal_data | ||
|
|
||
| data = {"a": ["-1", "+1", "1", "12", "123", "99999", "+9999", None]} | ||
| expected = {"a": ["-01", "+01", "001", "012", "123", "99999", "+9999", None]} | ||
|
|
||
|
|
||
| def uses_pyarrow_backend(constructor: Constructor | ConstructorEager) -> bool: | ||
| return constructor.__name__ in { | ||
| "pandas_pyarrow_constructor", | ||
| "modin_pyarrow_constructor", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.skipif(PANDAS_VERSION < (1, 5), reason="different zfill behavior") | ||
| def test_str_zfill(request: pytest.FixtureRequest, constructor: Constructor) -> None: | ||
| if uses_pyarrow_backend(constructor): | ||
| reason = ( | ||
| "pandas with pyarrow backend doesn't support str.zfill, see " | ||
| "https://github.com/pandas-dev/pandas/issues/61485" | ||
| ) | ||
| request.applymarker(pytest.mark.xfail(reason=reason)) | ||
|
|
||
| df = nw.from_native(constructor(data)) | ||
| result = df.select(nw.col("a").str.zfill(3)) | ||
| assert_equal_data(result, expected) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(PANDAS_VERSION < (1, 5), reason="different zfill behavior") | ||
| def test_str_zfill_series( | ||
| request: pytest.FixtureRequest, constructor_eager: ConstructorEager | ||
| ) -> None: | ||
| if uses_pyarrow_backend(constructor_eager): | ||
| reason = ( | ||
| "pandas with pyarrow backend doesn't support str.zfill, see " | ||
| "https://github.com/pandas-dev/pandas/issues/61485" | ||
| ) | ||
| request.applymarker(pytest.mark.xfail(reason=reason)) | ||
|
|
||
| df = nw.from_native(constructor_eager(data), eager_only=True) | ||
| result = df["a"].str.zfill(3) | ||
| assert_equal_data({"a": result}, expected) |
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.
This number is based on this PR being merged and the current version in release is 1.30.0
Let me know if it should be changed!