Skip to content

Commit

Permalink
Change test to verify that the correct exceptions are thrown.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Aug 16, 2021
1 parent d804de5 commit d4abda9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
6 changes: 6 additions & 0 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"max": "nanmax",
"sum": "nansum",
"prod": "nanprod",
"product": "nanprod",
"mean": "nanmean",
"std": "nanstd",
"var": "nanvar",
Expand Down Expand Up @@ -6612,6 +6613,11 @@ def _apply_support_method_axis_1(self, method, *args, **kwargs):
"Row-wise operations currently do not " "support `bool_only`."
)

# This parameter is only necessary for axis 0 reductions that cuDF
# performs internally. cupy already upcasts smaller integer/bool types
# to int64 when accumulating.
kwargs.pop("cast_to_int", None)

prepared, mask, common_dtype = self._prepare_for_rowwise_op(
method, skipna
)
Expand Down
37 changes: 25 additions & 12 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,7 @@ def gdf(pdf):
"min",
"max",
"sum",
"prod",
"product",
"cummin",
"cummax",
Expand All @@ -1872,22 +1873,34 @@ def test_dataframe_reductions(data, axis, func, skipna):
pdf = pd.DataFrame(data=data)
gdf = cudf.DataFrame.from_pandas(pdf)

# These reductions don't support axis=1
if axis == 1 and func in ("kurt", "skew"):
return

# We need cupy-supported operations when performing rowwise ops.
if func not in cudf.core.dataframe._cupy_nan_methods_map and axis == 1:
return
# Reductions can fail in numerous possible ways when attempting row-wise
# reductions, which are only partially supported. Catching the appropriate
# exception here allows us to detect API breakage in the form of changing
# exceptions.
expected_exception = None
if axis == 1:
if func in ("kurt", "skew"):
expected_exception = NotImplementedError
elif func not in cudf.core.dataframe._cupy_nan_methods_map:
if skipna is False:
expected_exception = NotImplementedError
elif any(col.nullable for name, col in gdf.iteritems()):
expected_exception = ValueError
elif func in ("cummin", "cummax"):
expected_exception = AttributeError

# Test different degrees of freedom for var and std.
all_kwargs = [{"ddof": 1}, {"ddof": 2}] if func in ("var", "std") else [{}]
for kwargs in all_kwargs:
assert_eq(
getattr(pdf, func)(axis=axis, skipna=skipna, **kwargs),
getattr(gdf, func)(axis=axis, skipna=skipna, **kwargs),
check_dtype=False,
)
if expected_exception is not None:
with pytest.raises(expected_exception):
getattr(gdf, func)(axis=axis, skipna=skipna, **kwargs),
else:
assert_eq(
getattr(pdf, func)(axis=axis, skipna=skipna, **kwargs),
getattr(gdf, func)(axis=axis, skipna=skipna, **kwargs),
check_dtype=False,
)


@pytest.mark.parametrize(
Expand Down

0 comments on commit d4abda9

Please sign in to comment.