Skip to content

Fix panic on lossy decimal to float casting: round to saturation for overflows #7887

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

Merged
merged 10 commits into from
Jul 23, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test(decimal cast): add tests for positive and negative overflow when…
… casting Decimal256 to Float64
  • Loading branch information
kosiew committed Jul 10, 2025
commit 05ace0c53dea226d38ab6cd5eb8b923a2725f65a
12 changes: 12 additions & 0 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8675,13 +8675,25 @@ mod tests {
}
#[test]
fn test_cast_decimal256_to_f64_overflow() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to cover negative infinity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@klion26

Good catch.
I amended the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also please either add or ensure there is an existing test for casting Decimal128 (i128::MIN and i128::MAX to f64)

Copy link
Contributor

Choose a reason for hiding this comment

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

Update, I didn't notice that @kosiew added a follow on ticket to track this work:

// Test positive overflow (positive infinity)
let array = vec![Some(i256::MAX)];
let array = create_decimal256_array(array, 76, 2).unwrap();
let array = Arc::new(array) as ArrayRef;

let result = cast(&array, &DataType::Float64).unwrap();
let result = result.as_primitive::<Float64Type>();
assert!(result.value(0).is_infinite());
assert!(result.value(0) > 0.0); // Positive infinity

// Test negative overflow (negative infinity)
let array = vec![Some(i256::MIN)];
let array = create_decimal256_array(array, 76, 2).unwrap();
let array = Arc::new(array) as ArrayRef;

let result = cast(&array, &DataType::Float64).unwrap();
let result = result.as_primitive::<Float64Type>();
assert!(result.value(0).is_infinite());
assert!(result.value(0) < 0.0); // Negative infinity
}

#[test]
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy