FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle NaN/Inf in naturalsize by shuofengzhang · Pull Request #299 · python-humanize/humanize · GitHub

Handle NaN/Inf in naturalsize - #299

Open
shuofengzhang wants to merge 3 commits into
python-humanize:mainfrom
shuofengzhang:handle-non-finite-filesize
Open

Handle NaN/Inf in naturalsize#299
shuofengzhang wants to merge 3 commits into
python-humanize:mainfrom
shuofengzhang:handle-non-finite-filesize

Conversation

Copy link
Copy Markdown

What changed

  • Return a clear string for non‑finite inputs (NaN/±Inf) in naturalsize().
  • Add tests covering NaN and ±Inf.

Why

  • naturalsize() currently computes logs on non‑finite inputs, which yields confusing output.
  • This aligns with other humanize helpers that render NaN/Inf explicitly.

Testing

  • ✅ pytest -q

codecov Bot commented Mar 1, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (85bb7e7) to head (c19e4f1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #299   +/-   ##
=======================================
  Coverage   99.53%   99.54%           
=======================================
  Files          11       11           
  Lines         868      874    +6     
=======================================
+ Hits          864      870    +6     
  Misses          4        4           
Flag Coverage Δ
macos-latest 97.48% <100.00%> (+0.01%) ⬆️
ubuntu-latest 97.48% <100.00%> (+0.01%) ⬆️
windows-latest 95.88% <100.00%> (+0.02%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

hugovk commented Mar 1, 2026

Copy link
Copy Markdown
Member

Are there actual use cases where people have file sizes that are infinite or NaN?

hugovk added the changelog: Added For new features label Mar 1, 2026

shuofengzhang commented Mar 1, 2026
edited
Loading

Copy link
Copy Markdown
Author

Are there actual use cases where people have file sizes that are infinite or NaN?

It’s mostly defensive: naturalsize() accepts floats, and callers often pass computed values (ratios, averages, deltas) from metrics/ETL pipelines. Those can become NaN/±Inf after a divide‑by‑zero or overflow, or when size is unknown in a streaming context. Returning an explicit “NaN/±Inf” is clearer than producing a weird suffix or raising. Also, humanize.number already formats NaN/Inf explicitly, so this keeps behavior consistent across helpers.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Added For new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL