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

Add coverage selecting len from a dataframe (number of rows) #16005

Merged
merged 1 commit into from
Jun 13, 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
2 changes: 1 addition & 1 deletion python/cudf_polars/cudf_polars/containers/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def num_columns(self) -> int:
@cached_property
def num_rows(self) -> int:
"""Number of rows."""
return self.table.num_rows()
return 0 if len(self.columns) == 0 else self.table.num_rows()

@classmethod
def from_cudf(cls, df: cudf.DataFrame) -> Self:
Expand Down
26 changes: 26 additions & 0 deletions python/cudf_polars/tests/expressions/test_len.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import pytest

import polars as pl

from cudf_polars.testing.asserts import assert_gpu_result_equal


@pytest.mark.parametrize("dtype", [pl.UInt32, pl.Int32, None])
@pytest.mark.parametrize("empty", [False, True])
def test_len(dtype, empty):
if empty:
df = pl.LazyFrame({})
else:
df = pl.LazyFrame({"a": [1, 2, 3]})

if dtype is None:
q = df.select(pl.len())
else:
q = df.select(pl.len().cast(dtype))

# Workaround for https://github.com/pola-rs/polars/issues/16904
assert_gpu_result_equal(q, collect_kwargs={"projection_pushdown": False})
Loading