pathwaycom/pathway · error · TypeError

Filter argument of Table.filter() has to be bool, found {fil

Error message

Filter argument of Table.filter() has to be bool, found {filter_type}.

What it means

Table.filter() evaluates the static type of filter_expression with eval_type and requires exactly dt.BOOL. Anything else — Optional[bool], int, string, or any non-boolean expression — raises TypeError naming the found type. This catches filtering on a nullable boolean column or passing a truthy non-bool expression.

Source

Thrown at python/pathway/internals/table.py:523

            Table: Result has the same schema as `self` and its ids are subset of `self.id`.


        Example:

        >>> import pathway as pw
        >>> vertices = pw.debug.table_from_markdown('''
        ... label outdegree
        ...     1         3
        ...     7         0
        ... ''')
        >>> filtered = vertices.filter(vertices.outdegree == 0)
        >>> pw.debug.compute_and_print(filtered, include_id=False)
        label | outdegree
        7     | 0
        """
        filter_type = self.eval_type(filter_expression)
        if filter_type != dt.BOOL:
            raise TypeError(
                f"Filter argument of Table.filter() has to be bool, found {filter_type}."
            )
        ret = self._filter(filter_expression)
        if (
            filter_col := expr.get_column_filtered_by_is_none(filter_expression)
        ) is not None and filter_col.table == self:
            name = filter_col.name
            dtype = self._columns[name].dtype
            ret = ret.update_types(**{name: dt.unoptionalize(dtype)})
        return ret

    @trace_user_frame
    @desugar
    @check_arg_types
    def split(
        self, split_expression: expr.ColumnExpression
    ) -> tuple[Table[TSchema], Table[TSchema]]:
        """Split a table according to `split_expression` condition.

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Make the predicate explicitly boolean: t.filter(t.flag == True) or t.filter(t.flag.fill(True)) for Optional[bool]
  2. Combine null-safety: t.filter(t.flag.is_not_none() & t.flag.fill(False))
  3. Check the column dtype with t.schema / t['col'].dtype and fix the expression until it evaluates to bool

Example fix

# before
t.filter(t.flag)  # flag: Optional[bool] -> TypeError

# after
t.filter(t.flag.fill(False))
# or
t.filter(t.flag == True)
Defensive patterns

Strategy: type-guard

Validate before calling

def filter_is_bool(table, expression) -> bool:
    return table.eval_type(expression) == pw.dtype(bool) if hasattr(pw, 'dtype') else table.eval_type(expression).__class__.__name__ == 'BOOL'

Type guard

import pathway as pw

def is_bool_predicate(table: pw.Table, expr) -> bool:
    from pathway.internals import dtypes as dt
    return table.eval_type(expr) == dt.BOOL

Prevention

When it happens

Trigger: t.filter(t.flag) where flag is Optional[bool] (schema bool | None); t.filter(t.count) (int column); t.filter(t.name) (string); filtering on a column produced by an expression whose dtype is not exactly bool.

Common situations: Optional columns from connectors with missing values; porting pandas-style boolean masking where any truthy column works; using counts or comparisons-of-None as predicates.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/ce5e91378a2e9399. Report an issue: GitHub.