From f2829bd29a852a229c0ae761e2fbd5c1b083a641 Mon Sep 17 00:00:00 2001 From: Mrun25 <165297479+Mrun25@users.noreply.github.com> Date: Mon, 19 Oct 2026 12:01:03 +0530 Subject: [PATCH 1/2] fix: infer Feast types for additional Arrow types and report column name on inference failure (#7040) Signed-off-by: Mrun25 <165297479+Mrun25@users.noreply.github.com> --- sdk/python/feast/inference.py | 25 ++++++++++++----- .../infra/offline_stores/offline_utils.py | 5 +++- sdk/python/feast/type_map.py | 23 +++++++++++++++- sdk/python/tests/unit/test_type_map.py | 27 +++++++++++++++++++ 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/sdk/python/feast/inference.py b/sdk/python/feast/inference.py index 16023e3dac6..7daf860a603 100644 --- a/sdk/python/feast/inference.py +++ b/sdk/python/feast/inference.py @@ -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: @@ -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 [ @@ -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 ) ), ) @@ -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 [ @@ -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 ) ), ) diff --git a/sdk/python/feast/infra/offline_stores/offline_utils.py b/sdk/python/feast/infra/offline_stores/offline_utils.py index 6188d4f00b8..69fcefe2acb 100644 --- a/sdk/python/feast/infra/offline_stores/offline_utils.py +++ b/sdk/python/feast/infra/offline_stores/offline_utils.py @@ -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: diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 975e18ee195..1c836d40bc4 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -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 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: @@ -1683,7 +1699,12 @@ def pa_to_feast_value_type(pa_type_as_str: str) -> ValueType: "list": ValueType.BYTES_LIST, "list": ValueType.FLOAT_LIST, } - value_type = type_map[pa_type_as_str] + value_type = type_map.get(pa_type_as_str) + if 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." + ) if is_list: value_type = ValueType[value_type.name + "_LIST"] diff --git a/sdk/python/tests/unit/test_type_map.py b/sdk/python/tests/unit/test_type_map.py index d966a86c158..adc48afcad1 100644 --- a/sdk/python/tests/unit/test_type_map.py +++ b/sdk/python/tests/unit/test_type_map.py @@ -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", + 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]") From dfdef021c5fabfa05311824882444e4f50367f2d Mon Sep 17 00:00:00 2001 From: Mrunmayee Daware <165297479+Mrun25@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:50:55 +0530 Subject: [PATCH 2/2] fix: narrow Arrow type lookup before assignment Signed-off-by: Mrunmayee Daware <165297479+Mrun25@users.noreply.github.com> --- sdk/python/feast/type_map.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 1c836d40bc4..37d12437b10 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -1699,12 +1699,13 @@ def pa_to_feast_value_type(pa_type_as_str: str) -> ValueType: "list": ValueType.BYTES_LIST, "list": ValueType.FLOAT_LIST, } - value_type = type_map.get(pa_type_as_str) - if value_type is None: + 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"]