{"record":{"id":"899a37dfae787f71","repo":"pola-rs/polars","slug":"cannot-get-buffer-length-for-buffer-with-dtype-dt","errorCode":null,"errorMessage":"cannot get buffer length for buffer with dtype {dtype!r}","messagePattern":"cannot get buffer length for buffer with dtype (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/interchange/utils.py","lineNumber":157,"sourceCode":"    elif format_str == \"tdD\":\n        return Date\n    elif format_str == \"ttu\":\n        return Time\n    elif (match := re.fullmatch(r\"tD([mun])\", format_str)) is not None:\n        time_unit = match.group(1) + \"s\"\n        return Duration(time_unit=time_unit)  # type: ignore[arg-type]\n\n    msg = f\"unsupported temporal data type: {dtype!r}\"\n    raise NotImplementedError(msg)\n\n\ndef get_buffer_length_in_elements(buffer_size: int, dtype: Dtype) -> int:\n    \"\"\"Get the length of a buffer in elements.\"\"\"\n    bits_per_element = dtype[1]\n    bytes_per_element, rest = divmod(bits_per_element, 8)\n    if rest > 0:\n        msg = f\"cannot get buffer length for buffer with dtype {dtype!r}\"\n        raise ValueError(msg)\n    return buffer_size // bytes_per_element\n\n\ndef polars_dtype_to_data_buffer_dtype(dtype: PolarsDataType) -> PolarsDataType:\n    \"\"\"Get the data type of the data buffer.\"\"\"\n    if dtype.is_integer() or dtype.is_float() or dtype == Boolean:\n        return dtype\n    elif dtype.is_temporal():\n        return Int32 if dtype == Date else Int64\n    elif dtype == String:\n        return UInt8\n    elif dtype in (Enum, Categorical):\n        return UInt32\n\n    msg = f\"unsupported data type: {dtype}\"\n    raise NotImplementedError(msg)\n","sourceCodeStart":139,"sourceCodeEnd":174,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/interchange/utils.py#L139-L174","documentation":"The buffer's element bit-width is not a multiple of 8, so its byte length cannot be evenly converted to an element count; this indicates a non-standard/unsupported physical dtype in the interchange representation.","triggerScenarios":"Thrown at py-polars/src/polars/interchange/utils.py:157 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The buffer dtype has no fixed item size known to the interchange utils; convert the column to a supported fixed-width dtype before accessing buffer length."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}