{"record":{"id":"98285ca7caf21891","repo":"pola-rs/polars","slug":"only-supported-for-scalars","errorCode":null,"errorMessage":"only supported for scalars","messagePattern":"only supported for scalars","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/frame/horizontal.rs","lineNumber":124,"sourceCode":"            );\n        }\n        out_width = 0;\n\n        owned_df = dfs\n            .iter()\n            .filter(|df| df.shape() != (0, 0))\n            .cloned()\n            .map(|mut df| {\n                out_width += df.width();\n                let h = df.height();\n\n                if h != output_height {\n                    if unit_length_as_scalar && h == 1 {\n                        // SAFETY: We extend each scalar column length to\n                        // `output_height`. Then, we set the height of the resulting dataframe.\n                        unsafe { df.columns_mut() }.iter_mut().for_each(|c| {\n                            let Column::Scalar(s) = c else {\n                                panic!(\"only supported for scalars\");\n                            };\n\n                            *c = Column::Scalar(s.resize(output_height));\n                        });\n                    } else {\n                        let diff = output_height - h;\n\n                        // SAFETY: We extend each column with nulls to the point of being of length\n                        // `output_height`. Then, we set the height of the resulting dataframe.\n                        unsafe { df.columns_mut() }.iter_mut().for_each(|c| {\n                            *c = c.extend_constant(AnyValue::Null, diff).unwrap();\n                        });\n                    }\n                    unsafe {\n                        df.set_height(output_height);\n                    }\n                }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-core/src/frame/horizontal.rs#L106-L142","documentation":"During horizontal concatenation, when unit_length_as_scalar is set, polars expands height-1 frames to the output height by resizing each column. This branch only works on Column::Scalar variants; if a height-1 frame carries a materialized (non-scalar) column, the invariant is violated and it panics 'only supported for scalars'.","triggerScenarios":"horizontally_concatenate (used by concat how=\"horizontal\"/hstack style paths) where a DataFrame of height 1 contains materialized columns instead of scalar columns while scalar expansion is requested.","commonSituations":"Internal invariant break after operations that materialize scalar columns (e.g., certain casts, with_columns, or IPC round trips) before a horizontal concat; usually a polars bug rather than user error.","solutions":["Upgrade polars to the latest patch release; this class of invariant break gets fixed upstream","Work around it: materialize the height-1 frames fully (broadcast to output height yourself) before the horizontal concat","If reproducible, file a polars issue with the minimal example and version information"],"exampleFix":"# before\npl.concat([df_wide, df_one_row], how=\"horizontal\")\n\n# after\n# broadcast the height-1 frame to the target height first\nheight = df_wide.height\ndf_one_row = df_one_row.select(pl.all().repeat_by(height).explode())\npl.concat([df_wide, df_one_row], how=\"horizontal\")","handlingStrategy":"fallback","validationCode":"fn all_height1_are_scalar(df: &DataFrame) -> bool {\n    df.height() == 1 && df.get_columns().iter().all(|c| matches!(c, Column::Scalar(_)))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Broadcast height-1 frames to the target height yourself before horizontal concat","Pin a polars version where the issue does not reproduce and regression-test concat paths","Report minimal reproductions upstream; this panic marks a polars invariant break, not user error"],"tags":["polars","horizontal-concat","scalar-column","panic","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}