Skip to content
Merged
Show file tree
Hide file tree
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 __hash__ method for FeatureService
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
  • Loading branch information
felixwang9817 committed Apr 19, 2022
commit d52a0052958795c8ccc6a75fc95d66d2b9ba3398
2 changes: 1 addition & 1 deletion sdk/python/feast/feature_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __str__(self):
return str(MessageToJson(self.to_proto()))

def __hash__(self):
return hash((id(self), self.name))
return hash((self.name))
Comment thread
felixwang9817 marked this conversation as resolved.
Outdated

def __eq__(self, other):
if not isinstance(other, FeatureService):
Expand Down
45 changes: 44 additions & 1 deletion sdk/python/tests/unit/test_feature_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from feast import FeatureService
from feast.feature_service import FeatureService
from feast.feature_view import FeatureView
from feast.field import Field
from feast.infra.offline_stores.file_source import FileSource
from feast.types import Float32


def test_feature_service_with_description():
Expand All @@ -12,3 +16,42 @@ def test_feature_service_without_description():
feature_service = FeatureService(name="my-feature-service", features=[])
#
assert feature_service.to_proto().spec.description == ""


def test_hash():
file_source = FileSource(name="my-file-source", path="test.parquet")
feature_view = FeatureView(
name="my-feature-view",
entities=[],
schema=[
Field(name="feature1", dtype=Float32),
Field(name="feature2", dtype=Float32),
],
source=file_source,
)
feature_service_1 = FeatureService(
name="my-feature-service", features=[feature_view[["feature1", "feature2"]]]
)
feature_service_2 = FeatureService(
name="my-feature-service", features=[feature_view[["feature1", "feature2"]]]
)
feature_service_3 = FeatureService(
name="my-feature-service", features=[feature_view[["feature1"]]]
)
feature_service_4 = FeatureService(
name="my-feature-service",
features=[feature_view[["feature1"]]],
description="test",
)

s1 = {feature_service_1, feature_service_2}
assert len(s1) == 1

s2 = {feature_service_1, feature_service_3}
assert len(s2) == 2

s3 = {feature_service_3, feature_service_4}
assert len(s3) == 2

s4 = {feature_service_1, feature_service_2, feature_service_3, feature_service_4}
assert len(s4) == 3