From 729608c17f1530bec48974bdeb20fa6ad90c3c71 Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Thu, 27 Jun 2024 00:43:11 +0000 Subject: [PATCH] Fix pylibcudf num_rows for 0 columns case and add interop to docs --- .../user_guide/api_docs/pylibcudf/index.rst | 1 + .../user_guide/api_docs/pylibcudf/interop.rst | 6 +++++ python/cudf/cudf/_lib/pylibcudf/table.pyx | 2 ++ .../cudf/cudf/pylibcudf_tests/test_table.py | 22 +++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 docs/cudf/source/user_guide/api_docs/pylibcudf/interop.rst create mode 100644 python/cudf/cudf/pylibcudf_tests/test_table.py diff --git a/docs/cudf/source/user_guide/api_docs/pylibcudf/index.rst b/docs/cudf/source/user_guide/api_docs/pylibcudf/index.rst index f98298ff052..e9dad705cbf 100644 --- a/docs/cudf/source/user_guide/api_docs/pylibcudf/index.rst +++ b/docs/cudf/source/user_guide/api_docs/pylibcudf/index.rst @@ -19,6 +19,7 @@ This page provides API documentation for pylibcudf. gpumemoryview groupby io/index.rst + interop join lists merge diff --git a/docs/cudf/source/user_guide/api_docs/pylibcudf/interop.rst b/docs/cudf/source/user_guide/api_docs/pylibcudf/interop.rst new file mode 100644 index 00000000000..881ab8d7be4 --- /dev/null +++ b/docs/cudf/source/user_guide/api_docs/pylibcudf/interop.rst @@ -0,0 +1,6 @@ +======= +interop +======= + +.. automodule:: cudf._lib.pylibcudf.interop + :members: diff --git a/python/cudf/cudf/_lib/pylibcudf/table.pyx b/python/cudf/cudf/_lib/pylibcudf/table.pyx index d93ac78721b..d91fa0474b0 100644 --- a/python/cudf/cudf/_lib/pylibcudf/table.pyx +++ b/python/cudf/cudf/_lib/pylibcudf/table.pyx @@ -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): diff --git a/python/cudf/cudf/pylibcudf_tests/test_table.py b/python/cudf/cudf/pylibcudf_tests/test_table.py new file mode 100644 index 00000000000..cf1d51f6491 --- /dev/null +++ b/python/cudf/cudf/pylibcudf_tests/test_table.py @@ -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