diff --git a/sdk/python/feast/infra/compute_engines/local/nodes.py b/sdk/python/feast/infra/compute_engines/local/nodes.py index 71e78a8380e..b1cf3dc59d2 100644 --- a/sdk/python/feast/infra/compute_engines/local/nodes.py +++ b/sdk/python/feast/infra/compute_engines/local/nodes.py @@ -95,7 +95,11 @@ def execute(self, context: ExecutionContext) -> ArrowTableValue: if context.entity_df is not None: entity_df = self.backend.from_arrow(pa.Table.from_pandas(context.entity_df)) - entity_schema = dict(zip(entity_df.columns, entity_df.dtypes)) + # Infer from the pandas dtypes: the inference does not recognise + # the datetime dtypes of other backends (e.g. Polars). + entity_schema = dict( + zip(context.entity_df.columns, context.entity_df.dtypes) + ) entity_ts_col = infer_entity_timestamp_column(entity_schema) if entity_ts_col != ENTITY_TS_ALIAS: diff --git a/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py b/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py index 3e51f600e01..ed53b54de70 100644 --- a/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py +++ b/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py @@ -211,6 +211,37 @@ def test_local_join_node(): assert "__entity_event_timestamp" in result_df.columns +@pytest.mark.parametrize("backend_name", ["pandas", "polars"]) +def test_local_join_node_infers_entity_timestamp_column(backend_name): + """The entity timestamp column is found by dtype when it has another name.""" + if backend_name == "polars": + pytest.importorskip("polars") + from feast.infra.compute_engines.backends.factory import BackendFactory + + context = create_context( + node_outputs={"source": ArrowTableValue(pa.Table.from_pandas(sample_df))} + ) + context.entity_df = pd.DataFrame({"entity_id": [1, 2], "ts": [now, now]}) + + join_node = LocalJoinNode( + name="join", + backend=BackendFactory.from_name(backend_name), + column_info=ColumnInfo( + join_keys=["entity_id"], + feature_cols=["value"], + ts_col="event_timestamp", + created_ts_col=None, + ), + ) + join_node.add_input(MagicMock()) + join_node.inputs[0].name = "source" + + result_df = join_node.execute(context).data.to_pandas() + assert len(result_df) == 4 + assert "ts" not in result_df.columns + assert (result_df[ENTITY_TS_ALIAS] == now).all() + + def test_local_dedup_node(): # Duplicate rows for each entity with different event and created timestamps df = pd.DataFrame(