X Tutup
Skip to content

BUG: Should np.from_dlpack raise BufferError instead of ValueError on unsupported dl_device values? #30937

@lucyleeow

Description

@lucyleeow

Describe the issue:

Relates to #30341 and #30936

In the from_dlpack docs it says:

BufferError – The dlpack and dlpack_device methods on the input array may raise BufferError when the data cannot be exported as DLPack (e.g., incompatible dtype, strides, or device).

I read the meaning as: incompatible dtype, incompatible strides, or incompatible device - which would suggest a BufferError should be raised when device is incompatible?

I understand BufferError may seem like an odd choice (#30341 (comment)) but just raising the question from my interpretation of the docs.

Reproduce the code example:

x_torch = torch.arange(5, device='cuda')
np.from_dlpack(x_torch)

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Unsupported device in DLTensor.

Python and NumPy Versions:

2.4.2
3.14.2 | packaged by conda-forge | (main, Feb 4 2026, 15:49:49) [GCC 14.3.0]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

scikit-learn/scikit-learn#32755 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - BugsprintableIssue fits the time-frame and setting of a sprint

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup