Skip to content

Commit

Permalink
Update test_dac_deflator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-rivera committed Nov 11, 2024
1 parent 47adc6a commit 0e53d1c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_dac_deflator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,36 @@ def test_to_constant(tolerance=0.01):
)


def test_to_constant_lcu_USA(tolerance=0.01):

# Perform the deflation calculation
test_df = oecd_dac_deflate(
data=df,
base_year=2022,
source_currency="LCU",
target_currency="USA",
id_column="donor_code",
use_source_codes=True,
value_column="N",
)

# Calculate the percentage deviation
deviations = abs((test_df["value"] - test_df["D"]) / test_df["D"])

# Filter out rows where D is NaN to avoid unnecessary comparisons
mask = test_df["D"].notna() & (deviations >= tolerance)
failing_rows = test_df[mask]

failing_rows = failing_rows.loc[lambda d: d.donor_code < 20000]

# Assert that no rows exceed the tolerance
assert failing_rows.empty, (
f"Deviation exceeded {tolerance*100:.2f}% in the following"
f"donors:\n"
f"{failing_rows.donor_code.unique()}"
)


def test_to_current(tolerance=0.01):

# Perform the adjustment to current currency
Expand Down

0 comments on commit 0e53d1c

Please sign in to comment.