Repository navigation
fix: Keep the source event timestamp separate from request data in Dask retrieval #7177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2addbfb
6317454
331281d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from datetime import timedelta | ||
| from pathlib import Path | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
| from pandas.testing import assert_frame_equal | ||
|
|
||
| from feast import Entity, FeatureStore, FeatureView, Field, FileSource, RepoConfig | ||
| from feast.types import Int64, ValueType | ||
|
|
||
|
|
||
| def _store(tmp_path: Path, timestamp_fields: dict[str, str]) -> FeatureStore: | ||
| entity = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64) | ||
| feature_views = [] | ||
| for name, timestamp_field in timestamp_fields.items(): | ||
| source_path = tmp_path / f"{name}.parquet" | ||
| pd.DataFrame( | ||
| { | ||
| "driver_id": [1, 1, 1], | ||
| timestamp_field: pd.to_datetime( | ||
| [ | ||
| "2025-01-01T00:00:00Z", | ||
| "2025-01-02T00:00:00Z", | ||
| "2025-01-03T00:00:00Z", | ||
| ] | ||
| ), | ||
| name: [10, 20, 30], | ||
| } | ||
| ).to_parquet(source_path, index=False) | ||
| feature_views.append( | ||
| FeatureView( | ||
| name=f"{name}_view", | ||
| entities=[entity], | ||
| schema=[ | ||
| Field(name="driver_id", dtype=Int64), | ||
| Field(name=name, dtype=Int64), | ||
| ], | ||
| source=FileSource( | ||
| path=str(source_path), timestamp_field=timestamp_field | ||
| ), | ||
| ttl=timedelta(days=7), | ||
| ) | ||
| ) | ||
| store = FeatureStore( | ||
| config=RepoConfig( | ||
| project="timestamp_collision", | ||
| provider="local", | ||
| registry=str(tmp_path / "registry.db"), | ||
| online_store={"type": "sqlite", "path": str(tmp_path / "online.db")}, | ||
| offline_store={"type": "file"}, | ||
| repo_path=tmp_path, | ||
| ) | ||
| ) | ||
| store.apply([entity, *feature_views]) | ||
| return store | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these cases exercise the public API but hard-code the file store, so they do not check the retrieval contract across the universal store matrix. the component rule requires a universal integration regression when retrieval behavior changes. we need to add the timestamp-name collision to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in bb0ca85: |
||
|
|
||
| @pytest.mark.parametrize("full_feature_names", [False, True]) | ||
| @pytest.mark.parametrize("filter_by_created_timestamp", [False, True]) | ||
| @pytest.mark.parametrize( | ||
| "request_value", | ||
| [ | ||
| pd.Timestamp("2025-01-10T00:00:00Z"), | ||
| pd.Timestamp("2024-12-25T00:00:00Z"), | ||
| pd.Timestamp("2025-01-02T01:00:00Z"), | ||
| "not a timestamp", | ||
| 7, | ||
| ], | ||
| ids=["later", "earlier", "between-rows", "string", "integer"], | ||
| ) | ||
| def test_request_column_named_like_source_timestamp_field( | ||
| tmp_path: Path, | ||
| request_value: object, | ||
| filter_by_created_timestamp: bool, | ||
| full_feature_names: bool, | ||
| ) -> None: | ||
| store = _store(tmp_path, {"trips": "feature_timestamp"}) | ||
| requests = pd.DataFrame( | ||
| { | ||
| "driver_id": [1], | ||
| "event_timestamp": pd.to_datetime(["2025-01-02T12:00:00Z"]), | ||
| # Request data that shares the source timestamp name, plus the | ||
| # names a temporary alias would take. | ||
| "feature_timestamp": [request_value], | ||
| "__feature_timestamp": ["request label"], | ||
| "___feature_timestamp": ["another label"], | ||
| } | ||
| ) | ||
| original = requests.copy(deep=True) | ||
|
|
||
| result = store.get_historical_features( | ||
| entity_df=requests, | ||
| features=["trips_view:trips"], | ||
| filter_by_created_timestamp=filter_by_created_timestamp, | ||
| full_feature_names=full_feature_names, | ||
| ).to_df() | ||
|
|
||
| feature_column = "trips_view__trips" if full_feature_names else "trips" | ||
| assert result[feature_column].astype("float64").tolist() == [20] | ||
| assert set(result.columns) == set(requests.columns) | {feature_column} | ||
| assert_frame_equal(result[requests.columns], original) | ||
| assert_frame_equal(requests, original) | ||
|
|
||
|
|
||
| def test_request_timestamp_alias_does_not_collide_with_request_data( | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| store = _store(tmp_path, {"trips": "event_timestamp"}) | ||
| requests = pd.DataFrame( | ||
| { | ||
| "driver_id": [1], | ||
| "event_timestamp": pd.to_datetime(["2025-01-02T12:00:00Z"]), | ||
| "__event_timestamp": pd.to_datetime(["2025-01-10T00:00:00Z"]), | ||
| } | ||
| ) | ||
| original = requests.copy(deep=True) | ||
|
|
||
| result = store.get_historical_features( | ||
| entity_df=requests, features=["trips_view:trips"] | ||
| ).to_df() | ||
|
|
||
| assert result["trips"].astype("float64").tolist() == [20] | ||
| assert set(result.columns) == set(requests.columns) | {"trips"} | ||
| assert_frame_equal(result[requests.columns], original) | ||
|
|
||
|
|
||
| def test_feature_views_sharing_a_colliding_timestamp_field(tmp_path: Path) -> None: | ||
| store = _store(tmp_path, {"trips": "ts", "rating": "ts"}) | ||
| requests = pd.DataFrame( | ||
| { | ||
| "driver_id": [1], | ||
| "event_timestamp": pd.to_datetime(["2025-01-02T12:00:00Z"]), | ||
| "ts": pd.to_datetime(["2025-01-10T00:00:00Z"]), | ||
| "ts__": pd.to_datetime(["2024-12-25T00:00:00Z"]), | ||
| } | ||
| ) | ||
| original = requests.copy(deep=True) | ||
|
|
||
| result = store.get_historical_features( | ||
| entity_df=requests, features=["trips_view:trips", "rating_view:rating"] | ||
| ).to_df() | ||
|
|
||
| assert result["trips"].astype("float64").tolist() == [20] | ||
| assert result["rating"].astype("float64").tolist() == [20] | ||
| assert set(result.columns) == set(requests.columns) | {"trips", "rating"} | ||
| assert_frame_equal(result[requests.columns], original) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new universal case fails in Ray CI in both feature-name modes: expected
[20, 20, 40], actual[30.0, nan, 40.0]. Ray uses the request'sfeature_timestampas the cutoff when that column exists, so the first result comes from afterevent_timestamp. this exposes an existing Ray bug, but leaves the new suite red. we need to fix that path or narrowly mark this known Ray failure with a tracked issue while preserving the file-store assertions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I checked it, and the Ray failure isn't caused by this PR. Running the new test on master without the Dask change, Ray gives the same
[30.0, nan, 40.0](Ray 2.58.0), and 0.68.0 does the same. I've opened #7190 for it.In 796e6b1 I marked only the Ray case as a known failure (
xfail(strict=True), linking #7190), so the file-store and DuckDB assertions are unchanged, and the test will turn red again once Ray is fixed, as a reminder to remove the mark. The Ray offline suite now gives 52 passed, 2 xfailed, 4 skipped (CI had 52 passed, 2 failed).I'm happy to fix the Ray path in a follow-up PR.