-
Notifications
You must be signed in to change notification settings - Fork 915
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
Implement cudf.MultiIndex.from_arrays
#14740
Implement cudf.MultiIndex.from_arrays
#14740
Conversation
""" | ||
Convert arrays to MultiIndex. | ||
|
||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing sortorder
docstring in parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Added
|
||
@pytest.mark.parametrize( | ||
"array", | ||
[list, tuple, np.array, pd.Index, cudf.Index, pd.Series, cudf.Series], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also test cupy arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Added
for array in arrays: | ||
if not (is_list_like(array) or is_column_like(array)): | ||
raise TypeError(error_msg) | ||
code, level = factorize(array, sort=True) | ||
codes.append(code) | ||
levels.append(level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a functional exercise, this can rewrite as a map
statement:
code_levels = map(functools.partial(factorize, sort=True), array)
codes, levels = [x[0] for x in code_levels], [x[1] for x in code_levels]
Error checking is also functional:
if not all (is_list_like(arr) or is_column_like(arr) for arr in arrays):
raise TypeError(error_msg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya my idea was just to do the validation + factorization in the same loop
/merge |
Description
Implements
cudf.MultiIndex.from_arrays
Checklist