Skip to content

Commit 79aa736

Browse files
committed
Simplified error messages
Signed-off-by: Mwad22 <51929507+Mwad22@users.noreply.github.com>
1 parent 3aca976 commit 79aa736

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

‎sdk/python/feast/errors.py‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,23 @@ def __init__(self, offline_store_name: str, data_source_name: str):
8989

9090

9191
class FeatureNameCollisionError(Exception):
92-
def __init__(self, feature_refs_collisions: List[str]):
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))
92+
def __init__(self, feature_refs_collisions: List[str], full_feature_names):
93+
if full_feature_names:
94+
collisions = [ref.replace(":", "__") for ref in feature_refs_collisions]
95+
error_message = (
96+
"To resolve this collision, please ensure that the features in question "
97+
"have different names."
98+
)
99+
else:
100+
collisions = [ref.split(":")[1] for ref in feature_refs_collisions]
101+
error_message = (
102+
"To resolve this collision, either use the full feature name by setting "
103+
"'full_feature_names=True', or ensure that the features in question have different names."
104+
)
105+
106+
feature_names = ", ".join(set(collisions))
98107
super().__init__(
99-
f"The following feature name(s) have collisions: {feature_names}. Set 'full_feature_names' "
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}."
108+
f"Duplicate features named {feature_names} found.\n{error_message}"
103109
)
104110

105111

‎sdk/python/feast/feature_store.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -614,20 +614,27 @@ def _entity_row_to_field_values(
614614

615615

616616
def _validate_feature_refs(feature_refs: List[str], full_feature_names: bool = False):
617+
collided_feature_refs = []
618+
617619
if full_feature_names:
618620
collided_feature_refs = [
619621
ref for ref, occurrences in Counter(feature_refs).items() if occurrences > 1
620622
]
621-
if len(collided_feature_refs) > 0:
622-
raise FeatureNameCollisionError(collided_feature_refs)
623623
else:
624624
feature_names = [ref.split(":")[1] for ref in feature_refs]
625-
feature_name, occurrences = Counter(feature_names).most_common(1)[0]
626-
if occurrences > 1:
627-
collided_feature_refs = [
628-
ref for ref in feature_refs if ref.endswith(":" + feature_name)
629-
]
630-
raise FeatureNameCollisionError(collided_feature_refs)
625+
collided_feature_names = [
626+
ref
627+
for ref, occurrences in Counter(feature_names).items()
628+
if occurrences > 1
629+
]
630+
631+
for feature_name in collided_feature_names:
632+
collided_feature_refs.extend(
633+
[ref for ref in feature_refs if ref.endswith(":" + feature_name)]
634+
)
635+
636+
if len(collided_feature_refs) > 0:
637+
raise FeatureNameCollisionError(collided_feature_refs, full_feature_names)
631638

632639

633640
def _group_feature_refs(

0 commit comments

Comments
 (0)