Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:
repos:
# Pre-commit maintained utility hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
Expand All @@ -27,15 +27,15 @@ repos:

# Ruff linter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.15.2
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
require_serial: true

# Black formatter
- repo: https://github.com/psf/black
rev: 24.10.0
rev: 26.1.0
hooks:
- id: black
require_serial: true
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os
import sys


sys.path.insert(0, os.path.abspath("../src"))

# -- Project information -----------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import nox


try:
from nox_poetry import Session
from nox_poetry import session
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dapla-statbank-client"
description = "Handles data transfer Statbank <-> Dapla for Statistics Norway"
license = "MIT"
version = "1.4.0"
version = "1.4.1"
readme = "README.md"
authors = [{name = "Carl F. Corneil", email = "cfc@ssb.no"}, {name = "Statistics Norway"}]
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion src/statbank/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _build_headers(self: Self) -> dict[str, str]:
}

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

with Netrc(self._config.netrc_path) as authfile:
auth_record = authfile[host]
Expand Down
2 changes: 1 addition & 1 deletion src/statbank/statbank_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(
"""Initialize the formatter with specified format strings."""
super().__init__(*args, **kwargs)

self.colors = colors if colors else {}
self.colors = colors or {}

def format(self, record: logging.LogRecord) -> str:
"""Format the specified record as text."""
Expand Down
8 changes: 8 additions & 0 deletions src/statbank/uttrekk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import math
import sys
import warnings
from decimal import ROUND_HALF_UP
from decimal import Decimal
from decimal import localcontext
Expand All @@ -15,6 +16,7 @@
from typing import TypedDict
from typing import overload

import numpy as np
import pandas as pd
import requests as r
import requests.auth
Expand Down Expand Up @@ -554,6 +556,12 @@ def _round(
) -> str:
if pd.isna(n):
result: str = ""
elif n in [np.inf, -np.inf]:
warnings.warn(
"Found Infinite values in your data, why? Remove them?",
stacklevel=1,
)
result = ""
elif round_up and decimals and (n or n == 0):
with localcontext() as ctx:
ctx.rounding = ROUND_HALF_UP
Expand Down
12 changes: 12 additions & 0 deletions tests/test_statbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from unittest import mock

import ipywidgets as widgets
import numpy as np
import pandas as pd
import pytest
import requests
Expand All @@ -36,6 +37,17 @@ def test_round_up_zero():
assert StatbankUttrekksBeskrivelse._round(0.0, 0) == "0" # noqa: SLF001


def test_round_handles_inf_values():
assert StatbankUttrekksBeskrivelse._round(np.inf, 0) == "" # noqa: SLF001
assert StatbankUttrekksBeskrivelse._round(-np.inf, 0) == "" # noqa: SLF001


@pytest.mark.parametrize("value", [np.inf, -np.inf])
def test_round_warns_on_inf_values(value: float):
with pytest.warns(UserWarning, match="Found Infinite values in your data"):
assert StatbankUttrekksBeskrivelse._round(value, 0) == "" # noqa: SLF001


def fake_user():
return "tbf"

Expand Down