Skip to content

Commit

Permalink
scenario filter: handle iterable typed col (#1384)
Browse files Browse the repository at this point in the history
* scenario filter: handle iterable typed col
resolves #1375

* with naming

---------

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Jun 10, 2024
1 parent f0656ce commit cd8aed7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions taipy/gui_core/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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():
Expand Down

0 comments on commit cd8aed7

Please sign in to comment.