Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/spm-subsample-test-core552.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated the subsampling holder test to supply a yearly input before checking reform storage.
13 changes: 9 additions & 4 deletions policyengine_us/tests/core/test_social_security_real_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,22 @@ def load(self):
def test_dataset_rebuild_keeps_new_input_provenance_when_old_cache_shares_key():
from policyengine_core.data import Dataset

simulation = SimulationBuilder().build_from_variables(make_system(), {})
# The 2022 input carries over to 2023. Both cores cache that carry-over
# as a derived return under the key the dataset's input then reuses, so
# the adapter's pre-rebuild snapshot captures it.
simulation = SimulationBuilder().build_from_variables(
make_system(), {"independent_input": {"2022": [0.0]}}
)
assert scalar(simulation, PUBLIC, "2023") == 0
since = earliest_source_dependency(simulation, requested="2023")
assert since is not None
assert scalar(simulation, "independent_input", "2023") == 0
old_holder = simulation.get_holder("independent_input")
# Core may leave a missing input's default uncached. Store the derived
# entry this test needs under the key the dataset's input then reuses.
old_holder.put_in_cache(np.array([0.0]), period("2023"), derived=True)
assert old_holder.is_derived(period("2023"))
assert sequence_number(simulation, "independent_input", "2023") >= since
assert ("independent_input", period("2023")) in hooks._derived_cached_returns(
simulation
)

class TinyDataset:
data_format = Dataset.TIME_PERIOD_ARRAYS
Expand Down
4 changes: 4 additions & 0 deletions policyengine_us/tests/core/test_spm_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@ def test_subsampling_never_changes_which_policy_a_holder_belongs_to(
# Core 3.33.1 and later discard calculated caches when rebuilding;
# earlier versions imported them as inputs. Calculate again so
# both behaviors exercise holders for the reform's definitions.
# Supply an input to exercise yearly storage after the rebuild.
changed.set_input(
"is_household_head", 2024, np.ones(changed.person.count, dtype=bool)
)
for variable in ("reform_only_income", "is_household_head"):
changed.calculate(variable, 2024)
holder = changed.get_holder(variable)
Expand Down
Loading