Handle NaN/Inf in naturalsize#299
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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. |
What changed
naturalsize().Why
naturalsize()currently computes logs on non‑finite inputs, which yields confusing output.Testing
pytest -q