From 867afb49f0d1b02dbee2c0e2a7e56c63b0abc59c Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sat, 16 Nov 2024 22:40:45 +0100 Subject: [PATCH] 16 dac eu institutions non usd non eur constant (#17) * add and fix tests * fix USD bug removes making currency deflator 1 when USD --- pydeflate/core/exchange.py | 2 -- tests/test_dac_totals.py | 45 ++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/pydeflate/core/exchange.py b/pydeflate/core/exchange.py index a01e596..9b33852 100644 --- a/pydeflate/core/exchange.py +++ b/pydeflate/core/exchange.py @@ -37,8 +37,6 @@ def __post_init__(self): self.exchange_data = self.exchange_rate( self.source_currency, self.target_currency ) - if self.source_currency == "USA": - self.exchange_data["pydeflate_EXCHANGE_D"] = 1 def _get_exchange_rate(self, currency): """Helper function to fetch exchange rates for a given currency.""" diff --git a/tests/test_dac_totals.py b/tests/test_dac_totals.py index 19c39f8..c7040cd 100644 --- a/tests/test_dac_totals.py +++ b/tests/test_dac_totals.py @@ -33,7 +33,7 @@ "donor_code": [742] * 4, "currency": ["EUR"] * 4, "prices": ["current"] * 4, - "value": [1974, 2429, 2672, 2986], + "value": [1974, 2429, 2672, 2896], "expected_value": [1995, 2403, 2619, 2896], } df_eur = pd.DataFrame(data_eur) @@ -62,6 +62,30 @@ } df_lcu = pd.DataFrame(data_lcu) +data_eui_gbp = { + "year": [2020, 2021, 2022, 2023], + "indicator": ["total_oda_official_definition"] * 4, + "donor_code": [918] * 4, + "currency": ["USD"] * 4, + "prices": ["current"] * 4, + "value": [19568, 19054, 22534, 26926], + "expected_value": [16882, 15490, 19693, 21662], +} + +df_eui_gbp = pd.DataFrame(data_eui_gbp) + +data_aus_gbp = { + "year": [2020, 2021, 2022, 2023], + "indicator": ["total_oda_official_definition"] * 4, + "donor_code": [801] * 4, + "currency": ["USD"] * 4, + "prices": ["current"] * 4, + "value": [2869, 3546, 3046, 3253], + "expected_value": [2629, 2822, 2432, 2617], +} + +df_aus_gbp = pd.DataFrame(data_aus_gbp) + usd_to = { "year": [2020, 2021, 2022, 2023], "indicator": ["total_oda_official_definition"] * 4, @@ -75,6 +99,7 @@ df_usd_to_gbp = pd.DataFrame(usd_to) + def run_constant_test( data, source_currency, @@ -142,19 +167,31 @@ def test_to_constant_usd(): def test_to_constant_eur(): run_constant_test( - data=df_eur, source_currency="EUR", target_currency="EUR", tolerance=0.05 + data=df_eur, source_currency="EUR", target_currency="EUR", tolerance=0.02 ) def test_to_constant_can(): run_constant_test( - data=df_can, source_currency="CAN", target_currency="USA", tolerance=0.05 + data=df_can, source_currency="CAN", target_currency="USA", tolerance=0.02 ) def test_to_constant_lcu(): run_constant_test( - data=df_lcu, source_currency="EUR", target_currency="LCU", tolerance=0.05 + data=df_lcu, source_currency="EUR", target_currency="LCU", tolerance=0.02 + ) + + +def test_eui_gbp_constant(): + run_constant_test( + data=df_eui_gbp, source_currency="USD", target_currency="GBP", tolerance=0.02 + ) + + +def test_aus_gbp_constant(): + run_constant_test( + data=df_aus_gbp, source_currency="USD", target_currency="GBP", tolerance=0.02 )