Skip to content

fix: ambiguous truth value of array during materialization#6259

Open
alan-gauthier-jt wants to merge 1 commit intofeast-dev:masterfrom
alan-gauthier-jt:fix-array-materialize
Open

fix: ambiguous truth value of array during materialization#6259
alan-gauthier-jt wants to merge 1 commit intofeast-dev:masterfrom
alan-gauthier-jt:fix-array-materialize

Conversation

@alan-gauthier-jt
Copy link
Copy Markdown

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

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.

Signed-off-by: Alan Gauthier <alan.gauthier@jobteaser.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant