Skip to content

Commit d510325

Browse files
committed
Fixed linting and unit tests
Signed-off-by: jyejare <jyejare@redhat.com>
1 parent 19c7540 commit d510325

6 files changed

Lines changed: 155 additions & 96 deletions

File tree

sdk/python/feast/feature_store.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,8 @@ def teardown(self):
10841084

10851085
def get_historical_features(
10861086
self,
1087-
features: Union[List[str], FeatureService],
10881087
entity_df: Optional[Union[pd.DataFrame, str]] = None,
1088+
features: Union[List[str], FeatureService] = [],
10891089
full_feature_names: bool = False,
10901090
start_date: Optional[datetime] = None,
10911091
end_date: Optional[datetime] = None,
@@ -1154,7 +1154,9 @@ def get_historical_features(
11541154
"""
11551155

11561156
if entity_df is not None and (start_date is not None or end_date is not None):
1157-
raise ValueError("Cannot specify both entity_df and start_date/end_date. Use either entity_df for entity-based retrieval or start_date/end_date for timestamp range retrieval.")
1157+
raise ValueError(
1158+
"Cannot specify both entity_df and start_date/end_date. Use either entity_df for entity-based retrieval or start_date/end_date for timestamp range retrieval."
1159+
)
11581160

11591161
if entity_df is None and end_date is None:
11601162
end_date = datetime.now()
@@ -1192,6 +1194,13 @@ def get_historical_features(
11921194
utils._validate_feature_refs(_feature_refs, full_feature_names)
11931195
provider = self._get_provider()
11941196

1197+
# Optional kwargs
1198+
kwargs = {}
1199+
if start_date is not None:
1200+
kwargs["start_date"] = start_date
1201+
if end_date is not None:
1202+
kwargs["end_date"] = end_date
1203+
11951204
job = provider.get_historical_features(
11961205
self.config,
11971206
feature_views,
@@ -1200,8 +1209,7 @@ def get_historical_features(
12001209
self._registry,
12011210
self.project,
12021211
full_feature_names,
1203-
start_date,
1204-
end_date,
1212+
**kwargs,
12051213
)
12061214

12071215
return job

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ def get_historical_features(
124124
registry: BaseRegistry,
125125
project: str,
126126
full_feature_names: bool = False,
127-
start_date: Optional[datetime] = None,
128-
end_date: Optional[datetime] = None,
127+
**kwargs,
129128
) -> RetrievalJob:
130129
assert isinstance(config.offline_store, PostgreSQLOfflineStoreConfig)
131130
for fv in feature_views:
132131
assert isinstance(fv.batch_source, PostgreSQLSource)
132+
start_date: Optional[datetime] = kwargs.get("start_date", None)
133+
end_date: Optional[datetime] = kwargs.get("end_date", None)
133134

134135
# Handle non-entity retrieval mode
135136
if entity_df is None:
@@ -140,6 +141,7 @@ def get_historical_features(
140141
end_date = make_tzaware(end_date)
141142

142143
# Calculate start_date from TTL if not provided
144+
143145
if start_date is None:
144146
# Find the maximum TTL across all feature views to ensure we capture enough data
145147
max_ttl_seconds = 0
@@ -157,9 +159,13 @@ def get_historical_features(
157159
else:
158160
start_date = make_tzaware(start_date)
159161

160-
entity_df = pd.DataFrame({
161-
'event_timestamp': pd.date_range(start=start_date, end=end_date, freq='1s', tz=timezone.utc)[:1] # Just one row
162-
})
162+
entity_df = pd.DataFrame(
163+
{
164+
"event_timestamp": pd.date_range(
165+
start=start_date, end=end_date, freq="1s", tz=timezone.utc
166+
)[:1] # Just one row
167+
}
168+
)
163169

164170
entity_schema = _get_entity_schema(entity_df, config)
165171

@@ -564,7 +570,7 @@ def _get_entity_schema(
564570
{% endfor %}
565571
)
566572
567-
SELECT
573+
SELECT
568574
base.event_timestamp,
569575
{% set all_entities = [] %}
570576
{% for featureview in featureviews %}

sdk/python/feast/infra/offline_stores/offline_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ def get_historical_features(
301301
registry: BaseRegistry,
302302
project: str,
303303
full_feature_names: bool = False,
304-
start_date: Optional[datetime] = None,
305-
end_date: Optional[datetime] = datetime.now(),
306304
) -> RetrievalJob:
307305
"""
308306
Retrieves the point-in-time correct historical feature values for the specified entity rows.
@@ -319,6 +317,8 @@ def get_historical_features(
319317
full_feature_names: If True, feature names will be prefixed with the corresponding feature view name,
320318
changing them from the format "feature" to "feature_view__feature" (e.g. "daily_transactions"
321319
changes to "customer_fv__daily_transactions").
320+
321+
Keyword Args:
322322
start_date: Start date for the timestamp range when retrieving features without entity_df.
323323
end_date: End date for the timestamp range when retrieving features without entity_df. By default, the current time is used.
324324

sdk/python/feast/infra/passthrough_provider.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ def get_historical_features(
462462
registry: BaseRegistry,
463463
project: str,
464464
full_feature_names: bool,
465-
start_date: Optional[datetime] = None,
466-
end_date: Optional[datetime] = None,
465+
**kwargs,
467466
) -> RetrievalJob:
468467
job = self.offline_store.get_historical_features(
469468
config=config,
@@ -473,8 +472,7 @@ def get_historical_features(
473472
registry=registry,
474473
project=project,
475474
full_feature_names=full_feature_names,
476-
start_date=start_date,
477-
end_date=end_date,
475+
**kwargs,
478476
)
479477

480478
return job

sdk/python/feast/infra/provider.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ def get_historical_features(
248248
registry: BaseRegistry,
249249
project: str,
250250
full_feature_names: bool,
251-
start_date: Optional[datetime] = None,
252-
end_date: Optional[datetime] = None,
251+
**kwargs,
253252
) -> RetrievalJob:
254253
"""
255254
Retrieves the point-in-time correct historical feature values for the specified entity rows.

0 commit comments

Comments
 (0)