Skip to content

Commit

Permalink
Add pandas compatible output to Series.unique (rapidsai#13959)
Browse files Browse the repository at this point in the history
Partially addresses rapidsai#8175
This PR makes changes to `Series.unique`, where a cupy array is returned to match `pd.Series.unique` where a numpy array is returned.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: rapidsai#13959
  • Loading branch information
galipremsagar authored Aug 25, 2023
1 parent 384b33f commit aef903c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,8 @@ def unique(self):
dtype: object
"""
res = self._column.unique()
if cudf.get_option("mode.pandas_compatible"):
return res.values
return Series(res, name=self.name)

@_cudf_nvtx_annotate
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,3 +2254,12 @@ def test_series_nlargest_nsmallest_str_error(attr):
assert_exceptions_equal(
getattr(gs, attr), getattr(ps, attr), ([], {"n": 1}), ([], {"n": 1})
)


def test_series_unique_pandas_compatibility():
gs = cudf.Series([10, 11, 12, 11, 10])
ps = gs.to_pandas()
with cudf.option_context("mode.pandas_compatible", True):
actual = gs.unique()
expected = ps.unique()
assert_eq(actual, expected)

0 comments on commit aef903c

Please sign in to comment.