{"record":{"id":"53079dbbd70e625b","repo":"pathwaycom/pathway","slug":"index-in-expression-r-has-to-be-an-int","errorCode":null,"errorMessage":"Index in {expression!r} has to be an int.","messagePattern":"Index in (.+?) has to be an int\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/type_interpreter.py","lineNumber":536,"sourceCode":"                )\n            if not expression._check_if_exists or default_dtype == dt.JSON:\n                return _wrap(expression, dt.JSON)\n            else:\n                return _wrap(expression, dt.Optional(dt.JSON))\n        elif object_dtype.equivalent_to(dt.Optional(dt.JSON)):\n            # optional json\n            raise TypeError(f\"Cannot get from {Json | None}.\")\n        else:\n            # sequence\n            if (\n                not isinstance(object_dtype, (dt.Array, dt.Tuple, dt.List))\n                and object_dtype != dt.ANY\n            ):\n                raise TypeError(\n                    f\"Object in {expression!r} has to be a JSON or sequence.\"\n                )\n            if index_dtype != dt.INT:\n                raise TypeError(f\"Index in {expression!r} has to be an int.\")\n\n            if isinstance(object_dtype, dt.Array):\n                return _wrap(expression, object_dtype.strip_dimension())\n            if object_dtype == dt.ANY:\n                return _wrap(expression, dt.ANY)\n\n            if isinstance(object_dtype, dt.List):\n                if expression._check_if_exists:\n                    return _wrap(expression, dt.Optional(object_dtype.wrapped))\n                else:\n                    return _wrap(expression, object_dtype.wrapped)\n            assert isinstance(object_dtype, dt.Tuple)\n            if object_dtype == dt.ANY_TUPLE:\n                return _wrap(expression, dt.ANY)\n\n            assert not isinstance(object_dtype.args, EllipsisType)\n            dtypes = object_dtype.args\n","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/type_interpreter.py#L518-L554","documentation":"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.","triggerScenarios":"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.","commonSituations":"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().","solutions":["Convert the index column to int before use: t.with_columns(idx=pw.this.idx.astype(int))","Use an int literal for positional access: t.values.get(0)","If the target column is actually JSON (keyed by strings), retype the column as pw.Json instead of List"],"exampleFix":"// before\nres = t.select(x=t.values.get(t.idx))  # t.idx is str\n\n// after\nt = t.with_columns(idx=pw.this.idx.astype(int))\nres = t.select(x=t.values.get(t.idx))","handlingStrategy":"type-guard","validationCode":"import pathway as pw\n\ndef is_int_col(col) -> bool:\n    return col._column.dtype.equivalent_to(pw.int_) or col._column.dtype == pw.INT","typeGuard":"from pathway.internals import dtype as dt\n\ndef is_int_dtype(dtype) -> bool:\n    return dtype.equivalent_to(dt.INT) or dtype == dt.INT","tryCatchPattern":"try:\n    out = t.select(x=t.values.get(t.idx))\nexcept TypeError as e:\n    if 'has to be an int' in str(e):\n        t = t.with_columns(idx=pw.this.idx.astype(int))\n        out = t.select(x=t.values.get(t.idx))\n    else:\n        raise","preventionTips":["Keep index columns typed as int in schemas","Cast index columns with .astype(int) right after reading from string-heavy sources like CSV","Remember string keys are only valid on pw.Json columns"],"tags":["pathway","types","indexing","json"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}