-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
strip_chars
to string namespace (#715)
* feat: add `strip_chars` to string namespace * fix: remove unnecessary "\n" * doc: complete docstrings /doctests * perf: hard-code whitespace instead of importing from `string` * Update narwhals/_arrow/series.py Co-authored-by: Francesco Bruzzesi <[email protected]> * doc: better docstrings --------- Co-authored-by: Francesco Bruzzesi <[email protected]>
- Loading branch information
1 parent
b8d9b08
commit e117a5e
Showing
10 changed files
with
145 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
- head | ||
- slice | ||
- starts_with | ||
- strip_chars | ||
- tail | ||
- to_datetime | ||
- to_lowercase | ||
|
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
- head | ||
- slice | ||
- starts_with | ||
- strip_chars | ||
- tail | ||
show_source: false | ||
show_bases: false |
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
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
from tests.utils import compare_dicts | ||
|
||
data = {"a": ["foobar", "bar\n", " baz"]} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("characters", "expected"), | ||
[ | ||
(None, {"a": ["foobar", "bar", "baz"]}), | ||
("foo", {"a": ["bar", "bar\n", " baz"]}), | ||
], | ||
) | ||
def test_str_strip_chars(constructor: Any, characters: str | None, expected: Any) -> None: | ||
df = nw.from_native(constructor(data)) | ||
result_frame = df.select(nw.col("a").str.strip_chars(characters)) | ||
compare_dicts(result_frame, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("characters", "expected"), | ||
[ | ||
(None, {"a": ["foobar", "bar", "baz"]}), | ||
("foo", {"a": ["bar", "bar\n", " baz"]}), | ||
], | ||
) | ||
def test_str_strip_chars_series( | ||
constructor_eager: Any, characters: str | None, expected: Any | ||
) -> None: | ||
df = nw.from_native(constructor_eager(data), eager_only=True) | ||
|
||
result_series = df["a"].str.strip_chars(characters) | ||
assert result_series.to_list() == expected["a"] |