diff --git a/changelog.d/spm-subsample-test-core552.fixed.md b/changelog.d/spm-subsample-test-core552.fixed.md new file mode 100644 index 00000000000..fc0610014bc --- /dev/null +++ b/changelog.d/spm-subsample-test-core552.fixed.md @@ -0,0 +1 @@ +Updated the subsampling holder test to supply a yearly input before checking reform storage. diff --git a/policyengine_us/tests/core/test_social_security_real_core.py b/policyengine_us/tests/core/test_social_security_real_core.py index 29e5ff44f62..f5025a82d54 100644 --- a/policyengine_us/tests/core/test_social_security_real_core.py +++ b/policyengine_us/tests/core/test_social_security_real_core.py @@ -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 diff --git a/policyengine_us/tests/core/test_spm_system.py b/policyengine_us/tests/core/test_spm_system.py index 8c8020cbf49..b81553bc242 100644 --- a/policyengine_us/tests/core/test_spm_system.py +++ b/policyengine_us/tests/core/test_spm_system.py @@ -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)