diff --git a/ibis/expr/types/arrays.py b/ibis/expr/types/arrays.py index ba02a91634ef..65c99c5ca8d8 100644 --- a/ibis/expr/types/arrays.py +++ b/ibis/expr/types/arrays.py @@ -393,6 +393,36 @@ def map(self, func: Callable[[ir.Value], ir.Value]) -> ir.ArrayValue: │ [104.0] │ │ [] │ └───────────────────────┘ + + `.map()` also supports more complex callables like `functools.partial` + and lambdas with closures + + >>> from functools import partial + >>> def add(x, y): + ... return x + y + ... + >>> add2 = partial(add, y=2) + >>> t.a.map(add2) + ┏━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ArrayMap(a) ┃ + ┡━━━━━━━━━━━━━━━━━━━━━━┩ + │ array │ + ├──────────────────────┤ + │ [3, None, ... +1] │ + │ [6] │ + │ [] │ + └──────────────────────┘ + >>> y = 2 + >>> t.a.map(lambda x: x + y) + ┏━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ArrayMap(a) ┃ + ┡━━━━━━━━━━━━━━━━━━━━━━┩ + │ array │ + ├──────────────────────┤ + │ [3, None, ... +1] │ + │ [6] │ + │ [] │ + └──────────────────────┘ """ @functools.wraps(func) @@ -441,6 +471,36 @@ def filter( │ [4] │ │ [] │ └──────────────────────┘ + + `.filter()` also supports more complex callables like `functools.partial` + and lambdas with closures + + >>> from functools import partial + >>> def gt(x, y): + ... return x > y + ... + >>> gt1 = partial(gt, y=1) + >>> t.a.filter(gt1) + ┏━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ArrayFilter(a) ┃ + ┡━━━━━━━━━━━━━━━━━━━━━━┩ + │ array │ + ├──────────────────────┤ + │ [2] │ + │ [4] │ + │ [] │ + └──────────────────────┘ + >>> y = 1 + >>> t.a.filter(lambda x: x > y) + ┏━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ArrayFilter(a) ┃ + ┡━━━━━━━━━━━━━━━━━━━━━━┩ + │ array │ + ├──────────────────────┤ + │ [2] │ + │ [4] │ + │ [] │ + └──────────────────────┘ """ @functools.wraps(predicate)