Fix IntegerVectors membership for empty vectors - #42631
Open
vivek41-glitch wants to merge 2 commits into
Open
Conversation
|
Documentation preview for this PR (built with commit 06c69b2; changes) is ready! 🎉 |
Contributor
|
please rebase to latest develop and fix the lint |
vivek41-glitch
force-pushed
the
fix/integervectors-empty-max-42527-v2
branch
from
August 6, 2026 14:09
2c859eb to
06c69b2
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.
Fixes #42527.
Summary
This PR fixes the membership check for empty integer vectors in
IntegerVectorsConstraints.The original issue reported that the following returned
False:even though the empty vector satisfies the given constraint.
Root cause
The implementation of
IntegerVectorsConstraints.__contains__directly returned the result ofWhen
singleton=True,check_integer_list_constraintsreturns:Noneotherwise.For an empty vector, the returned value is
[]. Although this represents a valid result, an empty list is falsy in Python, causing__contains__to incorrectly returnFalse.This PR changes the membership test to explicitly check whether the result is
None, preserving valid empty vectors while still rejecting invalid ones.Additional issue discovered
While investigating the reported bug, I found that
check_integer_list_constraintsalso did not correctly handle empty lists formin_partandmax_part.The implementation previously called:
which raises a
ValueErrorfor empty lists.This PR updates these checks to use appropriate defaults:
This gives the expected mathematical behavior for empty vectors and allows the constraint checks to work correctly without raising exceptions.
Tests
Added doctests covering the empty-vector membership cases:
All affected doctests pass successfully.