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
6 changes: 5 additions & 1 deletion sdk/python/feast/infra/compute_engines/local/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading