From d5d9251d9b77be4e8ffa45f30bdb73b1f2da1949 Mon Sep 17 00:00:00 2001 From: ssb-jox Date: Thu, 3 Oct 2024 06:37:07 +0000 Subject: [PATCH 1/9] added period function --- src/ssb_konjunk/timestamp.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ssb_konjunk/timestamp.py b/src/ssb_konjunk/timestamp.py index 3e826eb..0ff8f47 100644 --- a/src/ssb_konjunk/timestamp.py +++ b/src/ssb_konjunk/timestamp.py @@ -263,3 +263,23 @@ def get_ssb_timestamp(*args: int, frequency: str = "M") -> str | None: return _get_timestamp_yearly(*valid_args) else: return _get_timestamp_special(*valid_args, frequency=frequency) + + +def check_periodic_year(year: int, cycle_year: int, period: int) -> bool: + """Check if a year is a part of a periodic cycle. + + An example of use: a functionality should be performed every third + year, starting in year 2021. I.e. not in 2022 and 2023, but in + 2024. Then this function should return True when passing + 2024 as the year argument, 2021 (or 2015, 2018, 2024 and so) is + passed as the cycle year and period is passed as 3 (triennal period). + + Args: + year: the year to check. + cycle_year: a year in the cycle. + period: the number of years in a period. + + Returns: + bool: whether or not the year is part of the triennal cycle. + """ + return (year - cycle_year) % period == 0 \ No newline at end of file From 582427470e19559679b3df543c09b315df4f0da8 Mon Sep 17 00:00:00 2001 From: ssb-jox Date: Thu, 3 Oct 2024 06:41:29 +0000 Subject: [PATCH 2/9] Added test --- src/ssb_konjunk/timestamp.py | 2 +- tests/test_timestamp.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ssb_konjunk/timestamp.py b/src/ssb_konjunk/timestamp.py index 0ff8f47..387a881 100644 --- a/src/ssb_konjunk/timestamp.py +++ b/src/ssb_konjunk/timestamp.py @@ -282,4 +282,4 @@ def check_periodic_year(year: int, cycle_year: int, period: int) -> bool: Returns: bool: whether or not the year is part of the triennal cycle. """ - return (year - cycle_year) % period == 0 \ No newline at end of file + return abs(year - cycle_year) % period == 0 \ No newline at end of file diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py index 1d6dc76..31849dd 100644 --- a/tests/test_timestamp.py +++ b/tests/test_timestamp.py @@ -15,6 +15,7 @@ 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 check_periodic_year def test_check_even() -> None: @@ -173,3 +174,11 @@ def test_check_valid_year() -> None: match=f"The order of args is start date and then end date. Therefore first year arg can not be bigger than the last. Your args are start year:{year1} end year:{year2}.", ): _check_valid_year(year1, year2) + +def test_check_periodic_year() -> None: + """Test of function check_periodic_year.""" + assert check_periodic_year(2024, 2021, 3) == True + assert check_periodic_year(2024, 2021, 2) == False + assert check_periodic_year(2021, 2024, 3) == True + assert check_periodic_year(2021, 2021, 3) == True + assert check_periodic_year(2021, 2022, 1) == True \ No newline at end of file From 8831f6885f81bf80958f856d26dc218c3d3eae0b Mon Sep 17 00:00:00 2001 From: ssb-jox Date: Thu, 3 Oct 2024 06:47:11 +0000 Subject: [PATCH 3/9] update --- poetry.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 65a8049..d91fda0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" @@ -3168,6 +3168,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, From 09c537c8f537b8d0e859441793fdb939b7ee7f11 Mon Sep 17 00:00:00 2001 From: ssb-jox Date: Thu, 3 Oct 2024 06:54:22 +0000 Subject: [PATCH 4/9] Ignores .ipynb --- .gitignore | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 495bb5e..2c7d033 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,11 @@ *.xlsx *.zip +# Notebooks shall be stored in .py or .R-format. +# See https://adr.ssb.no/0020-lagringsformat-for-jupyter-notebooks/ +*.ipynb + + # The section below is from the GitHub .gitignore template for Python: # https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore @@ -204,18 +209,7 @@ rsconnect/ # ignore poetry in .config .poetry/** -/.python-version -/.pytype/ -/docs/_build/ - -# Visual Studio Code -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets -# Local History for Visual Studio Code -.history/ -# Built Visual Studio Code Extensions -*.vsix + +# Blaise specific ignores +*.bdix +*.bdbx From 7545291a3888c857fec7d0fb52e331591e4a1dd3 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Thu, 3 Oct 2024 08:59:43 +0200 Subject: [PATCH 5/9] nox --- src/ssb_konjunk/timestamp.py | 2 +- tests/test_timestamp.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ssb_konjunk/timestamp.py b/src/ssb_konjunk/timestamp.py index 387a881..d883fce 100644 --- a/src/ssb_konjunk/timestamp.py +++ b/src/ssb_konjunk/timestamp.py @@ -282,4 +282,4 @@ def check_periodic_year(year: int, cycle_year: int, period: int) -> bool: Returns: bool: whether or not the year is part of the triennal cycle. """ - return abs(year - cycle_year) % period == 0 \ No newline at end of file + return abs(year - cycle_year) % period == 0 diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py index 31849dd..6514703 100644 --- a/tests/test_timestamp.py +++ b/tests/test_timestamp.py @@ -14,8 +14,8 @@ 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 check_periodic_year +from ssb_konjunk.timestamp import get_ssb_timestamp def test_check_even() -> None: @@ -175,10 +175,11 @@ def test_check_valid_year() -> None: ): _check_valid_year(year1, year2) + def test_check_periodic_year() -> None: """Test of function check_periodic_year.""" assert check_periodic_year(2024, 2021, 3) == True assert check_periodic_year(2024, 2021, 2) == False assert check_periodic_year(2021, 2024, 3) == True assert check_periodic_year(2021, 2021, 3) == True - assert check_periodic_year(2021, 2022, 1) == True \ No newline at end of file + assert check_periodic_year(2021, 2022, 1) == True From b317d4b2a2a7c8493f64288497ae4f83949e4d8f Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Thu, 3 Oct 2024 09:02:17 +0200 Subject: [PATCH 6/9] nox --- src/ssb_konjunk/timestamp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ssb_konjunk/timestamp.py b/src/ssb_konjunk/timestamp.py index d883fce..2b6a5b7 100644 --- a/src/ssb_konjunk/timestamp.py +++ b/src/ssb_konjunk/timestamp.py @@ -282,4 +282,7 @@ def check_periodic_year(year: int, cycle_year: int, period: int) -> bool: Returns: bool: whether or not the year is part of the triennal cycle. """ - return abs(year - cycle_year) % period == 0 + if abs(year - cycle_year) % period == 0: + return True + else: + return False From 2a2800d891e85b398c8dcdc0a404bb68114e16a4 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Thu, 3 Oct 2024 09:04:58 +0200 Subject: [PATCH 7/9] imporved --- tests/test_timestamp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py index 6514703..7d6ae9d 100644 --- a/tests/test_timestamp.py +++ b/tests/test_timestamp.py @@ -178,8 +178,8 @@ def test_check_valid_year() -> None: def test_check_periodic_year() -> None: """Test of function check_periodic_year.""" - assert check_periodic_year(2024, 2021, 3) == True - assert check_periodic_year(2024, 2021, 2) == False - assert check_periodic_year(2021, 2024, 3) == True - assert check_periodic_year(2021, 2021, 3) == True - assert check_periodic_year(2021, 2022, 1) == True + assert check_periodic_year(2024, 2021, 3) + assert not check_periodic_year(2024, 2021, 2) + assert check_periodic_year(2021, 2024, 3) + assert check_periodic_year(2021, 2021, 3) + assert check_periodic_year(2021, 2022, 1) From 624fb39536f59b977064919b308aaacf1e7f99db Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Thu, 3 Oct 2024 09:14:34 +0200 Subject: [PATCH 8/9] Added the docs for rounding --- docs/ssb_konjunk.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index 1d72a88..0ecbe8e 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -49,3 +49,11 @@ ssb\_konjunk.xml\_handling module :members: :undoc-members: :show-inheritance: + +ssb\_konjunk.rounding module +--------------------------------- + +.. automodule:: ssb_konjunk.rounding + :members: + :undoc-members: + :show-inheritance: From 47726984fe93373dec3b5b065a19690b7350724a Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Thu, 3 Oct 2024 09:27:43 +0200 Subject: [PATCH 9/9] Bump release --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9cc4f0e..43f9231 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ssb-konjunk" -version = "0.1.9" +version = "0.1.10" description = "SSB Konjunk" authors = ["Edvard Garmannslund "] license = "MIT"