Calculates the boolean AND of all values in the expression.
For each group: - Returns True if all non-null values are True - Returns False if any non-null value is False - Returns null if the group is empty or contains only null values
Examples:
| >>> import daft
>>> from daft.functions import bool_and
>>> df = daft.from_pydict({"a": [True, None, True], "b": [True, False, None], "c": [None, None, None]})
>>> df.agg(bool_and(df["a"]), bool_and(df["b"]), bool_and(df["c"])).show()
|
╭──────┬───────┬──────╮
│ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- │
│ Bool ┆ Bool ┆ Bool │
╞══════╪═══════╪══════╡
│ true ┆ false ┆ None │
╰──────┴───────┴──────╯
(Showing first 1 of 1 rows)
Source code in daft/functions/agg.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231 | def bool_and(expr: Expression) -> Expression:
"""Calculates the boolean AND of all values in the expression.
For each group:
- Returns True if all non-null values are True
- Returns False if any non-null value is False
- Returns null if the group is empty or contains only null values
Examples:
>>> import daft
>>> from daft.functions import bool_and
>>> df = daft.from_pydict({"a": [True, None, True], "b": [True, False, None], "c": [None, None, None]})
>>> df.agg(bool_and(df["a"]), bool_and(df["b"]), bool_and(df["c"])).show()
╭──────┬───────┬──────╮
│ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- │
│ Bool ┆ Bool ┆ Bool │
╞══════╪═══════╪══════╡
│ true ┆ false ┆ None │
╰──────┴───────┴──────╯
<BLANKLINE>
(Showing first 1 of 1 rows)
"""
return Expression._from_pyexpr(expr._expr.bool_and())
|