{"record":{"id":"c3a9f66f8ae053f7","repo":"pola-rs/polars","slug":"cannot-infer-dtype-from-original-value-r-string","errorCode":null,"errorMessage":"cannot infer dtype from {original_value!r} string value","messagePattern":"cannot infer dtype from (.+?) string value","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/database/_inference.py","lineNumber":204,"sourceCode":"    # temporal dtypes\n    elif value.startswith((\"DATETIME\", \"TIMESTAMP\")) and not (value.endswith(\"[D]\")):\n        if any((tz in value.replace(\" \", \"\")) for tz in (\"TZ\", \"TIMEZONE\")):\n            if \"WITHOUT\" not in value:\n                return None  # there's a timezone, but we don't know what it is\n        unit = timeunit_from_precision(modifier) if modifier else \"us\"\n        dtype = Datetime(time_unit=(unit or \"us\"))  # type: ignore[arg-type]\n    else:\n        value = re.sub(r\"\\d\", \"\", value)\n        if value in (\"INTERVAL\", \"TIMEDELTA\", \"DURATION\"):\n            dtype = Duration\n        elif value == \"DATE\":\n            dtype = Date\n        elif value == \"TIME\":\n            dtype = Time\n\n    if not dtype and raise_unmatched:\n        msg = f\"cannot infer dtype from {original_value!r} string value\"\n        raise ValueError(msg)\n\n    return dtype\n\n\ndef dtype_from_cursor_description(\n    description: tuple[Any, ...],\n) -> PolarsDataType | None:\n    \"\"\"Attempt to infer Polars dtype from database cursor description `type_code`.\"\"\"\n    type_code, _disp_size, internal_size, precision, scale, *_ = description\n    dtype: PolarsDataType | None = None\n\n    if isclass(type_code):\n        # python types, eg: int, float, str, etc\n        with suppress(TypeError):\n            dtype = parse_py_type_into_dtype(type_code)  # type: ignore[arg-type]\n\n    elif isinstance(type_code, str):\n        # database/sql type names, eg: \"VARCHAR\", \"NUMERIC\", \"BLOB\", etc","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/database/_inference.py#L186-L222","documentation":"polars' database type-inference helper maps a database type-name string (e.g. \"INT\", \"VARCHAR\", \"DATE\") to a polars dtype. When the provided name matches none of the known mappings and `raise_unmatched=True`, the helper raises ValueError instead of returning a dtype. It indicates the database reported a column type the mapper does not recognize.","triggerScenarios":"Calling `dtype_from_database_typename` (directly, or via `dtype_from_cursor_description` / `_dtype_from_name`) with a type string not in the mapping table, e.g. a vendor-specific type like \"NVARCHAR2\", \"UUID\", or a custom domain type, while raise_unmatched is True (the default for cursor-description-driven inference).","commonSituations":"Reading from less-common databases or drivers whose column type names differ from the canonical set (Oracle, SQLite variants, custom types); upgrading a database or driver that returns new type names; calling the inference helper directly with an unnormalized name (wrong case or whitespace if the caller did not normalize).","solutions":["Pass `raise_unmatched=False` and handle the None return, supplying a fallback dtype yourself.","Check the inferred schema and override the offending column with `schema_overrides` / `dtypes` in read_database instead of relying on inference.","Normalize the type name (uppercase, strip parameters like \"VARCHAR(50)\") before calling, or map the custom type to a supported one beforehand.","Open a polars issue to add the missing database type name to the inference table."],"exampleFix":"// before\ndtype = dtype_from_database_typename(\"NVARCHAR2\")  # raises\n// after\ndtype = dtype_from_database_typename(\"NVARCHAR2\", raise_unmatched=False)\nif dtype is None:\n    dtype = pl.String","handlingStrategy":"validation","validationCode":"from polars.io.database._inference import dtype_from_database_typename\nif dtype_from_database_typename(type_name, raise_unmatched=False) is None:\n    dtype = pl.String  # fallback or explicit override","typeGuard":"def is_inferable_type(name: str) -> bool:\n    return dtype_from_database_typename(name, raise_unmatched=False) is not None","tryCatchPattern":"try:\n    dtype = dtype_from_database_typename(name)\nexcept ValueError:\n    dtype = pl.String  # or schema_overrides[name]","preventionTips":["Pass raise_unmatched=False when types may be database-specific","Use schema_overrides/dtypes for columns with exotic DB types","Pin well-known drivers whose type names are in the inference table","Normalize and test type names from your target database once, up front"],"tags":["polars","database","type-inference","dtype"],"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"}