fix: ambiguous truth value of array during materialization#6259
Open
alan-gauthier-jt wants to merge 1 commit intofeast-dev:masterfrom
Open
fix: ambiguous truth value of array during materialization#6259alan-gauthier-jt wants to merge 1 commit intofeast-dev:masterfrom
alan-gauthier-jt wants to merge 1 commit intofeast-dev:masterfrom
Conversation
d35e16c to
ea8f7da
Compare
Signed-off-by: Alan Gauthier <alan.gauthier@jobteaser.com>
ea8f7da to
33d1613
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.
What this PR does / why we need it:
feast materializecrashes withValueError: The truth value of an empty array is ambiguouswhen a scalar feature column contains an empty numpy array (e.g.np.array([])). This is a real-world scenario when a DataFrame row has a missing value represented as an empty array rather thanNoneornp.nan.Root cause: In
_convert_scalar_values_to_proto(sdk/python/feast/type_map.py), the null check usesnot pd.isnull(value)for every value in the loop.pd.isnull()is vectorised — whenvalueis a numpy array, it returns a boolean array instead of a scalar. Applying Python'snotoperator to that array raisesValueError. The same issue exists in:BOOLscalar path (not pd.isnull(value)in a list comprehension)UNIX_TIMESTAMPearly-return path (_python_datetime_to_int_timestamp(values)called with the raw values list, including any array-like values)sample == 0)Fix: Before calling
pd.isnull(), guard both scalar conversion loops (generic and BOOL) and the sample type-validation with an explicitisinstance(value, np.ndarray)check. Any array-like value in a scalar feature column is unmappable to a protobuf scalar field anyway, so it is safely treated as null →ProtoValue().np.array([])(empty)ValueErrorcrashProtoValue()(null)np.array([np.nan, 1.0])ValueErrorcrashProtoValue()(null)np.array([1.0, 2.0])ValueErrorcrashProtoValue()(null)NoneProtoValue()(null)ProtoValue(field=value)Which issue(s) this PR fixes:
Fixes #6255
Checks
git commit -s)Testing Strategy
Misc