feat: add as_of attribute for persistent vector variables#1365
Merged
feat: add as_of attribute for persistent vector variables#1365
Conversation
6 tasks
eraviart
approved these changes
Mar 4, 2026
Member
eraviart
left a comment
There was a problem hiding this comment.
Needed for longitudinal simulations
d100785 to
32ad81b
Compare
Introduces as_of = True / "start" / "end" on Variable, enabling values set at a given instant to persist forward in time until explicitly overridden — the vectorial analogue of OpenFisca parameters. - Variable: set_as_of() setter normalises True → "start", rejects invalid values, and guards against incompatible set_input helpers - Holder.get_array: falls back to _get_as_of() when no exact match - Holder._get_as_of: O(log P) lookup via bisect on _sorted_instants, with a linear-scan fallback for cloned holders - Holder._set: reference sharing for unchanged arrays + defensive read-only copy to prevent in-place mutation of stored data - Holder.clone: copies _sorted_instants independently - 14 unit tests covering persistence, conventions, reference sharing, read-only guard, and declaration validation - pyproject.toml: exclude docs/ from codespell (French design docs) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion - Add "Ce qui a été implémenté — v44.3.0" section: Variable.as_of attribute, Holder changes, mitigated risks, 14 tests, known gaps - Add "Limite de l'implémentation actuelle : stockage dense" section: explains why reference sharing is ineffective for scattered individual changes (e.g. civil servants changing grade), quantifies the memory gap vs patch-based storage, and sketches the patch storage model that v_next should implement Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ersion to 44.5.0 Made-with: Cursor
32ad81b to
8beb444
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
as_of = True / "start" / "end"onVariable: a value set at a given instant persists forward in time until explicitly overridden — the vectorial analogue of OpenFisca parametersHolder.get_arrayfalls back to_get_as_of()when no exact period match is foundbisecton a sorted instants list, with a linear-scan fallback for cloned holdersas_ofwithset_inputhelpers (semantically incompatible)pyproject.toml: excludedocs/from codespell (French-language design docs)Test plan
tests/core/test_asof_variable.py— all pass locallytest_yamlshell-script failures are pre-existing)as_of = Truenormalises to"start"as_of = "end"usesperiod.stopas reference instantwriteable=False, caller array untouched🤖 Generated with Claude Code