Skip to content

Commit fb8c88e

Browse files
add casefold for string
1 parent 1314059 commit fb8c88e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: pandas/core/strings.py

+5
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,7 @@ def rindex(self, sub, start=0, end=None):
29332933
remaining to lowercase.
29342934
Series.str.swapcase : Converts uppercase to lowercase and lowercase to
29352935
uppercase.
2936+
Series.str.casefold: Removes all case distinctions in the string.
29362937
29372938
Examples
29382939
--------
@@ -2985,6 +2986,7 @@ def rindex(self, sub, start=0, end=None):
29852986
_shared_docs['capitalize'] = dict(type='be capitalized',
29862987
method='capitalize')
29872988
_shared_docs['swapcase'] = dict(type='be swapcased', method='swapcase')
2989+
_shared_docs['casefold'] = dict(type='be casefolded', method='casefold')
29882990
lower = _noarg_wrapper(lambda x: x.lower(),
29892991
docstring=_shared_docs['casemethods'] %
29902992
_shared_docs['lower'])
@@ -3000,6 +3002,9 @@ def rindex(self, sub, start=0, end=None):
30003002
swapcase = _noarg_wrapper(lambda x: x.swapcase(),
30013003
docstring=_shared_docs['casemethods'] %
30023004
_shared_docs['swapcase'])
3005+
casefold = _noarg_wrapper(lambda x: x.casefold(),
3006+
docstring=_shared_docs['casemethods'] %
3007+
_shared_docs['casefold'])
30033008

30043009
_shared_docs['ismethods'] = ("""
30053010
Check whether all characters in each string are %(type)s.

Diff for: pandas/tests/test_strings.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def assert_series_or_index_equal(left, right):
7676
'len', 'lower', 'lstrip', 'partition',
7777
'rpartition', 'rsplit', 'rstrip',
7878
'slice', 'slice_replace', 'split',
79-
'strip', 'swapcase', 'title', 'upper'
79+
'strip', 'swapcase', 'title', 'upper', 'casefold'
8080
], [()] * 100, [{}] * 100))
8181
ids, _, _ = zip(*_any_string_method) # use method name as fixture-id
8282

@@ -3424,3 +3424,11 @@ def test_method_on_bytes(self):
34243424
expected = Series(np.array(
34253425
['ad', 'be', 'cf'], 'S2').astype(object))
34263426
tm.assert_series_equal(result, expected)
3427+
3428+
def test_casefold(self):
3429+
values = Series(['ss', NA, 'case', 'ssd'])
3430+
s = Series(['ß', NA, 'case', 'ßd'])
3431+
exp = s.str.casefold()
3432+
3433+
assert isinstance(exp, Series)
3434+
assert_series_equal(exp, values)

0 commit comments

Comments
 (0)