diff options
| author | Jay Bourque <jay.bourque@continuum.io> | 2013-05-10 15:32:24 -0500 |
|---|---|---|
| committer | Jay Bourque <jay.bourque@continuum.io> | 2013-05-10 15:32:24 -0500 |
| commit | 6dc709a5aa0b17b5a74b7456d7cbd2580d9063f6 (patch) | |
| tree | b8891ddafcd824f1082da92e702d47ea1ba0d912 /numpy | |
| parent | 6b892cf994889518a948987be8c57353d4250dad (diff) | |
| download | numpy-6dc709a5aa0b17b5a74b7456d7cbd2580d9063f6.tar.gz | |
Fix array_equal and array_equiv issue
array_equal() and array_equiv() don't work for string arrays and record arrays. This is because those methods use numpy.equals ufunc for comparison, and there are no equal ufuncs registered for strings and record arrays. Replace numpy.equals with '==' array operation, which handles strings and record arrays.
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/numeric.py | 4 | ||||
| -rw-r--r-- | numpy/core/tests/test_numeric.py | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index d689982db..a20bf3dcd 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2137,7 +2137,7 @@ def array_equal(a1, a2): return False if a1.shape != a2.shape: return False - return bool(equal(a1,a2).all()) + return bool((a1 == a2).all()) def array_equiv(a1, a2): """ @@ -2179,7 +2179,7 @@ def array_equiv(a1, a2): except: return False try: - return bool(equal(a1,a2).all()) + return bool(asarray(a1 == a2).all()) except ValueError: return False diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 3a6118f06..5c8de3734 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -656,6 +656,12 @@ class TestArrayComparisons(TestCase): res = array_equal(array([1,2]), array([1,3])) assert_(not res) assert_(type(res) is bool) + res = array_equal(array(['a'], dtype='S1'), array(['a'], dtype='S1')) + assert_(res) + assert_(type(res) is bool) + res = array_equal(array([('a',1)], dtype='S1,u4'), array([('a',1)], dtype='S1,u4')) + assert_(res) + assert_(type(res) is bool) def test_array_equiv(self): res = array_equiv(array([1,2]), array([1,2])) |
