diff --git a/src/koza/utils/row_filter.py b/src/koza/utils/row_filter.py index 5214af0..43b6771 100644 --- a/src/koza/utils/row_filter.py +++ b/src/koza/utils/row_filter.py @@ -22,6 +22,7 @@ def __init__(self, filters: List[ColumnFilter] = None): 'eq': eq, 'ne': ne, 'in': self.inlist, # not using operator.contains because the it expects opposite argument order + 'in_exact': self.inlist_exact, # not using operator.contains because the it expects opposite argument order } def include_row(self, row) -> bool: @@ -52,5 +53,24 @@ def include_row(self, row) -> bool: return include_row - def inlist(self, column_value, filter_value): - return column_value in filter_value + def inlist(self, column_value, filter_values): + print('FILTER VALUES',filter_values) + #Check if the passed in column is exactly matched against + #For a filter_list of ['abc','def','ghi']; this will be true + #for column_value 'abc' but not 'abcde.' + col_exact_match = column_value in filter_values + #The following iterates through all filters and will return true if + #the text of the filter is found within the column_value. + #So for the above example this boolean will return True, because :'abc' in 'abcde': returns True. + if(type(column_value)==str): + col_inexact_match = any([filter_value in column_value for filter_value in filter_values]) + else: + col_inexact_match = False + return col_exact_match or col_inexact_match + + def inlist_exact(self, column_value, filter_values): + #Check if the passed in column is exactly matched against + #For a filter_list of ['abc','def','ghi']; this will be true + #for column_value 'abc' but not 'abcde.' + col_exact_match = column_value in filter_values + return col_exact_match