aboutsummaryrefslogtreecommitdiff
path: root/venv/lib/python3.8/site-packages/narwhals/_ibis/expr_struct.py
blob: f268281297e15e541ddbf7d3e3bb512416d976e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import ibis.expr.types as ir

    from narwhals._ibis.expr import IbisExpr


class IbisExprStructNamespace:
    def __init__(self, expr: IbisExpr) -> None:
        self._compliant_expr = expr

    def field(self, name: str) -> IbisExpr:
        def func(expr: ir.StructColumn) -> ir.Column:
            return expr[name]

        return self._compliant_expr._with_callable(func).alias(name)