{"record":{"id":"6aca71cd15a4c3f4","repo":"pola-rs/polars","slug":"mod","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/utils/mod.rs","lineNumber":870,"sourceCode":"        df1.width(),\n        df2.width(),\n    )\n}\n\n/// This takes ownership of the DataFrame so that drop is called earlier.\n/// Does not check if schema is correct\npub fn accumulate_dataframes_vertical_unchecked<I>(dfs: I) -> DataFrame\nwhere\n    I: IntoIterator<Item = DataFrame>,\n{\n    let mut iter = dfs.into_iter();\n    let additional = iter.size_hint().0;\n    let mut acc_df = iter.next().unwrap();\n    acc_df.reserve_chunks(additional);\n\n    for df in iter {\n        if acc_df.width() != df.width() {\n            panic!(\"{}\", width_mismatch(&acc_df, &df));\n        }\n\n        acc_df.vstack_mut_owned_unchecked(df);\n    }\n    acc_df\n}\n\n/// This takes ownership of the DataFrame so that drop is called earlier.\n/// # Panics\n/// Panics if `dfs` is empty.\npub fn accumulate_dataframes_vertical<I>(dfs: I) -> PolarsResult<DataFrame>\nwhere\n    I: IntoIterator<Item = DataFrame>,\n{\n    let mut iter = dfs.into_iter();\n    let additional = iter.size_hint().0;\n    let mut acc_df = iter.next().unwrap();\n    acc_df.reserve_chunks(additional);","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/utils/mod.rs#L852-L888","documentation":"accumulate_dataframes_vertical_unchecked stacks DataFrames vertically without checking schema compatibility, but it does check that all frames have the same width. When a subsequent frame's width differs from the accumulated one, it panics with the width_mismatch message. 'Unchecked' means column names/dtypes are not validated — only width.","triggerScenarios":"Passing an iterator of DataFrames with differing column counts to accumulate_dataframes_vertical_unchecked; called from scan/read/execution paths (finish, finish_reader, execute_chunks, chunk_df_for_writing) when file/fragment schemas disagree.","commonSituations":"Reading multiple CSV/parquet files with different numbers of columns through one scan; schema drift between partitions; a projection changing width mid-iteration; concatenating frames where a select dropped a column.","solutions":["Ensure all input DataFrames have the same number of columns before calling (pad with nulls or drop extra columns)","When reading heterogeneous files, use explicit schema overrides / a unified schema (e.g. hive/partitioned scan schemas) so every fragment yields the same width","Use the checked accumulate_dataframes_vertical (or lazy concat with 'diagonal'/'vertical_relaxed' how) instead of the _unchecked variant","Log/print each df.width() in the iterator to find which frame diverges"],"exampleFix":"// before\nlet df = accumulate_dataframes_vertical_unchecked(frames);\n// after\nlet width = frames.peek().map(|f| f.width());\nlet frames = frames.map(|f| if f.width() == width { f } else { fix_or_pad(f) });\nlet df = accumulate_dataframes_vertical_unchecked(frames);","handlingStrategy":"validation","validationCode":"let widths: Vec<usize> = frames.iter().map(|f| f.width()).collect();\nif !widths.iter().all(|w| *w == widths[0]) {\n    panic!(\"frame widths differ: {:?}\", widths);\n}","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(|| accumulate_dataframes_vertical_unchecked(frames.clone())) {\n    Ok(df) => df,\n    Err(_) => accumulate_dataframes_vertical(frames), // checked variant\n}","preventionTips":["Use accumulate_dataframes_vertical (checked) unless profiling proves the unchecked one matters","Use lazy concat with how='diagonal' or 'vertical_relaxed' for heterogeneous sources","Enforce a unified schema when scanning multiple files/partitions"],"tags":["rust","polars","dataframe","concat"],"backgroundTag":"shape-mismatch","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"}