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: Fix casting decimal to decimal for high precision #16049

Merged
merged 3 commits into from
May 5, 2024

Conversation

stinodego
Copy link
Member

Closes #16027

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels May 4, 2024
Comment on lines -15 to -18
let min_for_precision = 9_i128
.saturating_pow(1 + to_precision as u32)
.saturating_neg();
let max_for_precision = 9_i128.saturating_pow(1 + to_precision as u32);
Copy link
Member Author

@stinodego stinodego May 4, 2024

Choose a reason for hiding this comment

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

It's pretty bizarre to me that someone wrote this logic. I guess the intention was to define the bounds as e.g. 999 for precision 3, but it completely misses that mark. Am I missing something?

@@ -50,7 +50,7 @@ def test_modulo() -> None:
("value", "sqltype", "prec_scale", "expected_value", "expected_dtype"),
[
(64.5, "numeric", "(3,1)", D("64.5"), pl.Decimal(3, 1)),
(512.5, "decimal", "(3,1)", D("512.5"), pl.Decimal(3, 1)),
Copy link
Member Author

Choose a reason for hiding this comment

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

This should have failed. New logic properly causes this to fail.

@stinodego stinodego marked this pull request as ready for review May 4, 2024 21:21
Copy link

codecov bot commented May 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.96%. Comparing base (e17ef46) to head (4dbd338).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16049      +/-   ##
==========================================
- Coverage   80.96%   80.96%   -0.01%     
==========================================
  Files        1386     1386              
  Lines      178385   178383       -2     
  Branches     3060     3060              
==========================================
- Hits       144438   144431       -7     
- Misses      33460    33465       +5     
  Partials      487      487              
Flag Coverage Δ
python 74.50% <100.00%> (-0.03%) ⬇️
rust 78.14% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented May 4, 2024

CodSpeed Performance Report

Merging #16049 will improve performances by 24.72%

Comparing fix-decimal-cast (4dbd338) with main (e17ef46)

Summary

⚡ 1 improvements
✅ 34 untouched benchmarks

Benchmarks breakdown

Benchmark main fix-decimal-cast Change
test_filter2 2.8 ms 2.2 ms +24.72%

@stinodego stinodego merged commit aa2e77b into main May 5, 2024
50 checks passed
@stinodego stinodego deleted the fix-decimal-cast branch May 5, 2024 20:06
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Off-by-one error when casting to Decimal with set precision
1 participant