Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monthlyisation fix #165

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)
dataset = datasets_by_name[dataset]
if isinstance(dataset, type):
self.dataset: Dataset = dataset()
self.dataset: Dataset = dataset(require=True)

Check warning on line 156 in policyengine_core/simulations/simulation.py

View check run for this annotation

Codecov / codecov/patch

policyengine_core/simulations/simulation.py#L156

Added line #L156 was not covered by tests
else:
self.dataset = dataset
self.build_from_dataset()
Expand Down Expand Up @@ -227,6 +227,7 @@

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

try:
data = self.dataset.load()
except FileNotFoundError as e:
Expand Down Expand Up @@ -576,6 +577,7 @@
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
Loading