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

Fix pylibcudf Table.num_rows for 0 columns case and add interop to docs #16108

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading