@@ -204,14 +204,13 @@ def __init__(
204204 def _normalize_probabilities (self , weights ):
205205 if len (weights ) == 0 :
206206 return weights
207- else :
208- weights = np .array (weights )
209- if np .any (weights < 0 ):
210- raise AssertionError ("Probabilities must be greater than or equal to zero." )
211- if np .all (weights == 0 ):
212- raise AssertionError ("At least one probability must be greater than zero." )
213- weights = weights / weights .sum ()
214- return list (weights )
207+ weights = np .array (weights )
208+ if np .any (weights < 0 ):
209+ raise AssertionError ("Probabilities must be greater than or equal to zero." )
210+ if np .all (weights == 0 ):
211+ raise AssertionError ("At least one probability must be greater than zero." )
212+ weights = weights / weights .sum ()
213+ return list (weights )
215214
216215 def flatten (self ):
217216 transforms = []
@@ -232,16 +231,15 @@ def flatten(self):
232231 def __call__ (self , data ):
233232 if len (self .transforms ) == 0 :
234233 return data
235- else :
236- index = self .R .multinomial (1 , self .weights ).argmax ()
237- _transform = self .transforms [index ]
238- data = apply_transform (_transform , data , self .map_items , self .unpack_items )
239- # if the data is a mapping (dictionary), append the OneOf transform to the end
240- if isinstance (data , Mapping ):
241- for key in data .keys ():
242- if key + InverseKeys .KEY_SUFFIX in data :
243- self .push_transform (data , key , extra_info = {"index" : index })
244- return data
234+ index = self .R .multinomial (1 , self .weights ).argmax ()
235+ _transform = self .transforms [index ]
236+ data = apply_transform (_transform , data , self .map_items , self .unpack_items )
237+ # if the data is a mapping (dictionary), append the OneOf transform to the end
238+ if isinstance (data , Mapping ):
239+ for key in data .keys ():
240+ if key + InverseKeys .KEY_SUFFIX in data :
241+ self .push_transform (data , key , extra_info = {"index" : index })
242+ return data
245243
246244 def inverse (self , data ):
247245 if len (self .transforms ) == 0 :
0 commit comments