humanize icon indicating copy to clipboard operation
humanize copied to clipboard

intword fails to parse numbers >= 1 Googol

Open MajorTanya opened this issue 2 years ago • 1 comments

What did you do?

I tried to use humanize to convert 10_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000 (1 Googol) to the text output “1 googol” by calling humanize.intword() with the number.

What did you expect to happen?

I expected the text output to be “1 googol” as the documentation for intword claims the library can handle numbers of this size.

What actually happened?

The output was just the number as a string, without any word at all: '10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'

This is also the case for numbers larger than 1 Googol.

What versions are you using?

  • OS: Windows 11 Pro 22H2 22621.1992
  • Python: Python 3.11.4 (also tried 3.10.11, 3.9.13, 3.8.10, and 3.7.9)
  • Humanize: 4.7.0 (4.6.0 for Python 3.7.9)

Please include code that reproduces the issue.

The best reproductions are self-contained scripts with minimal dependencies.

>>> import humanize
# 1 Googol:
>>> GOOGOL = 10_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000
>>> humanize.intword(GOOGOL)
'10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'

# 1 Googol minus 1:
>>> humanize.intword(GOOGOL - 1)
'10000000000000001323945434466030186557813051577054744406252071157760.0 decillion'

# 1000 Googol:
>>> humanize.intword(GOOGOL * 1000)
'10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'

The fact that it doesn't seem to work in any Python versions going all the way back to 3.8 in humanize v4.7.0 (and Python 3.7 with v4.6.0) seems odd to me. It leads me to believe that either I am misunderstanding the documentation, I am using the library wrongly, or something is wrong with how humanize handles a Googol. If humanize is not supposed to parse a googol to the string “1 googol”, the docs should be updated to reflect that. Currently, they state:

Supports up to decillion (33 digits) and googol (100 digits). Which I understood meaning “Can parse and display a googol”.

My apologies if the problem turns out to be me misunderstanding/-using.

MajorTanya avatar Jul 26 '23 03:07 MajorTanya

At first glance, the docstring and constants have been in the codebase for 12 years (https://github.com/python-humanize/humanize/commit/0cf11999e31e2ce2e1adaa50134518ced7ef2aaf), but there's no test for googol, so sounds like a bug/regression.

Possibly related to https://github.com/python-humanize/humanize/pull/87 (released in 4.5.0), see also https://github.com/python-humanize/humanize/issues/91.

hugovk avatar Jul 26 '23 05:07 hugovk