{"record":{"id":"9b0222d32bc99963","repo":"pola-rs/polars","slug":"the-given-column-schema-names-do-not-match-the-dat","errorCode":null,"errorMessage":"the given column-schema names do not match the data dictionary","messagePattern":"the given column-schema names do not match the data dictionary","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/construction/dataframe.py","lineNumber":92,"sourceCode":"    )\n\n_MIN_NUMPY_SIZE_FOR_MULTITHREADING = 1000\n\n\ndef dict_to_pydf(\n    data: Mapping[str, ArrayLike | NonNestedLiteral | None],\n    schema: SchemaDefinition | None = None,\n    *,\n    schema_overrides: SchemaDict | None = None,\n    strict: bool = True,\n    nan_to_null: bool = False,\n    allow_multithreaded: bool = True,\n) -> PyDataFrame:\n    \"\"\"Construct a PyDataFrame from a dictionary of sequences.\"\"\"\n    if isinstance(schema, Mapping) and data:\n        if not all((col in schema) for col in data):\n            msg = \"the given column-schema names do not match the data dictionary\"\n            raise ValueError(msg)\n        data = {col: data[col] for col in schema}\n\n    column_names, schema_overrides = _unpack_schema(\n        schema, lookup_names=data.keys(), schema_overrides=schema_overrides\n    )\n    if not column_names:\n        column_names = list(data)\n\n    if data and _NUMPY_AVAILABLE:\n        # if there are 3 or more numpy arrays of sufficient size, we multi-thread:\n        count_numpy = sum(\n            int(\n                allow_multithreaded\n                and _check_for_numpy(val)\n                and isinstance(val, np.ndarray)\n                and len(val) > _MIN_NUMPY_SIZE_FOR_MULTITHREADING\n                # integers and non-nan floats are zero-copy\n                and nan_to_null","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/construction/dataframe.py#L74-L110","documentation":"Raised by dict_to_pydf when a schema (mapping of column names to dtypes) is supplied alongside a data dict, but the data dict contains keys not present in the schema. Polars validates that every data key exists in the schema before reordering data to schema order, raising ValueError on any mismatch.","triggerScenarios":"Calling pl.DataFrame({'a': [1], 'b': [2]}, schema={'a': pl.Int64, 'c': pl.Int64}) — a schema key that doesn't exist in the data dict; also via pl.from_dict or sequence_to_pydf with dict data and a mismatched schema.","commonSituations":"Typos in schema column names, schema built from a stale list of columns after upstream data changed, generating schema programmatically and missing a renamed column.","solutions":["Ensure every key in the data dict appears in the schema mapping","Omit the schema parameter and let Polars infer dtypes","Print/set(data) and set(schema) and diff them to find the mismatch"],"exampleFix":"// before\npl.DataFrame({'a': [1, 2], 'b': [3, 4]}, schema={'a': pl.Int64, 'c': pl.Int64})\n// after\npl.DataFrame({'a': [1, 2], 'b': [3, 4]}, schema={'a': pl.Int64, 'b': pl.Int64})","handlingStrategy":"validation","validationCode":"missing = set(data) - set(schema or {})\nif missing:\n    raise ValueError(f'schema is missing data columns: {missing}')","typeGuard":"def schema_matches_data(data: dict, schema: dict | None) -> bool:\n    return schema is None or set(data) <= set(schema)","tryCatchPattern":"try:\n    df = pl.DataFrame(data, schema=schema)\nexcept ValueError as e:\n    if 'column-schema names do not match' in str(e):\n        df = pl.DataFrame(data)  # fall back to inferred schema\n    else:\n        raise","preventionTips":["Derive the schema from the data keys programmatically","Diff set(data) vs set(schema) in a debug assertion","Avoid hand-maintained schema literals for wide dicts"],"tags":["python","polars","dataframe-construction","schema"],"backgroundTag":"schema-validation-failed","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"}