fix: guard interpolator and grid search against edge cases#1201
Merged
fix: guard interpolator and grid search against edge cases#1201
Conversation
…ence Two defensive fixes: - interpolator.__getitem__ now raises a clear IndexError when instances list is empty instead of a cryptic index-out-of-range - grid_search_result.log_evidences() handles None log_evidence values instead of crashing on NoneType - float subtraction Co-Authored-By: Claude Opus 4.6 <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.
Summary
Two defensive fixes for edge cases surfaced by the Apr 10 release build:
interpolator.__getitem__— raises a clearIndexError("Cannot interpolate: no instances have been added")when the instances list is empty, instead of a crypticIndexError: list index out of range.grid_search_result.log_evidences()— handlesNonelog_evidence values (which occur when a nested sampler doesn't compute evidence) by returningNonein the list instead of crashing withTypeError: unsupported operand type(s) for -: 'NoneType' and 'float'.Relates to PyAutoLabs/PyAutoArray#269.
API Changes
GridSearchResult.log_evidences()now returnsNoneentries for samples wherelog_evidenceisNone, instead of raisingTypeError. Callers that iterate the result should handleNonevalues.See full details below.
Test Plan
test_autofit/— 1205 passedFull API Changes (for automation & release notes)
Changed Behaviour
GridSearchResult.log_evidences()— previously crashed if any sample hadlog_evidence = None. Now returnsNonefor those entries instead of raisingTypeError.AbstractInterpolator.__getitem__()— previously raised bareIndexErroron empty instances. Now raisesIndexErrorwith descriptive message.Migration
No migration needed. Both changes are backwards-compatible — code that previously worked continues to work. Code that previously crashed now gets a meaningful error or a
Nonevalue.🤖 Generated with Claude Code