{"record":{"id":"827040e1ddddb1bd","repo":"pola-rs/polars","slug":"cannot-pass-a-dictionary-as-a-single-positional-ar","errorCode":null,"errorMessage":"Cannot pass a dictionary as a single positional argument.\nIf you merely want the *keys*, use:\n  • df.method(*your_dict.keys())\nIf you need the key value pairs, use one of:\n  • unpack as keywords:    df.method(**your_dict)\n  • build expressions:     df.method(expr.alias(k) for k, expr in your_dict.items())","messagePattern":"Cannot pass a dictionary as a single positional argument\\.\nIf you merely want the \\*keys\\*, use:\n  • df\\.method\\(\\*your_dict\\.keys\\(\\)\\)\nIf you need the key value pairs, use one of:\n  • unpack as keywords:    df\\.method\\(\\*\\*your_dict\\)\n  • build expressions:     df\\.method\\(expr\\.alias\\(k\\) for k, expr in your_dict\\.items\\(\\)\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/parse/expr.py","lineNumber":240,"sourceCode":"\n\ndef _parse_inputs_as_iterable(\n    inputs: tuple[Any, ...] | tuple[Iterable[Any]],\n) -> Iterable[Any]:\n    if not inputs:\n        return []\n\n    # Ensures that the outermost element cannot be a Dictionary (as an iterable)\n    if len(inputs) == 1 and isinstance(inputs[0], Mapping):\n        msg = (\n            \"Cannot pass a dictionary as a single positional argument.\\n\"\n            \"If you merely want the *keys*, use:\\n\"\n            \"  • df.method(*your_dict.keys())\\n\"\n            \"If you need the key value pairs, use one of:\\n\"\n            \"  • unpack as keywords:    df.method(**your_dict)\\n\"\n            \"  • build expressions:     df.method(expr.alias(k) for k, expr in your_dict.items())\"\n        )\n        raise TypeError(msg)\n\n    # Treat elements of a single iterable as separate inputs\n    if len(inputs) == 1 and _is_iterable(inputs[0]):\n        return inputs[0]\n\n    return inputs\n\n\ndef _is_iterable(input: Any) -> bool:\n    return isinstance(input, Iterable) and not isinstance(\n        input, (str, bytes, pl.Series)\n    )\n\n\ndef _parse_named_inputs(\n    named_inputs: dict[str, IntoExpr], *, structify: bool = False\n) -> Iterable[PyExpr]:\n    for name, input in named_inputs.items():","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/parse/expr.py#L222-L258","documentation":"_parse_inputs_as_iterable rejects a single dict passed positionally, because it is ambiguous whether the caller meant keys, values, or key/expression pairs. The error message spells out the intended idioms for each intent.","triggerScenarios":"Calling expression-accepting methods like df.select({...}), df.with_columns({...}), filter with predicates chains (map_groups, _chain_predicates) with exactly one positional dict argument, e.g. df.select({\"a\": pl.col(\"x\")}).","commonSituations":"Migrating from pandas-style rename/aggregation dicts, or from older polars versions/APIs that accepted positional dicts of named expressions.","solutions":["Unpack the dict as keyword arguments: df.method(**your_dict).","Pass only the keys: df.method(*your_dict.keys()).","Build expressions from items: df.method(expr.alias(k) for k, expr in your_dict.items()).","Pass a list of expressions instead: df.method([expr1, expr2])."],"exampleFix":"// before\ndf.select({\"total\": pl.col(\"x\").sum()})\n// after\ndf.select(total=pl.col(\"x\").sum())  # or df.select(**{\"total\": pl.col(\"x\").sum()})","handlingStrategy":"validation","validationCode":"def validate_expr_args(inputs):\n    if len(inputs) == 1 and isinstance(inputs[0], dict):\n        raise TypeError(\"pass dict as **kwargs or list of expressions, not a single positional dict\")","typeGuard":"def is_single_positional_dict(args) -> bool:\n    return len(args) == 1 and isinstance(args[0], dict)","tryCatchPattern":"try:\n    result = df.select(arg)\nexcept TypeError as e:\n    if \"dictionary as a single positional argument\" in str(e):\n        result = df.select(**arg)\n    else:\n        raise","preventionTips":["Always use keyword unpacking (**) for named-expression dicts.","Keep a thin wrapper that converts dicts to keyword args before calling polars.","Check polars migration notes when upgrading — positional dicts were never supported here.","Lint for df.select({...}) patterns in your codebase."],"tags":["polars","api-usage","dict"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}