Skip to content

Commit

Permalink
Monthlyisation fix (#165)
Browse files Browse the repository at this point in the history
* Adjust datasets to not automatically generate

* Fix bug in Core monthlyisation

* Versioning
  • Loading branch information
nikhilwoodruff authored Feb 29, 2024
1 parent 94b78ef commit 2a2bcd9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
fixed:
- Fixed a bug in Core monthlyisation.
6 changes: 2 additions & 4 deletions policyengine_core/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Dataset:

_table_cache: Dict[str, pd.DataFrame] = None

def __init__(self, regenerate: bool = False):
def __init__(self, require: bool = False):
# Setup dataset
if self.file_path is None:
raise ValueError(
Expand Down Expand Up @@ -66,9 +66,7 @@ def __init__(self, regenerate: bool = False):
"You tried to instantiate a Dataset object, but no time_period has been provided."
)

if regenerate:
self.generate()
elif not self.exists:
if not self.exists and require:
if self.url is not None:
self.download()
else:
Expand Down
4 changes: 3 additions & 1 deletion policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(
)
dataset = datasets_by_name[dataset]
if isinstance(dataset, type):
self.dataset: Dataset = dataset()
self.dataset: Dataset = dataset(require=True)
else:
self.dataset = dataset
self.build_from_dataset()
Expand Down Expand Up @@ -227,6 +227,7 @@ def build_from_dataset(self) -> None:

builder = SimulationBuilder()
builder.populations = self.populations

try:
data = self.dataset.load()
except FileNotFoundError as e:
Expand Down Expand Up @@ -576,6 +577,7 @@ def _calculate(
start_instants = [
str(known_period.start)
for known_period in known_periods
if known_period.unit == variable.definition_period
]
latest_known_period = known_periods[
np.argmax(start_instants)
Expand Down

0 comments on commit 2a2bcd9

Please sign in to comment.