@@ -566,18 +566,29 @@ def run_random_search(self):
566566 print (f"metric_to_rank_by is: '{ self .metric_to_rank_by } '" )
567567 print (
568568 f"Type of metric_to_rank_by is: { str (type (self .metric_to_rank_by ))} " )
569+ def has_valid_metric (num ):
570+ try :
571+ float (num )
572+ return True
573+ except Exception as exc :
574+ print (exc )
575+ return False
576+ rows_having_a_valid_metric = oracles [self .metric_to_rank_by ].apply (lambda x : has_valid_metric (x ))
577+ oracles_having_valid_metrics = oracles [rows_having_a_valid_metric ]
578+
569579 if self .direction == "maximize" or self .direction == "max" :
570-
571- best = float (oracles [oracles [self .metric_to_rank_by ]
572- != self .metric_to_rank_by ]
573- [self .metric_to_rank_by ].astype (float ).max ())
580+ best = float ( oracles_having_valid_metrics [ self . metric_to_rank_by ]. astype ( float ). max ())
581+ # best = float(oracles[oracles[self.metric_to_rank_by]
582+ # != self.metric_to_rank_by]
583+ # [self.metric_to_rank_by].astype(float).max())
574584 else :
575585 print (f"metric_to_rank_by is: '{ self .metric_to_rank_by } '" )
576586 print (
577587 f"Type of metric_to_rank_by is: { str (type (self .metric_to_rank_by ))} " )
578- best = float (oracles [oracles [self .metric_to_rank_by ]
579- != self .metric_to_rank_by ]
580- [self .metric_to_rank_by ].astype (float ).min ())
588+ best = float (oracles_having_valid_metrics [self .metric_to_rank_by ].astype (float ).min ())
589+ # best = float(oracles[oracles[self.metric_to_rank_by]
590+ # != self.metric_to_rank_by]
591+ # [self.metric_to_rank_by].astype(float).min())
581592 print (f"Best result this trial was: { best } " )
582593 print (f"Type of best result: { type (best )} " )
583594 self .best_model_path = \
0 commit comments