Skip to content
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

Simple NumPy 2 fixes that are clearly no behavior change #15876

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MAINT: Avoid numpy.array with copy=False (meaning changed)
  • Loading branch information
seberg committed May 29, 2024
commit 2b1ca4839153fa692bcdc647a49c6cd3609f58d1
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/buffer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def from_host_memory(cls, data: Any) -> Self:
"""Create an owner from a buffer or array like object

Data must implement `__array_interface__`, the buffer protocol, and/or
be convertible to a buffer object using `numpy.array()`
be convertible to a buffer object using `numpy.asanyarray()`

The host memory is copied to a new device allocation.

Expand All @@ -209,7 +209,7 @@ def from_host_memory(cls, data: Any) -> Self:
"""

# Convert to numpy array, this will not copy data in most cases.
ary = numpy.array(data, copy=False, subok=True)
ary = numpy.asanyarray(data)
# Extract pointer and size
ptr, size = get_ptr_and_size(ary.__array_interface__)
# Copy to device memory
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/buffer/spillable_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def from_host_memory(cls, data: Any) -> Self:
"""Create a spillabe buffer from host memory.

Data must implement `__array_interface__`, the buffer protocol, and/or
be convertible to a buffer object using `numpy.array()`
be convertible to a buffer object using `numpy.asanyarray()`

The new buffer is marked as spilled to host memory already.

Expand All @@ -165,7 +165,7 @@ def from_host_memory(cls, data: Any) -> Self:

# Convert to a memoryview using numpy array, this will not copy data
# in most cases.
data = memoryview(numpy.array(data, copy=False, subok=True))
data = memoryview(numpy.asanyarray(data))
if not data.c_contiguous:
raise ValueError("Buffer data must be C-contiguous")
data = data.cast("B") # Make sure itemsize==1
Expand Down