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