Skip to content

Commit 824cedd

Browse files
authored
Merge pull request #273 from statisticsnorway/rounding-up-infinites
rounding infinites
2 parents 4051123 + 7cc261d commit 824cedd

File tree

8 files changed

+26
-8
lines changed

8 files changed

+26
-8
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33
repos:
44
# Pre-commit maintained utility hooks
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.6.0
6+
rev: v6.0.0
77
hooks:
88
- id: check-added-large-files
99
- id: check-merge-conflict
@@ -27,15 +27,15 @@ repos:
2727

2828
# Ruff linter
2929
- repo: https://github.com/astral-sh/ruff-pre-commit
30-
rev: v0.6.9
30+
rev: v0.15.2
3131
hooks:
3232
- id: ruff
3333
args: ["--fix", "--exit-non-zero-on-fix"]
3434
require_serial: true
3535

3636
# Black formatter
3737
- repo: https://github.com/psf/black
38-
rev: 24.10.0
38+
rev: 26.1.0
3939
hooks:
4040
- id: black
4141
require_serial: true

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import os
1616
import sys
1717

18-
1918
sys.path.insert(0, os.path.abspath("../src"))
2019

2120
# -- Project information -----------------------------------------------------

noxfile.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import nox
1212

13-
1413
try:
1514
from nox_poetry import Session
1615
from nox_poetry import session

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dapla-statbank-client"
33
description = "Handles data transfer Statbank <-> Dapla for Statistics Norway"
44
license = "MIT"
5-
version = "1.4.0"
5+
version = "1.4.1"
66
readme = "README.md"
77
authors = [{name = "Carl F. Corneil", email = "cfc@ssb.no"}, {name = "Statistics Norway"}]
88
requires-python = ">=3.10"

src/statbank/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _build_headers(self: Self) -> dict[str, str]:
176176
}
177177

178178
def _get_auth(self) -> requests.auth.AuthBase:
179-
host = cast(str, self._config.endpoint_base.host)
179+
host = cast("str", self._config.endpoint_base.host)
180180

181181
with Netrc(self._config.netrc_path) as authfile:
182182
auth_record = authfile[host]

src/statbank/statbank_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(
2121
"""Initialize the formatter with specified format strings."""
2222
super().__init__(*args, **kwargs)
2323

24-
self.colors = colors if colors else {}
24+
self.colors = colors or {}
2525

2626
def format(self, record: logging.LogRecord) -> str:
2727
"""Format the specified record as text."""

src/statbank/uttrekk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import math
88
import sys
9+
import warnings
910
from decimal import ROUND_HALF_UP
1011
from decimal import Decimal
1112
from decimal import localcontext
@@ -15,6 +16,7 @@
1516
from typing import TypedDict
1617
from typing import overload
1718

19+
import numpy as np
1820
import pandas as pd
1921
import requests as r
2022
import requests.auth
@@ -554,6 +556,12 @@ def _round(
554556
) -> str:
555557
if pd.isna(n):
556558
result: str = ""
559+
elif n in [np.inf, -np.inf]:
560+
warnings.warn(
561+
"Found Infinite values in your data, why? Remove them?",
562+
stacklevel=1,
563+
)
564+
result = ""
557565
elif round_up and decimals and (n or n == 0):
558566
with localcontext() as ctx:
559567
ctx.rounding = ROUND_HALF_UP

tests/test_statbank.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from unittest import mock
1313

1414
import ipywidgets as widgets
15+
import numpy as np
1516
import pandas as pd
1617
import pytest
1718
import requests
@@ -36,6 +37,17 @@ def test_round_up_zero():
3637
assert StatbankUttrekksBeskrivelse._round(0.0, 0) == "0" # noqa: SLF001
3738

3839

40+
def test_round_handles_inf_values():
41+
assert StatbankUttrekksBeskrivelse._round(np.inf, 0) == "" # noqa: SLF001
42+
assert StatbankUttrekksBeskrivelse._round(-np.inf, 0) == "" # noqa: SLF001
43+
44+
45+
@pytest.mark.parametrize("value", [np.inf, -np.inf])
46+
def test_round_warns_on_inf_values(value: float):
47+
with pytest.warns(UserWarning, match="Found Infinite values in your data"):
48+
assert StatbankUttrekksBeskrivelse._round(value, 0) == "" # noqa: SLF001
49+
50+
3951
def fake_user():
4052
return "tbf"
4153

0 commit comments

Comments
 (0)