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 test and serialization
Signed-off-by: Francisco Javier Arceo <franciscojavierarceo@users.noreply.github.com>
  • Loading branch information
franciscojavierarceo committed Apr 4, 2024
commit 270f6c0d30ac77c5f52deda9b3b62b682c730cef
13 changes: 13 additions & 0 deletions sdk/python/feast/on_demand_feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,23 @@ def from_proto(
== "user_defined_function"
and on_demand_feature_view_proto.spec.feature_transformation.user_defined_function.body_text
!= ""
and on_demand_feature_view_proto.spec.mode == "pandas"
):
transformation = PandasTransformation.from_proto(
on_demand_feature_view_proto.spec.feature_transformation.user_defined_function
)
elif (
on_demand_feature_view_proto.spec.feature_transformation.WhichOneof(
"transformation"
)
== "user_defined_function"
and on_demand_feature_view_proto.spec.feature_transformation.user_defined_function.body_text
!= ""
and on_demand_feature_view_proto.spec.mode == "python"
):
transformation = PythonTransformation.from_proto(
on_demand_feature_view_proto.spec.feature_transformation.user_defined_function
)
elif (
on_demand_feature_view_proto.spec.feature_transformation.WhichOneof(
"transformation"
Expand Down
31 changes: 20 additions & 11 deletions sdk/python/tests/unit/test_on_demand_python_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class TestOnDemandPythonTransformation(unittest.TestCase):
def setUp(self):
# data_dir = tempfile.TemporaryDirectory()
with tempfile.TemporaryDirectory() as data_dir:
self.store = FeatureStore(
config=RepoConfig(
Expand Down Expand Up @@ -83,10 +82,10 @@ def pandas_view(inputs: pd.DataFrame) -> pd.DataFrame:
mode="python",
)
def python_view(inputs: Dict[str, Any]) -> Dict[str, Any]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a little confused about the required signature here. Are these functions supposed to accept a dict of lists (looks like that in this test) and apply the udf for all entities at once? I thought from the previous PR that the goal was to have a udf that would be applied to individual entities...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also alter the tests so that more than one entity is passed? this will probably fail in such a case as only first entity is processed. If we are sticking with this signature, udf should look something like this:

return {
                'conv_rate_plus_acc_python': [
                    conv_rate + acc_rate
                    for conv_rate, acc_rate in zip(inputs['conv_rate'], inputs['acc_rate'])
                ]
            }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at _infer_features_dict you'll see it expects a dict of lists. I added an explicit test that shows this will result in a type failure when running the apply operations. We can add singleton execution as a follow up but this is sufficient to highlight the currently supported behavior and then we can cut a release.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franciscojavierarceo got it, good... that's probably more efficient anyway. no rush, but in that case it will probably be a good idea to change type annotations for relevant functions to Dict[str, List[Any]].

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually originally had that setup but I received a ton of type failures from that which is why I did it this way.

Let me address both of those as folllowups. I want to merge this and cut a release.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an issue here #4075, will close it later.

output: Dict[str, Any] = {
"conv_rate_plus_acc_python": inputs["conv_rate"]
+ inputs["acc_rate"]
}
output: Dict[str, Any] = {"conv_rate_plus_acc_python": []}
output["conv_rate_plus_acc_python"].append(
inputs["conv_rate"][0] + inputs["acc_rate"][0]
)
return output

self.store.apply(
Expand All @@ -110,7 +109,7 @@ def test_python_pandas_parity(self):
"driver_hourly_stats:acc_rate",
"python_view:conv_rate_plus_acc_python",
],
).to_df()
).to_dict()

online_pandas_response = self.store.get_online_features(
entity_rows=entity_rows,
Expand All @@ -121,10 +120,20 @@ def test_python_pandas_parity(self):
],
).to_df()

assert len(online_python_response) == 4
assert all(
key in online_python_response.keys()
for key in [
"driver_id",
"acc_rate",
"conv_rate",
"conv_rate_plus_acc_python",
]
)
assert len(online_python_response["conv_rate_plus_acc_python"]) == 1
assert (
online_python_response["conv_rate_plus_acc_python"]
.equals(online_pandas_response["conv_rate_plus_acc_pandas"])
.equals(
online_python_response["conv_rate"] + online_python_response["acc_rate"]
)
online_python_response["conv_rate_plus_acc_python"][0]
== online_pandas_response["conv_rate_plus_acc_pandas"][0]
== online_python_response["conv_rate"][0]
+ online_python_response["acc_rate"][0]
)