pathwaycom/pathway · error · ValueError

output: {result_schema} of the iterated function does not c

Error message

output: {result_schema}  of the iterated function does not correspond to the input: {input_schema}

What it means

During iteration (pw.iterate / transform_iterate), Pathway feeds each output table back as the input of the next step, so every returned table must have exactly the same column schema as the correspondingly named input table. This code compares input_schema to result_schema via schema._dtypes() and raises when they differ, because a fixed-point iteration cannot change types between steps.

Source

Thrown at python/pathway/internals/operator.py:383

                raise TypeError(f"{name} has to be a Table instead of {type(arg)}")

        assert all(isinstance(table, pw.Table) for table in input)

        # call iteration logic with copied input and sort result by input order
        raw_result = self.func_spec.func(**input_copy, **iterated_with_universe_copy)
        arg_tuple = as_arg_tuple(raw_result)
        result = arg_tuple.process_input(input)
        if not iterated_with_universe_copy.is_key_subset_of(result):
            raise ValueError(
                "not all arguments marked as iterated returned from iteration"
            )
        for name, table in result.items():
            input_table: pw.Table = input[name]
            assert isinstance(table, pw.Table)
            input_schema = input_table.schema._dtypes()
            result_schema = table.schema._dtypes()
            if input_schema != result_schema:
                raise ValueError(
                    f"output: {result_schema}  of the iterated function does not correspond to the input: {input_schema}"  # noqa
                )
            table._sort_columns_by_other(input_table)

        # designate iterated arguments
        self.iterated_with_universe = input.intersect_keys(iterated_with_universe_copy)
        self.iterated = input.intersect_keys(result).subtract_keys(
            iterated_with_universe_copy
        )
        self.extra = input.subtract_keys(result)

        # do the same for proxied arguments
        self.iterated_with_universe_copy = iterated_with_universe_copy
        self.iterated_copy = input_copy.intersect_keys(result).subtract_keys(
            iterated_with_universe_copy
        )
        self.extra_copy = input_copy.subtract_keys(self.iterated_copy)

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Make the returned schema identical to the input schema: keep exactly the same column names and dtypes, e.g. return t.select(*pw.iterate_kwargs) style patterns or explicitly reselect the original columns.
  2. Remove temporary/helper columns before returning (t.select(t.x, t.y) without the helper), or drop(*) the extras.
  3. If you must change the shape, compute it outside the iterate loop: run pw.iterate on a stable-schema table, then transform the fixed point afterwards.

Example fix

# before
@pw.table_transformer
def step(t: pw.Table):
    return t.select(rank=t.rank + 1, tmp=t.degree)  # adds 'tmp'

# after
@pw.table_transformer
def step(t: pw.Table):
    return t.select(rank=t.rank + 1)  # same columns as input
Defensive patterns

Strategy: validation

Validate before calling

import pathway as pw

def schemas_stable(inputs: dict, outputs: dict) -> bool:
    return all(
        name in outputs and inputs[name].schema._dtypes() == outputs[name].schema._dtypes()
        for name in inputs
    )

Prevention

When it happens

Trigger: A @pw.table_transformer iteration function that renames columns, adds or removes columns, or changes a column's dtype in its returned table, e.g. input {'v': int} but the returned table has {'v': float} or {'v': int, 'extra': str}.

Common situations: Refactoring an iterative transformer (e.g. graph algorithms like PageRank connected components) and adding a helper column to the output; casting a column inside select(); or a transformer that returns a reduced table with fewer columns.

Related errors


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