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 more validation to MultiIndex.to_frame #14671

Merged
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: 4 additions & 0 deletions python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,10 @@ def to_frame(self, index=True, name=no_default, allow_duplicates=False):
for level, name in enumerate(self.names)
]
else:
if not is_list_like(name):
raise TypeError(
"'name' must be a list / sequence of column names."
)
if len(name) != len(self.levels):
raise ValueError(
"'name' should have the same length as "
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/tests/test_multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,13 +1953,13 @@ def test_multiindex_to_frame_allow_duplicates(
):
gidx = cudf.from_pandas(pidx)

if (
if name is None or (
(
len(pidx.names) != len(set(pidx.names))
and not all(x is None for x in pidx.names)
)
and not allow_duplicates
and (name is None or name is no_default)
and name is no_default
):
assert_exceptions_equal(
pidx.to_frame,
Expand Down
Loading