pola-rs/polars · error · NotImplementedError

__dlpack__

Error message

__dlpack__

What it means

Sentinel NotImplementedError raised by PolarsBuffer.__dlpack__ in the interchange protocol. The DLPack export interface is deliberately not implemented for Polars buffers, so any consumer calling __dlpack__ on them hits this immediately regardless of input. Export via to_numpy/to_arrow instead.

Solutions

  1. Ensure the underlying object exposes a __dlpack__ method; if the buffer does not support DLPack, convert the data (e.g. via rechunk/cast) before exporting.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at py-polars/src/polars/interchange/buffer.py:67 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19). Data as JSON: /api/errors/4ce5d4bd880fb85b. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/interchange/buffer.py:67

            n_bytes, rest = divmod(n_bits, 8)
            # Round up to the nearest byte
            if rest == 0:
                return n_bytes
            else:
                return n_bytes + 1

        return self._data.len() * (dtype[1] // 8)

    @property
    def ptr(self) -> int:
        """Pointer to start of the buffer as an integer."""
        pointer, _, _ = self._data._get_buffer_info()
        return pointer

    def __dlpack__(self) -> NoReturn:
        """Represent this structure as DLPack interface."""
        msg = "__dlpack__"
        raise NotImplementedError(msg)

    def __dlpack_device__(self) -> tuple[DlpackDeviceType, None]:
        """Device type and device ID for where the data in the buffer resides."""
        return (DlpackDeviceType.CPU, None)

    def __repr__(self) -> str:
        bufsize = self.bufsize
        ptr = self.ptr
        device = self.__dlpack_device__()[0].name
        return f"PolarsBuffer(bufsize={bufsize}, ptr={ptr}, device={device!r})"

View on GitHub (pinned to 9b5d73fd00)