OSeMOSYS / otoole

OSeMOSYS Tools for Energy
https://otoole.readthedocs.io
MIT License
25 stars 18 forks source link

[Bug]: Discount Factor calculation fails if multiple regions are defined #242

Closed trevorb1 closed 2 hours ago

trevorb1 commented 3 hours ago

The Issue

If you run a multiple region model, the discount factor calculation fails

Expected Behavior

No response

Steps To Reproduce

run this test

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

        regions = region_multiple["VALUE"].to_list()
        years = year["VALUE"].to_list()
        actual = discount_factor(regions, years, discount_rate_multiple, 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)

with these fixtures

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

@fixture
def year():
    return pd.DataFrame(
        data=[2014, 2015, 2016, 2017, 2018, 2019, 2020], columns=["VALUE"]
    )

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

Log output

FAILED tests/results/test_results_package.py::TestDiscountFactor::test_df_two_regions - ValueError: Length of values (1) does not match length of index (2)

Operating System

Linux

What version of otoole are you running?

1.1.4

Possible Solution

No response

Anything else?

No response

trevorb1 commented 3 hours ago

Originally identified by @pdrpeters