Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 7 additions & 6 deletions sdk/python/feast/stream_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,18 @@ def __eq__(self, other):
if not super().__eq__(other):
return False

if not self.udf:
return not other.udf
if not other.udf:
if bool(self.udf) != bool(other.udf):
return False
if self.udf and self.udf.__code__.co_code != other.udf.__code__.co_code:
return False

if (
self.mode != other.mode
mode_to_string(self.mode) != mode_to_string(other.mode)
or self.timestamp_field != other.timestamp_field
or self.udf.__code__.co_code != other.udf.__code__.co_code
or self.udf_string != other.udf_string
or (self.udf_string or "") != (other.udf_string or "")
or self.aggregations != other.aggregations
or self.enable_tiling != other.enable_tiling
or self.tiling_hop_size != other.tiling_hop_size
):
return False

Expand Down
90 changes: 90 additions & 0 deletions sdk/python/tests/unit/test_stream_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,93 @@ def test_stream_feature_view_org_field():

sfv_other_org = StreamFeatureView(name="sfv-with-org", org="search", **common)
assert sfv_with_org != sfv_other_org


@pytest.mark.parametrize(
"changes",
[
{
"aggregations": [
Aggregation(
column="dummy_field",
function="max",
time_window=timedelta(days=7),
)
]
},
{"mode": "pandas"},
{"timestamp_field": "other_timestamp"},
{"enable_tiling": True},
{"enable_tiling": True, "tiling_hop_size": timedelta(minutes=10)},
],
)
def test_stream_feature_view_equality_without_udf(changes):
entity = Entity(name="driver_entity", join_keys=["test_key"])
stream_source = KafkaSource(
name="kafka",
timestamp_field="event_timestamp",
kafka_bootstrap_servers="",
message_format=AvroFormat(""),
topic="topic",
batch_source=FileSource(path="some path"),
)

def make_sfv(**kwargs):
args = dict(
name="test kafka stream feature view",
entities=[entity],
ttl=timedelta(days=30),
schema=[Field(name="dummy_field", dtype=Float32)],
source=stream_source,
timestamp_field="event_timestamp",
aggregations=[
Aggregation(
column="dummy_field",
function="sum",
time_window=timedelta(hours=1),
)
],
)
args.update(kwargs)
return StreamFeatureView(**args)

sfv = make_sfv()
assert sfv.udf is None
assert sfv == make_sfv()
assert sfv != make_sfv(**changes)
assert make_sfv(**changes) != sfv


def test_stream_feature_view_equality_with_udf():
entity = Entity(name="driver_entity", join_keys=["test_key"])
stream_source = KafkaSource(
name="kafka",
timestamp_field="event_timestamp",
kafka_bootstrap_servers="",
message_format=AvroFormat(""),
topic="topic",
batch_source=FileSource(path="some path"),
)

def udf_a(df):
return df

def udf_b(df):
return df.head(1)

def make_sfv(udf):
return StreamFeatureView(
name="test kafka stream feature view",
entities=[entity],
ttl=timedelta(days=30),
schema=[Field(name="dummy_field", dtype=Float32)],
source=stream_source,
timestamp_field="event_timestamp",
mode="pandas",
udf=udf,
)

assert make_sfv(udf_a) == make_sfv(udf_a)
assert make_sfv(udf_a) != make_sfv(None)
assert make_sfv(None) != make_sfv(udf_a)
assert make_sfv(udf_a) != make_sfv(udf_b)
Loading