{"record":{"id":"5312dbe47bfeec5e","repo":"pola-rs/polars","slug":"passing-expr-objects-to-the-dataframe-constructor","errorCode":null,"errorMessage":"passing Expr objects to the DataFrame constructor is not supported\\n\\nHint: Try evaluating the expression first using `select`, or if you meant to create an Object column containing expressions, pass a list of Expr objects instead.","messagePattern":"passing Expr objects to the DataFrame constructor is not supported\\\\n\\\\nHint: Try evaluating the expression first using `select`, or if you meant to create an Object column containing expressions, pass a list of Expr objects instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/construction/dataframe.py","lineNumber":355,"sourceCode":"def _expand_dict_values(\n    data: Mapping[str, ArrayLike | NonNestedLiteral | None],\n    *,\n    schema_overrides: SchemaDict | None = None,\n    strict: bool = True,\n    order: Sequence[str] | None = None,\n    nan_to_null: bool = False,\n) -> dict[str, Series]:\n    \"\"\"Expand any scalar values in dict data (propagate literal as array).\"\"\"\n    updated_data = {}\n    if data:\n        if any(isinstance(val, pl.Expr) for val in data.values()):\n            msg = (\n                \"passing Expr objects to the DataFrame constructor is not supported\"\n                \"\\n\\nHint: Try evaluating the expression first using `select`,\"\n                \" or if you meant to create an Object column containing expressions,\"\n                \" pass a list of Expr objects instead.\"\n            )\n            raise TypeError(msg)\n\n        dtypes = schema_overrides or {}\n        data = _expand_dict_data(data, dtypes, strict=strict)\n        array_len = max((arrlen(val) or 0) for val in data.values())\n        if array_len > 0:\n            for name, val in data.items():\n                dtype = dtypes.get(name)\n                if isinstance(val, dict) and dtype != Struct:\n                    vdf = pl.DataFrame(val, strict=strict)\n                    if (\n                        vdf.height == 1\n                        and array_len > 1\n                        and all(not d.is_nested() for d in vdf.schema.values())\n                    ):\n                        s_vals = {\n                            nm: vdf[nm].extend_constant(v, n=(array_len - 1))\n                            for nm, v in val.items()\n                        }","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/_utils/construction/dataframe.py#L337-L373","documentation":"Error \"passing Expr objects to the DataFrame constructor is not supported\\n\\nHint: Try evaluating the expression first using `select`, or if you meant to create an Object column containing expressions, pass a list of Expr objects instead.\" thrown in pola-rs/polars.","triggerScenarios":"Passing a bare Expr to the DataFrame constructor.","commonSituations":"See trigger scenarios.","solutions":["Evaluate the expression first with select(), or pass a list of Expr objects to build an Object column."],"exampleFix":"df = pl.DataFrame({'a':[1,2]}).select(pl.col('a')*2)","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}