{"record":{"id":"cacbb10045e9a608","repo":"pathwaycom/pathway","slug":"index-n","errorCode":null,"errorMessage":"Index n","messagePattern":"Index n","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/type_interpreter.py","lineNumber":570,"sourceCode":"            assert not isinstance(object_dtype.args, EllipsisType)\n            dtypes = object_dtype.args\n\n            if (\n                expression._const_index is None\n            ):  # no specified position, index is an Expression\n                assert isinstance(dtypes[0], dt.DType)\n                return_dtype = dtypes[0]\n                for dtype in dtypes[1:]:\n                    if isinstance(dtype, dt.DType):\n                        return_dtype = dt.types_lca(return_dtype, dtype, raising=False)\n                if expression._check_if_exists:\n                    return_dtype = dt.types_lca(\n                        return_dtype, default_dtype, raising=False\n                    )\n                return _wrap(expression, return_dtype)\n\n            if not isinstance(expression._const_index, int):\n                raise IndexError(\"Index n\")\n\n            try:\n                try_ret = dtypes[expression._const_index]\n                return _wrap(expression, try_ret)\n            except IndexError:\n                message = (\n                    f\"Index {expression._const_index} out of range for a tuple of\"\n                    + f\" type {object_dtype.typehint}.\"\n                )\n                if expression._check_if_exists:\n                    expression_info = get_expression_info(expression)\n                    warnings.warn(\n                        message\n                        + \" It refers to the following expression:\\n\"\n                        + expression_info\n                        + \"Consider using just the default value without .get().\"\n                    )\n                    return _wrap(expression, default_dtype)","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/type_interpreter.py#L552-L588","documentation":"Raised as IndexError('Index n') when a Tuple-typed column is accessed with an index expression that is not a compile-time integer constant. Pathway's type interpreter must resolve tuple element types statically, so dynamic (row-dependent) or non-integer indices into a Tuple are not supported.","triggerScenarios":"Calling t.tuple_col.get(t.some_column) or t.tuple_col[i_as_str] where the tuple column is typed as a heterogeneous Tuple (e.g. Tuple[int, str]) and the index is a column expression, float, or string instead of an int literal. Dynamic indexing works only for List/Array (homogeneous), not Tuple.","commonSituations":"Developer indexes a Tuple with a per-row column value; schema changed from List to Tuple and previously working dynamic access now fails; index computed as float (e.g. from division) instead of int.","solutions":["Use a constant int index for Tuple columns: t.tuple_col.get(1)","If the index must be dynamic, retype the column as pw.List or pw.Array (homogeneous elements) so dynamic int indexing is allowed","Convert a computed index to a constant via apply/apply_with_type returning the element directly"],"exampleFix":"// before\nres = t.select(x=t.tup.get(t.i))  # t.i is a column -> not a const int\n\n// after (dynamic index needs List, not Tuple)\nschema_tup = pw.schema_from_types(tup=pw.List[int])\n# or constant index:\nres = t.select(x=t.tup.get(1))","handlingStrategy":"validation","validationCode":"import pathway as pw\n\ndef tuple_const_get(tup_col, index):\n    # only constant ints are allowed on Tuple columns\n    assert isinstance(index, int) and not isinstance(index, bool), (\n        'Tuple access requires a constant int index'\n    )\n    return tup_col.get(index)","typeGuard":"def is_const_int_index(expr) -> bool:\n    ci = getattr(expr, '_const_index', None)\n    return isinstance(ci, int) and not isinstance(ci, bool)","tryCatchPattern":"try:\n    res = t.select(x=t.tup.get(idx))\nexcept IndexError as e:\n    if str(e) == 'Index n':\n        raise ValueError('Dynamic indices need pw.List, not pw.Tuple; retype the column') from e\n    raise","preventionTips":["Use constant int literals for Tuple column access","Use pw.List/pw.Array for per-row dynamic indexing","Encode element access logic inside pw.apply/apply_with_type when the index is data-driven"],"tags":["pathway","types","tuple","indexing"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}