diff --git a/src/oemof/solph/_helpers.py b/src/oemof/solph/_helpers.py index 15066af0c..ceae7e269 100644 --- a/src/oemof/solph/_helpers.py +++ b/src/oemof/solph/_helpers.py @@ -104,7 +104,12 @@ def create_time_index( else: hoy = 8760 number = round(hoy / interval) - if start is None: + if start is not None: + if year is not None: + raise ValueError( + "Arguments 'start' and 'year' are mutually exclusive." + ) + else: start = f"1/1/{year}" try: time_index = pd.date_range( diff --git a/tests/test_helpers.py b/tests/test_helpers.py index c33380a17..f878896b1 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -9,8 +9,10 @@ """ import os +import pytest from oemof.solph import helpers +from oemof.solph import create_time_index def test_creation_of_extended_path(): @@ -18,3 +20,25 @@ def test_creation_of_extended_path(): p = helpers.extend_basic_path("test_subfolder_X345qw34_tmp") assert os.path.isdir(p) os.rmdir(p) + + +def test_create_time_index(): + assert len(create_time_index(2014)) == 8761 + assert len(create_time_index(2012)) == 8785 # leap year + assert len(create_time_index(2014, interval=0.5)) == 17521 + assert len(create_time_index(2014, interval=0.5, number=10)) == 11 + assert len(create_time_index(2014, number=10)) == 11 + assert ( + str(create_time_index(2014, interval=0.5, number=10)[-1]) + == "2014-01-01 05:00:00" + ) + assert ( + str(create_time_index(2014, interval=2, number=10)[-1]) + == "2014-01-01 20:00:00" + ) + assert ( + str(create_time_index(interval=0.5, number=10, start="2025-01-02")[-1]) + == "2025-01-02 05:00:00" + ) + with pytest.raises(ValueError, match="mutually exclusive"): + create_time_index(year=2015, start="2025-01-02")