Skip to content

Commit d71e4c5

Browse files
mavysavydavMwad22
authored andcommitted
Grouped inferencing statements together in apply methods for easier readability (feast-dev#1667)
* grouped inferencing statements together Signed-off-by: David Y Liu <davidyliuliu@gmail.com> * update in testing Signed-off-by: David Y Liu <davidyliuliu@gmail.com> Signed-off-by: Mwad22 <51929507+Mwad22@users.noreply.github.com>
1 parent 0ce8210 commit d71e4c5

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

sdk/python/feast/feature_store.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
)
3232
from feast.feature_view import FeatureView
3333
from feast.inference import (
34-
infer_entity_value_type_from_feature_views,
3534
update_data_sources_with_inferred_event_timestamp_col,
35+
update_entities_with_inferred_types_from_feature_views,
3636
)
3737
from feast.infra.provider import Provider, RetrievalJob, get_provider
3838
from feast.online_response import OnlineResponse, _infer_online_entity_rows
@@ -228,8 +228,11 @@ def apply(
228228
assert isinstance(objects, list)
229229

230230
views_to_update = [ob for ob in objects if isinstance(ob, FeatureView)]
231-
entities_to_update = infer_entity_value_type_from_feature_views(
232-
[ob for ob in objects if isinstance(ob, Entity)], views_to_update
231+
entities_to_update = [ob for ob in objects if isinstance(ob, Entity)]
232+
233+
# Make inferences
234+
update_entities_with_inferred_types_from_feature_views(
235+
entities_to_update, views_to_update
233236
)
234237
update_data_sources_with_inferred_event_timestamp_col(
235238
[view.input for view in views_to_update]

sdk/python/feast/inference.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from feast.value_type import ValueType
99

1010

11-
def infer_entity_value_type_from_feature_views(
11+
def update_entities_with_inferred_types_from_feature_views(
1212
entities: List[Entity], feature_views: List[FeatureView]
13-
) -> List[Entity]:
13+
) -> None:
1414
"""
1515
Infer entity value type by examining schema of feature view input sources
1616
"""
@@ -57,8 +57,6 @@ def infer_entity_value_type_from_feature_views(
5757

5858
entity.value_type = inferred_value_type
5959

60-
return entities
61-
6260

6361
def update_data_sources_with_inferred_event_timestamp_col(
6462
data_sources: List[Union[BigQuerySource, FileSource]],

sdk/python/feast/repo_operations.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from feast import Entity, FeatureTable
1515
from feast.feature_view import FeatureView
1616
from feast.inference import (
17-
infer_entity_value_type_from_feature_views,
1817
update_data_sources_with_inferred_event_timestamp_col,
18+
update_entities_with_inferred_types_from_feature_views,
1919
)
2020
from feast.infra.provider import get_provider
2121
from feast.names import adjectives, animals
@@ -131,13 +131,19 @@ def apply_total(repo_config: RepoConfig, repo_path: Path):
131131
registry._initialize_registry()
132132
sys.dont_write_bytecode = True
133133
repo = parse_repo(repo_path)
134-
repo = ParsedRepo(
135-
feature_tables=repo.feature_tables,
136-
entities=infer_entity_value_type_from_feature_views(
137-
repo.entities, repo.feature_views
138-
),
139-
feature_views=repo.feature_views,
134+
data_sources = [t.input for t in repo.feature_views]
135+
136+
# Make sure the data source used by this feature view is supported by Feast
137+
for data_source in data_sources:
138+
data_source.validate()
139+
140+
# Make inferences
141+
update_entities_with_inferred_types_from_feature_views(
142+
repo.entities, repo.feature_views
140143
)
144+
update_data_sources_with_inferred_event_timestamp_col(data_sources)
145+
for view in repo.feature_views:
146+
view.infer_features_from_input_source()
141147

142148
sys.dont_write_bytecode = False
143149
for entity in repo.entities:
@@ -151,16 +157,6 @@ def apply_total(repo_config: RepoConfig, repo_path: Path):
151157
for t in repo.feature_views:
152158
repo_table_names.add(t.name)
153159

154-
data_sources = [t.input for t in repo.feature_views]
155-
156-
# Make sure the data source used by this feature view is supported by Feast
157-
for data_source in data_sources:
158-
data_source.validate()
159-
160-
update_data_sources_with_inferred_event_timestamp_col(data_sources)
161-
for view in repo.feature_views:
162-
view.infer_features_from_input_source()
163-
164160
tables_to_delete = []
165161
for registry_table in registry.list_feature_tables(project=project):
166162
if registry_table.name not in repo_table_names:

sdk/python/tests/test_inference.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
from feast.errors import RegistryInferenceFailure
1010
from feast.feature_view import FeatureView
1111
from feast.inference import (
12-
infer_entity_value_type_from_feature_views,
1312
update_data_sources_with_inferred_event_timestamp_col,
13+
update_entities_with_inferred_types_from_feature_views,
1414
)
1515

1616

17-
def test_infer_entity_value_type_from_feature_views(simple_dataset_1, simple_dataset_2):
17+
def test_update_entities_with_inferred_types_from_feature_views(
18+
simple_dataset_1, simple_dataset_2
19+
):
1820
with prep_file_source(
1921
df=simple_dataset_1, event_timestamp_column="ts_1"
2022
) as file_source, prep_file_source(
@@ -24,22 +26,23 @@ def test_infer_entity_value_type_from_feature_views(simple_dataset_1, simple_dat
2426
fv1 = FeatureView(name="fv1", entities=["id"], input=file_source, ttl=None,)
2527
fv2 = FeatureView(name="fv2", entities=["id"], input=file_source_2, ttl=None,)
2628

27-
actual_1 = infer_entity_value_type_from_feature_views(
28-
[Entity(name="id")], [fv1]
29-
)
30-
actual_2 = infer_entity_value_type_from_feature_views(
31-
[Entity(name="id")], [fv2]
32-
)
33-
assert actual_1 == [Entity(name="id", value_type=ValueType.INT64)]
34-
assert actual_2 == [Entity(name="id", value_type=ValueType.STRING)]
29+
actual_1 = Entity(name="id")
30+
actual_2 = Entity(name="id")
31+
32+
update_entities_with_inferred_types_from_feature_views([actual_1], [fv1])
33+
update_entities_with_inferred_types_from_feature_views([actual_2], [fv2])
34+
assert actual_1 == Entity(name="id", value_type=ValueType.INT64)
35+
assert actual_2 == Entity(name="id", value_type=ValueType.STRING)
3536

3637
with pytest.raises(RegistryInferenceFailure):
3738
# two viable data types
38-
infer_entity_value_type_from_feature_views([Entity(name="id")], [fv1, fv2])
39+
update_entities_with_inferred_types_from_feature_views(
40+
[Entity(name="id")], [fv1, fv2]
41+
)
3942

4043

4144
@pytest.mark.integration
42-
def test_infer_event_timestamp_column_for_data_source(simple_dataset_1):
45+
def test_update_data_sources_with_inferred_event_timestamp_col(simple_dataset_1):
4346
df_with_two_viable_timestamp_cols = simple_dataset_1.copy(deep=True)
4447
df_with_two_viable_timestamp_cols["ts_2"] = simple_dataset_1["ts_1"]
4548

0 commit comments

Comments
 (0)