pathwaycom/pathway · error · TypeError

Index in {expression!r} has to be an int.

Error message

Index in {expression!r} has to be an int.

What it means

Raised by the type interpreter when a JsonGet expression indexes a sequence column (Array/Tuple/List) with an index expression whose dtype is not INT. Pathway requires integer-typed indices for positional access into sequence columns; string keys are only allowed for JSON columns.

Source

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

                )
            if not expression._check_if_exists or default_dtype == dt.JSON:
                return _wrap(expression, dt.JSON)
            else:
                return _wrap(expression, dt.Optional(dt.JSON))
        elif object_dtype.equivalent_to(dt.Optional(dt.JSON)):
            # optional json
            raise TypeError(f"Cannot get from {Json | None}.")
        else:
            # sequence
            if (
                not isinstance(object_dtype, (dt.Array, dt.Tuple, dt.List))
                and object_dtype != dt.ANY
            ):
                raise TypeError(
                    f"Object in {expression!r} has to be a JSON or sequence."
                )
            if index_dtype != dt.INT:
                raise TypeError(f"Index in {expression!r} has to be an int.")

            if isinstance(object_dtype, dt.Array):
                return _wrap(expression, object_dtype.strip_dimension())
            if object_dtype == dt.ANY:
                return _wrap(expression, dt.ANY)

            if isinstance(object_dtype, dt.List):
                if expression._check_if_exists:
                    return _wrap(expression, dt.Optional(object_dtype.wrapped))
                else:
                    return _wrap(expression, object_dtype.wrapped)
            assert isinstance(object_dtype, dt.Tuple)
            if object_dtype == dt.ANY_TUPLE:
                return _wrap(expression, dt.ANY)

            assert not isinstance(object_dtype.args, EllipsisType)
            dtypes = object_dtype.args

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Convert the index column to int before use: t.with_columns(idx=pw.this.idx.astype(int))
  2. Use an int literal for positional access: t.values.get(0)
  3. If the target column is actually JSON (keyed by strings), retype the column as pw.Json instead of List

Example fix

// before
res = t.select(x=t.values.get(t.idx))  # t.idx is str

// after
t = t.with_columns(idx=pw.this.idx.astype(int))
res = t.select(x=t.values.get(t.idx))
Defensive patterns

Strategy: type-guard

Validate before calling

import pathway as pw

def is_int_col(col) -> bool:
    return col._column.dtype.equivalent_to(pw.int_) or col._column.dtype == pw.INT

Type guard

from pathway.internals import dtype as dt

def is_int_dtype(dtype) -> bool:
    return dtype.equivalent_to(dt.INT) or dtype == dt.INT

Try / catch

try:
    out = t.select(x=t.values.get(t.idx))
except TypeError as e:
    if 'has to be an int' in str(e):
        t = t.with_columns(idx=pw.this.idx.astype(int))
        out = t.select(x=t.values.get(t.idx))
    else:
        raise

Prevention

When it happens

Trigger: Calling table.arr_col.get(table.some_str_col), table.tuple_col[table.float_col], or passing a str/float/bool-typed column or literal as the index of a List/Array/Tuple column. Example: t.select(x=t.values.get('0')) where t.values is pw.List and '0' is a string.

Common situations: Index read from CSV as a string column and used without conversion; mixing up JSON key access (string) with sequence access (int); passing a Python str literal where an int literal was intended inside .get().

Related errors


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