Skip to content

Commit

Permalink
Remove unnecessary nunique function in series.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfalisse committed Feb 2, 2022
1 parent a4f1268 commit bcd84ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6031,11 +6031,12 @@ def nunique(self, axis=0, dropna=True):
"""
Count number of distinct elements in specified axis.
Return Series with number of distinct elements. Can ignore NaN values.
Parameters
----------
axis : {0 or 'index', 1 or 'columns'}, default 0
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for
column-wise.
dropna : bool, default True
Don't include NaN in the counts.
Expand All @@ -6053,12 +6054,11 @@ def nunique(self, axis=0, dropna=True):
dtype: int64
"""
if axis != 0:
raise NotImplementedError(
"axis parameter is not supported yet."
)
raise NotImplementedError("axis parameter is not supported yet.")

return cudf.Series(super().nunique(method="sort", dropna=dropna))


def from_dataframe(df, allow_copy=False):
return df_protocol.from_dataframe(df, allow_copy=allow_copy)

Expand Down
6 changes: 4 additions & 2 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import builtins
import copy
import pickle
import warnings
Expand Down Expand Up @@ -6420,10 +6421,11 @@ def nunique(self, method: builtins.str = "sort", dropna: bool = True):
Name and unique value counts of each column in frame.
"""
return {
name: col.distinct_count(method=method, dropna=dropna)
for name, col in self._data.items()
name: col.distinct_count(method=method, dropna=dropna)
for name, col in self._data.items()
}


def _get_replacement_values_for_columns(
to_replace: Any, value: Any, columns_dtype_map: Dict[Any, Any]
) -> Tuple[Dict[Any, bool], Dict[Any, Any], Dict[Any, Any]]:
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/cudf/core/single_column_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import builtins
from typing import Any, Dict, MutableMapping, Optional, Tuple, TypeVar, Union

import cupy
Expand Down Expand Up @@ -328,7 +329,7 @@ def _make_operands_for_binop(

def nunique(self, method: builtins.str = "sort", dropna: bool = True):
"""
Returns count of unique values for the column.
Return count of unique values for the column.
Parameters
----------
Expand All @@ -342,4 +343,4 @@ def nunique(self, method: builtins.str = "sort", dropna: bool = True):
int
Number of unique values in the column.
"""
return self._column.distinct_count(method=method, dropna=dropna)
return self._column.distinct_count(method=method, dropna=dropna)
3 changes: 1 addition & 2 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9095,7 +9095,7 @@ def test_dataframe_nunique(data):


@pytest.mark.parametrize(
"data", [{ "key": [0, 1, 1, 0, 0, 1], "val": [1, 8, 3, 9, -3, 8]}],
"data", [{"key": [0, 1, 1, 0, 0, 1], "val": [1, 8, 3, 9, -3, 8]}],
)
def test_dataframe_nunique_index(data):
gdf = cudf.DataFrame(data)
Expand All @@ -9113,4 +9113,3 @@ def test_dataframe_rename_duplicate_column():
ValueError, match="Duplicate column names are not allowed"
):
gdf.rename(columns={"a": "b"}, inplace=True)

0 comments on commit bcd84ad

Please sign in to comment.