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

Implement cudf.MultiIndex.from_arrays #14740

Merged
merged 5 commits into from
Jan 18, 2024

Conversation

mroeschke
Copy link
Contributor

Description

Implements cudf.MultiIndex.from_arrays

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke added Python Affects Python cuDF API. improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jan 11, 2024
@mroeschke mroeschke requested a review from a team as a code owner January 11, 2024 01:19
"""
Convert arrays to MultiIndex.

Parameters
Copy link
Contributor

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.

Copy link
Contributor Author

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],
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Added

Comment on lines +1481 to +1486
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)
Copy link
Contributor

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)

Copy link
Contributor Author

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

@mroeschke
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 734ca75 into rapidsai:branch-24.02 Jan 18, 2024
67 checks passed
@mroeschke mroeschke deleted the enh/mi_from_arrays branch January 18, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants