What happens
Calling subsample() on a PolicyEngine-UK simulation raises a TypeError:
Simulation.build_from_dataset() missing 1 required positional argument: 'dataset'
Reproduction
Run by the US + core hub on policyengine-uk 2.122.2, with policyengine-core at master 78a6c503 and at PolicyEngine/policyengine-core#573's head (same failure on both):
Microsimulation(dataset=...).subsample(n=10_000, seed=0, time_period=2026)
It has not been run on 2.125.1. The code below is unchanged on main, so the same failure is expected there.
Cause, read in the code
- policyengine-core,
policyengine_core/simulations/simulation.py (master 78a6c503): Simulation.subsample ends with self.build_from_dataset(), called with no arguments (line 3354). Core's own build_from_dataset(self) takes none (line 1080).
- policyengine-uk,
policyengine_uk/simulation.py (main e89b8abc): the override is build_from_dataset(self, dataset: Dataset) (line 455), which requires a positional dataset.
- policyengine-uk defines no
subsample of its own in simulation.py or microsimulation.py, so the inherited core method runs and hits the mismatch.
This predates core#573: it fails the same way on core master.
Options
- Override
subsample in policyengine-uk so that it works with the UK dataset classes, and add a test.
- Override it to raise a clear
NotImplementedError that points to the supported way to subsample UK data.
- Make the override's
dataset argument optional and fall back to self.dataset. Check first that core's subsample (which rebuilds self.dataset through Dataset.from_dataframe) produces something the UK builder can load; the signature may not be the only mismatch.
Whichever is chosen, a test that calls subsample() on a small UK simulation would catch a regression.
Not affected
Full-sample UK totals are identical under core master and core#573.
What happens
Calling
subsample()on a PolicyEngine-UK simulation raises aTypeError:Reproduction
Run by the US + core hub on policyengine-uk 2.122.2, with policyengine-core at master
78a6c503and at PolicyEngine/policyengine-core#573's head (same failure on both):It has not been run on 2.125.1. The code below is unchanged on
main, so the same failure is expected there.Cause, read in the code
policyengine_core/simulations/simulation.py(master78a6c503):Simulation.subsampleends withself.build_from_dataset(), called with no arguments (line 3354). Core's ownbuild_from_dataset(self)takes none (line 1080).policyengine_uk/simulation.py(maine89b8abc): the override isbuild_from_dataset(self, dataset: Dataset)(line 455), which requires a positionaldataset.subsampleof its own insimulation.pyormicrosimulation.py, so the inherited core method runs and hits the mismatch.This predates core#573: it fails the same way on core master.
Options
subsamplein policyengine-uk so that it works with the UK dataset classes, and add a test.NotImplementedErrorthat points to the supported way to subsample UK data.datasetargument optional and fall back toself.dataset. Check first that core'ssubsample(which rebuildsself.datasetthroughDataset.from_dataframe) produces something the UK builder can load; the signature may not be the only mismatch.Whichever is chosen, a test that calls
subsample()on a small UK simulation would catch a regression.Not affected
Full-sample UK totals are identical under core master and core#573.