Repository navigation
fix(spec): a window sum over absent terms is 0, like sum - #1174
Merged
Merged
Conversation
sum_back left a row absent where every term of its window was absent. sum over the same terms gives 0. A window now fills each absent term with 0 and sums, as sum does, so the row stays. This also holds where the window reaches nothing: a member a partition places nowhere, or a width no member carries. A shift without edge= still leaves its row absent.
FabianHofmann
force-pushed
the
fix/1172-window-sum-of-absent
branch
from
November 18, 2026 10:03
7e2bf7c to
80b3e7e
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
A window sum over absent terms stays 0, like sum. A member that within= places in no group has no window. A member whose width is absent has no window either. Both keep no row, as on master and as shift does. A width of 0 is a defined, empty window and gives 0. Test the refusal of a row left with no variable term. Test a where that reads sum_back over an absent parameter.
4 of 5 tasks
FabianHofmann
marked this pull request as ready for review
November 18, 2026 10:48
This was referenced Nov 18, 2026
Open
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.
Closes #1172.
Changes proposed in this Pull Request
Note
The following content was generated by AI.
sum_backnow sums likesum: each absent term counts as 0, so a defined window of only absent terms is 0 and the row stays. The issue's example buildsy[0] <= 0andy[1] <= 0.within=places in no group, or a member whose per-entity width is absent.shiftunder the same partition leaves that row absent too. A width of 0 is a defined, empty window and gives 0.SpecDataError("hold no variable term"), assum(x, over=t) <= 4already is on master.where:that readssum_backover an absent parameter now sees the sum of the present members (0 for an all-absent window), so the condition can flip from false to true.shiftwithoutedge=.Changed in this revision (after review):
sum_backmasks the result where the window is not defined (partition.grouped & within.notnull()). The two existing-test edits that encoded 0 for those cases are reverted.sum-backbuilder case is now a test of the refusal.where:readingsum_backover an absent parameter.Validation and reviewer notes
Fix.
operators.sum_backfills each lag with 0 through the shared_filled, assum_overdoes, and no longer masks by "any lag reached". It masks only where the window is not defined: where thewithin=partition holds no group, and where the width is absent.Tests.
test_spec_operators.py::test_a_defined_window_of_absent_terms_sums_to_zero_like_sum:xis masked tot ∈ {0, 3}. Parametrized over the foursum_backvariants (plain,edge='wrap',within=, per-group width), plus three cases: a width of 0 gives 0, a member in no group keeps no row, an absent width keeps no row. Checks the built rows, the solved values and the folded named expression. All 7 cases fail on master. The 2 undefined-window cases fail on the previous PR head.test_spec_builder.py::test_a_row_of_nothing_but_an_absent_window_is_refused_like_sum:sum_back(a * x, along=t, window=2) <= 4withaabsent att=0raisesSpecDataError. Replaces thesum-backcase removed fromtest_an_absent_row_masks_the_row_it_reaches. Fails on master.test_spec_builder.py::test_a_where_reads_a_window_of_absent_rows_as_the_sum_of_the_rest:where: sum_back(p, along=t, window=2) <= 1withpabsent att=0keepsx[0]. Fails on master.test_a_member_a_relation_sends_nowhere_reaches_nothing[sum-back-in-groups]andtest_a_window_width_no_member_carries_is_a_window_of_nothingare back to their master form.Compatibility with 1ea671d (
spec/prune-unbuilt): that commit turns the refusal into anEmptiedRowWarningand drop where the row holds. This PR changes onlysum_back, not the emptied-row check, so the two compose.Hole check.
evaluator._marksalready fills the window operand and says absence does not spread "out of a sum or a window". It now agrees with the build.Separate issue, not fixed here. An absent per-entity
shiftoffset is cast from NaN to int (operators.py,source = (ordinal - offset).astype(int)). Underedge='wrap'every position then reads position 0; underedge=0the row gets the fill instead of staying absent. This is the same on master and needs its own issue.Checks run locally (Python 3.13):
pytest test/test_spec*.py573 passed, 6 skipped;ruff check .andruff format --check .(v0.16.10) clean;mypy linopyclean. The issue's reproducer and the review's scenarios give the expected rows dense and withsparse=True.Checklist
AGENTS.md).doc.doc/release-notes.mdof the upcoming release is included.Generated by Claude Code