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

Fix type metadata issue preservation with Column.unique #13957

Merged
merged 2 commits 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
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,9 @@ def unique(self) -> ColumnBase:
"""
Get unique values in the data
"""
return drop_duplicates([self], keep="first")[0]
return drop_duplicates([self], keep="first")[0]._with_type_metadata(
self.dtype
)

def serialize(self) -> Tuple[dict, list]:
# data model:
Expand Down
22 changes: 21 additions & 1 deletion python/cudf/cudf/tests/test_interval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.


import numpy as np
import pandas as pd
import pytest

Expand Down Expand Up @@ -132,3 +134,21 @@ def test_create_interval_df(data1, data2, data3, data4, closed):
dtype="interval",
)
assert_eq(expect_three, got_three)


def test_interval_index_unique():
interval_list = [
np.nan,
pd.Interval(2.0, 3.0, closed="right"),
pd.Interval(3.0, 4.0, closed="right"),
np.nan,
pd.Interval(3.0, 4.0, closed="right"),
pd.Interval(3.0, 4.0, closed="right"),
]
pi = pd.Index(interval_list)
gi = cudf.from_pandas(pi)

expected = pi.unique()
actual = gi.unique()

assert_eq(expected, actual)