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
OnDemandFeatureView: keep udf and udf_string parameters for backwards…
… compatibility

Signed-off-by: tokoko <togurg14@freeuni.edu.ge>
  • Loading branch information
tokoko committed Feb 13, 2024
commit f0180e69e9a2bfbfa5152ce9ddbcddd8962a482a
20 changes: 19 additions & 1 deletion sdk/python/feast/on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import functools
import warnings
from datetime import datetime
from types import FunctionType
from typing import Any, Dict, List, Optional, Type, Union

import dill
Expand Down Expand Up @@ -77,7 +78,9 @@ def __init__( # noqa: C901
FeatureViewProjection,
]
],
transformation: Union[OnDemandPandasTransformation],
udf: Optional[FunctionType] = None,
udf_string: str = "",
transformation: Optional[Union[OnDemandPandasTransformation]] = None,
description: str = "",
tags: Optional[Dict[str, str]] = None,
owner: str = "",
Expand All @@ -92,6 +95,9 @@ def __init__( # noqa: C901
sources: A map from input source names to the actual input sources, which may be
feature views, or request data sources. These sources serve as inputs to the udf,
which will refer to them by name.
udf (deprecated): The user defined transformation function, which must take pandas
dataframes as inputs.
udf_string (deprecated): The source code version of the udf (for diffing and displaying in Web UI)
transformation: The user defined transformation.
description (optional): A human-readable description.
tags (optional): A dictionary of key-value pairs to store arbitrary metadata.
Expand All @@ -106,6 +112,18 @@ def __init__( # noqa: C901
owner=owner,
)

if not transformation:
if udf:
warnings.warn(
"udf and udf_string parameters are deprecated. Please use transformation=OnDemandPandasTransformation(udf, udf_string) instead.",
DeprecationWarning,
)
transformation = OnDemandPandasTransformation(udf, udf_string)
else:
raise Exception(
"OnDemandFeatureView needs to be initialized with either transformation or udf arguments"
)

self.source_feature_view_projections: Dict[str, FeatureViewProjection] = {}
self.source_request_sources: Dict[str, RequestSource] = {}
for odfv_source in sources:
Expand Down
11 changes: 7 additions & 4 deletions sdk/python/tests/unit/test_on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ def test_hash():
),
description="test",
)
on_demand_feature_view_4 = OnDemandFeatureView(
on_demand_feature_view_5 = OnDemandFeatureView(
name="my-on-demand-feature-view",
sources=sources,
schema=[
Field(name="output1", dtype=Float32),
Field(name="output2", dtype=Float32),
],
transformation=OnDemandPandasTransformation(
udf=udf2, udf_string="udf2 source code"
),
udf=udf2,
udf_string="udf2 source code",
description="test",
)

Expand All @@ -124,3 +123,7 @@ def test_hash():
on_demand_feature_view_4,
}
assert len(s4) == 3

assert on_demand_feature_view_5.transformation == OnDemandPandasTransformation(
udf2, "udf2 source code"
)