Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt711 committed Aug 13, 2024
1 parent cf3fabf commit 6e90ea5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
register_series_accessor,
)
from cudf.api.types import dtype
from cudf.core.algorithms import factorize
from cudf.core.algorithms import factorize, unique
from cudf.core.cut import cut
from cudf.core.dataframe import DataFrame, from_dataframe, from_pandas, merge
from cudf.core.dtypes import (
Expand Down
39 changes: 39 additions & 0 deletions python/cudf/cudf/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,42 @@ def _interpolation(column: ColumnBase, index: BaseIndex) -> ColumnBase:
first_nan_idx = valid_locs.values.argmax().item()
result[:first_nan_idx] = np.nan
return as_column(result)


def unique(values):
"""
Return unique values from array-like
Parameters
----------
values : 1d array-like
Returns
-------
cudf.Series,
The return can be:
* Index : when the input is an Index
* Categorical : when the input is a Categorical dtype
* cudf.Series : when the input is a Series
Return numpy.ndarray or ExtensionArray.
See Also
--------
Index.unique : Return unique values from an Index.
Series.unique : Return unique values of Series object.
Examples
--------
>>> cudf.unique(cudf.Series([2, 1, 3, 3]))
Series([2, 1, 3])
>>> cudf.unique(pd.Series([2] + [1] * 5))
Series([2, 1])
"""
try:
return values.unique()
except Exception:
raise TypeError(f"Cannot call unique on type {type(values)}")

0 comments on commit 6e90ea5

Please sign in to comment.