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
fixed the casting issue
Signed-off-by: Francisco Javier Arceo <franciscojavierarceo@users.noreply.github.com>
  • Loading branch information
franciscojavierarceo committed Mar 27, 2024
commit 74b77e6de9ed2adcd983bc2ffcae62ebb994c8e7
30 changes: 8 additions & 22 deletions sdk/python/feast/on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__( # noqa: C901

if mode not in {"python", "pandas", "substrait"}:
raise Exception(
f"Unknown mode {mode}. OnDemandFeatureView only supports python or pandas UDFs and substraits."
f"Unknown mode {mode}. OnDemandFeatureView only supports python or pandas UDFs and substrait."
)
else:
self.mode = mode
Expand All @@ -145,32 +145,12 @@ def __init__( # noqa: C901
feature_transformation = PandasTransformation(udf, udf_string)
elif mode == "python":
feature_transformation = PythonTransformation(udf, udf_string)
elif mode == "substrait":
feature_transformation = SubstraitTransformation(
substrait_plan=udf_string
)
else:
pass
else:
raise Exception(
"OnDemandFeatureView needs to be initialized with either feature_transformation or udf arguments"
)
else:
# Note inspecting the return signature won't work with isinstance so this is the best alternative
if mode == "pandas":
feature_transformation = PandasTransformation(
feature_transformation.udf, feature_transformation.udf_string
)
elif mode == "python":
feature_transformation = PythonTransformation(
feature_transformation.udf, feature_transformation.udf_string
)
elif mode == "substrait":
feature_transformation = SubstraitTransformation(
substrait_plan=feature_transformation.substrait_plan
)
else:
pass

self.source_feature_view_projections: Dict[str, FeatureViewProjection] = {}
self.source_request_sources: Dict[str, RequestSource] = {}
Expand Down Expand Up @@ -705,6 +685,7 @@ def mainify(obj) -> None:
obj.__module__ = "__main__"

def decorator(user_function):

return_annotation = inspect.signature(user_function).return_annotation
if (
return_annotation
Expand Down Expand Up @@ -745,7 +726,12 @@ def decorator(user_function):
else:
udf_string = dill.source.getsource(user_function)
mainify(user_function)
transformation = PandasTransformation(user_function, udf_string)
if mode == "pandas":
transformation = PandasTransformation(user_function, udf_string)
elif mode == "python":
transformation = PythonTransformation(user_function, udf_string)
elif mode == "substrait":
pass

on_demand_feature_view_obj = OnDemandFeatureView(
name=user_function.__name__,
Expand Down
11 changes: 10 additions & 1 deletion sdk/python/tests/unit/test_on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,16 @@ def test_python_native_transformation_mode():
with pytest.raises(TypeError):
assert (
on_demand_feature_view_python_native_err.feature_transformation
== PandasTransformation(python_native_udf, "python native udf source code")
== PythonTransformation(python_native_udf, "python native udf source code")
)

with pytest.raises(TypeError):
# This should fail
on_demand_feature_view_python_native_err.feature_transformation.transform(
{
"feature1": 0,
"feature2": 1,
}
)


Expand Down