From 53582ff34abed92d89e43a40a8ec1becf238c762 Mon Sep 17 00:00:00 2001 From: Stefan Vigerske Date: Thu, 22 Oct 2026 14:48:51 +0200 Subject: [PATCH] do not raise exceptions when filters could not be applied - when, e.g., some column is not available with the data, then skip the filter - when a filter could not be applied, treat this as if no instance survived the filter; it will then be deactivated because it is empty --- ipet/evaluation/IPETEvalTable.py | 5 +++-- ipet/evaluation/IPETFilter.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ipet/evaluation/IPETEvalTable.py b/ipet/evaluation/IPETEvalTable.py index 2301943..4436910 100644 --- a/ipet/evaluation/IPETEvalTable.py +++ b/ipet/evaluation/IPETEvalTable.py @@ -1786,7 +1786,7 @@ def evaluate(self, exp : Experiment): filtergroupdata = self.applyFilterGroup(reduceddata, fg, self.getRowIndex()) if (len(filtergroupdata) == 0): nonemptyactivefiltergroups.remove(fg) - logger.warning("Filtergroup {} is empty and has been deactived.".format(fg.getName())) + logger.warning("Filtergroup {} is empty and has been deactivated.".format(fg.getName())) continue logger.debug("Reduced data for filtergroup {} is:\n{}".format(fg.getName(), filtergroupdata)) self.filtered_instancewise[fg.name] = self.convertToHorizontalFormat(filtergroupdata) @@ -2019,7 +2019,8 @@ def computeFilterResults(self, df : pd.DataFrame): # # store the result (either by applying the filter, or by copying) # - f.storeResult(df, fcol) + if fcol is not None: + f.storeResult(df, fcol) if __name__ == '__main__': diff --git a/ipet/evaluation/IPETFilter.py b/ipet/evaluation/IPETFilter.py index d833427..7dfaf68 100644 --- a/ipet/evaluation/IPETFilter.py +++ b/ipet/evaluation/IPETFilter.py @@ -95,8 +95,8 @@ def compare(self, x, y): try: return method(x, y) except TypeError as t: - logger.error("Got type error %s comparing elements x:%s and y:%s" % (t, x, y)) - return 0 + logger.warning("Got type error %s comparing elements x:%s and y:%s" % (t, str(x).split('\n')[0], str(y).split('\n')[0])) + return None def method_le(self, x, y): return x <= y @@ -328,6 +328,8 @@ def applyListOperator(self, df, groupindex): | one |equal |True, if at least one value occurs twice in a group | | all |equal |True, if there is only a single value for this group | """ + if self.datakey not in df.columns: + return None # # 1. chose the right list function @@ -419,7 +421,11 @@ def applyFilter(self, df, groupindex = None): """ if self.operator in self.listoperators: filtercol = self.applyListOperator(df, groupindex) + if filtercol is None: + return None elif self.operator in self.valueoperators: + if self.datakey not in df.columns: + return None filtercol = self.applyValueOperator(df[[self.datakey]]) else: @@ -434,6 +440,8 @@ def applyFilter(self, df, groupindex = None): except: pass filtercol = self.comparison.compare(x, y) + if filtercol is None: + return None if groupindex is None: return filtercol @@ -661,6 +669,8 @@ def filterDataFrame(self, df, index): else: # apply the filter to the data frame rowwise and store the result in a temporary boolean column fcol = f_.applyFilter(df, index) + if fcol is None: + return [False]*len(df.index) if intersection_index is not None: intersection_index = intersection_index & fcol