diff options
author | wim glenn <wim.glenn@melbourneit.com.au> | 2015-06-15 03:56:26 +1000 |
---|---|---|
committer | wim glenn <wim.glenn@melbourneit.com.au> | 2015-06-15 03:56:26 +1000 |
commit | 0a08e7e50f5a445e54fd9a888a9d03a2fdeb9e9e (patch) | |
tree | 34ee4a01151d8e2df831096bdf446e0586cfd084 /numpy | |
parent | 899a2a2abafe565be634c134c76395753b906834 (diff) | |
download | numpy-0a08e7e50f5a445e54fd9a888a9d03a2fdeb9e9e.tar.gz |
BUG: fix inconsistency with np.array(['']) being truthy
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index c19d31a0d..a7d36ab42 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -2298,6 +2298,10 @@ STRING_nonzero (char *ip, PyArrayObject *ap) int i; npy_bool nonz = NPY_FALSE; + if ((len == 1) && (*ip == '\0')) { + return NPY_FALSE; + } + for (i = 0; i < len; i++) { if (!Py_STRING_ISSPACE(*ip)) { nonz = NPY_TRUE; @@ -2334,6 +2338,10 @@ UNICODE_nonzero (npy_ucs4 *ip, PyArrayObject *ap) ip = (npy_ucs4 *)buffer; } + if ((len == 1) && (*ip == '\0')) { + return NPY_FALSE; + } + for (i = 0; i < len; i++) { if (!PyArray_UCS4_ISSPACE(*ip)) { nonz = NPY_TRUE; diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index e6911d0e3..b0a565b0c 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -5731,5 +5731,14 @@ class TestArrayPriority(TestCase): assert_(isinstance(f(b, a), self.Other), msg) +class TestEmptyStringArray(TestCase): + + def test_empty_bstring_array_is_falsey(self): + self.assertFalse(np.array([b''])) + + def test_empty_ustring_array_is_falsey(self): + self.assertFalse(np.array([u''])) + + if __name__ == "__main__": run_module_suite() |