{"record":{"id":"bacfaa569283f0e7","repo":"pola-rs/polars","slug":"conversion-of-polars-data-type-dtype-r-to-ffi-no","errorCode":null,"errorMessage":"conversion of polars data type {dtype!r} to FFI not implemented","messagePattern":"conversion of polars data type (.+?) to FFI not implemented","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/convert.py","lineNumber":260,"sourceCode":"            str_repr: obj\n            for obj in globals().values()\n            if is_polars_dtype(obj)\n            and (str_repr := _dtype_str_repr_safe(obj)) is not None\n        }\n\n\n# Initialize once (poor man's singleton :)\nDataTypeMappings: Final[_DataTypeMappings] = _DataTypeMappings()\n\n\ndef dtype_to_ffiname(dtype: PolarsDataType) -> str:\n    \"\"\"Return FFI function name associated with the given Polars dtype.\"\"\"\n    try:\n        dtype = dtype.base_type()\n        return DataTypeMappings.DTYPE_TO_FFINAME[dtype]\n    except KeyError:  # pragma: no cover\n        msg = f\"conversion of polars data type {dtype!r} to FFI not implemented\"\n        raise NotImplementedError(msg) from None\n\n\ndef dtype_to_py_type(dtype: PolarsDataType) -> PythonDataType:\n    \"\"\"Convert a Polars dtype to a Python dtype.\"\"\"\n    try:\n        dtype = dtype.base_type()\n        return DataTypeMappings.DTYPE_TO_PY_TYPE[dtype]\n    except KeyError:  # pragma: no cover\n        msg = f\"conversion of polars data type {dtype!r} to Python type not implemented\"\n        raise NotImplementedError(msg) from None\n\n\ndef py_type_to_arrow_type(dtype: PythonDataType) -> pa.DataType:\n    \"\"\"Convert a Python dtype to an Arrow dtype.\"\"\"\n    try:\n        return DataTypeMappings.PY_TYPE_TO_ARROW_TYPE[dtype]\n    except KeyError:  # pragma: no cover\n        msg = f\"cannot parse Python data type {dtype!r} into Arrow data type\"","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/datatypes/convert.py#L242-L278","documentation":"The internal helper dtype_to_ffiname maps a polars dtype to its Rust-side FFI constructor name. If the dtype's base_type() has no entry in DTYPE_TO_FFINAME, NotImplementedError is raised. This mapping only covers known primitive dtypes, so custom extension dtypes or dtypes newer than the installed polars version fail here.","triggerScenarios":"Internal or third-party code (e.g. polars-optimizer plugins, meta/bridging code, or direct calls to polars.datatypes.convert.dtype_to_ffiname) encounters a dtype absent from the mapping — typically a custom extension dtype or one introduced in a different polars version.","commonSituations":"Version skew between polars and companion packages where a new dtype exists on one side only; user-registered extension types without FFI support; code calling polars' private convert API directly.","solutions":["Upgrade polars (and any companion packages) to matching versions so every dtype in use has an FFI mapping","Avoid feeding custom or newly-introduced dtypes into internal FFI conversion paths; stick to supported primitive dtypes","If you call dtype_to_ffiname directly, catch NotImplementedError and degrade to a supported representation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from polars.datatypes import convert\n\ndef has_ffiname(dtype) -> bool:\n    try:\n        convert.dtype_to_ffiname(dtype)\n        return True\n    except NotImplementedError:\n        return False\n\nassert has_ffiname(dtype), f'no FFI mapping for {dtype!r}'","typeGuard":null,"tryCatchPattern":"from polars.datatypes.convert import dtype_to_ffiname\n\ntry:\n    ffi_name = dtype_to_ffiname(dtype)\nexcept NotImplementedError:\n    # dtype too new or custom: degrade or reject explicitly\n    raise ValueError(f'unsupported dtype for FFI: {dtype!r}; upgrade polars') from None","preventionTips":["Keep polars and companion packages on matching versions","Do not push custom extension dtypes into internal FFI conversion paths","Treat NotImplementedError from convert helpers as a version/coverage signal, not a data error"],"tags":["dtype","ffi","internal","version-mismatch","not-implemented"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}