Skip to content

Commit

Permalink
Merge pull request #123 from statisticsnorway/122-rounding-00-to-no-d…
Browse files Browse the repository at this point in the history
…igits-leaves-digits-with-round_data

what if n is zero duh
  • Loading branch information
aecorn authored Apr 22, 2024
2 parents 4b1dd7d + 2910142 commit dd216a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dapla-statbank-client"
version = "1.2.0"
version = "1.2.1"
description = "Handles data transfer Statbank <-> Dapla for Statistics Norway"
authors = ["Statistics Norway", "Carl F. Corneil <[email protected]>"]
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/statbank/uttrekk.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ def _round_up(n: float, decimals: int = 0) -> str:
ctx.rounding = ROUND_HALF_UP
if pd.isna(n):
result: str = ""
elif decimals and n:
elif decimals and (n or n == 0):
result = str(round(Decimal(n), decimals))
elif n:
elif n or n == 0:
result = str(Decimal(n).to_integral_value())
else:
result = str(n)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_statbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
from statbank.uttrekk import StatbankUttrekksBeskrivelse


def test_round_up_zero():
assert StatbankUttrekksBeskrivelse._round_up(0.0, 0) == "0" # noqa: SLF001


def fake_user():
return "SSB-person-456"

Expand Down

0 comments on commit dd216a6

Please sign in to comment.