Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pandas compatible output to Series.unique #13959

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only doing this in pandas-compat mode because this marks the buffer as exposed, and may not work for string/struct types?

Copy link
Contributor Author

@galipremsagar galipremsagar Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will only work for numeric types (int, float..) and error for the rest of the types.


@_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)