8000 MAINT: revert gh-14800, which gave precedence to OO->O over OO->? by mattip · Pull Request #14845 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: revert gh-14800, which gave precedence to OO->O over OO->? #14845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions doc/release/upcoming_changes/14800.improvement.rst

This file was deleted.

14 changes: 8 additions & 6 deletions numpy/core/code_generators/generate_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def english_upper(s):
}

noobj = '?bBhHiIlLqQefdgFDGmM'
all = '?bBhHiIlLqQefdgFDGOmM'

O = 'O'
P = 'P'
ints = 'bBhHiIlLqQ'
Expand Down Expand Up @@ -429,47 +431,47 @@ def english_upper(s):
Ufunc(2, 1, None,
docstrings.get('numpy.core.umath.greater'),
'PyUFunc_SimpleBinaryComparisonTypeResolver',
TD(noobj, out='?', simd=[('avx2', ints)]),
TD(all, out='?', simd=[('avx2', ints)]),
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
TD('O', out='?'),
),
'greater_equal':
Ufunc(2, 1, None,
docstrings.get('numpy.core.umath.greater_equal'),
'PyUFunc_SimpleBinaryComparisonTypeResolver',
TD(noobj, out='?', simd=[('avx2', ints)]),
TD(all, out='?', simd=[('avx2', ints)]),
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
TD('O', out='?'),
),
'less':
Ufunc(2, 1, None,
docstrings.get('numpy.core.umath.less'),
'PyUFunc_SimpleBinaryComparisonTypeResolver',
TD(noobj, out='?', simd=[('avx2', ints)]),
TD(all, out='?', simd=[('avx2', ints)]),
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
TD('O', out='?'),
),
'less_equal':
Ufunc(2, 1, None,
docstrings.get('numpy.core.umath.less_equal'),
'PyUFunc_SimpleBinaryComparisonTypeResolver',
TD(noobj, out='?', simd=[('avx2', ints)]),
TD(all, out='?', simd=[('avx2', ints)]),
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
TD('O', out='?'),
),
'equal':
Ufunc(2, 1, None,
docstrings.get('numpy.core.umath.equal'),
'PyUFunc_SimpleBinaryComparisonTypeResolver',
TD(noobj, out='?', simd=[('avx2', ints)]),
TD(all, out='?', simd=[('avx2', ints)]),
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
TD('O', out='?'),
),
'not_equal':
Ufunc(2, 1, None,
docstrings.get('numpy.core.umath.not_equal'),
'PyUFunc_SimpleBinaryComparisonTypeResolver',
TD(noobj, out='?', simd=[('avx2', ints)]),
TD(all, out='?', simd=[('avx2', ints)]),
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
TD('O', out='?'),
),
Expand Down
3 changes: 1 addition & 2 deletions numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def test_normal_types(self):
# ragged array comparison returns True/False
a = np.array([1, np.array([1,2,3])], dtype=object)
b = np.array([1, np.array([1,2,3])], dtype=object)
res = op(a, b)
assert res.dtype == 'object'
self.assert_deprecated(op, args=(a, b), num=None)

def test_string(self):
# For two string arrays, strings always raised the broadcasting error:
Expand Down
15 changes: 5 additions & 10 deletions numpy/core/tests/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,18 +1090,13 @@ def __eq__(self, other):
return '=='

arr0d = np.array(HasComparisons())
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), '==')
assert_equal(arr0d == arr0d, True)
assert_equal(np.equal(arr0d, arr0d), True) # normal behavior is a cast

arr1d = np.array([HasComparisons()])
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)
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(['==']))

def test_object_array_reduction(self):
# Reductions on object arrays
Expand Down
6 changes: 2 additions & 4 deletions numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ def test_ignore_object_identity_in_equal(self):
# Check comparing identical objects whose comparison
# is not a simple boolean, e.g., arrays that are compared elementwise.
a = np.array([np.array([1, 2, 3]), None], dtype=object)
b = np.equal(a, a.copy())
assert b.shape == a.shape
assert_raises(ValueError, np.equal, a, a)

# Check error raised when comparing identical non-comparable objects.
class FunkyType(object):
Expand All @@ -192,8 +191,7 @@ def test_ignore_object_identity_in_not_equal(self):
# Check comparing identical objects whose comparison
# is not a simple boolean, e.g., arrays that are compared elementwise.
a = np.array([np.array([1, 2, 3]), None], dtype=object)
b = np.not_equal(a, a.copy())
assert b.shape == a.shape
assert_raises(ValueError, np.not_equal, a, a)

# Check error raised when comparing identical non-comparable objects.
class FunkyType(object):
Expand Down
8 changes: 2 additions & 6 deletions numpy/lib/arraysetops.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,11 @@ 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)
mask &= (ar1 != a)
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)
mask |= (ar1 == a)
return mask

# Otherwise use sorting
Expand Down
7 changes: 4 additions & 3 deletions numpy/linalg/tests/test_regression.py
1E0A
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def test_norm_object_array(self):
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, equivalent to "sum(x != 0)"
r = linalg.norm(testvector, ord=0)
assert_(r.dtype == 'bool')
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
assert_raises((AttributeError, DeprecationWarning),
linalg.norm, testvector, ord=0)
assert_raises(ValueError, linalg.norm, testvector, ord=-1)
assert_raises(ValueError, linalg.norm, testvector, ord=-2)

Expand Down
7 changes: 1 addition & 6 deletions numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4790,12 +4790,7 @@ def all(self, axis=None, out=None, keepdims=np._NoValue):

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:
d = r.view(type(self))
d = self.filled(True).all(axis=axis, **kwargs).view(type(self))
if d.ndim:
d.__setmask__(mask)
elif mask:
Expand Down
0