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): Fix str.to_integer panics for certain inputs #22243

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

math-hiyoko
Copy link

@math-hiyoko math-hiyoko commented Apr 12, 2025

Description

This PR addresses an issue #22242 where calling str.to_integer() with strict=True unexpectedly panics for certain inputs.

The problem occurs because the values s and base at line 118 do not always correspond correctly, which leads to the bug. This PR modifies how some_failures is retrieved in original order so that s and base are properly paired, preventing the panic.

let some_failures = if ca.len() == 1 {
ca.clone()
} else {
let all_failures = ca.filter(&failure_mask)?;
all_failures.unique()?.slice(0, 10).sort(false)
};
let some_error_msg = match base.len() {
1 => {
// we can ensure that base is not null.
let base = base.get(0).unwrap();
some_failures
.get(0)
.and_then(|s| <i64 as Num>::from_str_radix(s, base).err())
.map_or_else(
|| unreachable!("failed to extract ParseIntError"),
|e| format!("{}", e),
)
},
_ => {
let base_failures = base.filter(&failure_mask)?;
some_failures
.get(0)
.zip(base_failures.get(0))
.and_then(|(s, base)| <i64 as Num>::from_str_radix(s, base).err())
.map_or_else(
|| unreachable!("failed to extract ParseIntError"),
|e| format!("{}", e),
)
},
};

close #22242

@math-hiyoko math-hiyoko changed the title Fix panic in strict mode for str.to_integer() fix: panic in strict mode for str.to_integer() Apr 12, 2025
@math-hiyoko math-hiyoko changed the title fix: panic in strict mode for str.to_integer() fix: panic in strict mode for str.to_integer() for certain inputs Apr 12, 2025
Copy link

codecov bot commented Apr 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.77%. Comparing base (69ad1ba) to head (aef60d6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22243      +/-   ##
==========================================
- Coverage   80.78%   80.77%   -0.01%     
==========================================
  Files        1639     1639              
  Lines      235548   235549       +1     
  Branches     2714     2714              
==========================================
- Hits       190278   190270       -8     
- Misses      44630    44638       +8     
- Partials      640      641       +1     

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

@math-hiyoko math-hiyoko changed the title fix: panic in strict mode for str.to_integer() for certain inputs fix(rust): panic in strict mode for str.to_integer() for certain inputs Apr 12, 2025
@math-hiyoko math-hiyoko changed the title fix(rust): panic in strict mode for str.to_integer() for certain inputs fix(rust): Fix str.to_integer panics for certain inputs Apr 12, 2025
@github-actions github-actions bot added fix Bug fix rust Related to Rust Polars and removed title needs formatting labels Apr 12, 2025
@math-hiyoko
Copy link
Author

Can someone review this?
Although PR #22239 is almost finished, it’s necessary to merge this PR ahead of it.

@math-hiyoko math-hiyoko marked this pull request as draft April 13, 2025 06:19
@math-hiyoko math-hiyoko marked this pull request as ready for review April 13, 2025 07:02
@math-hiyoko
Copy link
Author

I’ve made some minor adjustments; everything is ready now.

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.

str.to_integer() fails with strict=True
1 participant