Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix comments
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 committed Aug 17, 2022
commit 45ec63cbe5dc4b0c3985bab4efe2c6d5f5e06797
16 changes: 13 additions & 3 deletions sdk/python/feast/feature_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ def infer_features(self, fvs_to_update: Optional[Dict[str, FeatureView]] = None)
projection = feature_grouping.projection

if fvs_to_update and feature_grouping.name in fvs_to_update:
# There are three situations to be handled. First, the projection specifies

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be easier to read if you have the cases within the blocks themselves, instead of all in one block before the if starts

# desired features, in which case we should select those desired features.
# Second, the projection does not specify any desired features but has
# already selected features, in which case nothing needs to be done. And
# third, the projection does not specify any desired features but has not
# yet selected features (since the original feature view did not yet have
# features), in which case we should select all possible inferred features.
if projection.desired_features:
# Select the specific desired features.
# First case, so we select the specific desired features.
desired_features = set(projection.desired_features)
actual_features = set(
[
Expand All @@ -115,8 +122,11 @@ def infer_features(self, fvs_to_update: Optional[Dict[str, FeatureView]] = None)
for f in fvs_to_update[feature_grouping.name].features:
if f.name in desired_features:
projection.features.append(f)
elif not projection.features:
# No features have been specifically selected, so all features will be added to the projection.
elif not projection.desired_features and projection.features:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be cleaner imo if you had early returns instead of the elif and else.. and maybe some example definitions

e.g.

if projection.desired_features:
  # The projection wants to reference inferred features. Validate they exist
   # Example: FeatureService(features=[[fv_with_no_schema["feature]])
   ...
   return

if projection.features:
  # The projection only references features from a FV's known schema (not inferred). 
  # Example 1: FeatureService(features=[fv_with_schema[["feature"]])
  # Example 2: FeatureService(features=[fv_with_schema])
  return

# The projection wants all features from a FV that has an inferred schema
# Example: FeatureService(features=[fv_with_no_schema])
...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if we can exit earlier than this. i.e in line 98 instead

# Second cass, so nothing needs to be done.
pass
else:
# Third case, so all inferred features will be selected.
projection.features = fvs_to_update[
feature_grouping.name
].features
Expand Down