Skip to content

fix(rust): Return correct Struct dtype from qcut when "include_breaks=True" on empty series - #27561

Closed
kimjune01 wants to merge 1 commit into
pola-rs:mainfrom
kimjune01:fix/qcut-empty-include-breaks
Closed

kimjune01 wants to merge 1 commit into
pola-rs:mainfrom
kimjune01:fix/qcut-empty-include-breaks

Conversation

@kimjune01

Copy link
Copy Markdown

Fixes #27284.

When a Series is empty (length 0), qcut with include_breaks=True hits the
early-return path at null_count() == len() (0 == 0) and returns a Categorical
column instead of the expected Struct with breakpoint + category fields.

This returns a properly-typed empty StructChunked with Float64 breakpoint and
Categorical category fields when include_breaks is set in the early-return path.

Tests cover empty series, empty series in lazy context, and all-null series.

@github-actions github-actions Bot added A-dtype-struct Area: struct data type fix Bug fix rust Related to Rust Polars first-contribution First contribution by user title needs formatting labels May 9, 2026
@codecov

codecov Bot commented May 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.55%. Comparing base (a84168f) to head (61d22ef).
⚠️ Report is 91 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-ops/src/series/ops/cut.rs 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27561      +/-   ##
==========================================
- Coverage   81.44%   80.55%   -0.90%     
==========================================
  Files        1837     1841       +4     
  Lines      255199   255962     +763     
  Branches     3179     3180       +1     
==========================================
- Hits       207857   206184    -1673     
- Misses      46518    48950    +2432     
- Partials      824      828       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alexander-beedie alexander-beedie changed the title fix(rust): return correct Struct dtype from qcut when include_breaks=True on empty series fix(rust): Return correct Struct dtype from qcut when include_breaks=True on empty series May 10, 2026
@alexander-beedie alexander-beedie changed the title fix(rust): Return correct Struct dtype from qcut when include_breaks=True on empty series fix(rust): Return correct Struct dtype from qcut when "include_breaks=True" on empty series May 10, 2026

@orlp orlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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



def test_qcut_empty_include_breaks() -> None:
# https://github.com/pola-rs/polars/issues/27284

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Our convention is to name the test test_name_27284.

…True on empty/all-null series

The early return path in qcut for empty or all-null series always returned
bare Categorical, ignoring include_breaks. This caused a schema mismatch
when downstream code called .struct.field("breakpoint") in lazy context.

Fixes pola-rs#27284
@mkzung

mkzung commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Hi @kimjune01, while fixing two other qcut panics on degenerate float input (all-NaN and infinite), I found they sit in the same early-return block your PR touches, and a correct all-NaN fix also needs the struct-aware return you added here. I've opened #28220, which includes your empty-series fix (credited) alongside the two extra cases, since they can't cleanly be separated. Didn't want to step on your work; very happy to defer, combine, or adjust however you and the maintainers prefer.

@kimjune01

Copy link
Copy Markdown
Author

I'm happy to have this PR closed and fold it into yours @mkzung

@orlp

orlp commented Jul 6, 2026

Copy link
Copy Markdown
Member

Superseded by #28220.

@orlp orlp closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dtype-struct Area: struct data type first-contribution First contribution by user fix Bug fix rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qcut with include_breaks=True returns Categorical instead of Struct on empty Series

3 participants