◐ Shell
reader mode source ↗
Skip to content

fix: Ambiguous truth value of array during materialization#6259

Merged
ntkathole merged 2 commits into
feast-dev:masterfrom
alan-gauthier-jt:fix-array-materialize
Apr 14, 2026
Merged

fix: Ambiguous truth value of array during materialization#6259
ntkathole merged 2 commits into
feast-dev:masterfrom
alan-gauthier-jt:fix-array-materialize

Conversation

@alan-gauthier-jt

@alan-gauthier-jt alan-gauthier-jt commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

feast materialize crashes with ValueError: The truth value of an empty array is ambiguous when 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 than None or np.nan.

Root cause: In _convert_scalar_values_to_proto (sdk/python/feast/type_map.py), the null check uses not pd.isnull(value) for every value in the loop. pd.isnull() is vectorised — when value is a numpy array, it returns a boolean array instead of a scalar. Applying Python's not operator to that array raises ValueError. The same issue exists in:

  • the BOOL scalar path (not pd.isnull(value) in a list comprehension)
  • the UNIX_TIMESTAMP early-return path (_python_datetime_to_int_timestamp(values) called with the raw values list, including any array-like values)
  • the sample type-validation check (sample == 0)

Fix: Before calling pd.isnull(), guard both scalar conversion loops (generic and BOOL) and the sample type-validation with an explicit isinstance(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().

Input value Behaviour before Behaviour after
np.array([]) (empty) ValueError crash ProtoValue() (null)
np.array([np.nan, 1.0]) ValueError crash ProtoValue() (null)
np.array([1.0, 2.0]) ValueError crash ProtoValue() (null)
None ProtoValue() (null) unchanged
scalar non-null ProtoValue(field=value) unchanged

Which issue(s) this PR fixes:

Fixes #6255

Checks

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

Testing Strategy

  • Unit tests
  • Integration tests
  • Manual tests
  • Testing is not required for this change

Misc


Open with Devin

@alan-gauthier-jt alan-gauthier-jt requested a review from a team as a code owner April 10, 2026 13:30
devin-ai-integration[bot]

This comment was marked as resolved.

@ntkathole ntkathole changed the title fix: ambiguous truth value of array during materialization Apr 13, 2026
@ntkathole

Copy link
Copy Markdown
Member

@alan-gauthier-jt I think even better if we fix this at https://github.com/feast-dev/feast/blob/master/sdk/python/feast/type_map.py by adding logic for scalar columns, skip array-like values when picking a sample.

@ntkathole ntkathole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Thanks @alan-gauthier-jt looks good

Signed-off-by: Alan Gauthier <alan.gauthier@jobteaser.com>
Signed-off-by: Alan Gauthier <alan.gauthier@jobteaser.com>
@ntkathole ntkathole force-pushed the fix-array-materialize branch from 9037bdc to b91978e Compare April 14, 2026 07:31
Hide details View details @ntkathole ntkathole merged commit d0c8984 into feast-dev:master Apr 14, 2026
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError: The truth value of an empty array is ambiguous during materialization

3 participants