{"record":{"id":"7a46494a4a758bfd","repo":"pathwaycom/pathway","slug":"wrong-output-universe-index-out-of-range","errorCode":null,"errorMessage":"wrong output universe. Index out of range","messagePattern":"wrong output universe\\. Index out of range","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/stdlib/utils/pandas_transformer.py","lineNumber":49,"sourceCode":"        result.append(reduced)\n\n    def _add_tables(first: pw.Table, *tables: pw.Table) -> pw.Table:\n        for table in tables:\n            first += table.with_universe_of(first)\n        return first\n\n    return _add_tables(*result)\n\n\ndef _argument_index(func_spec: FunctionSpec, arg: str | int | None) -> int | None:\n    if isinstance(arg, str):\n        try:\n            return func_spec.arg_names.index(arg)\n        except ValueError:\n            raise ValueError(f\"wrong output universe. No argument of name: {arg}\")\n    elif isinstance(arg, int):\n        if arg < 0 or arg >= len(func_spec.arg_names):\n            raise ValueError(\"wrong output universe. Index out of range\")\n    return arg\n\n\ndef _pandas_transformer(\n    *inputs: pw.Table,\n    func_spec: FunctionSpec,\n    output_schema: type[schema.Schema],\n    output_universe: str | int | None,\n) -> pw.Table:\n    output_universe_arg_index = _argument_index(func_spec, output_universe)\n    func = func_spec.func\n\n    def process_pandas_output(\n        result: pd.DataFrame | pd.Series, pandas_input: list[pd.DataFrame] = []\n    ):\n        if isinstance(result, pd.Series):\n            result = pd.DataFrame(result)\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/stdlib/utils/pandas_transformer.py#L31-L67","documentation":"When output_universe is given as an integer, _argument_index validates it against the number of arguments of the pandas UDF (len(func_spec.arg_names)). A negative index or one >= the argument count raises ValueError('wrong output universe. Index out of range') before the UDF ever runs.","triggerScenarios":"output_universe=1 for a single-argument UDF; output_universe=2 for a two-argument function; using -1 (Python-style negative indexing is rejected); hardcoding an index after removing a UDF parameter.","commonSituations":"Reusing a decorator config from a multi-input UDF on a simpler one; refactoring the UDF signature (dropping an argument) without updating the index; assuming negative indices are supported.","solutions":["Use a valid 0-based index: 0 <= output_universe < number of UDF parameters","Prefer the parameter-name form (output_universe='arg_name') so signature order changes cannot break it","Count the UDF parameters and fix or drop the output_universe argument"],"exampleFix":"# before\n@pw.pandas_transformer(output_universe=1)\ndef f(df: pd.DataFrame) -> pd.DataFrame: ...\n\n# after\n@pw.pandas_transformer(output_universe=0)\ndef f(df: pd.DataFrame) -> pd.DataFrame: ...","handlingStrategy":"validation","validationCode":"import inspect\nn = len(inspect.signature(your_udf).parameters)\nassert isinstance(output_universe, int) and 0 <= output_universe < n, f'output_universe index must be in [0, {n})'","typeGuard":"def output_universe_index_is_valid(func, i: Any) -> bool:\n    import inspect\n    return isinstance(i, int) and 0 <= i < len(inspect.signature(func).parameters)","tryCatchPattern":null,"preventionTips":["Use the argument-name form instead of a bare index","Re-check the decorator config whenever you add/remove UDF parameters","Remember negative indices are rejected even though pandas allows them"],"tags":["pathway","pandas","udf","argument-validation","index-error"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}