pathwaycom/pathway · error · ValueError
wrong output universe. Index out of range
Error message
wrong output universe. Index out of range
What it means
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.
Source
Thrown at python/pathway/stdlib/utils/pandas_transformer.py:49
result.append(reduced)
def _add_tables(first: pw.Table, *tables: pw.Table) -> pw.Table:
for table in tables:
first += table.with_universe_of(first)
return first
return _add_tables(*result)
def _argument_index(func_spec: FunctionSpec, arg: str | int | None) -> int | None:
if isinstance(arg, str):
try:
return func_spec.arg_names.index(arg)
except ValueError:
raise ValueError(f"wrong output universe. No argument of name: {arg}")
elif isinstance(arg, int):
if arg < 0 or arg >= len(func_spec.arg_names):
raise ValueError("wrong output universe. Index out of range")
return arg
def _pandas_transformer(
*inputs: pw.Table,
func_spec: FunctionSpec,
output_schema: type[schema.Schema],
output_universe: str | int | None,
) -> pw.Table:
output_universe_arg_index = _argument_index(func_spec, output_universe)
func = func_spec.func
def process_pandas_output(
result: pd.DataFrame | pd.Series, pandas_input: list[pd.DataFrame] = []
):
if isinstance(result, pd.Series):
result = pd.DataFrame(result)
View on GitHub (pinned to fa2f74a464)
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
Example fix
# before @pw.pandas_transformer(output_universe=1) def f(df: pd.DataFrame) -> pd.DataFrame: ... # after @pw.pandas_transformer(output_universe=0) def f(df: pd.DataFrame) -> pd.DataFrame: ...
Defensive patterns
Strategy: validation
Validate before calling
import inspect
n = len(inspect.signature(your_udf).parameters)
assert isinstance(output_universe, int) and 0 <= output_universe < n, f'output_universe index must be in [0, {n})' Type guard
def output_universe_index_is_valid(func, i: Any) -> bool:
import inspect
return isinstance(i, int) and 0 <= i < len(inspect.signature(func).parameters) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- wrong output universe. No argument of name: {arg}
- resulting universe does not match the universe of the indica
- index of resulting DataFrame must be unique
- direction argument of join should be of type asof_join.Direc
- The behavior argument of join should be of type pathway.temp
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/7a46494a4a758bfd.
Report an issue: GitHub.