Browse Source

scenario filter: handle iterable typed col (#1384)

* scenario filter: handle iterable typed col
resolves #1375

* with naming

---------

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 11 months ago
parent
commit
cd8aed7e86
1 changed files with 5 additions and 0 deletions
  1. 5 0
      taipy/gui_core/_adapters.py

+ 5 - 0
taipy/gui_core/_adapters.py

@@ -15,6 +15,7 @@ import math
 import sys
 import sys
 import typing as t
 import typing as t
 from abc import ABC, abstractmethod
 from abc import ABC, abstractmethod
+from collections.abc import Iterable
 from dataclasses import dataclass
 from dataclasses import dataclass
 from datetime import date, datetime
 from datetime import date, datetime
 from enum import Enum
 from enum import Enum
@@ -246,6 +247,8 @@ _operators: t.Dict[str, t.Callable] = {
     "contains": contains,
     "contains": contains,
 }
 }
 
 
+def _filter_iterable(list_val: Iterable, operator: t.Callable, val: t.Any):
+    return next(filter(lambda v: operator(v, val), list_val), None) is not None
 
 
 def _invoke_action(
 def _invoke_action(
     ent: t.Any, col: str, col_type: str, is_dn: bool, action: str, val: t.Any, col_fn: t.Optional[str]
     ent: t.Any, col: str, col_type: str, is_dn: bool, action: str, val: t.Any, col_fn: t.Optional[str]
@@ -260,6 +263,8 @@ def _invoke_action(
         if op := _operators.get(action):
         if op := _operators.get(action):
             cur_val = attrgetter(col_fn or col)(ent)
             cur_val = attrgetter(col_fn or col)(ent)
             cur_val = cur_val() if col_fn else cur_val
             cur_val = cur_val() if col_fn else cur_val
+            if isinstance(cur_val, Iterable):
+                return _filter_iterable(cur_val, op, val)
             return op(cur_val.isoformat() if isinstance(cur_val, (datetime, date)) else cur_val, val)
             return op(cur_val.isoformat() if isinstance(cur_val, (datetime, date)) else cur_val, val)
     except Exception as e:
     except Exception as e:
         if _is_debugging():
         if _is_debugging():