python-humanize / python-humanize/humanize

intword: values between 10^36 and a googol format as huge decillion counts, and rounding to the next unit does not carry

Offen
#356 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
756
Forks
148
Ø Merge
6 T. 1 Std.
Gemergte PRs (30 T.)
12

Beschreibung

What happened

intword handles values up to 1000 decillion (10^36) and exactly a googol
(10^100) well, but everything in between formats as an enormous decillion
count:

>>> import humanize
>>> humanize.intword(10**100)
'1.0 googol'
>>> humanize.intword(10**100 - 10**93)
'9999999000000000610151082626636586748864734715312950532670947852288.0 decillion'
>>> humanize.intword(10**50)
'100000000000000000.0 decillion'

A 67 digit unit count defeats the purpose of a human readable number, and
a value just below a googol that rounds up to it never carries to
"1.0 googol".

Verified on humanize 4.16.0 (published wheel) and on current main
(c3a124c), Python 3.11.

Why this looks like a bug rather than a choice

This is the same class of boundary behavior that #328 recently fixed for
metric() (carry to the next SI prefix when rounding reaches 1000). The
powers list jumps from decillion (10^33) to googol (10^100), and the
selection loop picks decillion for anything under a googol, no matter how
large the resulting count is. Values above the largest power already fall
back to str(value), which suggests the intended behavior for
"no reasonable unit" is the plain number, not a unit with a 67 digit
multiplier.

Expected

One of the following, whichever matches the project's intent:

  1. Values whose formatted count reaches 1000 of a unit with no adjacent
    next power fall back to str(value) (consistent with the existing
    above-maximum behavior), and values that round up to exactly the next
    power carry to it ("1.0 googol"), consistent with #328's carry rule.
  2. Or simply fall back to str(value) for the whole gap between 10^36
    and 10^100.

I am happy to open a PR with regression tests for the boundary cases once
maintainers confirm which behavior is intended.

How this was found

An automated review gate proposed edge case tests for the recent number.py
changes (the #328 carry fix among them) and executed them against the
code; the "carry just below the next unit" test failed with the output
above. The failing test and its observed output are reproducible by hand
as shown.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den im Bericht referenzierten Änderungen in number.py und reproduziere die Grenzbeispiele mit Python 3.11. Kläre mit den Maintainer:innen, ob die Lücke auf str(value) zurückfallen oder an der googol-Grenze weitergeführt werden soll, und füge anschließend Regressionstests für das ausgewählte Verhalten hinzu. Erledigt ist die Aufgabe, wenn Werte nahe 10^100 keine enormen Decillion-Zählwerte mehr erzeugen und das Runden der vereinbarten Regel folgt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.