Skip to content

fix: format exact zero as a whole number in fractional - #771

Open
Zhuyuyangyy wants to merge 1 commit into
staticdev:mainfrom
Zhuyuyangyy:fix/fractional-zero-whole-number
Open

Zhuyuyangyy wants to merge 1 commit into
staticdev:mainfrom
Zhuyuyangyy:fix/fractional-zero-whole-number

Conversation

@Zhuyuyangyy

Copy link
Copy Markdown

Summary

Return the integer representation "0" for exact zero in fractional, consistent with the function's whole-number formatting contract.

Currently both fractional(0) and fractional(0.0) return "0/1". The fix checks the already-converted float for exact zero before computing the fraction. Other values retain their existing truncation and denominator-limit behavior; for example, a nonzero 0.0001 still formats as "0/1" after approximation.

Tests cover integer, float, negative and string zero, plus positive/negative whole numbers, fractions, string inputs and approximation controls. The docstring and usage page include the zero example.

Local validation

  • New focused cases against the old implementation: 4 failures, 10 passes.
  • Patched numbers suite: 42 passed.
  • Full pytest suite with the declared pytest-mock/freezegun test dependencies available: 403 passed.
  • Numbers docstring examples: 11 passed.
  • Ruff lint/format, mypy on the changed Python files, and git diff --check passed.

This is local Python 3.12 validation; the Nox multi-Python matrix and upstream CI have not been run by this contribution.

Disclosure: this contribution was prepared and checked with AI assistance on behalf of the account owner. It has not received an independent human review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants