Repository navigation
Forward-merge release/26.12 into main - #25297
Merged
Merged
Conversation
…ty DataFrame (#24442) Assigning an empty column to an existing column of a zero-row DataFrame unnecessarily rebuilds every other column. Repeating this for each column makes column-wise operations expensive even though there are no rows to process. ```python import cudf df = cudf.DataFrame({f"c{i}": cudf.Series([], dtype="str") for i in range(287)}) for c in df.columns: df[c] = df[c].str.strip() ``` `DataFrame.__setitem__` handles this assignment through the same path used when assigning a non-empty column to a zero-row DataFrame. That path recreates the other columns with `column_empty()` to match the assigned column's length. It does so even when that length is zero, resulting in O(ncols²) calls to `column_empty()` when all columns are assigned in a loop. This PR adds a zero-length check so that assigning an empty column replaces only the target column. Assigning a non-empty column to a zero-row DataFrame still extends the other columns to the same number of rows, as before. | 287 columns, `df[c] = df[c].str.strip()` for each column | before | after | |---|---|---| | 0 rows | 18.8 s | 0.072 s | | 130,000 rows | 0.27 s | 0.28 s | "before" is the cudf-cu13 nightly built from 54cac9a (the base of this PR); "after" is the same nightly with this PR's Python change applied. Median of 5 runs after a warm-up, on an NVIDIA GB10 (driver 580.95.05) with pandas 3.0.6. ## Tests - `test_empty_dataframe_setitem_empty_column_keeps_other_columns`: checks that the other columns are not rebuilt, and compares against pandas with the same assignment applied to a DataFrame converted before the assignment. Fails without the fix, passes with it. - `python/cudf/cudf/tests/dataframe`: 10566 passed, 420 skipped, 62 xfailed with the fix. Without the fix, the only failure is the new test. Authors: - Hirota Akio (https://github.com/a-hirota) - Richard (Rick) Zamora (https://github.com/rjzamora) Approvers: - Richard (Rick) Zamora (https://github.com/rjzamora) URL: #24442
Contributor
Author
|
SUCCESS - forward-merge complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Forward-merge triggered by push to release/26.12 that creates a PR to keep main up-to-date. If this PR is unable to be immediately merged due to conflicts, it will remain open for the team to manually merge. See forward-merger docs for more info.