Skip to content

Commit

Permalink
Merge pull request #266 from anth-volk/fix/262-no-dataset
Browse files Browse the repository at this point in the history
Ensure every instance of `Simulation` class has `dataset`, fix `check_macro_cache`
  • Loading branch information
MaxGhenis authored Sep 3, 2024
2 parents c44ad2e + be9e7a8 commit 3bda5e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- bump: patch
changes:
changed:
- Ensure that every instance of 'Simulation' class has 'dataset' attribute, even if equal to 'None'
- Add better safeguards to 'check_macro_cache' method of 'Simulation' class
18 changes: 14 additions & 4 deletions policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(
self.reform = reform
self.tax_benefit_system = tax_benefit_system
self.branch_name = "default"
self.dataset = dataset

if dataset is None:
if self.default_dataset is not None:
Expand Down Expand Up @@ -607,7 +608,7 @@ def _calculate(

smc = SimulationMacroCache(self.tax_benefit_system)

# Check if cache could be used, if available, check if path exists
# Check if cache can be used, if available, check if path exists
is_cache_available = self.check_macro_cache(variable_name, str(period))
if is_cache_available:
smc.set_cache_path(
Expand Down Expand Up @@ -1418,9 +1419,18 @@ def check_macro_cache(self, variable_name: str, period: str) -> bool:
"""
Check if the variable is able to have cached value
"""
if hasattr(self, "dataset"):
if self.dataset.data_format == Dataset.FLAT_FILE:
return False

# Dataset should always exist, but just in case
if not hasattr(self, "dataset"):
return False

# If no dataset, no need to cache
if self.dataset is None:
return False

# If using a flat file dataset, we're unable to cache
if self.dataset.data_format == Dataset.FLAT_FILE:
return False

if self.is_over_dataset:
return True
Expand Down

0 comments on commit 3bda5e9

Please sign in to comment.