From f4472223e6ee7f6841a29ccacbe9bfc1da0bba6d Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 24 Oct 2024 11:57:47 +0100 Subject: [PATCH 1/3] Fix Subsample doesn't work with behavioural response simulations #296 --- policyengine_core/simulations/simulation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/policyengine_core/simulations/simulation.py b/policyengine_core/simulations/simulation.py index 482c90e4..156bb087 100644 --- a/policyengine_core/simulations/simulation.py +++ b/policyengine_core/simulations/simulation.py @@ -1549,6 +1549,11 @@ def subsample( # Update the dataset and rebuild the simulation self.dataset = Dataset.from_dataframe(df, self.dataset.time_period) self.build_from_dataset() + + # Ensure the baseline branch has the new data. + baseline_tax_benefit_system = self.baseline.tax_benefit_system + self.branches["baseline"] = self.clone() + self.branches["tax_benefit_system"] = baseline_tax_benefit_system return self From c765176b4877fcf9fc20658b85dcf71b1a6078ee Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 24 Oct 2024 11:58:28 +0100 Subject: [PATCH 2/3] Versioning --- changelog_entry.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29b..1fa7f744 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + fixed: + - Bug causing subsample to not work in some situations. From fa38af668de9683a9cd1d3e991a9b1b2caff81c0 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 24 Oct 2024 12:01:05 +0100 Subject: [PATCH 3/3] Add safety check --- policyengine_core/simulations/simulation.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/policyengine_core/simulations/simulation.py b/policyengine_core/simulations/simulation.py index 156bb087..a18312c2 100644 --- a/policyengine_core/simulations/simulation.py +++ b/policyengine_core/simulations/simulation.py @@ -1551,9 +1551,12 @@ def subsample( self.build_from_dataset() # Ensure the baseline branch has the new data. - baseline_tax_benefit_system = self.baseline.tax_benefit_system - self.branches["baseline"] = self.clone() - self.branches["tax_benefit_system"] = baseline_tax_benefit_system + if "baseline" in self.branches: + baseline_tax_benefit_system = self.branches[ + "baseline" + ].tax_benefit_system + self.branches["baseline"] = self.clone() + self.branches["tax_benefit_system"] = baseline_tax_benefit_system return self