瀏覽代碼

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 月之前
父節點
當前提交
cd8aed7e86
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      taipy/gui_core/_adapters.py

+ 5 - 0
taipy/gui_core/_adapters.py

@@ -15,6 +15,7 @@ import math
 import sys
 import typing as t
 from abc import ABC, abstractmethod
+from collections.abc import Iterable
 from dataclasses import dataclass
 from datetime import date, datetime
 from enum import Enum
@@ -246,6 +247,8 @@ _operators: t.Dict[str, t.Callable] = {
     "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(
     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):
             cur_val = attrgetter(col_fn or col)(ent)
             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)
     except Exception as e:
         if _is_debugging():