-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: Add Series.str.casefold #25419
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
ENH: Add Series.str.casefold #25419
Changes from 12 commits
9b8fed6
c0d067d
bfb3fa8
6608c25
0d9ebec
13b2442
3448d76
d147075
983332e
f9e52cc
a1a8891
eb119d8
893d426
522c021
bf35935
bf49467
22717a1
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 |
|---|---|---|
|
|
@@ -2943,6 +2943,8 @@ def rindex(self, sub, start=0, end=None): | |
| remaining to lowercase. | ||
| Series.str.swapcase : Converts uppercase to lowercase and lowercase to | ||
| uppercase. | ||
| Series.str.casefold: Removes all case distinctions in the string. | ||
| .. versionadded:: 0.25.0 | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -2995,6 +2997,7 @@ def rindex(self, sub, start=0, end=None): | |
| _shared_docs['capitalize'] = dict(type='be capitalized', | ||
| method='capitalize') | ||
| _shared_docs['swapcase'] = dict(type='be swapcased', method='swapcase') | ||
| _shared_docs['casefold'] = dict(type='be casefolded', method='casefold') | ||
|
||
| lower = _noarg_wrapper(lambda x: x.lower(), | ||
| docstring=_shared_docs['casemethods'] % | ||
| _shared_docs['lower']) | ||
|
|
@@ -3010,6 +3013,9 @@ def rindex(self, sub, start=0, end=None): | |
| swapcase = _noarg_wrapper(lambda x: x.swapcase(), | ||
| docstring=_shared_docs['casemethods'] % | ||
| _shared_docs['swapcase']) | ||
| casefold = _noarg_wrapper(lambda x: x.casefold(), | ||
| docstring=_shared_docs['casemethods'] % | ||
| _shared_docs['casefold']) | ||
|
|
||
| _shared_docs['ismethods'] = (""" | ||
| Check whether all characters in each string are %(type)s. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ def assert_series_or_index_equal(left, right): | |
| 'len', 'lower', 'lstrip', 'partition', | ||
| 'rpartition', 'rsplit', 'rstrip', | ||
| 'slice', 'slice_replace', 'split', | ||
| 'strip', 'swapcase', 'title', 'upper' | ||
| 'strip', 'swapcase', 'title', 'upper', 'casefold' | ||
| ], [()] * 100, [{}] * 100)) | ||
| ids, _, _ = zip(*_any_string_method) # use method name as fixture-id | ||
|
|
||
|
|
@@ -3424,3 +3424,12 @@ def test_method_on_bytes(self): | |
| expected = Series(np.array( | ||
| ['ad', 'be', 'cf'], 'S2').astype(object)) | ||
| tm.assert_series_equal(result, expected) | ||
|
|
||
| @pytest.mark.skipif(compat.PY2, reason='not in python2') | ||
| def test_casefold(self): | ||
| # GH25405 | ||
| casefolded = Series(['ss', NA, 'case', 'ssd']) | ||
|
||
| s = Series(['ß', NA, 'case', 'ßd']) | ||
| result = s.str.casefold() | ||
|
|
||
| tm.assert_series_equal(result, casefolded) | ||
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.
not sure if these are ordered here - if they r alphabetic then this is not in the right place; otherwise maybe put next to lower
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.
ok, the methods in
series.rstis alphabetically ordered, here is not. But I will move it up a bit!