Skip to content

Commit 4142997

Browse files
authored
Merge pull request #243 from OSeMOSYS/issue-242
Correct discount factor calcualtion for multiple regions
2 parents 3e1f05d + 443561a commit 4142997

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
Version 1.1.5
6+
=============
7+
- Correct discount factor calculation for multiple regions
8+
59
Version 1.1.4
610
=============
711
- Add result calculations for ``DiscountedCapitalInvestment``, ``DiscountedCostByTechnology``, and ``DiscountedOperationalCost``

src/otoole/results/result_package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ def discount_factor(
12161216
)
12171217

12181218
if regions and years:
1219-
discount_rate["YEAR"] = [years]
1219+
discount_rate["YEAR"] = [years] * len(discount_rate)
12201220
discount_factor = discount_rate.explode("YEAR").reset_index(level="REGION")
12211221
discount_factor["YEAR"] = discount_factor["YEAR"].astype("int64")
12221222
discount_factor["NUM"] = discount_factor["YEAR"] - discount_factor["YEAR"].min()

tests/conftest.py

+12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ def discount_rate():
6565
return df
6666

6767

68+
@fixture
69+
def discount_rate_multiple_regions():
70+
df = pd.DataFrame(
71+
data=[
72+
["SIMPLICITY", 0.05],
73+
["DUMMY", 0.05],
74+
],
75+
columns=["REGION", "VALUE"],
76+
).set_index(["REGION"])
77+
return df
78+
79+
6880
@fixture
6981
def discount_rate_idv():
7082
df = pd.DataFrame(

tests/results/test_results_package.py

+35
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ def region():
127127
return pd.DataFrame(data=["SIMPLICITY"], columns=["VALUE"])
128128

129129

130+
@fixture
131+
def region_multiple():
132+
return pd.DataFrame(data=["SIMPLICITY", "DUMMY"], columns=["VALUE"])
133+
134+
130135
@fixture
131136
def storage():
132137
return pd.DataFrame(data=["DAM"], columns=["VALUE"])
@@ -1485,6 +1490,36 @@ def test_df_empty_discount_rate(self, region, year, discount_rate_empty):
14851490
with raises(ValueError):
14861491
discount_factor(regions, years, discount_rate_empty, 1.0)
14871492

1493+
def test_df_two_regions(
1494+
self, region_multiple, year, discount_rate_multiple_regions
1495+
):
1496+
1497+
regions = region_multiple["VALUE"].to_list()
1498+
years = year["VALUE"].to_list()
1499+
actual = discount_factor(regions, years, discount_rate_multiple_regions, 0.0)
1500+
1501+
expected = pd.DataFrame(
1502+
data=[
1503+
["SIMPLICITY", 2014, 1],
1504+
["SIMPLICITY", 2015, 1.05],
1505+
["SIMPLICITY", 2016, 1.1025],
1506+
["SIMPLICITY", 2017, 1.157625],
1507+
["SIMPLICITY", 2018, 1.21550625],
1508+
["SIMPLICITY", 2019, 1.276281562],
1509+
["SIMPLICITY", 2020, 1.340095640],
1510+
["DUMMY", 2014, 1],
1511+
["DUMMY", 2015, 1.05],
1512+
["DUMMY", 2016, 1.1025],
1513+
["DUMMY", 2017, 1.157625],
1514+
["DUMMY", 2018, 1.21550625],
1515+
["DUMMY", 2019, 1.276281562],
1516+
["DUMMY", 2020, 1.340095640],
1517+
],
1518+
columns=["REGION", "YEAR", "VALUE"],
1519+
).set_index(["REGION", "YEAR"])
1520+
1521+
assert_frame_equal(actual, expected)
1522+
14881523

14891524
class TestDiscountFactorStorage:
14901525
def test_dfs_start(self, region, year, discount_rate_storage):

0 commit comments

Comments
 (0)