-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Implement Buffer Protocol for PandasBuffer #55671
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0ac11ef
Implement Buffer Protocol for PandasBuffer
WillAyd 28ad6d8
Add buffer.pyx
WillAyd 8878fae
switch mro
WillAyd 7a65b96
try PyLong_AsVoidPtr
WillAyd 7e1923e
fix pyright
WillAyd 41ae1a7
try simpler tests
WillAyd f003ebc
fix parametrization
WillAyd 572f358
try PyLong_Check
WillAyd 3a1ea10
Merge branch 'main' into buffer-buffer
WillAyd c1fc642
try intptr_t
WillAyd 55fd4ea
heap store
WillAyd 7592e34
try changing buf reference to numpy array
WillAyd c259aa4
Merge branch 'main' into buffer-buffer
WillAyd f1f911c
try as voidptr
WillAyd 0a1bc9e
Merge branch 'main' into buffer-buffer
WillAyd 7f84f00
Merge remote-tracking branch 'upstream/main' into buffer-buffer
WillAyd 6e5a6cd
add releasebuffer
WillAyd 2251916
Merge remote-tracking branch 'upstream/main' into buffer-buffer
WillAyd c45270f
try adding handle
WillAyd 0324242
remove handle
WillAyd 5e7a4de
lifecycle hack
WillAyd 2e86d60
try buffer copy
WillAyd 49a79c1
Merge branch 'main' into buffer-buffer
WillAyd 553438b
move buffer to C
WillAyd 9e15c5b
Some hacks
WillAyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from cpython cimport Py_buffer | ||
from libc.stdint cimport ( | ||
uint8_t, | ||
uintptr_t, | ||
) | ||
|
||
|
||
cdef class CBuffer: | ||
def __getbuffer__(self, Py_buffer *buffer, int flags): | ||
cdef Py_ssize_t itemsize = sizeof(uint8_t) | ||
cdef uintptr_t ptr = self.ptr | ||
cdef Py_ssize_t[1] shape = tuple((self.bufsize // itemsize,)) | ||
cdef Py_ssize_t[1] strides = tuple((itemsize,)) | ||
|
||
buffer.buf = <void*>ptr | ||
# assumes sizeof(unsigned char) == sizeof(uint8_t) | ||
# TODO: use C11 static_assert macro in Cython | ||
buffer.format = "@B" | ||
buffer.itemsize = itemsize | ||
buffer.len = self.bufsize | ||
buffer.ndim = 1 | ||
buffer.obj = self | ||
buffer.readonly = 1 | ||
buffer.shape = shape | ||
buffer.strides = strides | ||
buffer.suboffsets = NULL | ||
|
||
def __releasebuffer__(self, Py_buffer *buffer): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be a better way of doing this overall, but I figured since
self.ptr
returns an int it is an easy bolt on to the existing design