@@ -153,64 +153,114 @@ def test_feature_domains():
153153
154154
155155def test_one_input_conversion ():
156+ """Test one input conversions to one PredInput"""
156157 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+ ]
160167
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 ]
165169
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 ])
169172
170173
171174def test_one_input_conversion_domained ():
175+ """Test one input conversions with domains to one PredInput"""
172176 n_feats = 5
173177 np .random .seed (0 )
174-
178+ numpy1 = np .arange (0 , n_feats )
179+ numpy2 = numpy1 .reshape (1 , n_feats )
175180 domain_bounds = [[np .random .rand (), np .random .rand ()] for _ in range (n_feats )]
176181 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 )])
181182
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 )
186206
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+ ]
191215
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 ])
195220
196221
197222def test_one_output_conversion ():
223+ """Test one output conversions to one PredOutput"""
198224 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+ ]
202254
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 ]
207256
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 ])
211259
212260
213261def test_many_outputs_conversion ():
262+ """Test many output conversions to PredOutputs, using one row to produce
263+ List[PredOutputs] with one item"""
214264 numpy1 = np .arange (0 , 10 )
215265 numpy2 = np .arange (0 , 10 ).reshape (1 , 10 )
216266 df = pd .DataFrame (numpy2 , columns = ["output-{}" .format (i ) for i in range (10 )])
@@ -225,6 +275,7 @@ def test_many_outputs_conversion():
225275
226276
227277def test_many_outputs_conversion2 ():
278+ """Test many output conversions to many PredOutputs"""
228279 numpy1 = np .arange (0 , 100 ).reshape (10 , 10 )
229280 df = pd .DataFrame (numpy1 , columns = ["output-{}" .format (i ) for i in range (10 )])
230281
@@ -236,6 +287,8 @@ def test_many_outputs_conversion2():
236287
237288
238289def test_many_inputs_conversion ():
290+ """Test many input conversions to PredOutputs, using one row to produce
291+ List[PredInputs] with one item"""
239292 numpy1 = np .arange (0 , 10 )
240293 numpy2 = np .arange (0 , 10 ).reshape (1 , 10 )
241294 df = pd .DataFrame (numpy2 , columns = ["input-{}" .format (i ) for i in range (10 )])
@@ -250,6 +303,7 @@ def test_many_inputs_conversion():
250303
251304
252305def test_many_inputs_conversion2 ():
306+ """Test many input conversions to many PredInputs"""
253307 numpy1 = np .arange (0 , 100 ).reshape (10 , 10 )
254308 df = pd .DataFrame (numpy1 , columns = ["input-{}" .format (i ) for i in range (10 )])
255309
@@ -261,6 +315,7 @@ def test_many_inputs_conversion2():
261315
262316
263317def test_many_inputs_conversion_domained ():
318+ """Test many input conversions to many PredInputs with domains"""
264319 n_feats = 5
265320 n_datapoints = 100
266321 np .random .seed (0 )
0 commit comments