{"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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/selectors.py","lineNumber":423,"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":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/selectors.py#L405-L441","documentation":"Inside Selector._by_dtype (used by cs.by_dtype), each input must be a Polars DataType class/instance or a plain Python type that maps to one (int, float, str...). The loop over collection inputs rejects any element that is not such a type and raises this TypeError, telling you both the offending input type and its value.","triggerScenarios":"cs.by_dtype([pl.Int64, 'string']) — a string like 'string' or 'Int64' inside the collection instead of pl.String; or nested non-type objects like None or dtype instances of other libraries (numpy.dtypes).","commonSituations":"Users passing dtype names as strings (common after coming from pandas 'float64' style), or mixing dtypes from configuration files where they were serialized as strings.","solutions":["Replace string dtype names with Polars dtype objects: 'string' -> pl.String, 'int64' -> pl.Int64.","Map strings programmatically: dtypes = [getattr(pl, d.upper()) for d in str_dtypes].","Remove None or non-dtype entries from the collection before calling cs.by_dtype.","Check each element with polars.datatypes.is_polars_dtype(d) or isinstance(d, type) beforehand."],"exampleFix":"// before\ncs.by_dtype([\"string\", \"float\"])\n// after\ncs.by_dtype([pl.String, pl.Float64])","handlingStrategy":"validation","validationCode":"from polars.datatypes import is_polars_dtype\nbad = [t for t in dtypes if not (is_polars_dtype(t) or isinstance(t, type))]\nif bad:\n    raise ValueError(f\"not polars dtypes: {bad!r}\")","typeGuard":"def is_dtype_like(t) -> bool:\n    from polars.datatypes import is_polars_dtype\n    return is_polars_dtype(t) or isinstance(t, type)","tryCatchPattern":"try:\n    sel = cs.by_dtype(*dtypes)\nexcept TypeError as e:\n    if \"cannot parse input\" in str(e):\n        dtypes = [getattr(pl, str(t).upper()) for t in dtypes if isinstance(t, str)]\n        sel = cs.by_dtype(*dtypes)\n    else:\n        raise","preventionTips":["Never pass dtype names as strings — always pl.String, pl.Float64, etc.","Sanitize config-sourced dtype lists with a string->dtype mapping table.","Check collections element-wise, not just the collection itself."],"tags":["polars","selectors","dtype","type-error"],"backgroundTag":"unsupported-dtype","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"}