10000 Merge pull request #14845 from mattip/revert-14800 · numpy/numpy@718c63f · GitHub
[go: up one dir, main page]

Skip to content

Commit 718c63f

Browse files
authored
Merge pull request #14845 from mattip/revert-14800
MAINT: revert gh-14800, which gave precedence to OO->O over OO->?
2 parents 480dc6b + e6a9c11 commit 718c63f

File tree

8 files changed

+23
-51
lines changed

8 files changed

+23
-51
lines changed

doc/release/upcoming_changes/14800.improvement.rst

Lines changed: 0 additions & 14 deletions
This file was deleted.

numpy/core/code_generators/generate_umath.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ def english_upper(s):
227227
}
228228

229229
noobj = '?bBhHiIlLqQefdgFDGmM'
230+
all = '?bBhHiIlLqQefdgFDGOmM'
231+
230232
O = 'O'
231233
P = 'P'
232234
ints = 'bBhHiIlLqQ'
@@ -429,47 +431,47 @@ def english_upper(s):
429431
Ufunc(2, 1, None,
430432
docstrings.get('numpy.core.umath.greater'),
431433
'PyUFunc_SimpleBinaryComparisonTypeResolver',
432-
TD(noobj, out='?', simd=[('avx2', ints)]),
434+
TD(all, out='?', simd=[('avx2', ints)]),
433435
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
434436
TD('O', out='?'),
435437
),
436438
'greater_equal':
437439
Ufunc(2, 1, None,
438440
docstrings.get('numpy.core.umath.greater_equal'),
439441
'PyUFunc_SimpleBinaryComparisonTypeResolver',
440-
TD(noobj, out='?', simd=[('avx2', ints)]),
442+
TD(all, out='?', simd=[('avx2', ints)]),
441443
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
442444
TD('O', out='?'),
443445
),
444446
'less':
445447
Ufunc(2, 1, None,
446448
docstrings.get('numpy.core.umath.less'),
447449
'PyUFunc_SimpleBinaryComparisonTypeResolver',
448-
TD(noobj, out='?', simd=[('avx2', ints)]),
450+
TD(all, out='?', simd=[('avx2', ints)]),
449451
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
450452
TD('O', out='?'),
451453
),
452454
'less_equal':
453455
Ufunc(2, 1, None,
454456
docstrings.get('numpy.core.umath.less_equal'),
455457
'PyUFunc_SimpleBinaryComparisonTypeResolver',
456-
TD(noobj, out='?', simd=[('avx2', ints)]),
458+
TD(all, out='?', simd=[('avx2', ints)]),
457459
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
458460
TD('O', out='?'),
459461
),
460462
'equal':
461463
Ufunc(2, 1, None,
462464
docstrings.get('numpy.core.umath.equal'),
463465
'PyUFunc_SimpleBinaryComparisonTypeResolver',
464-
TD(noobj, out='?', simd=[('avx2', ints)]),
466+
TD(all, out='?', simd=[('avx2', ints)]),
465467
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
466468
TD('O', out='?'),
467469
),
468470
'not_equal':
469471
Ufunc(2, 1, None,
470472
docstrings.get('numpy.core.umath.not_equal'),
471473
'PyUFunc_SimpleBinaryComparisonTypeResolver',
472-
TD(noobj, out='?', simd=[('avx2', ints)]),
474+
TD(all, out='?', simd=[('avx2', ints)]),
473475
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
474476
TD('O', out='?'),
475477
),

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ def test_normal_types(self):
175175
# ragged array comparison returns True/False
176176
a = np.array([1, np.array([1,2,3])], dtype=object)
177177
b = np.array([1, np.array([1,2,3])], dtype=object)
178-
res = op(a, b)
179-
assert res.dtype == 'object'
178+
self.assert_deprecated(op, args=(a, b), num=None)
180179

181180
def test_string(self):
182181
# For two string arrays, strings always raised the broadcasting error:

numpy/core/tests/test_ufunc.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,18 +1090,13 @@ def __eq__(self, other):
10901090
return '=='
10911091

10921092
arr0d = np.array(HasComparisons())
1093-
assert_equal(arr0d == arr0d, '==')
1094-
assert_equal(np.equal(arr0d, arr0d), '==')
1095-
assert_equal(np.equal(arr0d, arr0d, dtype=bool), True)
1096-
assert_equal(np.equal(arr0d, arr0d, dtype=object), '==')
1093+
assert_equal(arr0d == arr0d, True)
1094+
assert_equal(np.equal(arr0d, arr0d), True) # normal behavior is a cast
10971095

10981096
arr1d = np.array([HasComparisons()])
1099-
ret_obj = np.array(['=='], dtype=object)
1100-
ret_bool = np.array([True])
1101-
assert_equal(arr1d == arr1d, ret_obj)
1102-
assert_equal(np.equal(arr1d, arr1d), ret_obj)
1103-
assert_equal(np.equal(arr1d, arr1d, dtype=object), ret_obj)
1104-
assert_equal(np.equal(arr1d, arr1d, dtype=bool), ret_bool)
1097+
assert_equal(arr1d == arr1d, np.array([True]))
1098+
assert_equal(np.equal(arr1d, arr1d), np.array([True])) # normal behavior is a cast
1099+
assert_equal(np.equal(arr1d, arr1d, dtype=object), np.array(['==']))
11051100

11061101
def test_object_array_reduction(self):
11071102
# Reductions on object arrays

numpy/core/tests/test_umath.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ def test_ignore_object_identity_in_equal(self):
173173
# Check comparing identical objects whose comparison
174174
# is not a simple boolean, e.g., arrays that are compared elementwise.
175175
a = np.array([np.array([1, 2, 3]), None], dtype=object)
176-
b = np.equal(a, a.copy())
177-
assert b.shape == a.shape
176+
assert_raises(ValueError, np.equal, a, a)
178177

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

198196
# Check error raised when comparing identical non-comparable objects.
199197
class FunkyType(object):

numpy/lib/arraysetops.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,11 @@ def in1d(ar1, ar2, assume_unique=False, invert=False):
562562
if invert:
563563
mask = np.ones(len(ar1), dtype=bool)
564564
for a in ar2:
565-
# convert object arrays to bool
566-
# cannot use np.not_equal until 'S' and 'U' have loops
567-
mask &= (ar1 != a).astype(bool)
565+
mask &= (ar1 != a)
568566
else:
569567
mask = np.zeros(len(ar1), dtype=bool)
570568
for a in ar2:
571-
# convert object arrays to bool
572-
# cannot use np.equal until 'S' and 'U' have loops
573-
mask |= (ar1 == a).astype(bool)
569+
mask |= (ar1 == a)
574570
return mask
575571

576572
# Otherwise use sorting

numpy/linalg/tests/test_regression.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ def test_norm_object_array(self):
109109
assert_raises(ValueError, linalg.norm, testvector, ord='nuc')
110110
assert_raises(ValueError, linalg.norm, testvector, ord=np.inf)
111111
assert_raises(ValueError, linalg.norm, testvector, ord=-np.inf)
112-
# Succeeds, equivalent to "sum(x != 0)"
113-
r = linalg.norm(testvector, ord=0)
114-
assert_(r.dtype == 'bool')
112+
with warnings.catch_warnings():
113+
warnings.simplefilter("error", DeprecationWarning)
114+
assert_raises((AttributeError, DeprecationWarning),
115+
linalg.norm, testvector, ord=0)
115116
assert_raises(ValueError, linalg.norm, testvector, ord=-1)
116117
assert_raises(ValueError, linalg.norm, testvector, ord=-2)
117118

numpy/ma/core.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,12 +4790,7 @@ def all(self, axis=None, out=None, keepdims=np._NoValue):
47904790

47914791
mask = _check_mask_axis(self._mask, axis, **kwargs)
47924792
if out is None:
4793-
r = self.filled(True).all(axis=axis, **kwargs)
4794-
# object dtypes with axis=None return a scalar
4795-
if isinstance(r, bool):
4796-
d = type(self)(r)
4797-
else:
4798-
d = r.view(type(self))
4793+
d = self.filled(True).all(axis=axis, **kwargs).view(type(self))
47994794
if d.ndim:
48004795
d.__setmask__(mask)
48014796
elif mask:

0 commit comments

Comments
 (0)
0