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

Improvements for __cuda_array_interface__ tests #15188

Merged
merged 4 commits into from
Mar 5, 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
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/single_column_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ def __cuda_array_interface__(self):
try:
return self._column.__cuda_array_interface__
except NotImplementedError:
raise AttributeError
raise AttributeError(
f"'{type(self).__name__}' object has no attribute "
"'__cuda_array_interface__'"
)

@_cudf_nvtx_annotate
def factorize(self, sort=False, use_na_sentinel=True):
Expand Down
27 changes: 15 additions & 12 deletions python/cudf/cudf/tests/test_cuda_array_interface.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.

import types
from contextlib import ExitStack as does_not_raise

import cupy
import numba.cuda
import numpy as np
import pandas as pd
import pytest
from numba import cuda

import cudf
from cudf.core.buffer.spill_manager import get_global_manager
Expand All @@ -25,7 +25,7 @@ def test_cuda_array_interface_interop_in(dtype, module):
if dtype in DATETIME_TYPES:
expectation = pytest.raises(ValueError)
elif module == "numba":
module_constructor = cuda.to_device
module_constructor = numba.cuda.to_device

with expectation:
module_data = module_constructor(np_data)
Expand Down Expand Up @@ -55,7 +55,7 @@ def to_host_function(x):
return cupy.asnumpy(x)

elif module == "numba":
module_constructor = cuda.as_cuda_array
module_constructor = numba.cuda.as_cuda_array

def to_host_function(x):
return x.copy_to_host()
Expand Down Expand Up @@ -89,7 +89,7 @@ def to_host_function(x):

elif module == "numba":
expectation = pytest.raises(NotImplementedError)
module_constructor = cuda.as_cuda_array
module_constructor = numba.cuda.as_cuda_array

def to_host_function(x):
return x.copy_to_host()
Expand Down Expand Up @@ -135,9 +135,11 @@ def test_cuda_array_interface_as_column(dtype, nulls, mask_type):

if mask_type == "bools":
if nulls == "some":
obj.__cuda_array_interface__["mask"] = cuda.to_device(mask)
obj.__cuda_array_interface__["mask"] = numba.cuda.to_device(mask)
elif nulls == "all":
obj.__cuda_array_interface__["mask"] = cuda.to_device([False] * 10)
obj.__cuda_array_interface__["mask"] = numba.cuda.to_device(
[False] * 10
)

expect = sr
got = cudf.Series(obj)
Expand Down Expand Up @@ -193,10 +195,11 @@ def test_cuda_array_interface_pytorch():

assert_eq(got, cudf.Series(buffer, dtype=np.bool_))

index = cudf.Index([], dtype="float64")
tensor = torch.tensor(index)
got = cudf.Index(tensor)
assert_eq(got, index)
# TODO: This test fails with PyTorch 2. Is it still expected to be valid?
# index = cudf.Index([], dtype="float64")
# tensor = torch.tensor(index)
vyasr marked this conversation as resolved.
Show resolved Hide resolved
# got = cudf.Index(tensor)
# assert_eq(got, index)

index = cudf.core.index.RangeIndex(start=0, stop=100)
tensor = torch.tensor(index)
Expand All @@ -212,7 +215,7 @@ def test_cuda_array_interface_pytorch():

str_series = cudf.Series(["a", "g"])

with pytest.raises(NotImplementedError):
with pytest.raises(AttributeError):
str_series.__cuda_array_interface__

cat_series = str_series.astype("category")
Expand Down
Loading