Skip to content

metric: Fix precision format#159

Merged
hugovk merged 1 commit intopython-humanize:mainfrom
e-nikolov:patch-1
Dec 9, 2023
Merged

metric: Fix precision format#159
hugovk merged 1 commit intopython-humanize:mainfrom
e-nikolov:patch-1

Conversation

@e-nikolov
Copy link
Copy Markdown
Contributor

Currently if I try to print a 2 digit number with precision 0, I get this error:
ValueError: Format specifier missing precision because the format results in a negative precision number.

This PR makes sure that the precision is at least 0

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Dec 3, 2023

Please can you share a snippet of code that reproduces the problem, and also include tests?

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5cb0323) 99.19% compared to head (e5a3976) 99.19%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #159   +/-   ##
=======================================
  Coverage   99.19%   99.19%           
=======================================
  Files           9        9           
  Lines         746      746           
=======================================
  Hits          740      740           
  Misses          6        6           
Flag Coverage Δ
macos-latest 97.58% <100.00%> (ø)
ubuntu-latest 97.58% <100.00%> (ø)
windows-latest 96.11% <100.00%> (ø)

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.

@e-nikolov
Copy link
Copy Markdown
Contributor Author

@hugovk

I added a couple of tests.

A snippet that shows the problem would be something like this:

import humanize

print(humanize.metric(10, "", 0))

# expected:     10
# actual:       ValueError: Format specifier missing precision

@hugovk hugovk added the changelog: Fixed For any bug fixes label Dec 9, 2023
@hugovk hugovk changed the title metric: Fix precision format metric: Fix precision format Dec 9, 2023
@hugovk hugovk merged commit 43d6dc6 into python-humanize:main Dec 9, 2023
@hugovk
Copy link
Copy Markdown
Member

hugovk commented Dec 9, 2023

Thank you!

@moi90
Copy link
Copy Markdown

moi90 commented Jul 7, 2024

I ran into the same problem (and found the same fix). It would be great to release a new version to PyPI that includes this fix.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Jul 7, 2024

Thanks for the ping, we're long overdue a release, I'll make one this week.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Jul 8, 2024

4.10.0 is released!

@moi90
Copy link
Copy Markdown

moi90 commented Jul 8, 2024

Great!

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

Labels

changelog: Fixed For any bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants