Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): Improve error message for mismatched input lengths #22091

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ydagosto
Copy link
Contributor

@ydagosto ydagosto commented Apr 3, 2025

Closes: #22080

Overview

This PR improves the error handling in corr and pearson_corr functions by replacing a panic assertion with a descriptive PolarsError::ComputeError.

Previously, when input Series to corr had mismatched lengths, Polars would panic with an unhelpful Rust assertion error.
This PR introduces a proper ComputeError with a clear and actionable message:
"Input Series to corr must have the same length, but got lengths {} and {}."
This improves the developer experience and allows for cleaner error propagation in the future.

Ouptut log

polars.exceptions.ComputeError: Input Series must have the same length but got 2 and 3.

Notes

Removed redundant input length validation in CovState::new() and PearsonState::new() since the check is already performed in cov() and pearson_corr().

@github-actions github-actions bot added fix Bug fix rust Related to Rust Polars labels Apr 3, 2025
@ydagosto ydagosto force-pushed the fix-corr-length-error branch 2 times, most recently from 9f93d63 to c4d509a Compare April 3, 2025 03:57
@ydagosto ydagosto changed the title fix(rust): Improve error message for mismatched input lengths in fix(rust): Improve error message for mismatched input lengths Apr 3, 2025
@ydagosto ydagosto force-pushed the fix-corr-length-error branch 4 times, most recently from b12533e to a27d5b1 Compare April 3, 2025 04:00
@ydagosto ydagosto marked this pull request as ready for review April 3, 2025 04:02
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 67.50000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 80.89%. Comparing base (f5511f6) to head (97db07e).
Report is 77 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-compute/src/var_cov.rs 66.66% 7 Missing ⚠️
...s/polars-plan/src/dsl/function_expr/correlation.rs 53.84% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #22091   +/-   ##
=======================================
  Coverage   80.88%   80.89%           
=======================================
  Files        1641     1641           
  Lines      236509   236555   +46     
  Branches     2701     2705    +4     
=======================================
+ Hits       191307   191351   +44     
  Misses      44563    44563           
- Partials      639      641    +2     

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

Copy link
Collaborator

@coastalwhite coastalwhite left a comment

Choose a reason for hiding this comment

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

The error needs to be propagated up. We don't want the unwrap because that is still a panic.

@ydagosto ydagosto force-pushed the fix-corr-length-error branch 3 times, most recently from 567414c to 2f7122f Compare April 3, 2025 15:18
…remove redundant validation

- Propagate input length validation error using `PolarsResult` in `cov` and `pearson_corr`.
- Removed redundant validation inside `CovState::new()` and `PearsonState::new()` since validation is already performed at the API boundary.
@ydagosto ydagosto force-pushed the fix-corr-length-error branch from 2f7122f to 97db07e Compare April 3, 2025 15:22
@ydagosto
Copy link
Contributor Author

ydagosto commented Apr 3, 2025

polars.exceptions.ComputeError

@coastalwhite - error should now be propagated all the way. Also removed some assertions that seemed redundant. Let me know what you think

@ydagosto ydagosto requested a review from coastalwhite April 7, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when calling corr with unequal length inputs
2 participants