@@ -153,64 +153,114 @@ def test_feature_domains():
153
153
154
154
155
155
def test_one_input_conversion ():
156
+ """Test one input conversions to one PredInput"""
156
157
numpy1 = np .arange (0 , 10 )
157
- numpy2 = np .arange (0 , 10 ).reshape (1 , 10 )
158
- series = pd .Series (numpy1 , index = ["input-{}" .format (i ) for i in range (10 )])
159
- df = pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (10 )])
158
+ numpy2 = numpy1 .reshape (1 , 10 )
159
+
160
+ to_convert = [
161
+ numpy1 ,
162
+ numpy2 ,
163
+ pd .Series (numpy1 , index = ["input-{}" .format (i ) for i in range (10 )]),
164
+ pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (10 )]),
165
+ numpy1 .tolist ()
166
+ ]
160
167
161
- ta_numpy1 = one_input_convert (numpy1 )
162
- ta_numpy2 = one_input_convert (numpy2 )
163
- ta_series = one_input_convert (series )
164
- ta_df = one_input_convert (df )
168
+ converted = [one_input_convert (x ) for x in to_convert ]
165
169
166
- assert ta_numpy1 .equals (ta_numpy2 )
167
- assert ta_numpy2 .equals (ta_series )
168
- assert ta_series .equals (ta_df )
170
+ for i in range (len (converted )- 1 ):
171
+ assert converted [i ].equals (converted [i + 1 ])
169
172
170
173
171
174
def test_one_input_conversion_domained ():
175
+ """Test one input conversions with domains to one PredInput"""
172
176
n_feats = 5
173
177
np .random .seed (0 )
174
-
178
+ numpy1 = np .arange (0 , n_feats )
179
+ numpy2 = numpy1 .reshape (1 , n_feats )
175
180
domain_bounds = [[np .random .rand (), np .random .rand ()] for _ in range (n_feats )]
176
181
domains = [feature_domain ((lb , ub )) for lb , ub in domain_bounds ]
177
- numpy1 = np .arange (0 , n_feats )
178
- numpy2 = np .arange (0 , n_feats ).reshape (1 , n_feats )
179
- series = pd .Series (numpy1 , index = ["input-{}" .format (i ) for i in range (n_feats )])
180
- df = pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (n_feats )])
181
182
182
- ta_numpy1 = one_input_convert (numpy1 , feature_domains = domains )
183
- ta_numpy2 = one_input_convert (numpy2 , feature_domains = domains )
184
- ta_series = one_input_convert (series , feature_domains = domains )
185
- ta_df = one_input_convert (df , feature_domains = domains )
183
+ to_convert = [
184
+ numpy1 ,
185
+ numpy2 ,
186
+ pd .Series (numpy1 , index = ["input-{}" .format (i ) for i in range (n_feats )]),
187
+ pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (n_feats )]),
188
+ numpy1 .tolist ()
189
+ ]
190
+ converted = [one_input_convert (x , feature_domains = domains ) for x in to_convert ]
191
+
192
+ for i in range (len (converted ) - 1 ):
193
+ for j in range (n_feats ):
194
+ assert converted [i ].getFeatures ().get (j ).getDomain ().getLowerBound ()\
195
+ == domain_bounds [j ][0 ]
196
+ assert converted [i ].getFeatures ().get (j ).getDomain ().getUpperBound ()\
197
+ == domain_bounds [j ][1 ]
198
+
199
+ assert converted [i ].equals (converted [i + 1 ])
200
+
201
+
202
+ def test_one_input_one_feature_conversion ():
203
+ """Test one input, one feature conversions to one PredInput"""
204
+ numpy1 = np .arange (0 , 1 )
205
+ numpy2 = numpy1 .reshape (1 , 1 )
186
206
187
- for converted in [ta_numpy1 , ta_numpy2 , ta_df , ta_series ]:
188
- for i in range (n_feats ):
189
- assert converted .getFeatures ().get (i ).getDomain ().getLowerBound () == domain_bounds [i ][0 ]
190
- assert converted .getFeatures ().get (i ).getDomain ().getUpperBound () == domain_bounds [i ][1 ]
207
+ to_convert = [
208
+ numpy1 ,
209
+ numpy2 ,
210
+ pd .Series (numpy1 , index = ["input-{}" .format (i ) for i in range (1 )]),
211
+ pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (1 )]),
212
+ numpy1 .tolist (),
213
+ numpy1 .tolist ()[0 ]
214
+ ]
191
215
192
- assert ta_numpy1 .equals (ta_numpy2 )
193
- assert ta_numpy2 .equals (ta_series )
194
- assert ta_series .equals (ta_df )
216
+ converted = [one_input_convert (x ) for x in to_convert ]
217
+
218
+ for i in range (len (converted ) - 1 ):
219
+ assert converted [i ].equals (converted [i + 1 ])
195
220
196
221
197
222
def test_one_output_conversion ():
223
+ """Test one output conversions to one PredOutput"""
198
224
numpy1 = np .arange (0 , 10 )
199
- numpy2 = np .arange (0 , 10 ).reshape (1 , 10 )
200
- series = pd .Series (numpy1 , index = ["output-{}" .format (i ) for i in range (10 )])
201
- df = pd .DataFrame (numpy2 , columns = ["output-{}" .format (i ) for i in range (10 )])
225
+ numpy2 = numpy1 .reshape (1 , 10 )
226
+
227
+ to_convert = [
228
+ numpy1 ,
229
+ numpy2 ,
230
+ pd .Series (numpy1 , index = ["output-{}" .format (i ) for i in range (10 )]),
231
+ pd .DataFrame (numpy2 , columns = ["output-{}" .format (i ) for i in range (10 )]),
232
+ numpy1 .tolist ()
233
+ ]
234
+
235
+ converted = [one_output_convert (x ) for x in to_convert ]
236
+
237
+ for i in range (len (converted ) - 1 ):
238
+ assert converted [i ].equals (converted [i + 1 ])
239
+
240
+
241
+ def test_one_output_one_value_conversion ():
242
+ """Test one output, one value conversions to one PredOutput"""
243
+ numpy1 = np .arange (0 , 1 )
244
+ numpy2 = numpy1 .reshape (1 , 1 )
245
+
246
+ to_convert = [
247
+ numpy1 ,
248
+ numpy2 ,
249
+ pd .Series (numpy1 , index = ["output-{}" .format (i ) for i in range (1 )]),
250
+ pd .DataFrame (numpy2 , columns = ["output-{}" .format (i ) for i in range (1 )]),
251
+ numpy1 .tolist (),
252
+ numpy1 .tolist ()[0 ]
253
+ ]
202
254
203
- ta_numpy1 = one_output_convert (numpy1 )
204
- ta_numpy2 = one_output_convert (numpy2 )
205
- ta_series = one_output_convert (series )
206
- ta_df = one_output_convert (df )
255
+ converted = [one_output_convert (x ) for x in to_convert ]
207
256
208
- assert ta_numpy1 .equals (ta_numpy2 )
209
- assert ta_numpy2 .equals (ta_series )
210
- assert ta_series .equals (ta_df )
257
+ for i in range (len (converted ) - 1 ):
258
+ assert converted [i ].equals (converted [i + 1 ])
211
259
212
260
213
261
def test_many_outputs_conversion ():
262
+ """Test many output conversions to PredOutputs, using one row to produce
263
+ List[PredOutputs] with one item"""
214
264
numpy1 = np .arange (0 , 10 )
215
265
numpy2 = np .arange (0 , 10 ).reshape (1 , 10 )
216
266
df = pd .DataFrame (numpy2 , columns = ["output-{}" .format (i ) for i in range (10 )])
@@ -225,6 +275,7 @@ def test_many_outputs_conversion():
225
275
226
276
227
277
def test_many_outputs_conversion2 ():
278
+ """Test many output conversions to many PredOutputs"""
228
279
numpy1 = np .arange (0 , 100 ).reshape (10 , 10 )
229
280
df = pd .DataFrame (numpy1 , columns = ["output-{}" .format (i ) for i in range (10 )])
230
281
@@ -236,6 +287,8 @@ def test_many_outputs_conversion2():
236
287
237
288
238
289
def test_many_inputs_conversion ():
290
+ """Test many input conversions to PredOutputs, using one row to produce
291
+ List[PredInputs] with one item"""
239
292
numpy1 = np .arange (0 , 10 )
240
293
numpy2 = np .arange (0 , 10 ).reshape (1 , 10 )
241
294
df = pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (10 )])
@@ -250,6 +303,7 @@ def test_many_inputs_conversion():
250
303
251
304
252
305
def test_many_inputs_conversion2 ():
306
+ """Test many input conversions to many PredInputs"""
253
307
numpy1 = np .arange (0 , 100 ).reshape (10 , 10 )
254
308
df = pd .DataFrame (numpy1 , columns = ["input-{}" .format (i ) for i in range (10 )])
255
309
@@ -261,6 +315,7 @@ def test_many_inputs_conversion2():
261
315
262
316
263
317
def test_many_inputs_conversion_domained ():
318
+ """Test many input conversions to many PredInputs with domains"""
264
319
n_feats = 5
265
320
n_datapoints = 100
266
321
np .random .seed (0 )
0 commit comments