fix: Fix categorical value count sort panic regression#26412
Open
bayoumi17m wants to merge 4 commits intopola-rs:mainfrom
Open
fix: Fix categorical value count sort panic regression#26412bayoumi17m wants to merge 4 commits intopola-rs:mainfrom
bayoumi17m wants to merge 4 commits intopola-rs:mainfrom
Conversation
dda5bc3 to
b714be6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26412 +/- ##
=======================================
Coverage 80.99% 81.00%
=======================================
Files 1782 1782
Lines 243104 243138 +34
Branches 3078 3078
=======================================
+ Hits 196901 196950 +49
+ Misses 45400 45385 -15
Partials 803 803 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2 tasks
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.
Overview
Fix panic when calling list operations (e.g.,
list.sort()) on lists containing structs with Categorical or Enum fields. This is a regression introduced in #25661 when we modified the operations to usetry_apply_amortized_same_type.Root Cause / Proposed fix
Root Cause
amortized_iter()converts structs to physical types, stripping_PL_CATEGORICAL2metadatatry_apply_amortized_same_typetries to collect with the original dtype (which has metadata)ListArray::newdoes strict dtype comparison including Arrow metadata → panicBefore #25661,
try_apply_amortizedinferred the dtype from collected values, andsame_type()handled conversion afterward.Proposed Fix
For list operations, check if inner type contains categoricals enums. If so, fall back to the more flexible
try_apply_amortized+same_typeapproach that worked before #25661.Originally, I did this in all list functions but extracted it to a helper that applies some closure F
Questions
polars/crates/polars-core/src/chunked_array/list/iterator.rs
Lines 140 to 147 in e55c3b0
AI Usage
Fixes #26383