Skip to content

Commit 4beb952

Browse files
committed
Add unit testing.
Original NumPy Commit: 81b97607339ac68b27cf72ba7923345d58e2895e
1 parent 1ff7258 commit 4beb952

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
3+
4+
def test_fast_return():
5+
""""""
6+
a = np.array([1, 2, 3], dtype='i')
7+
assert np.asarray(a) is a
8+
assert np.asarray(a, dtype='i') is a
9+
# This may produce a new view or a copy, but is never the same object.
10+
assert np.asarray(a, dtype='l') is not a
11+
12+
unequal_type = np.dtype('i', metadata={'spam': True})
13+
b = np.asarray(a, dtype=unequal_type)
14+
assert b is not a
15+
assert b.base is a
16+
17+
equivalent_requirement = np.dtype('i', metadata={'spam': True})
18+
c = np.asarray(b, dtype=equivalent_requirement)
19+
# A quirk of the metadata test is that equivalent metadata dicts are still
20+
# separate objects and so don't evaluate as the same array type description.
21+
assert unequal_type == equivalent_requirement
22+
assert unequal_type is not equivalent_requirement
23+
assert c is not b
24+
assert c.dtype is equivalent_requirement

0 commit comments

Comments
 (0)