Skip to content

Commit aad1c47

Browse files
committed
Merge branch 'fix_string_contains_case_insensitive_with_no_regex' of https://github.com/benjwadams/pandas into benjwadams-fix_string_contains_case_insensitive_with_no_regex
Conflicts: doc/source/v0.14.1.txt
2 parents 5a07b7b + 6116d43 commit aad1c47

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

doc/source/v0.14.1.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ Experimental
158158
~~~~~~~~~~~~
159159

160160
- ``io.gbq.read_gbq`` and ``io.gbq.to_gbq`` were refactored to remove the
161-
dependency on the Google ``bq.py`` command line client. This submodule
162-
now uses ``httplib2`` and the Google ``apiclient`` and ``oauth2client`` API client
163-
libraries which should be more stable and, therefore, reliable than
164-
``bq.py`` (:issue:`6937`).
161+
dependency on the Google ``bq.py`` command line client. This submodule
162+
now uses ``httplib2`` and the Google ``apiclient`` and ``oauth2client`` API client
163+
libraries which should be more stable and, therefore, reliable than
164+
``bq.py`` (:issue:`6937`).
165165

166166
.. _whatsnew_0141.bug_fixes:
167167

@@ -267,3 +267,4 @@ Bug Fixes
267267
- Bug in ``DatetimeIndex.intersection`` doesn't preserve timezone (:issue:`4690`)
268268

269269
- Bug in ``Float64Index`` assignment with a non scalar indexer (:issue:`7586`)
270+
- Bug in ``pandas.core.strings.str_contains`` does not properly match in a case insensitive fashion when ``regex=False`` and ``case=False`` (:issue:`7505`)

pandas/core/strings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ def str_contains(arr, pat, case=True, flags=0, na=np.nan, regex=True):
189189

190190
f = lambda x: bool(regex.search(x))
191191
else:
192-
f = lambda x: pat in x
192+
if case:
193+
f = lambda x: pat in x
194+
else:
195+
upper_pat = pat.upper()
196+
f = lambda x: upper_pat in x
197+
return _na_map(f, str_upper(arr), na, dtype=bool)
193198
return _na_map(f, arr, na, dtype=bool)
194199

195200

pandas/tests/test_strings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ def test_contains(self):
189189
self.assertEqual(result.dtype, np.bool_)
190190
tm.assert_almost_equal(result, expected)
191191

192+
# case insensitive using regex
193+
values = ['Foo', 'xYz', 'fOOomMm__fOo', 'MMM_']
194+
result = strings.str_contains(values, 'FOO|mmm', case=False)
195+
expected = [True, False, True, True]
196+
tm.assert_almost_equal(result, expected)
197+
198+
# case insensitive without regex
199+
result = strings.str_contains(values, 'foo', regex=False, case=False)
200+
expected = [True, False, True, False]
201+
tm.assert_almost_equal(result, expected)
202+
192203
# mixed
193204
mixed = ['a', NA, 'b', True, datetime.today(), 'foo', None, 1, 2.]
194205
rs = strings.str_contains(mixed, 'o')

0 commit comments

Comments
 (0)