Skip to content

Commit c8c9cff

Browse files
authored
refactor: improve ak.to_cudf errors and documentation (#3850)
* improve cudf highlevel functions errors and docstring * some consistent docstrings regarding array-like with the rest of the highlevel functions * this is actually a series * perhaps notimplementederror is better here
1 parent 303bcdd commit c8c9cff

File tree

8 files changed

+55
-41
lines changed

8 files changed

+55
-41
lines changed

docs/reference/gpu-backend.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/reference/toctree.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656

5757
generated/ak.to_dataframe
5858

59+
.. toctree::
60+
:caption: Converting to cuDF Series
61+
62+
generated/ak.to_cudf
63+
5964
.. toctree::
6065
:caption: Converting ROOT RDataFrames
6166

src/awkward/operations/ak_to_cudf.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,52 @@
88

99

1010
@high_level_function()
11-
def to_cudf(
12-
array: ak.Array,
13-
):
14-
"""Create a cuDF.Series out of the given ak array
11+
def to_cudf(array):
12+
"""
13+
Args:
14+
array: Array-like data (anything #ak.to_layout recognizes).
15+
16+
Converts an Awkward Array into a cuDF Series.
1517
1618
Buffers that are not already in GPU memory will be transferred, and some
1719
structural reformatting may happen to account for differences in architecture.
20+
21+
This function requires the `cudf` library (< 25.12.00) and a compatible GPU.
22+
cuDF versions 25.12.00 and later are not currently supported due to
23+
incompatible changes in cuDF internals.
24+
25+
See also #ak.to_cupy, #ak.from_cupy, #ak.to_dataframe.
1826
"""
19-
import cudf
27+
# Dispatch
28+
yield (array,)
29+
30+
# Implementation
31+
return _impl(array)
32+
33+
34+
def _impl(array):
35+
try:
36+
import cudf
37+
except ImportError as err:
38+
raise ImportError(
39+
"""to use ak.to_cudf, you must install the 'cudf' package with:
40+
41+
pip install cudf-cu13
42+
or
43+
conda install -c rapidsai cudf cuda-version=13"""
44+
) from err
45+
46+
from packaging.version import parse as parse_version
47+
48+
if parse_version(cudf.__version__) >= parse_version("25.12.00"):
49+
raise NotImplementedError(
50+
f"ak.to_cudf is not supported for cudf >= 25.12.00 (you have {cudf.__version__}). "
51+
"cudf internals changed in ways that are incompatible with the current implementation"
52+
)
53+
54+
layout = ak.to_layout(array, allow_record=False)
2055

2156
if hasattr(cudf.Series, "_from_column"):
22-
return cudf.Series._from_column(array.layout._to_cudf(cudf, None, len(array)))
57+
return cudf.Series._from_column(layout._to_cudf(cudf, None, len(layout)))
2358
# older Series invocation
24-
return cudf.Series(array.layout._to_cudf(cudf, None, len(array)))
59+
return cudf.Series(layout._to_cudf(cudf, None, len(layout)))

src/awkward/operations/ak_to_raggedtensor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
def to_raggedtensor(array):
1616
"""
1717
Args:
18-
array: Array-like data. May be a high level #ak.Array,
19-
or low-level #ak.contents.ListOffsetArray, #ak.contents.ListArray,
20-
#ak.contents.RegularArray, #ak.contents.NumpyArray
18+
array: Array-like data (anything #ak.to_layout recognizes).
2119
2220
Converts `array` (only ListOffsetArray, ListArray, RegularArray and NumpyArray data types supported)
2321
into a ragged tensor, if possible.

src/awkward/operations/ak_to_safetensors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def to_safetensors(
2727
):
2828
"""
2929
Args:
30-
array: An Awkward Array or array-like object to serialize.
30+
array: Array-like data (anything #ak.to_layout recognizes).
3131
destination (path-like): Name of the output file, file path, or
3232
remote URL passed to [fsspec.core.url_to_fs](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.core.url_to_fs)
3333
for remote writing.

src/awkward/operations/ak_to_tensorflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
def to_tensorflow(array):
1616
"""
1717
Args:
18-
array: Array-like data. May be a high level #ak.Array,
19-
or low-level #ak.contents.ListOffsetArray, #ak.contents.ListArray,
20-
#ak.contents.RegularArray, #ak.contents.NumpyArray
18+
array: Array-like data (anything #ak.to_layout recognizes).
2119
2220
Converts `array` (only ListOffsetArray, ListArray, RegularArray and NumpyArray data types supported)
2321
into a TensorFlow Tensor, if possible.

src/awkward/operations/ak_to_torch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
def to_torch(array):
1616
"""
1717
Args:
18-
array: Array-like data. May be a high level #ak.Array,
19-
or low-level #ak.contents.ListOffsetArray, #ak.contents.ListArray,
20-
#ak.contents.RegularArray, #ak.contents.NumpyArray
18+
array: Array-like data (anything #ak.to_layout recognizes).
2119
2220
Converts `array` (only ListOffsetArray, ListArray, RegularArray and NumpyArray data types supported)
2321
into a PyTorch Tensor, if possible.

tests-cuda/test_3051_to_cuda.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def test_nested():
3636
]
3737

3838

39+
@pytest.mark.xfail(
40+
parse_version(cudf.__version__) >= parse_version("25.12.00"),
41+
reason="cudf internals changed since v25.12.00",
42+
)
3943
def test_null():
4044
arr = ak.Array([12, None, 21, 12])
4145
# calls ByteMaskedArray._to_cudf not NumpyArray

0 commit comments

Comments
 (0)