Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realease012 #45

Merged
merged 2 commits into from
Aug 19, 2024
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
2,352 changes: 2,351 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-konjunk"
version = "0.1.1"
version = "0.1.2"
description = "SSB Konjunk"
authors = ["Edvard Garmannslund <[email protected]>"]
license = "MIT"
Expand All @@ -18,6 +18,7 @@ python = "^3.10"
click = ">=8.0.1"
pandas = "^2.2.0"
pendulum = "^3.0.0"
dapla-toolbelt = "^2.0.19"

[tool.poetry.group.dev.dependencies]
pygments = ">=2.10.0"
Expand Down
35 changes: 0 additions & 35 deletions src/ssb_konjunk/functions.py

This file was deleted.

32 changes: 14 additions & 18 deletions src/ssb_konjunk/timestamp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Functions to create timestamp according to SSB standard."""


def check_even(elements: list[int]) -> bool:
def _check_even(elements: list[int]) -> bool:
"""Function to check if number is even."""
return len(elements) % 2 == 0

Expand Down Expand Up @@ -158,7 +158,7 @@ def _check_frequency_suport(frequency: str) -> None:
)


def get_timestamp_daily(*args: int) -> str | None:
def _get_timestamp_daily(*args: int) -> str | None:
"""Function to create timestamp if frequency is daily."""
if len(args) == 3:
_check_valid_year(args[0])
Expand All @@ -178,7 +178,7 @@ def get_timestamp_daily(*args: int) -> str | None:
raise ValueError(f"Ikke gyldig mende args, du har antall:{len(args)}")


def get_timestamp_yearly(*args: int) -> str | None:
def _get_timestamp_yearly(*args: int) -> str | None:
"""Function to create timstamp if frequency is yearly."""
if len(args) == 2:
_check_valid_year(args[0], args[1])
Expand All @@ -189,16 +189,8 @@ def get_timestamp_yearly(*args: int) -> str | None:
)


def get_timestamp_special(*args: int, frequency: str) -> str | None:
"""Function to create timestamp if frequency is now Y or D.

Args:
args: Up to six arguments with int, to create timestamp for.
frequency: Letter for which frequency the data is, Y for year etc.

Returns:
string|None: Returns time stamp in ssb format.
"""
def _get_timestamp_special(*args: int, frequency: str) -> str | None:
"""Function to create timestamp if frequency is not Y or D."""
_check_valid_args(*args, frequency=frequency)

if frequency in ["M", "W"]:
Expand All @@ -222,7 +214,7 @@ def get_timestamp_special(*args: int, frequency: str) -> str | None:


def get_ssb_timestamp(*args: int, frequency: str = "M") -> str | None:
"""Function to create a string in ssb timestamp format.
r"""Function to create a string in ssb timestamp format.

Args:
args: Up to six arguments with int, to create timestamp for.
Expand All @@ -233,6 +225,10 @@ def get_ssb_timestamp(*args: int, frequency: str = "M") -> str | None:

Raises:
ValueError: Raises error for wrong values in args.

Example:
>>> get_ssb_timestamp(2024,8,1, frequency='D')
'p2024-08-01'
"""
_check_frequency_suport(frequency)

Expand All @@ -254,16 +250,16 @@ def get_ssb_timestamp(*args: int, frequency: str = "M") -> str | None:
valid_args = [arg for arg in args if arg]

if frequency == "D":
return get_timestamp_daily(*valid_args)
return _get_timestamp_daily(*valid_args)

if not check_even(valid_args) or len(valid_args) > 4:
if not _check_even(valid_args) or len(valid_args) > 4:
print(
f"For frekvens '{frequency}', må du ha enten to eller fire argumenter. Du har:",
len(valid_args),
)
return None
else:
if frequency == "Y":
return get_timestamp_yearly(*valid_args)
return _get_timestamp_yearly(*valid_args)
else:
return get_timestamp_special(*valid_args, frequency=frequency)
return _get_timestamp_special(*valid_args, frequency=frequency)
2 changes: 1 addition & 1 deletion src/ssb_konjunk/xml_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import dapla


def read_xml(xml_file: str, fs: dapla.gcs.GCSFileSystem = None) -> ET.Element:
def read_xml(xml_file: str, fs: dapla.gcs.GCSFileSystem | None = None) -> ET.Element:
"""Funtion to get xml root from disk.

Args:
Expand Down
6 changes: 0 additions & 6 deletions tests/test_functions.py

This file was deleted.

32 changes: 17 additions & 15 deletions tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from ssb_konjunk.timestamp import _check_even
from ssb_konjunk.timestamp import _check_valid_day
from ssb_konjunk.timestamp import _check_valid_half_year
from ssb_konjunk.timestamp import _check_valid_month
Expand All @@ -10,41 +11,42 @@
from ssb_konjunk.timestamp import _check_valid_trimester
from ssb_konjunk.timestamp import _check_valid_week
from ssb_konjunk.timestamp import _check_valid_year
from ssb_konjunk.timestamp import check_even
from ssb_konjunk.timestamp import _get_timestamp_daily
from ssb_konjunk.timestamp import _get_timestamp_special
from ssb_konjunk.timestamp import _get_timestamp_yearly
from ssb_konjunk.timestamp import get_ssb_timestamp
from ssb_konjunk.timestamp import get_timestamp_daily
from ssb_konjunk.timestamp import get_timestamp_special
from ssb_konjunk.timestamp import get_timestamp_yearly


def test_check_even() -> None:
"""Test of function check_even."""
"""Test of function _check_even."""
# Testing True
assert check_even([2, 1]) is True
assert _check_even([2, 1]) is True
# Testing False
assert check_even([3, 2, 1]) is False
assert _check_even([3, 2, 1]) is False


def test_get_timestamp_daily() -> None:
"""Test of function get_timestamp_daily."""
"""Test of function _get_timestamp_daily."""
# Testing True
assert get_timestamp_daily(2020, 1, 1, 2020, 1, 31) == "p2020-01-01_p2020-01-31"
assert _get_timestamp_daily(2020, 1, 1, 2020, 1, 31) == "p2020-01-01_p2020-01-31"


def test_get_timestamp_yearly() -> None:
"""Test of function get_timestamp_yearly."""
"""Test of function _get_timestamp_yearly."""
# Testing True
assert get_timestamp_yearly(2020, 2021) == "p2020_p2021"
assert _get_timestamp_yearly(2020, 2021) == "p2020_p2021"


def test_test_get_timestamp_special() -> None:
"""Test of function get_timestamp_special."""
"""Test of function _get_timestamp_special."""
# Testing month
assert get_timestamp_special(2020, 1, 2021, 2, frequency="M") == "p2020-01_p2021-02"
assert (
_get_timestamp_special(2020, 1, 2021, 2, frequency="M") == "p2020-01_p2021-02"
)
# Testing quarter
assert get_timestamp_special(2020, 1, 2021, 2, frequency="Q") == "p2020Q1_p2021Q2"
assert _get_timestamp_special(2020, 1, 2021, 2, frequency="Q") == "p2020Q1_p2021Q2"
# Testing term
assert get_timestamp_special(2020, 1, 2021, 2, frequency="B") == "p2020B1_p2021B2"
assert _get_timestamp_special(2020, 1, 2021, 2, frequency="B") == "p2020B1_p2021B2"


def test_get_ssb_timestamp() -> None:
Expand Down
Loading