pathwaycom/pathway · error · ValueError

wrong iteration limit

Error message

wrong iteration limit

What it means

pw.iterate() runs a function repeatedly until a fixed point, with an optional iteration_limit guarding against non-convergence. The limit must be at least 1 (None means unlimited); zero or negative limits are rejected immediately as nonsensical before the iteration graph is built.

Source

Thrown at python/pathway/internals/common.py:87

    ...   4
    ...   5
    ...   6
    ...   7
    ...   8''')
    >>> ret = pw.iterate(collatz_transformer, iterated=tab)
    >>> pw.debug.compute_and_print(ret, include_id=False)
    val
    1
    1
    1
    1
    1
    1
    1
    1
    """
    if iteration_limit is not None and iteration_limit < 1:
        raise ValueError("wrong iteration limit")
    fn_spec = function_spec(func)
    return G.add_iterate(
        fn_spec, lambda node: node(**kwargs), iteration_limit=iteration_limit
    )


@check_arg_types
@trace_user_frame
def apply(
    fun: Callable,
    *args: expr.ColumnExpression | Value,
    **kwargs: expr.ColumnExpression | Value,
) -> expr.ColumnExpression:
    """Applies function to column expressions, column-wise.
    Output column type deduced from type-annotations of a function.

    Example:

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Pass a positive limit: iteration_limit=100, or omit it (None) for unlimited iterations.
  2. If 0 conventionally means 'no limit' in your config, translate it: iteration_limit=None if cfg.limit == 0 else cfg.limit.
  3. Add validation of user-supplied limits before calling pw.iterate.

Example fix

# before
pw.iterate(step, iteration_limit=0)

# after
pw.iterate(step, iteration_limit=None)  # unlimited
pw.iterate(step, iteration_limit=1000)   # bounded
Defensive patterns

Strategy: validation

Validate before calling

assert iteration_limit is None or iteration_limit >= 1, 'iteration_limit must be >= 1 or None'

Prevention

When it happens

Trigger: Calling pw.iterate(func, iteration_limit=0) or passing a negative limit, often because a variable intended as a real limit was never set (defaulted to 0) or was computed/decremented to a non-positive value.

Common situations: Configuration read from CLI args/env with a default of 0 meaning 'unlimited' in the user's head but not Pathway's; loops decrementing a limit variable and re-calling iterate with the exhausted value.

Related errors


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