From cd8aed7e86cefebd2183f235fac7fa083b6ae258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fred=20Lef=C3=A9v=C3=A8re-Laoide?= <90181748+FredLL-Avaiga@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:39:25 +0200 Subject: [PATCH] scenario filter: handle iterable typed col (#1384) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * scenario filter: handle iterable typed col resolves #1375 * with naming --------- Co-authored-by: Fred Lefévère-Laoide --- taipy/gui_core/_adapters.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/taipy/gui_core/_adapters.py b/taipy/gui_core/_adapters.py index 7acf0e4919..db55c49fbf 100644 --- a/taipy/gui_core/_adapters.py +++ b/taipy/gui_core/_adapters.py @@ -15,6 +15,7 @@ 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 @@ def get_hash(): "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():