Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions sdk/python/feast/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
from feast.value_type import ValueType


def _infer_column_value_type(
source: DataSource, col_name: str, col_datatype: str
) -> ValueType:
"""Map a source column type to a Feast ValueType, naming the column on failure."""
try:
return source.source_datatype_to_feast_value_type()(col_datatype)
except ValueError as e:
raise RegistryInferenceFailure(
"feature view",
f"column '{col_name}' has an unsupported type: {e}",
) from e


def update_data_sources_with_inferred_event_timestamp_col(
data_sources: List[DataSource], config: RepoConfig
) -> None:
Expand Down Expand Up @@ -247,7 +260,7 @@ def _infer_features_and_entities(
field = Field(
name=col_name,
dtype=from_value_type(
fv.batch_source.source_datatype_to_feast_value_type()(col_datatype)
_infer_column_value_type(fv.batch_source, col_name, col_datatype)
),
)
if field.name not in [
Expand All @@ -266,8 +279,8 @@ def _infer_features_and_entities(
field = Field(
name=feature_name,
dtype=from_value_type(
fv.batch_source.source_datatype_to_feast_value_type()(
col_datatype
_infer_column_value_type(
fv.batch_source, col_name, col_datatype
)
),
)
Expand Down Expand Up @@ -322,7 +335,7 @@ def _infer_on_demand_features_and_entities(
field = Field(
name=col_name,
dtype=from_value_type(
batch_source.source_datatype_to_feast_value_type()(col_datatype)
_infer_column_value_type(batch_source, col_name, col_datatype)
),
)
if field.name not in [
Expand All @@ -343,8 +356,8 @@ def _infer_on_demand_features_and_entities(
field = Field(
name=feature_name,
dtype=from_value_type(
batch_source.source_datatype_to_feast_value_type()(
col_datatype
_infer_column_value_type(
batch_source, col_name, col_datatype
)
),
)
Expand Down
5 changes: 4 additions & 1 deletion sdk/python/feast/infra/offline_stores/offline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def get_pyarrow_schema_from_batch_source(
pa_schema = []
column_names = []
for column_name, column_type in column_names_and_types:
value_type = batch_source.source_datatype_to_feast_value_type()(column_type)
try:
value_type = batch_source.source_datatype_to_feast_value_type()(column_type)
except ValueError as e:
raise ValueError(f"column '{column_name}': {e}") from e
if value_type in (ValueType.VALUE_LIST, ValueType.VALUE_SET):
pa_type = _parse_pa_type_str(column_type)
else:
Expand Down
24 changes: 23 additions & 1 deletion sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,10 +1653,26 @@ def pa_to_feast_value_type(pa_type_as_str: str) -> ValueType:

if pa_type_as_str.startswith("timestamp"):
value_type = ValueType.UNIX_TIMESTAMP
elif pa_type_as_str.startswith("date32") or pa_type_as_str.startswith("date64"):
# Mirror the DataFrame inference path, which maps "date" to UNIX_TIMESTAMP.
value_type = ValueType.UNIX_TIMESTAMP
Comment on lines +1656 to +1658

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Inferred date lists fail during materialization

For list<item: date32[day]>, pa_to_feast_value_type now infers UNIX_TIMESTAMP_LIST, but materialization rejects nonempty date lists. _sanitize_list_value converts elements into datetime.date objects, which timestamp-list validation rejects.

Learn more

The existing list parser unwraps list<item: date32[day]>, so the new date32 branch also enables inference of date-list features. Materialization supplies Arrow columns as numpy arrays through _columns_to_proto_values. For a date32 list, _sanitize_list_value calls tolist() on the inner numpy array and produces Python datetime.date values. _convert_list_values_to_proto then validates those values against the timestamp-list types, which exclude datetime.date, and raises a runtime TypeError.

Example: A pandas frame containing {"dates": [[date(2026, 11, 1)]]} written with to_parquet(..., use_compliant_nested_type=False) exposes list<item: date32[day]>. Inference now succeeds, but serializing the retrieved Arrow column raises TypeError: Value "2026-11-01" is of type <class 'datetime.date'> not of type <class 'numpy.datetime64'>.

Recommended fix: Normalize date32 list elements to supported midnight-UTC datetime values before validation and serialization, or extend both timestamp-list validation and timestamp conversion to handle datetime.date. Add a regression test that infers the schema from a real date32-list column and passes its Arrow-to-numpy values through python_values_to_proto_values.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

elif pa_type_as_str.startswith("map<"):
value_type = ValueType.MAP
elif pa_type_as_str == "large_string":
value_type = ValueType.JSON
elif pa_type_as_str == "large_binary":
value_type = ValueType.BYTES
elif pa_type_as_str == "halffloat":
value_type = ValueType.FLOAT
elif pa_type_as_str.startswith("decimal128") or pa_type_as_str.startswith(
"decimal256"
):
# Mirror the DataFrame inference path, which maps "decimal" to DECIMAL.
value_type = ValueType.DECIMAL
elif pa_type_as_str.startswith("dictionary<"):
# pandas writes "category" columns as Arrow dictionaries; the DataFrame
# inference path maps "category" to STRING.
value_type = ValueType.STRING
elif pa_type_as_str.startswith("struct<") or pa_type_as_str.startswith("struct{"):
value_type = ValueType.STRUCT
else:
Expand All @@ -1683,7 +1699,13 @@ def pa_to_feast_value_type(pa_type_as_str: str) -> ValueType:
"list<element: bytes>": ValueType.BYTES_LIST,
"list<element: float>": ValueType.FLOAT_LIST,
}
value_type = type_map[pa_type_as_str]
mapped_value_type = type_map.get(pa_type_as_str)
if mapped_value_type is None:
raise ValueError(
f"Feast cannot infer a value type for the Arrow type '{pa_type_as_str}'. "
"Declare the feature view schema explicitly, or extend the Arrow type mapping."
)
value_type = mapped_value_type

if is_list:
value_type = ValueType[value_type.name + "_LIST"]
Expand Down
27 changes: 27 additions & 0 deletions sdk/python/tests/unit/test_type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2742,3 +2742,30 @@ def test_pandas_and_arrow_int_inference_agree(dtype):
)
from_arrow = pa_to_feast_value_type(str(pyarrow.array(values).type))
assert from_pandas == from_arrow


@pytest.mark.parametrize(
"pa_type, expected",
[
("date32[day]", ValueType.UNIX_TIMESTAMP),
("date64[ms]", ValueType.UNIX_TIMESTAMP),
("decimal128(3, 2)", ValueType.DECIMAL),
("decimal256(10, 4)", ValueType.DECIMAL),
(
"dictionary<values=string, indices=int8, ordered=0>",
ValueType.STRING,
),
("halffloat", ValueType.FLOAT),
("large_binary", ValueType.BYTES),
],
)
def test_pa_to_feast_value_type_pandas_written_parquet_types(pa_type, expected):
"""Arrow types written by pandas to Parquet infer the same Feast type the
DataFrame inference path produces (issue #7040)."""
assert pa_to_feast_value_type(pa_type) == expected


def test_pa_to_feast_value_type_unsupported_type_raises_descriptive_error():
"""An unmapped Arrow type raises a descriptive error, not a bare KeyError."""
with pytest.raises(ValueError, match=r"time32\[s\]"):
pa_to_feast_value_type("time32[s]")
Loading