Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct discount factor calcualtion for multiple regions #243

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

Version 1.1.5
=============
- Correct discount factor calculation for multiple regions

Version 1.1.4
=============
- Add result calculations for ``DiscountedCapitalInvestment``, ``DiscountedCostByTechnology``, and ``DiscountedOperationalCost``
Expand Down
2 changes: 1 addition & 1 deletion src/otoole/results/result_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ def discount_factor(
)

if regions and years:
discount_rate["YEAR"] = [years]
discount_rate["YEAR"] = [years] * len(discount_rate)
discount_factor = discount_rate.explode("YEAR").reset_index(level="REGION")
discount_factor["YEAR"] = discount_factor["YEAR"].astype("int64")
discount_factor["NUM"] = discount_factor["YEAR"] - discount_factor["YEAR"].min()
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ def discount_rate():
return df


@fixture
def discount_rate_multiple_regions():
df = pd.DataFrame(
data=[
["SIMPLICITY", 0.05],
["DUMMY", 0.05],
],
columns=["REGION", "VALUE"],
).set_index(["REGION"])
return df


@fixture
def discount_rate_idv():
df = pd.DataFrame(
Expand Down
35 changes: 35 additions & 0 deletions tests/results/test_results_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def region():
return pd.DataFrame(data=["SIMPLICITY"], columns=["VALUE"])


@fixture
def region_multiple():
return pd.DataFrame(data=["SIMPLICITY", "DUMMY"], columns=["VALUE"])


@fixture
def storage():
return pd.DataFrame(data=["DAM"], columns=["VALUE"])
Expand Down Expand Up @@ -1485,6 +1490,36 @@ def test_df_empty_discount_rate(self, region, year, discount_rate_empty):
with raises(ValueError):
discount_factor(regions, years, discount_rate_empty, 1.0)

def test_df_two_regions(
self, region_multiple, year, discount_rate_multiple_regions
):

regions = region_multiple["VALUE"].to_list()
years = year["VALUE"].to_list()
actual = discount_factor(regions, years, discount_rate_multiple_regions, 0.0)

expected = pd.DataFrame(
data=[
["SIMPLICITY", 2014, 1],
["SIMPLICITY", 2015, 1.05],
["SIMPLICITY", 2016, 1.1025],
["SIMPLICITY", 2017, 1.157625],
["SIMPLICITY", 2018, 1.21550625],
["SIMPLICITY", 2019, 1.276281562],
["SIMPLICITY", 2020, 1.340095640],
["DUMMY", 2014, 1],
["DUMMY", 2015, 1.05],
["DUMMY", 2016, 1.1025],
["DUMMY", 2017, 1.157625],
["DUMMY", 2018, 1.21550625],
["DUMMY", 2019, 1.276281562],
["DUMMY", 2020, 1.340095640],
],
columns=["REGION", "YEAR", "VALUE"],
).set_index(["REGION", "YEAR"])

assert_frame_equal(actual, expected)


class TestDiscountFactorStorage:
def test_dfs_start(self, region, year, discount_rate_storage):
Expand Down
Loading