Skip to content

Commit e82371d

Browse files
YassinNouh21ntkathole
authored andcommitted
fix: preserve timestamp range for min_event_timestamp and fix formatting
The entity_df fix alone would cause min_event_timestamp to be computed as end_date - TTL (instead of start_date - TTL), clipping valid data from the query window. Override entity_df_event_timestamp_range to (start_date, end_date) in non-entity mode so the full range is used. Also fix ruff formatting in the test file. Signed-off-by: yassinnouh21 <yassinnouh21@gmail.com>
1 parent 558e864 commit e82371d

File tree

2 files changed

+32
-20
lines changed
  • sdk/python
    • feast/infra/offline_stores/contrib/postgres_offline_store
    • tests/unit/infra/offline_stores/contrib/postgres_offline_store

2 files changed

+32
-20
lines changed

sdk/python/feast/infra/offline_stores/contrib/postgres_offline_store/postgres.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,18 @@ def get_historical_features(
167167
offline_utils.infer_event_timestamp_from_entity_df(entity_schema)
168168
)
169169

170-
entity_df_event_timestamp_range = _get_entity_df_event_timestamp_range(
171-
entity_df,
172-
entity_df_event_timestamp_col,
173-
config,
174-
)
170+
# In non-entity mode, use the actual requested range so that
171+
# min_event_timestamp (= range[0] - TTL) doesn't clip the window.
172+
# The synthetic entity_df only has end_date, which would wrongly
173+
# set min_event_timestamp to end_date - TTL instead of start_date - TTL.
174+
if start_date is not None and end_date is not None:
175+
entity_df_event_timestamp_range = (start_date, end_date)
176+
else:
177+
entity_df_event_timestamp_range = _get_entity_df_event_timestamp_range(
178+
entity_df,
179+
entity_df_event_timestamp_col,
180+
config,
181+
)
175182

176183
@contextlib.contextmanager
177184
def query_generator() -> Iterator[str]:

sdk/python/tests/unit/infra/offline_stores/contrib/postgres_offline_store/test_postgres.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -638,22 +638,27 @@ def test_non_entity_entity_df_uses_end_date(self):
638638
return_value={"event_timestamp": "timestamp"}
639639
)
640640

641-
with patch.multiple(
642-
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres",
643-
_get_conn=MagicMock(),
644-
_upload_entity_df=MagicMock(),
645-
_get_entity_schema=mock_get_entity_schema,
646-
_get_entity_df_event_timestamp_range=MagicMock(
647-
return_value=(start_date, end_date)
641+
with (
642+
patch.multiple(
643+
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres",
644+
_get_conn=MagicMock(),
645+
_upload_entity_df=MagicMock(),
646+
_get_entity_schema=mock_get_entity_schema,
647+
_get_entity_df_event_timestamp_range=MagicMock(
648+
return_value=(start_date, end_date)
649+
),
650+
),
651+
patch(
652+
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres.offline_utils.get_expected_join_keys",
653+
return_value=[],
654+
),
655+
patch(
656+
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres.offline_utils.assert_expected_columns_in_entity_df",
657+
),
658+
patch(
659+
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres.offline_utils.get_feature_view_query_context",
660+
return_value=[],
648661
),
649-
), patch(
650-
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres.offline_utils.get_expected_join_keys",
651-
return_value=[],
652-
), patch(
653-
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres.offline_utils.assert_expected_columns_in_entity_df",
654-
), patch(
655-
"feast.infra.offline_stores.contrib.postgres_offline_store.postgres.offline_utils.get_feature_view_query_context",
656-
return_value=[],
657662
):
658663
PostgreSQLOfflineStore.get_historical_features(
659664
config=test_repo_config,

0 commit comments

Comments
 (0)