Skip to content

Commit

Permalink
Merge pull request #4770 from galipremsagar/4623
Browse files Browse the repository at this point in the history
[REVIEW] Fix readonly flag in `Column. __cuda_array_interface__`
  • Loading branch information
Keith Kraus authored Apr 2, 2020
2 parents 211e4e9 + ac02e99 commit d1815ec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
- PR #4755 Fix Java build to deal with new quantiles API
- PR #4720 Fix issue related to `dtype` param not being adhered incase of cuda arrays
- PR #4777 Fix data pointer for column slices of zero length
- PR #4770 Fix readonly flag in `Column. __cuda_array_interface__`


# cuDF 0.13.0 (31 Mar 2020)
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def __cuda_array_interface__(self):
"shape": (len(self),),
"strides": (self.dtype.itemsize,),
"typestr": self.dtype.str,
"data": (self.data_ptr, True),
"data": (self.data_ptr, False),
"version": 1,
}

Expand Down
46 changes: 46 additions & 0 deletions python/cudf/cudf/tests/test_cuda_array_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,49 @@ def test_column_from_ephemeral_cupy_try_lose_reference():
a.name = "b"
b = cupy.asarray([1, 1, 1]) # noqa: F841
assert_eq(pd.Series([1, 2, 3]), a.to_pandas())


@pytest.mark.skipif(
cupy.cuda.runtime.runtimeGetVersion() >= 10020,
reason="Pytorch doesn't support 10.2 cuda yet \
without building from source.",
)
def test_cuda_array_interface_pytorch():
torch = pytest.importorskip("torch")
series = cudf.Series([1, -1, 10, -56])
tensor = torch.tensor(series)
got = cudf.Series(tensor)

assert_eq(got, series)
from cudf.core.buffer import Buffer

buffer = Buffer(cupy.ones(10, dtype=np.bool_))
tensor = torch.tensor(buffer)
got = cudf.Series(tensor, dtype=np.bool_)

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

with pytest.raises(RuntimeError):
torch.tensor(cudf.core.Index())

index = cudf.core.index.RangeIndex(start=0, stop=100)
tensor = torch.tensor(index)
got = cudf.Series(tensor)

assert_eq(got, cudf.Series(index))

index = cudf.core.index.GenericIndex([1, 2, 8, 6])
tensor = torch.tensor(index)
got = cudf.Series(tensor)

assert_eq(got, cudf.Series(index))

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

with pytest.raises(NotImplementedError):
str_series.__cuda_array_interface__

cat_series = str_series.astype("category")

with pytest.raises(TypeError):
cat_series.__cuda_array_interface__

0 comments on commit d1815ec

Please sign in to comment.