Skip to content

feat: Extend Expr.reinterpret to all numeric types of the same size#26401

Open
leudz wants to merge 4 commits intopola-rs:mainfrom
leudz:Extend-Expr.reinterpret
Open

feat: Extend Expr.reinterpret to all numeric types of the same size#26401
leudz wants to merge 4 commits intopola-rs:mainfrom
leudz:Extend-Expr.reinterpret

Conversation

@leudz
Copy link

@leudz leudz commented Feb 3, 2026

Fixes #13659

Following the implementation outlined in this comment, reinterpret now works with all numeric types as long as they have the same size.
reinterpret takes a DataType argument instead of a bool.

  1. I used AI to help expend the pattern in reinterpret.rs.
  2. I confirm that I have reviewed all changes myself, and I believe they are
    relevant and correct.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Feb 3, 2026
}
#[cfg(not(feature = "dtype-u128"))]
{
unimplemented!()
Copy link
Author

Choose a reason for hiding this comment

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

unimplemented!() was used originally so I kept it. unreachable!() might make more sense.
This comment applies to all of them.

Comment on lines 371 to 391
fn reinterpret_signed(&self) -> Series {
match self.inner_dtype() {
#[cfg(feature = "dtype-f16")]
DataType::Float16 => reinterpret_list_chunked::<Float16Type, Int16Type>(self),
DataType::Float32 => reinterpret_list_chunked::<Float32Type, Int32Type>(self),
DataType::Float64 => reinterpret_list_chunked::<Float64Type, Int64Type>(self),
_ => unimplemented!(),
}
.into_series()
}

fn reinterpret_unsigned(&self) -> Series {
match self.inner_dtype() {
#[cfg(feature = "dtype-f16")]
DataType::Float16 => reinterpret_list_chunked::<Float16Type, UInt16Type>(self),
DataType::Float32 => reinterpret_list_chunked::<Float32Type, UInt32Type>(self),
DataType::Float64 => reinterpret_list_chunked::<Float64Type, UInt64Type>(self),
_ => unimplemented!(),
}
.into_series()
}
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure where/how these are used. They are reinterpreting floats, which is interesting.
Should I add the new type combinations here?

@github-actions github-actions bot added the changes-dsl Do not merge if this label is present and red. label Feb 3, 2026
@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 38.23529% with 84 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.99%. Comparing base (8b8dc1e) to head (02cf963).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...ates/polars-core/src/chunked_array/ops/bit_repr.rs 28.23% 61 Missing ⚠️
crates/polars-ops/src/series/ops/reinterpret.rs 43.24% 21 Missing ⚠️
.../polars-python/src/lazyframe/visitor/expr_nodes.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #26401   +/-   ##
=======================================
  Coverage   80.99%   80.99%           
=======================================
  Files        1782     1782           
  Lines      243078   243123   +45     
  Branches     3078     3078           
=======================================
+ Hits       196879   196925   +46     
+ Misses      45396    45395    -1     
  Partials      803      803           

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes-dsl Do not merge if this label is present and red. enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend Expr.reinterpret to arbitrary primitive numeric types

1 participant

Comments