Skip to content

daft.functions.list_bool_and#

list_bool_and #

list_bool_and(list_expr: Expression) -> Expression

Calculates the boolean AND of all values in a list.

For each list: - Returns True if all non-null values are True - Returns False if any non-null value is False - Returns null if the list is empty or contains only null values

Parameters:

Name Type Description Default
list_expr List Expression

expression to calculate the boolean AND of.

required

Returns:

Name Type Description
Expression Boolean Expression

an expression with the result of the boolean AND operation.

Examples:

1
2
3
4
>>> import daft
>>> from daft.functions import list_bool_and
>>> df = daft.from_pydict({"values": [[True, True], [True, False], [None, None], []]})
>>> df.with_column("result", list_bool_and(df["values"])).collect()
╭───────────────┬────────╮
│ values        ┆ result │
│ ---           ┆ ---    │
│ List[Bool]    ┆ Bool   │
╞═══════════════╪════════╡
│ [true, true]  ┆ true   │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ [true, false] ┆ false  │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ [None, None]  ┆ None   │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ []            ┆ None   │
╰───────────────┴────────╯
(Showing first 4 of 4 rows)
Source code in daft/functions/list.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def list_bool_and(list_expr: Expression) -> Expression:
    """Calculates the boolean AND of all values in a list.

    For each list:
    - Returns True if all non-null values are True
    - Returns False if any non-null value is False
    - Returns null if the list is empty or contains only null values

    Args:
        list_expr (List Expression): expression to calculate the boolean AND of.

    Returns:
        Expression (Boolean Expression): an expression with the result of the boolean AND operation.

    Examples:
        >>> import daft
        >>> from daft.functions import list_bool_and
        >>> df = daft.from_pydict({"values": [[True, True], [True, False], [None, None], []]})
        >>> df.with_column("result", list_bool_and(df["values"])).collect()
        ╭───────────────┬────────╮
        │ values        ┆ result │
        │ ---           ┆ ---    │
        │ List[Bool]    ┆ Bool   │
        ╞═══════════════╪════════╡
        │ [true, true]  ┆ true   │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
        │ [true, false] ┆ false  │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
        │ [None, None]  ┆ None   │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
        │ []            ┆ None   │
        ╰───────────────┴────────╯
        <BLANKLINE>
        (Showing first 4 of 4 rows)
    """
    return Expression._call_builtin_scalar_fn("list_bool_and", list_expr)