Skip to content

fix: Correctly handle min and max bounds less than 1 for Decimal#131

Merged
Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom
jhall-bp:decimal-validation
Sep 4, 2025
Merged

fix: Correctly handle min and max bounds less than 1 for Decimal#131
Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom
jhall-bp:decimal-validation

Conversation

@jhall-bp
Copy link
Copy Markdown
Contributor

Motivation

Issue: #130

dy.Decimal currently crashes during validation when instantiated with a min or max value that is 0 or less. This PR changes the way that the number of digits before the decimal place of a decimal.Decimal is calculated so that smaller mix/max values can be used as constraints.

Changes

  • The _num_digits helper function used for validating dy.Decimal inputs has been changed to use the digits and exponent values from decimal.Decimal.as_tuple() to calculate the number of digits instead of using math.log10
  • Update test cases for dy.Decimal

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d8916e8) to head (a54be69).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #131   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         2450      2451    +1     
=========================================
+ Hits          2450      2451    +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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

@borchero Oliver Borchert (borchero) merged commit 028055d into Quantco:main Sep 4, 2025
20 checks passed
@borchero Oliver Borchert (borchero) changed the title fix: Correctly handle min and max bounds less than 1 for Decimal (#130) fix: Correctly handle min and max bounds less than 1 for Decimal Sep 4, 2025
@jhall-bp Jesse (jhall-bp) deleted the decimal-validation branch September 13, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimals with explicit precision and a min/max of 0 raise math domain error during validation

2 participants