Skip to content

Commit

Permalink
16 dac eu institutions non usd non eur constant (#17)
Browse files Browse the repository at this point in the history
* add and fix tests

* fix USD bug

removes making currency deflator 1 when USD
  • Loading branch information
jm-rivera authored Nov 16, 2024
1 parent 6c52e6f commit 867afb4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
2 changes: 0 additions & 2 deletions pydeflate/core/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
45 changes: 41 additions & 4 deletions tests/test_dac_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -75,6 +99,7 @@
df_usd_to_gbp = pd.DataFrame(usd_to)



def run_constant_test(
data,
source_currency,
Expand Down Expand Up @@ -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
)


Expand Down

0 comments on commit 867afb4

Please sign in to comment.