From 6d15bb6d2ea24654efcf673d515d57ac6f4b432e Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 08:55:41 +0100 Subject: [PATCH 01/13] New func --- src/ssb_konjunk/prompts.py | 23 +++++++++++++++++++++++ tests/test_prompts.py | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 58a722b..e19c52f 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -248,3 +248,26 @@ def validate_day(day: int | str) -> str: if int(day) < 10: day = "0" + str(int(day)) return str(day) + +def quarter_for_month(month: str|int) -> int: + """Find corresponding quarter for a month. + + Args: + month: Month to find corresponding quarter for. + + Returns: + int: The corresponding quarter. + """ + month = int(month) + + if month < 1 or month > 12: + raise ValueError(f"Invalid month: {month}") + + if month < 4: + return 1 + elif month < 7: + return 2 + elif month < 10: + return 3 + else: + return 4 \ No newline at end of file diff --git a/tests/test_prompts.py b/tests/test_prompts.py index 5653cd7..4c5f8bb 100644 --- a/tests/test_prompts.py +++ b/tests/test_prompts.py @@ -6,6 +6,7 @@ from ssb_konjunk.prompts import extract_start_end_dates from ssb_konjunk.prompts import iterate_years_months from ssb_konjunk.prompts import validate_month +from ssb_konjunk.prompts import quarter_for_month """Test of function days in month""" @@ -140,3 +141,14 @@ def test_validate_month() -> None: assert validate_month(10) == "10" assert validate_month("10") == "10" + +def test_quarter_for_month() -> None: + # Test with valid integer month + assert quarter_for_month(2) == 1 + + # Test with valid string month + assert quarter_for_month('12') == 4 + + # Test with invalid month + with pytest.raises(ValueError): + quarter_for_month(13) \ No newline at end of file From e180bfc72fd0385bd4512d386b986954b5e610c5 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 08:57:48 +0100 Subject: [PATCH 02/13] pre-commit --- src/ssb_konjunk/prompts.py | 13 +++++++------ tests/test_prompts.py | 11 ++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index e19c52f..114224c 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -249,20 +249,21 @@ def validate_day(day: int | str) -> str: day = "0" + str(int(day)) return str(day) -def quarter_for_month(month: str|int) -> int: + +def quarter_for_month(month: str | int) -> int: """Find corresponding quarter for a month. - + Args: month: Month to find corresponding quarter for. - + Returns: int: The corresponding quarter. """ month = int(month) - + if month < 1 or month > 12: raise ValueError(f"Invalid month: {month}") - + if month < 4: return 1 elif month < 7: @@ -270,4 +271,4 @@ def quarter_for_month(month: str|int) -> int: elif month < 10: return 3 else: - return 4 \ No newline at end of file + return 4 diff --git a/tests/test_prompts.py b/tests/test_prompts.py index 4c5f8bb..4aca26d 100644 --- a/tests/test_prompts.py +++ b/tests/test_prompts.py @@ -5,8 +5,8 @@ from ssb_konjunk.prompts import days_in_month from ssb_konjunk.prompts import extract_start_end_dates from ssb_konjunk.prompts import iterate_years_months -from ssb_konjunk.prompts import validate_month from ssb_konjunk.prompts import quarter_for_month +from ssb_konjunk.prompts import validate_month """Test of function days in month""" @@ -142,13 +142,14 @@ def test_validate_month() -> None: assert validate_month(10) == "10" assert validate_month("10") == "10" + def test_quarter_for_month() -> None: # Test with valid integer month assert quarter_for_month(2) == 1 - + # Test with valid string month - assert quarter_for_month('12') == 4 - + assert quarter_for_month("12") == 4 + # Test with invalid month with pytest.raises(ValueError): - quarter_for_month(13) \ No newline at end of file + quarter_for_month(13) From cffb86d4902957e9805eaa838c77f7f20eb4af1e Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:09:16 +0100 Subject: [PATCH 03/13] docstring fix --- src/ssb_konjunk/prompts.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 114224c..214dea1 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -258,6 +258,9 @@ def quarter_for_month(month: str | int) -> int: Returns: int: The corresponding quarter. + + Raises: + ValueError: If invalid month """ month = int(month) From 669d45a8eaa20ae17a9416790d4c669a499c0cd3 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:10:26 +0100 Subject: [PATCH 04/13] preocmmit --- src/ssb_konjunk/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 214dea1..884dc22 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -258,7 +258,7 @@ def quarter_for_month(month: str | int) -> int: Returns: int: The corresponding quarter. - + Raises: ValueError: If invalid month """ From 523d62ddad90dd72d7f22969fe6581c13cbd1785 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:18:25 +0100 Subject: [PATCH 05/13] New version and docs --- docs/ssb_konjunk.rst | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index 1d72a88..ddac8f2 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.statbank\_formating module +--------------------------------- + +.. automodule:: ssb_konjunk.statbank_formating + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b7701ad..2145a7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ssb-konjunk" -version = "0.1.6" +version = "0.1.7" description = "SSB Konjunk" authors = ["Edvard Garmannslund "] license = "MIT" From 996202d07e4909acab3fce69936991c29952092a Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:19:24 +0100 Subject: [PATCH 06/13] New func --- src/ssb_konjunk/prompts.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 884dc22..82fab48 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -275,3 +275,26 @@ def quarter_for_month(month: str | int) -> int: return 3 else: return 4 + +def months_in_quarter(quarter: int | str) -> list[int]: + """Return the three months in the quarter. + + Args: + quarter: the relevant quarter. + + Returns: + list: a list with the months in the quarter. + """ + quarter = int(quarter) + + if quarter < 1 or quarter > 4: + raise ValueError(f"Invalid quarter: {quarter}") + + if quarter == 1: + return [1,2,3] + elif quarter == 2: + return [4,5,6] + elif quarter == 3: + return [7,8,9] + elif quarter == 4: + return [10,11,12] \ No newline at end of file From 4fdc6ea2e442781d54ca7899f5c96e174b7c8aba Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:22:50 +0100 Subject: [PATCH 07/13] precommit --- src/ssb_konjunk/prompts.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 82fab48..6470696 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -276,25 +276,26 @@ def quarter_for_month(month: str | int) -> int: else: return 4 + def months_in_quarter(quarter: int | str) -> list[int]: """Return the three months in the quarter. - + Args: quarter: the relevant quarter. - + Returns: list: a list with the months in the quarter. """ quarter = int(quarter) - + if quarter < 1 or quarter > 4: raise ValueError(f"Invalid quarter: {quarter}") - + if quarter == 1: - return [1,2,3] + return [1, 2, 3] elif quarter == 2: - return [4,5,6] + return [4, 5, 6] elif quarter == 3: - return [7,8,9] + return [7, 8, 9] elif quarter == 4: - return [10,11,12] \ No newline at end of file + return [10, 11, 12] From 431dbcf75aae2d6666a477ab025395ae6d221af0 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:23:22 +0100 Subject: [PATCH 08/13] precommit --- src/ssb_konjunk/prompts.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 6470696..6765402 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -285,6 +285,9 @@ def months_in_quarter(quarter: int | str) -> list[int]: Returns: list: a list with the months in the quarter. + + Raises: + ValueError: If invalid quarter. """ quarter = int(quarter) From d5575788f02a63aa57a1cc7ad334968aa8f7ddeb Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:24:18 +0100 Subject: [PATCH 09/13] precommit --- src/ssb_konjunk/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 6765402..38476a3 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -285,7 +285,7 @@ def months_in_quarter(quarter: int | str) -> list[int]: Returns: list: a list with the months in the quarter. - + Raises: ValueError: If invalid quarter. """ From 348d465c267c9dd67c4b59628e433e2eb0621055 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:24:31 +0100 Subject: [PATCH 10/13] precommit --- docs/ssb_konjunk.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index ddac8f2..c0b9cb5 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -56,4 +56,4 @@ ssb\_konjunk.statbank\_formating module .. automodule:: ssb_konjunk.statbank_formating :members: :undoc-members: - :show-inheritance: \ No newline at end of file + :show-inheritance: From 836090aa8721760202b1b22b4bcadd6eb6f45315 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:40:19 +0100 Subject: [PATCH 11/13] error --- docs/ssb_konjunk.rst | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index c0b9cb5..64587f4 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -48,12 +48,4 @@ ssb\_konjunk.xml\_handling module .. automodule:: ssb_konjunk.xml_handling :members: :undoc-members: - :show-inheritance: - -ssb\_konjunk.statbank\_formating module ---------------------------------- - -.. automodule:: ssb_konjunk.statbank_formating - :members: - :undoc-members: - :show-inheritance: + :show-inheritance: \ No newline at end of file From 1816163b68e34b3d13e638c137f76e410bd465f0 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:41:31 +0100 Subject: [PATCH 12/13] precommit --- docs/ssb_konjunk.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index 64587f4..1d72a88 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -48,4 +48,4 @@ ssb\_konjunk.xml\_handling module .. automodule:: ssb_konjunk.xml_handling :members: :undoc-members: - :show-inheritance: \ No newline at end of file + :show-inheritance: From 3087b583d0324d045df650559989d316bee60ef5 Mon Sep 17 00:00:00 2001 From: Johanne Saxegaard Date: Tue, 17 Dec 2024 09:44:51 +0100 Subject: [PATCH 13/13] mypy --- src/ssb_konjunk/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 38476a3..80b1569 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -300,5 +300,5 @@ def months_in_quarter(quarter: int | str) -> list[int]: return [4, 5, 6] elif quarter == 3: return [7, 8, 9] - elif quarter == 4: + else: return [10, 11, 12]