{"record":{"id":"4ce323f1361e830f","repo":"pola-rs/polars","slug":"cannot-parse-input-input-type-into-polars-select","errorCode":null,"errorMessage":"cannot parse input {input_type} into Polars selector{input_detail}","messagePattern":"cannot parse input (.+?) into Polars selector(.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/selectors.py","lineNumber":420,"sourceCode":"                elif dt is pydatetime.datetime:\n                    selectors += [datetime()]\n                elif dt is pydatetime.timedelta:\n                    selectors += [duration()]\n                elif dt is pydatetime.date:\n                    selectors += [date()]\n                elif dt is PyDecimal:\n                    selectors += [decimal()]\n                elif dt is builtins.list or dt is tuple:\n                    selectors += [list()]\n                else:\n                    input_type = (\n                        input\n                        if type(input) is type\n                        else f\"of type {type(input).__name__!r}\"\n                    )\n                    input_detail = \"\" if type(input) is type else f\" (given: {input!r})\"\n                    msg = f\"cannot parse input {input_type} into Polars selector{input_detail}\"\n                    raise TypeError(msg) from None\n            else:\n                input_type = (\n                    input\n                    if type(input) is type\n                    else f\"of type {type(input).__name__!r}\"\n                )\n                input_detail = \"\" if type(input) is type else f\" (given: {input!r})\"\n                msg = f\"cannot parse input {input_type} into Polars selector{input_detail}\"\n                raise TypeError(msg) from None\n\n        dtype_selector = cls._from_pyselector(PySelector.by_dtype(concrete_dtypes))\n\n        if len(selectors) == 0:\n            return dtype_selector\n\n        selector = selectors[0]\n        for s in selectors[1:]:\n            selector = selector | s","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/selectors.py#L402-L438","documentation":"Selector._by_dtype (the engine behind cs.by_dtype) recognizes polars dtypes and a fixed allowlist of Python types (int, float, bool, str, bytes, object, NoneType, datetime/date/time/timedelta, decimal.Decimal, list, tuple). Inside an iterable input, any OTHER type object (e.g. numpy scalar types, set, a pandas dtype class) falls through to a TypeError. Note the message formats the builtin `input` name rather than the failing element, so the printed 'type' can look confusing.","triggerScenarios":"cs.by_dtype([np.float32]); cs.by_dtype([set]); cs.by_dtype((pd.CategoricalDtype,)); any collection containing an unrecognized class.","commonSituations":"Numpy/pandas dtype objects leaking into dtype lists from cross-library code; teams assuming numpy types are accepted because polars converts them elsewhere (pl.from_numpy).","solutions":["Convert numpy/pandas types to polars dtypes: cs.by_dtype(pl.Float32) or Python builtins (cs.by_dtype(float))","Map numpy types before calling: {np.int64: int, np.float64: float, np.float32: pl.Float32}","Use the ready-made selectors: cs.numeric(), cs.float(), cs.integer()"],"exampleFix":"# before\ncs.by_dtype([np.float32])\n\n# after\ncs.by_dtype(pl.Float32)","handlingStrategy":"validation","validationCode":"ALLOWED = {int, float, bool, str, bytes, object, type(None)}\ndef parseable(dt) -> bool:\n    return is_polars_dtype(dt) or dt in ALLOWED\nbad = [dt for dt in dtypes if not parseable(dt)]\nif bad:\n    raise TypeError(f'convert to polars dtypes first: {bad}')","typeGuard":"from polars.datatypes import is_polars_dtype\nimport datetime as _dt\nimport decimal\n\nALLOWED_PY = {int, float, bool, str, bytes, object, type(None),\n              _dt.datetime, _dt.date, _dt.time, _dt.timedelta, decimal.Decimal, list, tuple}\n\ndef is_by_dtype_input(x) -> bool:\n    return is_polars_dtype(x) or x in ALLOWED_PY","tryCatchPattern":null,"preventionTips":["cs.by_dtype accepts polars dtypes and Python builtins only; normalize numpy/pandas dtypes yourself","Prefer cs.numeric()/cs.temporal() over hand-built dtype lists when possible"],"tags":["polars","selectors","by-dtype","numpy","type-error"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}