naturalsize() truncates non-integer byte counts below the base ("1 Bytes")
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #507 by @ekanshul — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start at the naturalsize() implementation and its tests; the issue identifies the int() conversion and singular check as the relevant behavior. Compare the formatting path for values above the base with values below it, then add tests for fractional byte counts, including gnu=True. Done means fractional inputs retain their decimal part while integer input keeps its current output.
Written by the indexing model from the issue text.
Description
On current main:
>>> import humanize
>>> humanize.naturalsize(1.5)
'1 Bytes'
>>> humanize.naturalsize(1.9)
'1 Bytes'
>>> humanize.naturalsize(1500)
'1.5 kB'
From 1 kB upwards the fraction is kept using format, but below the base the value is truncated with int(). The singular check also compares the untruncated value with 1, so 1.5 is shown as "1 Bytes".
In #239 you mentioned that "1.1 Bytes" would be better than "1 Bytes" for non-integer input, and that tests for non-integer input were missing.
Proposal:
- Format non-integer values below the base with
format, like larger units (e.g. "1.5 Bytes", and "1.5B" withgnu=True). - Keep integer input unchanged ("300 Bytes", "1 Byte").
- Add tests for non-integer input.
Would you be happy with this? If so, we'd like to send a PR.
- Dominant language
- Python
- Stars
- 768
- Forks
- 243
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-humanize/humanize
-
intcomma returns exponential notation for large floatsPossibly taken @Omarinho12345 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-humanize/humanize#521 ·
Maintainers usually reply within 1 day
-
intcomma returns scientific notation for large floatsPossibly taken @TheNetherWatcher claimed this 47 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
python-humanize/humanize#431 ·
Maintainers usually reply within 1 day
-
metric() adds a digit when a value rounds into quettaPossibly taken @SashaMIT claimed this 49 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
python-humanize/humanize#423 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
python-humanize/humanize#512 · 1 comment ·
Maintainers usually reply within 1 day
-
naturalsize() ignores the locale decimal separatorPossibly taken @ekanshul claimed this 29 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-humanize/humanize#460 ·
Maintainers usually reply within 1 day
All issues in python-humanize/humanize
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
mozilla-ai/cq#601 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
LUCJ pass manager raises NoEdgeBetweenNodes when an edge is bad for two two-qubit gatesPossibly taken @hat-im claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
opensubtitlescom: provider rejects pt-PT even though its own converter maps itPossibly taken @paulo-0308 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Diaoul/subliminal#1405 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100