Skip to content

Commit

Permalink
Correct when df is empty and add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfalisse committed Apr 13, 2022
1 parent 1509af5 commit cc5c79e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5135,7 +5135,7 @@ def _reduce(
)
source = self._get_columns_by_label(numeric_cols)
if source.empty:
return source.astype("float64")
return Series(index=cudf.StringIndex([]))

axis = source._get_axis_from_axis_arg(axis)

Expand Down
18 changes: 18 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9197,3 +9197,21 @@ def test_std_different_dtypes(data):

with pytest.raises(TypeError):
gdf.std()


@pytest.mark.parametrize(
"data",
[
{
"id": ["a", "a", "a", "b", "b", "b", "c", "c", "c"],
"val1": ["v", "n", "k", "l", "m", "i", "y", "r", "w"],
"val2": ["d", "d", "d", "e", "e", "e", "f", "f", "f"],
}
],
)
def test_empty_numeric_only(data):
gdf = cudf.DataFrame(data)
pdf = gdf.to_pandas()
expected = pdf.prod(numeric_only=True)
actual = gdf.prod(numeric_only=True)
assert_eq(expected, actual)

0 comments on commit cc5c79e

Please sign in to comment.