Skip to content

Commit

Permalink
Fix datetime bug to aviud time_subset without hours cutting to hour 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
irm-codebase committed Dec 15, 2024
1 parent 3f2f9be commit 7319ec1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/calliope/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Implements the Calliope configuration class."""

from collections.abc import Hashable
from datetime import datetime
from pathlib import Path
from typing import Annotated, Literal, TypeVar

Expand Down Expand Up @@ -111,7 +110,7 @@ class Init(ConfigBaseModel):
Defaults to False to mitigate unexpected broadcasting when applying overrides.
"""

time_subset: tuple[datetime, datetime] | None = Field(default=None)
time_subset: tuple[str, str] | None = Field(default=None)
"""
Subset of timesteps as an two-element list giving the **inclusive** range.
For example, ["2005-01", "2005-04"] will create a time subset from "2005-01-01 00:00:00" to "2005-04-31 23:59:59".
Expand Down Expand Up @@ -149,7 +148,7 @@ class BuildOperate(ConfigBaseModel):
"frozen": True,
"json_schema_extra": hide_from_schema(
["start_window_idx"]
), # FIXME-remove, config should not be altered by our code
), # FIXME-remove, config should not be altered within calliope our code
"revalidate_instances": "always",
"use_attribute_docstrings": True,
}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_backend_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
@pytest.mark.parametrize("valid_backend", ["pyomo", "gurobi"])
def test_valid_model_backend(simple_supply, valid_backend):
"""Requesting a valid model backend must result in a backend instance."""
build_config = simple_supply.config.build.update({"backend": valid_backend})
backend_obj = backend.get_model_backend(
valid_backend, simple_supply._model_data, simple_supply.applied_math
build_config, simple_supply._model_data, simple_supply.applied_math
)
assert isinstance(backend_obj, BackendModel)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_build_operate_not_allowed_build(self):


class TestBuild:
@pytest.fixture(scope="class")
@pytest.fixture
def init_model(self):
return build_model({}, "simple_supply,two_hours,investment_costs")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def override(param):

assert check_error_or_warning(
error,
"subset time range ['2005-03', '2005-04'] is outside the input data time range [2005-01-01 00:00:00, 2005-01-05 23:00:00]",
"subset time range ('2005-03', '2005-04') is outside the input data time range [2005-01-01 00:00:00, 2005-01-05 23:00:00]",
)

# should fail: time subset out of range of input data
Expand Down

0 comments on commit 7319ec1

Please sign in to comment.