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

Add humanize.metric() for converting big/small numbers to SI units #22

Merged
merged 2 commits into from Jun 19, 2022

Conversation

bwoodsend
Copy link
Contributor

Fixes nothing!

Changes proposed in this pull request:

  • Fix scientific() on small positive numbers.
  • Add humanize.metric() for converting big/small numbers to SI units.

Checking a number is negative using `'-' in string_value` leads to confusion
because 1e-30 and -1e30 both contain a '-' but only one of them is negative.
This bug had found its way into the tests and the docstring.

Additionally, the removal of redundant leading '0's and '+'s from the exponent
would only kick in if both were present so that 1e20 would become 10⁺²⁰ instead
of just 10²⁰ and the insertion of negative exponents could lead to outputs such
as 3.00 x 10⁻⁺²⁰.
@bwoodsend
Copy link
Contributor Author

Uhm, why did precommit do that?

@hugovk hugovk added the changelog: Added For new features label Jun 18, 2022
@hugovk
Copy link
Member

hugovk commented Jun 18, 2022

Haha! That's autoflake fixing:

src/humanize/__init__.py:5:1: F401 'humanize.number.metric' imported but unused

The real fix is to add metric to __all__ in src/humanize/__init__.py.

@hugovk hugovk changed the title metric Add humanize.metric() for converting big/small numbers to SI units Jun 18, 2022
@bwoodsend bwoodsend force-pushed the metric branch 6 times, most recently from 746aafb to 3bb8a45 Compare June 18, 2022 17:45
@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2022

Codecov Report

Merging #22 (19726a0) into main (7688f20) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
+ Coverage   99.08%   99.09%   +0.01%     
==========================================
  Files           9        9              
  Lines         658      666       +8     
==========================================
+ Hits          652      660       +8     
  Misses          6        6              
Flag Coverage Δ
macos-latest 97.89% <100.00%> (+0.02%) ⬆️
ubuntu-latest 97.89% <100.00%> (+0.02%) ⬆️
windows-latest 97.59% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/humanize/__init__.py 100.00% <ø> (ø)
src/humanize/number.py 96.89% <100.00%> (+0.12%) ⬆️
tests/test_number.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7688f20...19726a0. Read the comment docs.

@hugovk
Copy link
Member

hugovk commented Jun 18, 2022

Thanks for this!

For metric let's add the required space between the number and the unit (maybe with exceptions for plane angular degrees, minutes, and seconds (°, ′, and ″)?).

https://en.wikipedia.org/wiki/International_System_of_Units#General_rules

I guess we should do this also when there's no SI unit but we end up with a metric k or so on?

I think this will replace PR #1 as well.

@hugovk hugovk enabled auto-merge June 19, 2022 08:45
@hugovk hugovk merged commit 29d37fb into python-humanize:main Jun 19, 2022
@hugovk
Copy link
Member

hugovk commented Jun 19, 2022

Thank you!

@hugovk hugovk mentioned this pull request Jun 19, 2022
@bwoodsend bwoodsend deleted the metric branch June 19, 2022 10:10
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.

None yet

3 participants