-
-
Notifications
You must be signed in to change notification settings - Fork 145
Add defaults to str accessor methods #1305
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,10 @@ def test_string_accessors_string_series(): | |
check(assert_type(s.str.cat(sep="X"), str), str) | ||
_check(assert_type(s.str.center(10), "pd.Series[str]")) | ||
_check(assert_type(s.str.get(2), "pd.Series[str]")) | ||
s_dict = pd.Series( # example from the doc of str.get | ||
[{"name": "Hello", "value": "World"}, {"name": "Goodbye", "value": "Planet"}] | ||
) | ||
_check(assert_type(s_dict.str.get("name"), "pd.Series[str]")) | ||
_check(assert_type(s.str.ljust(80), "pd.Series[str]")) | ||
_check(assert_type(s.str.lower(), "pd.Series[str]")) | ||
_check(assert_type(s.str.lstrip("a"), "pd.Series[str]")) | ||
|
@@ -166,14 +170,30 @@ def test_string_accessors_string_series(): | |
_check( | ||
assert_type(s.str.translate({241: "n"}), "pd.Series[str]"), | ||
) | ||
_check( | ||
assert_type(s.str.translate({241: 240}), "pd.Series[str]"), | ||
) | ||
trans_table: dict[int, int] = {ord("a"): ord("b")} | ||
_check( # tests covariance of table values (table is read-only) | ||
assert_type(s.str.translate(trans_table), "pd.Series[str]"), | ||
) | ||
_check(assert_type(s.str.upper(), "pd.Series[str]")) | ||
_check(assert_type(s.str.wrap(80), "pd.Series[str]")) | ||
_check(assert_type(s.str.zfill(10), "pd.Series[str]")) | ||
s_bytes = pd.Series([b"a1", b"b2", b"c3"]) | ||
_check(assert_type(s_bytes.str.decode("utf-8"), "pd.Series[str]")) | ||
_check( | ||
assert_type( | ||
s_bytes.str.decode("utf-8", dtype=pd.StringDtype()), "pd.Series[str]" | ||
) | ||
) | ||
s_list = pd.Series([["apple", "banana"], ["cherry", "date"], ["one", "eggplant"]]) | ||
_check(assert_type(s_list.str.join("-"), "pd.Series[str]")) | ||
|
||
# wrap doesn't accept positional arguments other than width | ||
with pytest.raises(TypeError): | ||
s.str.wrap(80, False) # type: ignore[misc] # pyright: ignore[reportCallIssue] | ||
|
||
|
||
def test_string_accessors_string_index(): | ||
idx = pd.Index(DATA) | ||
|
@@ -183,6 +203,10 @@ def test_string_accessors_string_index(): | |
check(assert_type(idx.str.cat(sep="X"), str), str) | ||
_check(assert_type(idx.str.center(10), "pd.Index[str]")) | ||
_check(assert_type(idx.str.get(2), "pd.Index[str]")) | ||
idx_dict = pd.Index( | ||
[{"name": "Hello", "value": "World"}, {"name": "Goodbye", "value": "Planet"}] | ||
) | ||
_check(assert_type(idx_dict.str.get("name"), "pd.Index[str]")) | ||
_check(assert_type(idx.str.ljust(80), "pd.Index[str]")) | ||
_check(assert_type(idx.str.lower(), "pd.Index[str]")) | ||
_check(assert_type(idx.str.lstrip("a"), "pd.Index[str]")) | ||
|
@@ -204,14 +228,30 @@ def test_string_accessors_string_index(): | |
_check( | ||
assert_type(idx.str.translate({241: "n"}), "pd.Index[str]"), | ||
) | ||
_check( | ||
assert_type(idx.str.translate({241: 240}), "pd.Index[str]"), | ||
) | ||
trans_table: dict[int, int] = {ord("a"): ord("b")} | ||
_check( # tests covariance of table values (table is read-only) | ||
assert_type(idx.str.translate(trans_table), "pd.Index[str]"), | ||
) | ||
_check(assert_type(idx.str.upper(), "pd.Index[str]")) | ||
_check(assert_type(idx.str.wrap(80), "pd.Index[str]")) | ||
_check(assert_type(idx.str.zfill(10), "pd.Index[str]")) | ||
idx_bytes = pd.Index([b"a1", b"b2", b"c3"]) | ||
_check(assert_type(idx_bytes.str.decode("utf-8"), "pd.Index[str]")) | ||
_check( | ||
assert_type( | ||
idx_bytes.str.decode("utf-8", dtype=pd.StringDtype()), "pd.Index[str]" | ||
) | ||
) | ||
idx_list = pd.Index([["apple", "banana"], ["cherry", "date"], ["one", "eggplant"]]) | ||
_check(assert_type(idx_list.str.join("-"), "pd.Index[str]")) | ||
|
||
# wrap doesn't accept positional arguments other than width | ||
with pytest.raises(TypeError): | ||
idx.str.wrap(80, False) # type: ignore[misc] # pyright: ignore[reportCallIssue] | ||
|
||
|
||
def test_string_accessors_bytes_series(): | ||
s = pd.Series(["a1", "b2", "c3"]) | ||
|
@@ -320,6 +360,11 @@ def test_series_overloads_partition(): | |
pd.Series, | ||
object, | ||
) | ||
check( | ||
assert_type(s.str.partition(expand=False), "pd.Series[type[object]]"), | ||
pd.Series, | ||
object, | ||
) | ||
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. It appears that I missed something when |
||
|
||
check(assert_type(s.str.rpartition(sep=";"), pd.DataFrame), pd.DataFrame) | ||
check( | ||
|
@@ -330,6 +375,11 @@ def test_series_overloads_partition(): | |
pd.Series, | ||
object, | ||
) | ||
check( | ||
assert_type(s.str.rpartition(expand=False), "pd.Series[type[object]]"), | ||
pd.Series, | ||
object, | ||
) | ||
|
||
|
||
def test_index_overloads_partition(): | ||
|
Uh oh!
There was an error while loading. Please reload this page.