8000 TST: Adjust tests for direct NEP 50 changes · numpy/numpy@be03e9b · GitHub
[go: up one dir, main page]

Skip to content

Commit be03e9b

Browse files
committed
TST: Adjust tests for direct NEP 50 changes
1 parent 35122dc commit be03e9b

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

numpy/core/tests/test_nditer.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ def test_iter_object_arrays_conversions():
11281128

11291129
def test_iter_common_dtype():
11301130
# Check that the iterator finds a common data type correctly
1131+
# (some checks are somewhat duplicate after adopting NEP 50)
11311132

11321133
i = nditer([array([3], dtype='f4'), array([0], dtype='f8')],
11331134
['common_dtype'],
@@ -1145,14 +1146,14 @@ def test_iter_common_dtype():
11451146
['common_dtype'],
11461147
[['readonly', 'copy']]*2,
11471148
casting='same_kind')
1148-
assert_equal(i.dtypes[0], np.dtype('f4'))
1149-
assert_equal(i.dtypes[1], np.dtype('f4'))
1149+
assert_equal(i.dtypes[0], np.dtype('f8'))
1150+
assert_equal(i.dtypes[1], np.dtype('f8'))
11501151
i = nditer([array([3], dtype='u4'), array(0, dtype='i4')],
11511152
['common_dtype'],
11521153
[['readonly', 'copy']]*2,
11531154
casting='safe')
1154-
assert_equal(i.dtypes[0], np.dtype('u4'))
1155-
assert_equal(i.dtypes[1], np.dtype('u4'))
1155+
assert_equal(i.dtypes[0], np.dtype('i8'))
1156+
assert_equal(i.dtypes[1], np.dtype('i8'))
11561157
i = nditer([array([3], dtype='u4'), array(-12, dtype='i4')],
11571158
['common_dtype'],
11581159
[['readonly', 'copy']]*2,
@@ -1551,7 +1552,8 @@ def test_iter_allocate_output_opaxes():
15511552
assert_equal(i.operands[0].dtype, np.dtype('u4'))
15521553

15531554
def test_iter_allocate_output_types_promotion():
1554-
# Check type promotion of automatic outputs
1555+
# Check type promotion of automatic outputs (this was more interesting
1556+
# before NEP 50...)
15551557

15561558
i = nditer([array([3], dtype='f4'), array([0], dtype='f8'), None], [],
15571559
[['readonly']]*2+[['writeonly', 'allocate']])
@@ -1561,10 +1563,10 @@ def test_iter_allocate_output_types_promotion():
15611563
assert_equal(i.dtypes[2], np.dtype('f8'))
15621564
i = nditer([array([3], dtype='f4'), array(0, dtype='f8'), None], [],
15631565
[['readonly']]*2+[['writeonly', 'allocate']])
1564-
assert_equal(i.dtypes[2], np.dtype('f4'))
1566+
assert_equal(i.dtypes[2], np.dtype('f8'))
15651567
i = nditer([array([3], dtype='u4'), array(0, dtype='i4'), None], [],
15661568
[['readonly']]*2+[['writeonly', 'allocate']])
1567-
assert_equal(i.dtypes[2], np.dtype('u4'))
1569+
assert_equal(i.dtypes[2], np.dtype('i8'))
15681570
i = nditer([array([3], dtype='u4'), array(-12, dtype='i4'), None], [],
15691571
[['readonly']]*2+[['writeonly', 'allocate']])
15701572
assert_equal(i.dtypes[2], np.dtype('i8'))

numpy/core/tests/test_numeric.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -763,20 +763,25 @@ def check_promotion_cases(self, promote_func):
763763
assert_equal(promote_func(np.array([b]), u8), np.dtype(np.uint8))
764764
assert_equal(promote_func(np.array([b]), i32), np.dtype(np.int32))
765765
assert_equal(promote_func(np.array([b]), u32), np.dtype(np.uint32))
766-
assert_equal(promote_func(np.array([i8]), i64), np.dtype(np.int8))
767-
assert_equal(promote_func(u64, np.array([i32])), np.dtype(np.int32))
768-
assert_equal(promote_func(i64, np.array([u32])), np.dtype(np.uint32))
766+
assert_equal(promote_func(np.array([i8]), i64), np.dtype(np.int64))
767+
# unsigned and signed unfortunately tend to promote to float64:
768+
assert_equal(promote_func(u64, np.array([i32])), np.dtype(np.float64))
769+
assert_equal(promote_func(i64, np.array([u32])), np.dtype(np.int64))
770+
assert_equal(promote_func(np.array([u16]), i32), np.dtype(np.int32))
769771
assert_equal(promote_func(np.int32(-1), np.array([u64])),
770772
np.dtype(np.float64))
771-
assert_equal(promote_func(f64, np.array([f32])), np.dtype(np.float32))
772-
assert_equal(promote_func(fld, np.array([f32])), np.dtype(np.float32))
773+
assert_equal(promote_func(f64, np.array([f32])), np.dtype(np.float64))
774+
assert_equal(promote_func(fld, np.array([f32])),
775+
np.dtype(np.longdouble))
773776
assert_equal(promote_func(np.array([f64]), fld), np.dtype(np.float64))
774777
assert_equal(promote_func(fld, np.array([c64])),
775-
np.dtype(np.complex64))
778+
np.dtype(np.clongdouble))
776779
assert_equal(promote_func(c64, np.array([f64])),
777780
np.dtype(np.complex128))
778781
assert_equal(promote_func(np.complex64(3j), np.array([f64])),
779782
np.dtype(np.complex128))
783+
assert_equal(promote_func(np.array([f32]), c128),
784+
np.dtype(np.complex128))
780785

781786
# coercion between scalars and 1-D arrays, where
782787
# the scalar has greater kind than the array
@@ -786,16 +791,6 @@ def check_promotion_cases(self, promote_func):
786791
assert_equal(promote_func(np.array([i8]), f64), np.dtype(np.float64))
787792
assert_equal(promote_func(np.array([u16]), f64), np.dtype(np.float64))
788793

789-
# uint and int are treated as the same "kind" for
790-
# the purposes of array-scalar promotion.
791-
assert_equal(promote_func(np.array([u16]), i32), np.dtype(np.uint16))
792-
793-
# float and complex are treated as the same "kind" for
794-
# the purposes of array-scalar promotion, so that you can do
795-
# (0j + float32array) to get a complex64 array instead of
796-
# a complex128 array.
797-
assert_equal(promote_func(np.array([f32]), c128),
798-
np.dtype(np.complex64))
799794

800795
def test_coercion(self):
801796
def res_type(a, b):

numpy/core/tests/test_ufunc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,10 +1882,10 @@ def test_ufunc_custom_out(self):
18821882
result = _rational_tests.test_add(a, b.astype(np.uint16), out=c)
18831883
assert_equal(result, target)
18841884

1885-
# But, it can be fooled, e.g. (use scalars, which forces legacy
1886-
# type resolution to kick in, which then fails):
1887-
with assert_raises(TypeError):
1888-
_rational_tests.test_add(a, np.uint16(2))
1885+
# This path used to go into legacy promotion, but doesn't now:
1886+
result = _rational_tests.test_add(a, np.uint16(2))
1887+
target = np.array([2, 3, 4], dtype=_rational_tests.rational)
1888+
assert_equal(result, target)
18891889

18901890
def test_operand_flags(self):
18911891
a = np.arange(16, dtype='l').reshape(4, 4)

numpy/lib/tests/test_index_tricks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ def test_accepts_npfloating(self):
245245
# regression test for #16466
246246
grid64 = mgrid[0.1:0.33:0.1, ]
247247
grid32 = mgrid[np.float32(0.1):np.float32(0.33):np.float32(0.1), ]
248-
assert_(grid32.dtype == np.float64)
249248
assert_array_almost_equal(grid64, grid32)
249+
# At some point this was float64, but NEP 50 changed it:
250+
assert grid32.dtype == np.float32
251+
assert grid64.dtype == np.float64
250252

251253
# different code path for single slice
252254
grid64 = mgrid[0.1:0.33:0.1]

0 commit comments

Comments
 (0)
0