{"record":{"id":"844f9c880fcb487d","repo":"pola-rs/polars","slug":"schema-overrides-should-be-of-type-list-or-dict-844f9c","errorCode":null,"errorMessage":"`schema_overrides` should be of type list or dict, got {qualified_type_name(schema_overrides)!r}","messagePattern":"`schema_overrides` should be of type list or dict, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/csv/functions.py","lineNumber":674,"sourceCode":"    else:\n        path = None\n        if isinstance(source, BytesIO):\n            source = source.getvalue()\n        if isinstance(source, StringIO):\n            source = source.getvalue().encode()\n\n    dtype_list: Sequence[tuple[str, PolarsDataType]] | None = None\n    dtype_slice: Sequence[PolarsDataType] | None = None\n    if schema_overrides is not None:\n        if isinstance(schema_overrides, dict):\n            dtype_list = []\n            for k, v in schema_overrides.items():\n                dtype_list.append((k, parse_into_dtype(v)))\n        elif isinstance(schema_overrides, Sequence):\n            dtype_slice = [parse_into_dtype(v) for v in schema_overrides]\n        else:\n            msg = f\"`schema_overrides` should be of type list or dict, got {qualified_type_name(schema_overrides)!r}\"\n            raise TypeError(msg)\n\n    processed_null_values = _process_null_values(null_values)\n\n    if isinstance(columns, str):\n        columns = [columns]\n    if isinstance(source, str) and is_glob_pattern(source):\n        scan_schema_overrides = (\n            dict(dtype_list) if dtype_list is not None else dtype_slice\n        )\n        from polars import scan_csv\n\n        scan = scan_csv(\n            source,\n            has_header=has_header,\n            separator=separator,\n            comment_prefix=comment_prefix,\n            quote_char=quote_char,\n            skip_rows=skip_rows,","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/csv/functions.py#L656-L692","documentation":"In _read_csv_impl (the engine behind read_csv), schema_overrides must be a dict mapping column name to dtype, or a Sequence (list/tuple) of dtypes applied positionally to the first columns. Anything else - a bare dtype, a string like 'Int64', a set, a generator - raises this TypeError naming the offending type. The value is parsed with parse_into_dtype per entry, so each dtype must also be a valid polars dtype or string alias.","triggerScenarios":"pl.read_csv('f.csv', schema_overrides=pl.Int64); schema_overrides='Utf8' (bare string, not a Sequence); schema_overrides={pl.Int64, pl.Float64} (set is not a dict and not ordered Sequence-eligible); schema_overrides=str (a type object instead of an instance).","commonSituations":"Copy-paste from read_csv(schema=...) examples where a dict is expected; passing a single dtype meant for one column; migrating pandas pd.read_csv(dtype=...) calls where dtype={'col': 'int32'} got simplified to a bare value; a string being treated as a Sequence of characters would silently almost work, but a non-Sequence always fails loudly.","solutions":["Wrap a single dtype in a list: schema_overrides=[pl.Int64]","Target specific columns with a dict: schema_overrides={'user_id': pl.Int64, 'name': pl.String}","Use polars dtype objects or their exact string aliases (e.g. 'i64', 'str'); parse_into_dtype rejects arbitrary strings"],"exampleFix":"# before\npl.read_csv('users.csv', schema_overrides=pl.Int64)\n\n# after - positional override for the first column\npl.read_csv('users.csv', schema_overrides=[pl.Int64])\n\n# after - override by column name\npl.read_csv('users.csv', schema_overrides={'user_id': pl.Int64})","handlingStrategy":"type-guard","validationCode":"def normalize_overrides(overrides):\n    if overrides is None or isinstance(overrides, dict):\n        return overrides\n    if isinstance(overrides, Sequence) and not isinstance(overrides, str):\n        return list(overrides)\n    return [overrides]  # bare dtype -> positional single override\n\npl.read_csv(path, schema_overrides=normalize_overrides(user_input))","typeGuard":"from collections.abc import Sequence\nfrom polars._typing import PolarsDataType\n\ndef is_valid_schema_overrides(x: object) -> bool:\n    return x is None or isinstance(x, dict) or (\n        isinstance(x, Sequence) and not isinstance(x, (str, bytes))\n    )","tryCatchPattern":"try:\n    df = pl.read_csv(path, schema_overrides=overrides)\nexcept TypeError as err:\n    if 'schema_overrides' in str(err):\n        raise ValueError(f'bad schema_overrides from config: {overrides!r}') from err\n    raise","preventionTips":["Type-annotate override variables as dict[str, PolarsDataType] | Sequence[PolarsDataType] | None so mypy catches misuse","Never pass a bare dtype or bare string; always wrap in [] or {}","When overrides come from config files, validate with isinstance checks at the config boundary, not inside read loops"],"tags":["polars","csv","schema","dtype","typeerror","argument-validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}