File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments