{"record":{"id":"68174cec8800cdb0","repo":"pola-rs/polars","slug":"dimensions-of-columns-arg-must-match-data-dimensio","errorCode":null,"errorMessage":"dimensions of columns arg must match data dimensions","messagePattern":"dimensions of columns arg must match data dimensions","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/construction/dataframe.py","lineNumber":1195,"sourceCode":"\ndef arrow_to_pydf(\n    data: pa.Table | pa.RecordBatch,\n    schema: SchemaDefinition | None = None,\n    *,\n    schema_overrides: SchemaDict | None = None,\n    strict: bool = True,\n    rechunk: bool = True,\n) -> PyDataFrame:\n    \"\"\"Construct a PyDataFrame from an Arrow Table or RecordBatch.\"\"\"\n    column_names, schema_overrides = _unpack_schema(\n        (schema or data.schema.names), schema_overrides=schema_overrides\n    )\n    try:\n        if column_names != data.schema.names:\n            data = data.rename_columns(column_names)\n    except pa.ArrowInvalid as e:\n        msg = \"dimensions of columns arg must match data dimensions\"\n        raise ValueError(msg) from e\n\n    batches: list[pa.RecordBatch]\n    if isinstance(data, pa.RecordBatch):\n        batches = [data]\n    elif data.num_columns == 0:\n        return PyDataFrame.empty_with_height(data.num_rows)\n    else:\n        batches = data.to_batches()\n\n    # supply the arrow schema so the metadata is intact\n    pydf = PyDataFrame.from_arrow_record_batches(batches, data.schema)\n\n    if rechunk:\n        pydf = pydf.rechunk()\n\n    if schema_overrides is not None:\n        pydf = _post_apply_columns(\n            pydf,","sourceCodeStart":1177,"sourceCodeEnd":1213,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/construction/dataframe.py#L1177-L1213","documentation":"Raised by arrow_to_pydf when the supplied `columns` (or schema) names cannot be applied to the arrow table because the counts differ, surfacing as ValueError chained from pa.ArrowInvalid during rename_columns. The rename fails because the number of new names doesn't equal the number of arrow columns.","triggerScenarios":"pl.from_arrow(pa.table({...}), schema=['a','b']) where the schema has a different number of names than the table's columns; also hit when pandas_to_pydf routes through arrow with mismatched names.","commonSituations":"Providing names only for a subset of arrow columns, forgetting that index columns become extra columns in the arrow table, stale schema lists after the source table gained/lost columns.","solutions":["Supply exactly as many column names as the arrow table has columns (data.schema.names)","Omit the schema/column_names argument to keep the arrow names","Inspect data.schema.names and align your names list to it, including index columns"],"exampleFix":"// before\npl.from_arrow(table, schema=['a', 'b'])  # table has 3 columns\n// after\npl.from_arrow(table, schema=['a', 'b', 'c'])","handlingStrategy":"validation","validationCode":"names = schema if isinstance(schema, list) else None\nassert names is None or len(names) == table.num_columns, \\\n    f'{len(names)} names for {table.num_columns} arrow columns'","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.from_arrow(table, schema=schema)\nexcept ValueError as e:\n    if 'must match data dimensions' in str(e):\n        df = pl.from_arrow(table)\n    else:\n        raise","preventionTips":["Compare your name list against table.schema.names before converting","Remember index columns add to the arrow table width","Let arrow names pass through when only dtypes matter"],"tags":["python","polars","pyarrow","conversion","shape"],"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"}