{"record":{"id":"bacfaa569283f0e7","repo":"pola-rs/polars","slug":"conversion-of-polars-data-type-dtype-r-to-ffi-not","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":269,"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":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/datatypes/convert.py#L251-L287","documentation":"dtype_to_ffiname maps a Polars dtype to an FFI function-name suffix via DataTypeMappings.DTYPE_TO_FFINAME; unknown dtypes raise NotImplementedError. It surfaces when polars' Arrow/FFI interchange layer (get_ffi_func) has no C-API function for the dtype.","triggerScenarios":"Calling low-level FFI-based interop (e.g. polars interchange with pyarrow via __arrow_c_array__ paths or internal get_ffi_func) with a dtype lacking a mapping — nested/exotic types like pl.Enum on older versions, pl.Categorical (old), pl.Object, custom extension dtypes.","commonSituations":"Bridging polars data into pyarrow/other libraries through FFI helpers; custom extension dtypes that were never mapped; version skew where a new dtype predates the FFI mapping.","solutions":["Convert via Arrow buffers instead: use Series.to_arrow() and let pyarrow handle the type.","Cast to a supported physical dtype first, e.g. s.cast(pl.UInt32) for categorical-like data.","Upgrade polars — newer releases add more DTYPE_TO_FFINAME entries."],"exampleFix":"// before\nget_ffi_func(\"...\", s.dtype, s)   # NotImplementedError for pl.Enum\n// after\npa_array = s.to_arrow()  # use Arrow interchange instead of FFI name lookup","handlingStrategy":"fallback","validationCode":"from polars.datatypes.convert import dtype_to_ffiname\ndef ffi_supported(dtype) -> bool:\n    try:\n        dtype_to_ffiname(dtype)\n        return True\n    except NotImplementedError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    func = get_ffi_func(name, dtype, series)\nexcept NotImplementedError:\n    pa_array = series.to_arrow()  # Arrow interchange fallback","preventionTips":["Prefer the public Arrow interchange API (to_arrow/__arrow_c_array__) over FFI helpers","Cast categorical/enum/object dtypes to physical types before FFI interop","Keep polars and pyarrow versions current"],"tags":["python","polars","ffi","dtype"],"backgroundTag":"method-not-implemented","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"}