Skip to content

Commit 082fca7

Browse files
committed
made error logic/messages more descriptive
Signed-off-by: Mwad22 <51929507+Mwad22@users.noreply.github.com>
1 parent f400d65 commit 082fca7

5 files changed

Lines changed: 43 additions & 18 deletions

File tree

‎sdk/python/feast/errors.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ def __init__(self, offline_store_name: str, data_source_name: str):
9090

9191
class FeatureNameCollisionError(Exception):
9292
def __init__(self, feature_refs_collisions: List[str]):
93-
feature_name_collisions = [ref.split(":")[1] for ref in feature_refs_collisions]
94-
feature_names = ", ".join(x for x in feature_name_collisions)
93+
collisions = [ref.split(":", 1) for ref in feature_refs_collisions]
94+
collision_feature_views = [y for (y, _) in collisions]
95+
collision_feature_names = [x for (_, x) in collisions]
96+
feature_names = ", ".join(set(collision_feature_names))
97+
feature_views = ", ".join(set(collision_feature_views))
9598
super().__init__(
9699
f"The following feature name(s) have collisions: {feature_names}. Set 'full_feature_names' "
97-
f"argument in the data retrieval function to True to use the full feature name which is prefixed by the feature view name."
100+
f"argument in the data retrieval function to True to use the full feature name which is prefixed "
101+
f"by the feature view name, or rename colliding features.\nCollisions occur in the following "
102+
f"feature view(s): {feature_views}."
98103
)
99104

100105

‎sdk/python/feast/feature_store.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ def get_online_features(
553553
project=self.project, allow_cache=True
554554
)
555555

556+
_validate_feature_refs(feature_refs, full_feature_names)
556557
grouped_refs = _group_feature_refs(feature_refs, all_feature_views)
557558
for table, requested_features in grouped_refs:
558559
entity_keys = _get_table_entity_keys(
@@ -613,13 +614,19 @@ def _entity_row_to_field_values(
613614

614615

615616
def _validate_feature_refs(feature_refs: List[str], full_feature_names: bool = False):
616-
feature_names = [ref.split(":")[1] for ref in feature_refs]
617-
feature_name, occurrences = Counter(feature_names).most_common(1)[0]
618-
if count > 1:
617+
if full_feature_names:
619618
collided_feature_refs = [
620-
ref for ref in feature_refs if ref.endswith(":" + feature_name)
621-
]
622-
raise FeatureNameCollisionError(collided_feature_refs)
619+
ref for ref, occurrences in Counter(feature_refs).items() if occurrences > 1]
620+
if len(collided_feature_refs) > 0:
621+
raise FeatureNameCollisionError(collided_feature_refs)
622+
else:
623+
feature_names = [ref.split(":")[1] for ref in feature_refs]
624+
feature_name, occurrences = Counter(feature_names).most_common(1)[0]
625+
if occurrences > 1:
626+
collided_feature_refs = [
627+
ref for ref in feature_refs if ref.endswith(":" + feature_name)
628+
]
629+
raise FeatureNameCollisionError(collided_feature_refs)
623630

624631

625632
def _group_feature_refs(

‎sdk/python/feast/infra/aws.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def get_historical_features(
129129
entity_df: Union[pandas.DataFrame, str],
130130
registry: Registry,
131131
project: str,
132+
full_feature_names: bool = False,
132133
) -> RetrievalJob:
133134
job = self.offline_store.get_historical_features(
134135
config=config,
@@ -137,5 +138,6 @@ def get_historical_features(
137138
entity_df=entity_df,
138139
registry=registry,
139140
project=project,
141+
full_feature_names=full_feature_names,
140142
)
141143
return job

‎sdk/python/tests/test_historical_retrieval.py‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,22 @@ def get_expected_training_df(
204204
expected_df = expected_df[[event_timestamp] + current_cols]
205205

206206
# Cast some columns to expected types, since we lose information when converting pandas DFs into Python objects.
207-
expected_column_types = {
208-
"order_is_success": "int32",
209-
"driver_stats__conv_rate": "float32",
210-
"customer_profile__current_balance": "float32",
211-
"customer_profile__avg_passenger_count": "float32",
212-
}
207+
208+
if full_feature_names:
209+
expected_column_types = {
210+
"order_is_success": "int32",
211+
"driver_stats__conv_rate": "float32",
212+
"customer_profile__current_balance": "float32",
213+
"customer_profile__avg_passenger_count": "float32",
214+
}
215+
else:
216+
expected_column_types = {
217+
"order_is_success": "int32",
218+
"conv_rate": "float32",
219+
"current_balance": "float32",
220+
"avg_passenger_count": "float32",
221+
}
222+
213223
for col, typ in expected_column_types.items():
214224
expected_df[col] = expected_df[col].astype(typ)
215225

‎sdk/python/tests/test_offline_online_store_consistency.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def check_offline_and_online_features(
267267
assert abs(df.to_dict()["value"][0] - expected_value) < 1e-6
268268
else:
269269
assert math.isnan(df.to_dict()["value"][0])
270-
271270

272271

273272
def run_offline_online_store_consistency_test(
@@ -341,13 +340,15 @@ def test_redis_offline_online_store_consistency(full_feature_names: bool):
341340
with prep_redis_fs_and_fv() as (fs, fv):
342341
run_offline_online_store_consistency_test(fs, fv, full_feature_names)
343342

343+
344344
@pytest.mark.parametrize("full_feature_names", [True, False])
345345
@pytest.mark.integration
346-
def test_dynamodb_offline_online_store_consistency(full_feature_names:bool):
346+
def test_dynamodb_offline_online_store_consistency(full_feature_names: bool):
347347
with prep_dynamodb_fs_and_fv() as (fs, fv):
348348
run_offline_online_store_consistency_test(fs, fv, full_feature_names)
349349

350+
350351
@pytest.mark.parametrize("full_feature_names", [True, False])
351-
def test_local_offline_online_store_consistency(full_feature_names:bool):
352+
def test_local_offline_online_store_consistency(full_feature_names: bool):
352353
with prep_local_fs_and_fv() as (fs, fv):
353354
run_offline_online_store_consistency_test(fs, fv, full_feature_names)

0 commit comments

Comments
 (0)