Skip to content

Commit

Permalink
Validate ignore_index type in drop_duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Sep 13, 2023
1 parent 3be772f commit d5d60a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,11 @@ def drop_duplicates(
ignore_index: bool, default False
If True, the resulting axis will be labeled 0, 1, ..., n - 1.
"""
if not isinstance(ignore_index, bool):
raise ValueError(
f"{ignore_index=} must be bool, "
f"not {type(ignore_index).__name__}"
)
subset = self._preprocess_subset(subset)
subset_cols = [name for name in self._column_names if name in subset]
if len(subset_cols) == 0:
Expand Down
6 changes: 6 additions & 0 deletions python/cudf/cudf/tests/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,9 @@ def test_drop_duplicates_multi_index():
gdf[col].drop_duplicates().to_pandas(),
pdf[col].drop_duplicates(),
)


def test_drop_duplicates_ignore_index_wrong_type():
gdf = cudf.DataFrame([1, 1, 2])
with pytest.raises(ValueError):
gdf.drop_duplicates(ignore_index="True")

0 comments on commit d5d60a5

Please sign in to comment.