Skip to content

Commit

Permalink
update exchange deflator
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-rivera committed Nov 11, 2024
1 parent f8a7816 commit a3a0d38
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pydeflate/sources/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ def _add_deflator(
exchange: str = "EXCHANGE",
year: str = "year",
) -> pd.DataFrame:

# if needed, clean exchange name
if exchange.endswith("_to") or exchange.endswith("_from"):
exchange_name = exchange.rsplit("_", 1)[0]
else:
exchange_name = exchange

# Identify the base year for the deflator
if measure is not None:
base_year = identify_base_year(group, measure=measure, year=year)
Expand All @@ -222,7 +229,9 @@ def _add_deflator(

# If base value is found and valid, calculate the deflator
if base_value.size > 0 and pd.notna(base_value[0]):
group[f"{exchange}_D"] = round(100 * group[exchange] / base_value[0], 6)
group[f"{exchange_name}_D"] = round(
100 * group[exchange] / base_value[0], 6
)

return group

Expand Down

0 comments on commit a3a0d38

Please sign in to comment.