[BUGFIX] Reject empty regex_list in ExpectColumnValuesToMatchRegexList#11958
Open
anxkhn wants to merge 2 commits into
Open
[BUGFIX] Reject empty regex_list in ExpectColumnValuesToMatchRegexList#11958anxkhn wants to merge 2 commits into
anxkhn wants to merge 2 commits into
Conversation
ExpectColumnValuesToMatchRegexList declared regex_list with no non-empty validator, so constructing it with regex_list=[] succeeded. The pandas metric then called pd.concat([], axis=1) and raised the opaque 'No objects to concatenate' at validate time. Add a pydantic validator on regex_list that fails fast at construction with a clear message, matching the existing validator on the sibling ExpectColumnValuesToNotMatchRegexList and the metric's own SQLAlchemy guard. Non-empty lists are unaffected. Add a unit regression test mirroring the not-match sibling's test_invalid_config. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
✅ Deploy Preview for niobium-lead-7998 canceled.
|
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.
ExpectColumnValuesToMatchRegexListdeclared itsregex_listfield with nonon-empty validator, so constructing it with an empty list succeeded:
At validate time the pandas metric builds its match frame with
pd.concat(regex_matches, axis=1, ...). With an emptyregex_listthe loopthat populates
regex_matchesnever runs, so the call becomespd.concat([], axis=1)and raisesValueError: No objects to concatenate. Thissurfaces to the user as a
MetricResolutionErrorwith the opaque message"No objects to concatenate", which gives no hint that the real problem is the
empty
regex_list.This is an asymmetry rather than a design choice:
(
column_values_match_regex_list.py: raises "At least one regex must besupplied in the regex_list.").
ExpectColumnValuesToNotMatchRegexListalready has a@pydantic.validator("regex_list")that rejects empties with "regex_list mustnot be empty". The
like_pattern_listexpectations have the same guard.Only
ExpectColumnValuesToMatchRegexListwas missing the construction-timevalidator, so its empty-list input reached the unguarded pandas
pd.concatandcrashed.
Change
@pydantic.validator("regex_list")toExpectColumnValuesToMatchRegexListthat raises
ValueError("regex_list must not be empty")when the list is empty.It is identical to the validator already used on the not-match sibling, so the
two expectations now behave consistently and fail fast at construction with a
clear message. Non-empty lists are unaffected.
@pytest.mark.unitregression test mirroring the not-match sibling'stest_invalid_config.How it behaves after the change
Checklist (from the template)