@@ -36,7 +36,6 @@ class BrainNumpyCoreMultiarrayTest(unittest.TestCase):
36
36
("is_busday" , "['2011-07-01', '2011-07-02', '2011-07-18']" ),
37
37
("lexsort" , "(('toto', 'tutu'), ('riri', 'fifi'))" ),
38
38
("packbits" , "np.array([1, 2])" ),
39
- ("ravel_multi_index" , "np.array([[1, 2], [2, 1]])" , "(3, 4)" ),
40
39
("unpackbits" , "np.array([[1], [2], [3]], dtype=np.uint8)" ),
41
40
("vdot" , "[1, 2]" , "[1, 2]" ),
42
41
("where" , "[True, False]" , "[1, 2]" , "[2, 1]" ),
@@ -77,105 +76,137 @@ def _inferred_numpy_func_call(self, func_name, *func_args):
77
76
)
78
77
return node .infer ()
79
78
79
+ def _inferred_numpy_no_alias_func_call (self , func_name , * func_args ):
80
+ node = builder .extract_node (
81
+ """
82
+ import numpy
83
+ func = numpy.{:s}
84
+ func({:s})
85
+ """ .format (
86
+ func_name , "," .join (func_args )
87
+ )
88
+ )
89
+ return node .infer ()
90
+
80
91
def test_numpy_function_calls_inferred_as_ndarray (self ):
81
92
"""
82
93
Test that calls to numpy functions are inferred as numpy.ndarray
83
94
"""
84
- for func_ in self .numpy_functions_returning_array :
85
- with self .subTest (typ = func_ ):
86
- inferred_values = list (self ._inferred_numpy_func_call (* func_ ))
87
- self .assertTrue (
88
- len (inferred_values ) == 1 ,
89
- msg = "Too much inferred values ({}) for {:s}" .format (
90
- inferred_values , func_ [0 ]
91
- ),
92
- )
93
- self .assertTrue (
94
- inferred_values [- 1 ].pytype () == ".ndarray" ,
95
- msg = "Illicit type for {:s} ({})" .format (
96
- func_ [0 ], inferred_values [- 1 ].pytype ()
97
- ),
98
- )
95
+ for infer_wrapper in (
96
+ self ._inferred_numpy_func_call ,
97
+ self ._inferred_numpy_no_alias_func_call ,
98
+ ):
99
+ for func_ in self .numpy_functions_returning_array :
100
+ with self .subTest (typ = func_ ):
101
+ inferred_values = list (infer_wrapper (* func_ ))
102
+ self .assertTrue (
103
+ len (inferred_values ) == 1 ,
104
+ msg = "Too much inferred values ({}) for {:s}" .format (
105
+ inferred_values , func_ [0 ]
106
+ ),
107
+ )
108
+ self .assertTrue (
109
+ inferred_values [- 1 ].pytype () == ".ndarray" ,
110
+ msg = "Illicit type for {:s} ({})" .format (
111
+ func_ [0 ], inferred_values [- 1 ].pytype ()
112
+ ),
113
+ )
99
114
100
115
def test_numpy_function_calls_inferred_as_bool (self ):
101
116
"""
102
117
Test that calls to numpy functions are inferred as bool
103
118
"""
104
- for func_ in self .numpy_functions_returning_bool :
105
- with self .subTest (typ = func_ ):
106
- inferred_values = list (self ._inferred_numpy_func_call (* func_ ))
107
- self .assertTrue (
108
- len (inferred_values ) == 1 ,
109
- msg = "Too much inferred values ({}) for {:s}" .format (
110
- inferred_values , func_ [0 ]
111
- ),
112
- )
113
- self .assertTrue (
114
- inferred_values [- 1 ].pytype () == "builtins.bool" ,
115
- msg = "Illicit type for {:s} ({})" .format (
116
- func_ [0 ], inferred_values [- 1 ].pytype ()
117
- ),
118
- )
119
+ for infer_wrapper in (
120
+ self ._inferred_numpy_func_call ,
121
+ self ._inferred_numpy_no_alias_func_call ,
122
+ ):
123
+ for func_ in self .numpy_functions_returning_bool :
124
+ with self .subTest (typ = func_ ):
125
+ inferred_values = list (infer_wrapper (* func_ ))
126
+ self .assertTrue (
127
+ len (inferred_values ) == 1 ,
128
+ msg = "Too much inferred values ({}) for {:s}" .format (
129
+ inferred_values , func_ [0 ]
130
+ ),
131
+ )
132
+ self .assertTrue (
133
+ inferred_values [- 1 ].pytype () == "builtins.bool" ,
134
+ msg = "Illicit type for {:s} ({})" .format (
135
+ func_ [0 ], inferred_values [- 1 ].pytype ()
136
+ ),
137
+ )
119
138
120
139
def test_numpy_function_calls_inferred_as_dtype (self ):
121
140
"""
122
141
Test that calls to numpy functions are inferred as numpy.dtype
123
142
"""
124
- for func_ in self .numpy_functions_returning_dtype :
125
- with self .subTest (typ = func_ ):
126
- inferred_values = list (self ._inferred_numpy_func_call (* func_ ))
127
- self .assertTrue (
128
- len (inferred_values ) == 1 ,
129
- msg = "Too much inferred values ({}) for {:s}" .format (
130
- inferred_values , func_ [0 ]
131
- ),
132
- )
133
- self .assertTrue (
134
- inferred_values [- 1 ].pytype () == "numpy.dtype" ,
135
- msg = "Illicit type for {:s} ({})" .format (
136
- func_ [0 ], inferred_values [- 1 ].pytype ()
137
- ),
138
- )
143
+ for infer_wrapper in (
144
+ self ._inferred_numpy_func_call ,
145
+ self ._inferred_numpy_no_alias_func_call ,
146
+ ):
147
+ for func_ in self .numpy_functions_returning_dtype :
148
+ with self .subTest (typ = func_ ):
149
+ inferred_values = list (infer_wrapper (* func_ ))
150
+ self .assertTrue (
151
+ len (inferred_values ) == 1 ,
152
+ msg = "Too much inferred values ({}) for {:s}" .format (
153
+ inferred_values , func_ [0 ]
154
+ ),
155
+ )
156
+ self .assertTrue (
157
+ inferred_values [- 1 ].pytype () == "numpy.dtype" ,
158
+ msg = "Illicit type for {:s} ({})" .format (
159
+ func_ [0 ], inferred_values [- 1 ].pytype ()
160
+ ),
161
+ )
139
162
140
163
def test_numpy_function_calls_inferred_as_none (self ):
141
164
"""
142
165
Test that calls to numpy functions are inferred as None
143
166
"""
144
- for func_ in self .numpy_functions_returning_none :
145
- with self .subTest (typ = func_ ):
146
- inferred_values = list (self ._inferred_numpy_func_call (* func_ ))
147
- self .assertTrue (
148
- len (inferred_values ) == 1 ,
149
- msg = "Too much inferred values ({}) for {:s}" .format (
150
- inferred_values , func_ [0 ]
151
- ),
152
- )
153
- self .assertTrue (
154
- inferred_values [- 1 ].pytype () == "builtins.NoneType" ,
155
- msg = "Illicit type for {:s} ({})" .format (
156
- func_ [0 ], inferred_values [- 1 ].pytype ()
157
- ),
158
- )
167
+ for infer_wrapper in (
168
+ self ._inferred_numpy_func_call ,
169
+ self ._inferred_numpy_no_alias_func_call ,
170
+ ):
171
+ for func_ in self .numpy_functions_returning_none :
172
+ with self .subTest (typ = func_ ):
173
+ inferred_values = list (infer_wrapper (* func_ ))
174
+ self .assertTrue (
175
+ len (inferred_values ) == 1 ,
176
+ msg = "Too much inferred values ({}) for {:s}" .format (
177
+ inferred_values , func_ [0 ]
178
+ ),
179
+ )
180
+ self .assertTrue (
181
+ inferred_values [- 1 ].pytype () == "builtins.NoneType" ,
182
+ msg = "Illicit type for {:s} ({})" .format (
183
+ func_ [0 ], inferred_values [- 1 ].pytype ()
184
+ ),
185
+ )
159
186
160
187
def test_numpy_function_calls_inferred_as_tuple (self ):
161
188
"""
162
189
Test that calls to numpy functions are inferred as tuple
163
190
"""
164
- for func_ in self .numpy_functions_returning_tuple :
165
- with self .subTest (typ = func_ ):
166
- inferred_values = list (self ._inferred_numpy_func_call (* func_ ))
167
- self .assertTrue (
168
- len (inferred_values ) == 1 ,
169
- msg = "Too much inferred values ({}) for {:s}" .format (
170
- inferred_values , func_ [0 ]
171
- ),
172
- )
173
- self .assertTrue (
174
- inferred_values [- 1 ].pytype () == "builtins.tuple" ,
175
- msg = "Illicit type for {:s} ({})" .format (
176
- func_ [0 ], inferred_values [- 1 ].pytype ()
177
- ),
178
- )
191
+ for infer_wrapper in (
192
+ self ._inferred_numpy_func_call ,
193
+ self ._inferred_numpy_no_alias_func_call ,
194
+ ):
195
+ for func_ in self .numpy_functions_returning_tuple :
196
+ with self .subTest (typ = func_ ):
197
+ inferred_values = list (infer_wrapper (* func_ ))
198
+ self .assertTrue (
199
+ len (inferred_values ) == 1 ,
200
+ msg = "Too much inferred values ({}) for {:s}" .format (
201
+ inferred_values , func_ [0 ]
202
+ ),
203
+ )
204
+ self .assertTrue (
205
+ inferred_values [- 1 ].pytype () == "builtins.tuple" ,
206
+ msg = "Illicit type for {:s} ({})" .format (
207
+ func_ [0 ], inferred_values [- 1 ].pytype ()
208
+ ),
209
+ )
179
210
180
211
181
212
if __name__ == "__main__" :
0 commit comments