fix: raise a clear exception when adapt data and the data mask disagree#399
Merged
Merged
Conversation
An adapt image defined on a different mask to the data cannot be indexed by the data's slim indexes. Until now this surfaced as a bare `IndexError` several frames deep inside `adaptive_pixel_signals_from`, where the first out-of-range index equals the adapt data's length — which reads as an off-by-one in the indexing rather than the mask mismatch it actually is. Check the lengths up front in `Mapper.pixel_signals_from` and raise an `InversionException` naming the likely cause (a stale adapt-image cache, see PyAutoGalaxy#516) and the remedy. A loud crash, not a silent guard — no fallback, no clamping. Two existing tests passed an unmasked 49-pixel adapt image against a 9-pixel mask, which the check correctly rejects. Both now build the adapt image on the data's own mask, as a real fit does; their assertions are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Companion to PyAutoGalaxy#516 / PyAutoLabs/PyAutoGalaxy#517 — the legibility half of that fix.
Summary
An adapt image defined on a different mask to the data cannot be indexed by the data's slim indexes. Until
now this surfaced as a bare
IndexErrorseveral frames deep insideadaptive_pixel_signals_from:Because slim indexes are ordered, the first out-of-range index equals the adapt data's length, so the
message always reads
index N ... size N— which looks like a classic off-by-one in the indexing. It isnot:
adaptive_pixel_signals_fromis correct, and the real fault is a mask mismatch several layers up. The2026-07-21 census filed exactly this misdiagnosis.
Mapper.pixel_signals_fromnow checks the lengths up front and raises anInversionExceptionnaming thelikely cause (a stale adapt-image cache) and the remedy. A loud crash, not a silent guard — no fallback, no
clamping, no
Nonehandling.Test changes
Two existing tests passed an unmasked 49-pixel adapt image (
image_7x7) against a 9-pixel mask, which thenew check correctly rejects:
test__adaptive_pixel_signals_from___matches_utiltest__pixel_signals_from__rectangular_adapt_density_mesh__matches_utilBoth now build the adapt image on the data's own mask, as a real fit does. Their assertions are unchanged —
the fixture was all-ones, so which entries were indexed never affected the result, which is why the
mismatch went unnoticed.
Adds
test__pixel_signals_from__adapt_data_on_a_different_mask__raises_clear_exception.pytest test_autoarray— 927 passed.API Changes
Mapper.pixel_signals_fromraisesexc.InversionExceptionwhenlen(adapt_data)differs fromover_sampler.mask.pixels_in_mask. This input was already broken — it previously raisedIndexErrorfromthe same call — so no working caller changes behaviour. Callers catching
IndexErroraround this path wouldneed to catch
InversionExceptioninstead; none exist in the stack.No signature, name or return-value changes.
🤖 Generated with Claude Code