pathwaycom/pathway · error · IndexError

Index {expression._const_index} out of range for a tuple of

Error message

Index {expression._const_index} out of range for a tuple of type {object_dtype.typehint}.

What it means

Raised when a constant int index is out of range for a Tuple-typed column. The interpreter looks up dtypes[const_index]; on IndexError it emits either a warning (if .get() with a default was used, telling you the tuple type can never contain that index so the default will always be returned) or raises this IndexError for plain access.

Source

Thrown at python/pathway/internals/type_interpreter.py:590

            try:
                try_ret = dtypes[expression._const_index]
                return _wrap(expression, try_ret)
            except IndexError:
                message = (
                    f"Index {expression._const_index} out of range for a tuple of"
                    + f" type {object_dtype.typehint}."
                )
                if expression._check_if_exists:
                    expression_info = get_expression_info(expression)
                    warnings.warn(
                        message
                        + " It refers to the following expression:\n"
                        + expression_info
                        + "Consider using just the default value without .get()."
                    )
                    return _wrap(expression, default_dtype)
                else:
                    raise IndexError(message)

    def eval_method_call(
        self,
        expression: expr.MethodCallExpression,
        state: TypeInterpreterState | None = None,
        **kwargs,
    ) -> expr.MethodCallExpression:
        expression = super().eval_method_call(expression, state=state, **kwargs)
        dtypes = tuple([arg._dtype for arg in expression._args])
        if (dtypes_and_handler := expression.get_function(dtypes)) is not None:
            return _wrap(expression, dt.wrap(dtypes_and_handler[1]))

        if len(dtypes) > 0:
            with_arguments = (
                f" with arguments of type {[dtype.typehint for dtype in dtypes[1:]]}"
            )
        else:
            with_arguments = ""

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Use an index within the declared tuple length (0 .. len-1)
  2. Update the schema if the data actually has more elements: Tuple[int, str, float]
  3. If tuple length varies per row, use pw.Json or a List type and dynamic int access instead of Tuple
  4. If you used .get(default), heed the warning: the default will always be returned, so replace tup.get(5, default) with just default

Example fix

// before
schema = pw.schema_from_types(tup=pw.Tuple[int, str])
res = t.select(x=t.tup.get(5, 0))

// after
schema = pw.schema_from_types(tup=pw.Tuple[int, str, float, int, int, int])
res = t.select(x=t.tup.get(5, 0))
Defensive patterns

Strategy: validation

Validate before calling

from pathway.internals import dtype as dt

def tuple_index_ok(tuple_dtype, n: int) -> bool:
    return isinstance(tuple_dtype, dt.Tuple) and 0 <= n < len(tuple_dtype.args)

Type guard

from pathway.internals import dtype as dt

def is_in_range_tuple(tuple_dtype, n: int) -> bool:
    return isinstance(tuple_dtype, dt.Tuple) and 0 <= n < len(tuple_dtype.args)

Try / catch

try:
    v = t.tup[5]
except IndexError as e:
    if 'out of range for a tuple' in str(e):
        v = DEFAULT  # or fix the schema
    else:
        raise

Prevention

When it happens

Trigger: t.tuple_col.get(5) where the column is Tuple[int, str] (valid indices 0..1); t.tup[3] with a 2-element tuple type. With .get() it degrades to a UserWarning suggesting to drop .get() and use the default directly; without .get() it raises.

Common situations: Schema tuple length changed (fewer elements) and old index now out of range; off-by-one in index; index computed from user config exceeding tuple length; developer expects runtime-length tuples but schema declares a fixed-length Tuple.

Related errors


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