Skip to content

Commit

Permalink
Merge pull request #15 from jm-rivera/fix-usa-bug
Browse files Browse the repository at this point in the history
Fix usa bug
  • Loading branch information
jm-rivera authored Nov 11, 2024
2 parents 55b30c0 + f0b1e9d commit 496987f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v2.0.1 (2024-11-10)
Fixes a bug with non-USD constant figures.

## v2.0.0 (2024-11-10)

🚀 Major Release
Expand Down
2 changes: 2 additions & 0 deletions pydeflate/core/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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
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 496987f

Please sign in to comment.