Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naturalsize output changed between 4.11.0 and 4.12.0 #239

Closed
davidboweninrupt opened this issue Feb 17, 2025 · 2 comments · Fixed by #240
Closed

naturalsize output changed between 4.11.0 and 4.12.0 #239

davidboweninrupt opened this issue Feb 17, 2025 · 2 comments · Fixed by #240
Labels
bug Something isn't working

Comments

@davidboweninrupt
Copy link

Possibly a result of #218, we are seeing that the output has changed:

  1. podman run -it python bash
  2. python -m pip install humanize==4.11.0
  3. python -c "import humanize; print(humanize.naturalsize(1.123456789))"

1 Bytes

  1. python -m pip install humanize==4.12.0
  2. python -c "import humanize; print(humanize.naturalsize(1.123456789))"

1.123456789 Bytes

Expected behaviour is that output would not change in a minor version or that it would be documented in the release notes.

@hugovk
Copy link
Member

hugovk commented Feb 17, 2025

Thanks for the report.

This was caused by some bad formatting replacement in fb61d5a / #226.

Let's fix it properly and make a patch release.


As an aside, we get:

>>> import humanize
>>> humanize.naturalsize(1.123456789 * 1000)
'1.1 kB'
>>> humanize.naturalsize(1.123456789 * 1000000)
'1.1 MB'

So I think it would be better to also get:

>>> humanize.naturalsize(1.123456789 * 1000000)
'1.1 Bytes'

Instead of:

>>> humanize.naturalsize(1.123456789 * 1000000)
'1 Bytes'

But that's another issue. And we're definitely missing tests for non-integer input:

([300], "300 Bytes"),
(["1000"], "1.0 kB"),
([10**3], "1.0 kB"),
([10**6], "1.0 MB"),
([10**9], "1.0 GB"),
([10**12], "1.0 TB"),
([10**15], "1.0 PB"),
([10**18], "1.0 EB"),
([10**21], "1.0 ZB"),
([10**24], "1.0 YB"),
([10**27], "1.0 RB"),
([10**30], "1.0 QB"),
([1000**1 * 31], "31.0 kB"),
([1000**2 * 32], "32.0 MB"),
([1000**3 * 33], "33.0 GB"),
([1000**4 * 34], "34.0 TB"),
([1000**5 * 35], "35.0 PB"),
([1000**6 * 36], "36.0 EB"),
([1000**7 * 37], "37.0 ZB"),
([1000**8 * 38], "38.0 YB"),
([1000**9 * 39], "39.0 RB"),
([1000**10 * 40], "40.0 QB"),
([300, True], "300 Bytes"),
([1024**1 * 31, True], "31.0 KiB"),
([1024**2 * 32, True], "32.0 MiB"),
([1024**3 * 33, True], "33.0 GiB"),
([1024**4 * 34, True], "34.0 TiB"),
([1024**5 * 35, True], "35.0 PiB"),
([1024**6 * 36, True], "36.0 EiB"),
([1024**7 * 37, True], "37.0 ZiB"),
([1024**8 * 38, True], "38.0 YiB"),
([1024**9 * 39, True], "39.0 RiB"),
([1024**10 * 40, True], "40.0 QiB"),
([1000**1 * 31, True], "30.3 KiB"),
([1000**2 * 32, True], "30.5 MiB"),
([1000**3 * 33, True], "30.7 GiB"),
([1000**4 * 34, True], "30.9 TiB"),
([1000**5 * 35, True], "31.1 PiB"),
([1000**6 * 36, True], "31.2 EiB"),
([1000**7 * 37, True], "31.3 ZiB"),
([1000**8 * 38, True], "31.4 YiB"),
([1000**9 * 39, True], "31.5 RiB"),
([1000**10 * 40, True], "31.6 QiB"),
([1000**1 * 31, False, True], "30.3K"),
([1000**2 * 32, False, True], "30.5M"),
([1000**3 * 33, False, True], "30.7G"),
([1000**4 * 34, False, True], "30.9T"),
([1000**5 * 35, False, True], "31.1P"),
([1000**6 * 36, False, True], "31.2E"),
([1000**7 * 37, False, True], "31.3Z"),
([1000**8 * 38, False, True], "31.4Y"),
([1000**9 * 39, False, True], "31.5R"),
([1000**10 * 40, False, True], "31.6Q"),
([300, False, True], "300B"),
([3000, False, True], "2.9K"),
([3000000, False, True], "2.9M"),
([1024, False, True], "1.0K"),
([1, False, False], "1 Byte"),
([3141592, False, False, "%.2f"], "3.14 MB"),
([3000, False, True, "%.3f"], "2.930K"),
([3000000000, False, True, "%.0f"], "3G"),
([10**26 * 30, True, False, "%.3f"], "2.423 RiB"),

@hugovk hugovk added the bug Something isn't working label Feb 17, 2025
@hugovk
Copy link
Member

hugovk commented Feb 17, 2025

#240 adds tests and should revert to the previous behaviour. How does it look?

dlax added a commit to dalibo/pg_activity that referenced this issue Feb 18, 2025
We are apparently affected by this issue:

  python-humanize/humanize#239

Let's avoid that version and wait for a fix.
dlax added a commit to dalibo/pg_activity that referenced this issue Feb 18, 2025
We are apparently affected by this issue:

  python-humanize/humanize#239

Let's avoid that version and wait for a fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants