Skip to content

Commit

Permalink
Fix pylibcudf Table.num_rows for 0 columns case and add interop to do…
Browse files Browse the repository at this point in the history
…cs (#16108)

There was a bug where Table.num_rows raised when we had 0 columns instead of returning 0.
I also added interop to the docs since that was missing.

Authors:
  - Thomas Li (https://github.com/lithomas1)

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #16108
  • Loading branch information
lithomas1 authored Jun 27, 2024
1 parent f267b1f commit e98d456
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/cudf/source/user_guide/api_docs/pylibcudf/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This page provides API documentation for pylibcudf.
gpumemoryview
groupby
io/index.rst
interop
join
lists
merge
Expand Down
6 changes: 6 additions & 0 deletions docs/cudf/source/user_guide/api_docs/pylibcudf/interop.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=======
interop
=======

.. automodule:: cudf._lib.pylibcudf.interop
:members:
2 changes: 2 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/table.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ cdef class Table:

cpdef int num_rows(self):
"""The number of rows in this table."""
if self.num_columns() == 0:
return 0
return self._columns[0].size()

cpdef list columns(self):
Expand Down
22 changes: 22 additions & 0 deletions python/cudf/cudf/pylibcudf_tests/test_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2024, NVIDIA CORPORATION.

import pyarrow as pa
import pytest

import cudf._lib.pylibcudf as plc


@pytest.mark.parametrize(
"arrow_tbl",
[
pa.table([]),
pa.table({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}),
pa.table({"a": [1, 2, 3]}),
pa.table({"a": [1], "b": [2], "c": [3]}),
],
)
def test_table_shape(arrow_tbl):
plc_tbl = plc.interop.from_arrow(arrow_tbl)

plc_tbl_shape = (plc_tbl.num_rows(), plc_tbl.num_columns())
assert plc_tbl_shape == arrow_tbl.shape

0 comments on commit e98d456

Please sign in to comment.