Repository: numba/numba

Issue:
`.strip()` not stripping `\t`.
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

For more general "how do I do X?" type questions, please speak to us in real
time on https://gitter.im/numba/numba or post to the Numba mailing list
https://groups.google.com/a/continuum.io/forum/#!forum/numba-users.

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I am using the latest released version of Numba (most recent is visible in
 the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

```
>>> from numba import njit
>>> s = '  \t bbcd\t '
>>> s.strip()
'bbcd'
>>> @njit
... def foo(s):
...     return s.strip()
...
>>> foo(s)
'\t bbcd\t'
>>>

```


Discussion:
Need to fix these 2 lines
https://github.com/numba/numba/blob/ad3303c25133d57127abf8be1cd72d6048f45813/numba/unicode.py#L890
https://github.com/numba/numba/blob/ad3303c25133d57127abf8be1cd72d6048f45813/numba/unicode.py#L879
Perhaps replacing `' '` with https://docs.python.org/3.7/library/string.html#string.whitespace
duplicate of #4188.
I'd like to take a look at this as my first issue. Is this okay even though the issue is marked as `duplicate` or should I resolve the original issue instead?
@shimst3r great, thanks for wanting to contribute. I'd go for resolving the issue reported here with `\t` and extending the testing for cover that, and then if you are happy with that move on to cover the contents of #4188. Hows that sound?

As a new contributor, some instructions for getting set up for development are [here](http://numba.pydata.org/numba-doc/latest/developer/contributing.html#getting-set-up) and are a great place to start.

Thanks!
Sounds great to me and thank you for the link. 👍 

Resolving patch:
diff --git a/numba/cpython/unicode.py b/numba/cpython/unicode.py
--- a/numba/cpython/unicode.py
+++ b/numba/cpython/unicode.py
@@ -1388,24 +1388,35 @@ def zfill_impl(string, width):
 # ------------------------------------------------------------------------------
 @register_jitable
 def unicode_strip_left_bound(string, chars):
-    chars = ' ' if chars is None else chars
     str_len = len(string)
 
-    for i in range(str_len):
-        if string[i] not in chars:
-            return i
+    if chars is not None:
+        for i in range(str_len):
+            if string[i] not in chars:
+                return i
+    else:
+        for i in range(str_len):
+            if not _PyUnicode_IsSpace(string[i]):
+                return i
+
     return str_len
 
 
 @register_jitable
 def unicode_strip_right_bound(string, chars):
-    chars = ' ' if chars is None else chars
     str_len = len(string)
 
-    for i in range(str_len - 1, -1, -1):
-        if string[i] not in chars:
-            i += 1
-            break
+    if chars is not None:
+        for i in range(str_len - 1, -1, -1):
+            if string[i] not in chars:
+                i += 1
+                break
+    else:
+        for i in range(str_len - 1, -1, -1):
+            if not _PyUnicode_IsSpace(string[i]):
+                i += 1
+                break
+
     return i
 
 


Test patch:
diff --git a/numba/tests/test_unicode.py b/numba/tests/test_unicode.py
--- a/numba/tests/test_unicode.py
+++ b/numba/tests/test_unicode.py
@@ -1701,7 +1701,15 @@ def test_strip(self):
             ('  tú quién te crees?   ', None),
             ('大处 着眼，小处着手。大大大处', '大处'),
             (' 大处大处  ', ''),
-            (' 大处大处  ', None)
+            ('\t\nabcd\t', '\ta'),
+            (' 大处大处  ', None),
+            ('\t abcd \t', None),
+            ('\n abcd \n', None),
+            ('\r abcd \r', None),
+            ('\x0b abcd \x0b', None),
+            ('\x0c abcd \x0c', None),
+            ('\u2029abcd\u205F', None),
+            ('\u0085abcd\u2009', None)
         ]
 
         # form with no parameter