Skip to content

Add Buffer.as_buffer_like method. #2925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kylebarron opened this issue Mar 21, 2025 · 2 comments
Open

Add Buffer.as_buffer_like method. #2925

kylebarron opened this issue Mar 21, 2025 · 2 comments

Comments

@kylebarron
Copy link
Contributor

The core Buffer class represents a block of memory in either CPU or GPU memory.

There's no current method on Buffer to expose the memory via the buffer protocol without always forcing a copy. The closest thing is the as_array_like method, which returns an ArrayLike, but there's no way to get a BytesLike from it.

So what I want is

    @abstractmethod
    def as_bytes_like(self) -> collections.abc.Buffer:

(#2814 tracks the unification of BytesLike and collections.abc.Buffer types)

In practice, this means that the obstore integration (#1661) won't need to force a memory copy when uploading data.

ref #1661 (comment), cc @TomAugspurger

@tomwhite
Copy link
Contributor

BTW there's a typo in the title; it should be 'Add Buffer.as_bytes_like method'.

Also, this will be fixed in #2972.

@kylebarron
Copy link
Contributor Author

kylebarron commented Apr 21, 2025

I called it "buffer" like to refer to the buffer protocol, hence the name in collections.abc.Buffer. FWIW I think that's a better name than "bytes like"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants