Skip to content

Forward-merge release/26.12 into main - #25297

Merged
GPUtester merged 1 commit into
mainfrom
release/26.12
Nov 14, 2026
Merged

GPUtester merged 1 commit into
mainfrom
release/26.12

Conversation

@rapids-bot

@rapids-bot rapids-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

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.

…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
@rapids-bot
rapids-bot Bot requested a review from a team as a code owner November 14, 2026 21:10
@rapids-bot
rapids-bot Bot requested a review from vyasr November 14, 2026 21:10
@GPUtester
GPUtester merged commit 26d20b6 into main Nov 14, 2026
12 checks passed
@rapids-bot

rapids-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

SUCCESS - forward-merge complete.

@github-actions github-actions Bot added the Python Affects Python cuDF API. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants