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

Apply metadata to keys before returning in Frame._encode #8560

Merged
merged 4 commits into from
Jul 16, 2021
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
5 changes: 5 additions & 0 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3258,6 +3258,11 @@ def _split(self, splits, keep_index=True):
def _encode(self):
keys, indices = libcudf.transform.table_encode(self)
keys = self.__class__._from_table(keys)
for col in keys._data:
keys._data[col] = keys._data[col]._with_type_metadata(
self._data[col].dtype
)

return keys, indices

def _reindex(
Expand Down
36 changes: 31 additions & 5 deletions python/cudf/cudf/tests/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,35 @@ def test_pivot_multi_values():
"level",
[
0,
1,
pytest.param(
1,
marks=pytest.mark.xfail(
reason="Categorical column indexes not supported"
),
),
2,
"foo",
"bar",
pytest.param(
"bar",
marks=pytest.mark.xfail(
reason="Categorical column indexes not supported"
),
),
"baz",
[],
[0, 1],
pytest.param(
[0, 1],
marks=pytest.mark.xfail(
reason="Categorical column indexes not supported"
),
),
["foo"],
["foo", "bar"],
pytest.param(
["foo", "bar"],
marks=pytest.mark.xfail(
reason="Categorical column indexes not supported"
),
),
pytest.param(
[0, 1, 2],
marks=pytest.mark.xfail(reason="Pandas behaviour unclear"),
Expand All @@ -416,7 +436,7 @@ def test_unstack_multiindex(level):
pdf = pd.DataFrame(
{
"foo": ["one", "one", "one", "two", "two", "two"],
"bar": ["A", "B", "C", "A", "B", "C"],
"bar": pd.Categorical(["A", "B", "C", "A", "B", "C"]),
"baz": [1, 2, 3, 4, 5, 6],
"zoo": ["x", "y", "z", "q", "w", "t"],
}
Expand All @@ -436,6 +456,12 @@ def test_unstack_multiindex(level):
[
pd.Index(range(0, 5), name=None),
pd.Index(range(0, 5), name="row_index"),
pytest.param(
pd.CategoricalIndex(["d", "e", "f", "g", "h"]),
marks=pytest.mark.xfail(
reason="Categorical column indexes not supported"
),
),
],
)
@pytest.mark.parametrize(
Expand Down