{"record":{"id":"35710aa11fb6ea8f","repo":"pola-rs/polars","slug":"schema-overrides-should-be-of-type-list-or-dict","errorCode":null,"errorMessage":"`schema_overrides` should be of type list or dict","messagePattern":"`schema_overrides` should be of type list or dict","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/csv/functions.py","lineNumber":323,"sourceCode":"    _check_arg_is_1byte(\"eol_char\", eol_char, can_be_empty=False)\n\n    projection, columns = parse_columns_arg(columns)\n    storage_options = storage_options or {}\n\n    if columns and not has_header:\n        for column in columns:\n            if not column.startswith(\"column_\"):\n                msg = (\n                    \"specified column names do not start with 'column_',\"\n                    \" but autogenerated header names were requested\"\n                )\n                raise ValueError(msg)\n\n    if schema_overrides is not None and not isinstance(\n        schema_overrides, (dict, Sequence)\n    ):\n        msg = \"`schema_overrides` should be of type list or dict\"\n        raise TypeError(msg)\n\n    if (\n        use_pyarrow\n        and schema_overrides is None\n        and n_rows is None\n        and n_threads is None\n        and not low_memory\n        and null_values is None\n    ):\n        include_columns: Sequence[str] | None = None\n        if columns:\n            if not has_header:\n                # Convert 'column_1', 'column_2', ... column names to 'f0', 'f1', ...\n                # column names for pyarrow, if CSV file does not contain a header.\n                include_columns = [f\"f{int(column[7:]) - 1}\" for column in columns]\n            else:\n                include_columns = columns\n","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/csv/functions.py#L305-L341","documentation":"read_csv accepts schema_overrides only as a dict {name: dtype} or a list of dtypes; the isinstance(schema_overrides, (dict, Sequence)) check (py-polars/src/polars/io/csv/functions.py:320-324) raises TypeError for anything else - a bare dtype, a set, a generator, or a numpy array are not Sequences per collections.abc.","triggerScenarios":"pl.read_csv(f, schema_overrides=pl.Int64) (a single dtype instead of a per-column mapping); schema_overrides={'a','b'} (set); a generator/iterator of dtypes; a numpy object array of dtypes.","commonSituations":"Trying to apply one dtype to the whole file (not supported - overrides are per column); configs delivering dtypes as comma-separated strings or iterables; building overrides with a set comprehension.","solutions":["Use a dict for named columns: schema_overrides={'a': pl.Int64}","Use a list for positional dtypes: schema_overrides=[pl.Int64, pl.Utf8]","Consume generators/sets into a list before the call: list(schema_overrides)","For a whole-file single dtype, use the `dtypes`-style parameter or cast after reading"],"exampleFix":"# before\ndf = pl.read_csv(\"f.csv\", schema_overrides=pl.Int64)\n# after\ndf = pl.read_csv(\"f.csv\", schema_overrides={\"a\": pl.Int64, \"b\": pl.Int64})","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\n\ndef normalize_overrides(schema_overrides):\n    if isinstance(schema_overrides, dict) or (\n        isinstance(schema_overrides, (list, tuple))\n        and all(isinstance(dt, pl.DataType) or True for dt in schema_overrides)\n    ):\n        return schema_overrides\n    if isinstance(schema_overrides, (set, frozenset)) or hasattr(schema_overrides, \"__next__\"):\n        return list(schema_overrides)\n    raise TypeError(\"schema_overrides must be a dict or a list of dtypes\")","typeGuard":"from collections.abc import Sequence\n\ndef is_valid_schema_overrides(o: object) -> bool:\n    return isinstance(o, (dict, list, tuple)) and not isinstance(o, (str, bytes))","tryCatchPattern":"try:\n    df = pl.read_csv(path, schema_overrides=ov)\nexcept TypeError as e:\n    if \"schema_overrides\" in str(e):\n        df = pl.read_csv(path, schema_overrides=list(ov))\n    else:\n        raise","preventionTips":["Always express overrides as {'col': dtype} - the most explicit and safest form","Materialize iterators/sets into lists before passing them","A single dtype for all columns is not supported; cast after reading instead"],"tags":["polars","csv","schema","dtypes","typeerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}