Skip to content

Commit

Permalink
fix: version check in to_cudf for API change (#3339)
Browse files Browse the repository at this point in the history
* version check in to_cudf for API change

fixes #3335

* style: pre-commit fixes

* Fix

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ianna Osborne <[email protected]>
Co-authored-by: Peter Fackeldey <[email protected]>
  • Loading branch information
4 people authored Jan 7, 2025
1 parent 432c07a commit 22b364a
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/awkward/contents/listoffsetarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,12 +2009,20 @@ def _to_arrow(
)

def _to_cudf(self, cudf: Any, mask: Content | None, length: int):
from packaging.version import parse as parse_version

cupy = Cupy.instance()
index = self._offsets.raw(cupy).astype("int32")
buf = cudf.core.buffer.as_buffer(index)
ind_buf = cudf.core.column.numerical.NumericalColumn(
data=buf, dtype=index.dtype, mask=None, size=len(index)
)

if parse_version(cudf.__version__) >= parse_version("24.10.00"):
ind_buf = cudf.core.column.numerical.NumericalColumn(
data=buf, dtype=index.dtype, mask=None, size=len(index)
)
else:
ind_buf = cudf.core.column.numerical.NumericalColumn(
buf, index.dtype, None, size=len(index)
)
cont = self._content._to_cudf(cudf, None, len(self._content))
if mask is not None:
m = np._module.packbits(mask, bitorder="little")
Expand All @@ -2034,13 +2042,21 @@ def _to_cudf(self, cudf: Any, mask: Content | None, length: int):
mask=m,
)

return cudf.core.column.lists.ListColumn(
size=length,
data=None,
mask=m,
children=(ind_buf, cont),
dtype=cudf.core.dtypes.ListDtype(cont.dtype),
)
if parse_version(cudf.__version__) >= parse_version("24.10.00"):
return cudf.core.column.lists.ListColumn(
size=length,
data=None,
mask=m,
children=(ind_buf, cont),
dtype=cudf.core.dtypes.ListDtype(cont.dtype),
)
else:
return cudf.core.column.lists.ListColumn(
length,
mask=m,
children=(ind_buf, cont),
dtype=cudf.core.dtypes.ListDtype(cont.dtype),
)

def _to_backend_array(self, allow_missing, backend):
array_param = self.parameter("__array__")
Expand Down

0 comments on commit 22b364a

Please sign in to comment.