Skip to content

Commit e2f2dad

Browse files
authored
Merge branch 'python-humanize:main' into precisedelta-rounding
2 parents 181031e + e705e43 commit e2f2dad

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed
File renamed without changes.

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v2.32.0
3+
rev: v2.34.0
44
hooks:
55
- id: pyupgrade
66
args: [--py37-plus]
77

88
- repo: https://github.com/psf/black
9-
rev: 22.3.0
9+
rev: 22.6.0
1010
hooks:
1111
- id: black
1212
args: [--target-version=py37]
@@ -42,7 +42,7 @@ repos:
4242
- id: python-check-blanket-noqa
4343

4444
- repo: https://github.com/pre-commit/pre-commit-hooks
45-
rev: v4.2.0
45+
rev: v4.3.0
4646
hooks:
4747
- id: check-json
4848
- id: check-merge-conflict
@@ -58,7 +58,7 @@ repos:
5858
files: "src/"
5959

6060
- repo: https://github.com/pre-commit/mirrors-mypy
61-
rev: v0.942
61+
rev: v0.961
6262
hooks:
6363
- id: mypy
6464
additional_dependencies: [pytest, types-freezegun, types-setuptools]
@@ -71,7 +71,7 @@ repos:
7171
args: [--max-py-version=3.11]
7272

7373
- repo: https://github.com/tox-dev/pyproject-fmt
74-
rev: 0.3.3
74+
rev: 0.3.4
7575
hooks:
7676
- id: pyproject-fmt
7777

docs/requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
mkdocs>=1.1
1+
mkdocs==1.3.0
22
mkdocs-material
3-
mkdocstrings[python]>=0.18
3+
mkdocstrings[python]==0.19.0
44
mkdocs-include-markdown-plugin
55
pygments
6-
pymdown-extensions>=9.2
6+
pymdown-extensions==9.5

src/humanize/number.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,36 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
205205
except (TypeError, ValueError):
206206
return str(value)
207207

208+
if value < 0:
209+
value *= -1
210+
negative_prefix = "-"
211+
else:
212+
negative_prefix = ""
213+
208214
if value < powers[0]:
209-
return str(value)
215+
return negative_prefix + str(value)
210216
for ordinal, power in enumerate(powers[1:], 1):
211217
if value < power:
212218
chopped = value / float(powers[ordinal - 1])
213219
if float(format % chopped) == float(10**3):
214220
chopped = value / float(powers[ordinal])
215221
singular, plural = human_powers[ordinal]
216222
return (
217-
" ".join([format, _ngettext(singular, plural, math.ceil(chopped))])
223+
negative_prefix
224+
+ " ".join(
225+
[format, _ngettext(singular, plural, math.ceil(chopped))]
226+
)
218227
) % chopped
219228
else:
220229
singular, plural = human_powers[ordinal - 1]
221230
return (
222-
" ".join([format, _ngettext(singular, plural, math.ceil(chopped))])
231+
negative_prefix
232+
+ " ".join(
233+
[format, _ngettext(singular, plural, math.ceil(chopped))]
234+
)
223235
) % chopped
224-
return str(value)
236+
237+
return negative_prefix + str(value)
225238

226239

227240
def apnumber(value: NumberOrString) -> str:

tests/test_number.py

+7
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,31 @@ def test_intword_powers() -> None:
7575
@pytest.mark.parametrize(
7676
"test_args, expected",
7777
[
78+
(["0"], "0"),
7879
(["100"], "100"),
80+
(["-100"], "-100"),
7981
(["1000"], "1.0 thousand"),
8082
(["12400"], "12.4 thousand"),
8183
(["12490"], "12.5 thousand"),
8284
(["1000000"], "1.0 million"),
85+
(["-1000000"], "-1.0 million"),
8386
(["1200000"], "1.2 million"),
8487
(["1290000"], "1.3 million"),
8588
(["999999999"], "1.0 billion"),
8689
(["1000000000"], "1.0 billion"),
90+
(["-1000000000"], "-1.0 billion"),
8791
(["2000000000"], "2.0 billion"),
8892
(["999999999999"], "1.0 trillion"),
8993
(["1000000000000"], "1.0 trillion"),
9094
(["6000000000000"], "6.0 trillion"),
95+
(["-6000000000000"], "-6.0 trillion"),
9196
(["999999999999999"], "1.0 quadrillion"),
9297
(["1000000000000000"], "1.0 quadrillion"),
9398
(["1300000000000000"], "1.3 quadrillion"),
99+
(["-1300000000000000"], "-1.3 quadrillion"),
94100
(["3500000000000000000000"], "3.5 sextillion"),
95101
(["8100000000000000000000000000000000"], "8.1 decillion"),
102+
(["-8100000000000000000000000000000000"], "-8.1 decillion"),
96103
([None], "None"),
97104
(["1230000", "%0.2f"], "1.23 million"),
98105
([10**101], "1" + "0" * 101),

0 commit comments

Comments
 (0)