diff options
| -rw-r--r-- | numpy/core/code_generators/generate_umath.py | 9 | ||||
| -rw-r--r-- | numpy/core/tests/test_ufunc.py | 14 | ||||
| -rw-r--r-- | numpy/lib/arraysetops.py | 4 | ||||
| -rw-r--r-- | numpy/lib/nanfunctions.py | 2 | ||||
| -rw-r--r-- | numpy/linalg/tests/test_regression.py | 4 | ||||
| -rw-r--r-- | numpy/ma/core.py | 1 |
6 files changed, 26 insertions, 8 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index aad7c9a05..760b9c919 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -431,6 +431,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(noobj, out='?', simd=[('avx2', ints)]), [TypeDescription('O', FullTypeDescr, 'OO', 'O')], + TD('O', out='?'), ), 'greater_equal': Ufunc(2, 1, None, @@ -438,6 +439,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(noobj, out='?', simd=[('avx2', ints)]), [TypeDescription('O', FullTypeDescr, 'OO', 'O')], + TD('O', out='?'), ), 'less': Ufunc(2, 1, None, @@ -445,6 +447,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(noobj, out='?', simd=[('avx2', ints)]), [TypeDescription('O', FullTypeDescr, 'OO', 'O')], + TD('O', out='?'), ), 'less_equal': Ufunc(2, 1, None, @@ -452,6 +455,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(noobj, out='?', simd=[('avx2', ints)]), [TypeDescription('O', FullTypeDescr, 'OO', 'O')], + TD('O', out='?'), ), 'equal': Ufunc(2, 1, None, @@ -459,6 +463,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(noobj, out='?', simd=[('avx2', ints)]), [TypeDescription('O', FullTypeDescr, 'OO', 'O')], + TD('O', out='?'), ), 'not_equal': Ufunc(2, 1, None, @@ -466,6 +471,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(noobj, out='?', simd=[('avx2', ints)]), [TypeDescription('O', FullTypeDescr, 'OO', 'O')], + TD('O', out='?'), ), 'logical_and': Ufunc(2, 1, True_, @@ -473,6 +479,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), TD(O, f='npy_ObjectLogicalAnd'), + TD(O, f='npy_ObjectLogicalAnd', out='?'), ), 'logical_not': Ufunc(1, 1, None, @@ -480,6 +487,7 @@ defdict = { None, TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), TD(O, f='npy_ObjectLogicalNot'), + TD(O, f='npy_ObjectLogicalNot', out='?'), ), 'logical_or': Ufunc(2, 1, False_, @@ -487,6 +495,7 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), TD(O, f='npy_ObjectLogicalOr'), + TD(O, f='npy_ObjectLogicalOr', out='?'), ), 'logical_xor': Ufunc(2, 1, False_, diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 707c690dd..d9f961581 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -1090,14 +1090,18 @@ class TestUfunc(object): return '==' arr0d = np.array(HasComparisons()) - assert_equal(arr0d == arr0d, True) - assert_equal(np.equal(arr0d, arr0d), True) # normal behavior is a cast + assert_equal(arr0d == arr0d, '==') + assert_equal(np.equal(arr0d, arr0d), '==') + assert_equal(np.equal(arr0d, arr0d, dtype=bool), True) assert_equal(np.equal(arr0d, arr0d, dtype=object), '==') arr1d = np.array([HasComparisons()]) - assert_equal(arr1d == arr1d, np.array([True])) - assert_equal(np.equal(arr1d, arr1d), np.array([True])) # normal behavior is a cast - assert_equal(np.equal(arr1d, arr1d, dtype=object), np.array(['=='])) + ret_obj = np.array(['=='], dtype=object) + ret_bool = np.array([True]) + assert_equal(arr1d == arr1d, ret_obj) + assert_equal(np.equal(arr1d, arr1d), ret_obj) + assert_equal(np.equal(arr1d, arr1d, dtype=object), ret_obj) + assert_equal(np.equal(arr1d, arr1d, dtype=bool), ret_bool) def test_object_array_reduction(self): # Reductions on object arrays diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index c30ad534b..cf45e181b 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -562,10 +562,14 @@ def in1d(ar1, ar2, assume_unique=False, invert=False): if invert: mask = np.ones(len(ar1), dtype=bool) for a in ar2: + # convert object arrays to bool + # cannot use np.not_equal until 'S' and 'U' have loops mask &= (ar1 != a).astype(bool) else: mask = np.zeros(len(ar1), dtype=bool) for a in ar2: + # convert object arrays to bool + # cannot use np.equal until 'S' and 'U' have loops mask |= (ar1 == a).astype(bool) return mask diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index 0ae74bbbb..457cca146 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -99,7 +99,7 @@ def _replace_nan(a, val): if a.dtype == np.object_: # object arrays do not support `isnan` (gh-9009), so make a guess - mask = (a != a).astype(bool) + mask = np.not_equal(a, a, dtype=bool) elif issubclass(a.dtype.type, np.inexact): mask = np.isnan(a) else: diff --git a/numpy/linalg/tests/test_regression.py b/numpy/linalg/tests/test_regression.py index 5f5c594cf..289566109 100644 --- a/numpy/linalg/tests/test_regression.py +++ b/numpy/linalg/tests/test_regression.py @@ -109,9 +109,9 @@ class TestRegression(object): assert_raises(ValueError, linalg.norm, testvector, ord='nuc') assert_raises(ValueError, linalg.norm, testvector, ord=np.inf) assert_raises(ValueError, linalg.norm, testvector, ord=-np.inf) - # Succeeds, but returns boolean? + # Succeeds, equivalent to "sum(x != 0)" r = linalg.norm(testvector, ord=0) - assert_(r.dtype == np.type('float64')) + assert_(r.dtype == 'bool') assert_raises(ValueError, linalg.norm, testvector, ord=-1) assert_raises(ValueError, linalg.norm, testvector, ord=-2) diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 1fae5c8cb..f98a29d82 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -4791,6 +4791,7 @@ class MaskedArray(ndarray): mask = _check_mask_axis(self._mask, axis, **kwargs) if out is None: r = self.filled(True).all(axis=axis, **kwargs) + # object dtypes with axis=None return a scalar if isinstance(r, bool): d = type(self)(r) else: |
