Skip to content

Commit 986abac

Browse files
committed
fix: Infer the entity timestamp column with the Polars backend
LocalJoinNode inferred the entity timestamp column from the dtypes of the backend DataFrame. The inference only recognises pandas datetime dtypes, so with the Polars backend an entity_df whose timestamp column is not named event_timestamp raised EntityTimestampInferenceException. Infer it from the pandas entity_df instead. Signed-off-by: Yihang Chen <yhc0720@berkeley.edu>
1 parent 2dfb9e6 commit 986abac

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎sdk/python/feast/infra/compute_engines/local/nodes.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ def execute(self, context: ExecutionContext) -> ArrowTableValue:
9595
if context.entity_df is not None:
9696
entity_df = self.backend.from_arrow(pa.Table.from_pandas(context.entity_df))
9797

98-
entity_schema = dict(zip(entity_df.columns, entity_df.dtypes))
98+
# Infer from the pandas dtypes: the inference does not recognise
99+
# the datetime dtypes of other backends (e.g. Polars).
100+
entity_schema = dict(
101+
zip(context.entity_df.columns, context.entity_df.dtypes)
102+
)
99103
entity_ts_col = infer_entity_timestamp_column(entity_schema)
100104

101105
if entity_ts_col != ENTITY_TS_ALIAS:

‎sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,37 @@ def test_local_join_node():
211211
assert "__entity_event_timestamp" in result_df.columns
212212

213213

214+
@pytest.mark.parametrize("backend_name", ["pandas", "polars"])
215+
def test_local_join_node_infers_entity_timestamp_column(backend_name):
216+
"""The entity timestamp column is found by dtype when it has another name."""
217+
if backend_name == "polars":
218+
pytest.importorskip("polars")
219+
from feast.infra.compute_engines.backends.factory import BackendFactory
220+
221+
context = create_context(
222+
node_outputs={"source": ArrowTableValue(pa.Table.from_pandas(sample_df))}
223+
)
224+
context.entity_df = pd.DataFrame({"entity_id": [1, 2], "ts": [now, now]})
225+
226+
join_node = LocalJoinNode(
227+
name="join",
228+
backend=BackendFactory.from_name(backend_name),
229+
column_info=ColumnInfo(
230+
join_keys=["entity_id"],
231+
feature_cols=["value"],
232+
ts_col="event_timestamp",
233+
created_ts_col=None,
234+
),
235+
)
236+
join_node.add_input(MagicMock())
237+
join_node.inputs[0].name = "source"
238+
239+
result_df = join_node.execute(context).data.to_pandas()
240+
assert len(result_df) == 4
241+
assert "ts" not in result_df.columns
242+
assert (result_df[ENTITY_TS_ALIAS] == now).all()
243+
244+
214245
def test_local_dedup_node():
215246
# Duplicate rows for each entity with different event and created timestamps
216247
df = pd.DataFrame(

0 commit comments

Comments
 (0)