forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tokoko/odfv-pluggable
Odfv pluggable
- Loading branch information
Showing
7 changed files
with
145 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from types import FunctionType | ||
|
||
import dill | ||
import pandas as pd | ||
|
||
from feast.protos.feast.core.OnDemandFeatureView_pb2 import ( | ||
UserDefinedFunction as UserDefinedFunctionProto, | ||
) | ||
|
||
|
||
class OnDemandPandasTransformation: | ||
def __init__(self, udf: FunctionType, udf_string: str = ""): | ||
""" | ||
Creates an OnDemandPandasTransformation object. | ||
Args: | ||
udf: The user defined transformation function, which must take pandas | ||
dataframes as inputs. | ||
udf_string: The source code version of the udf (for diffing and displaying in Web UI) | ||
""" | ||
self.udf = udf | ||
self.udf_string = udf_string | ||
|
||
def transform(self, df: pd.DataFrame) -> pd.DataFrame: | ||
return self.udf.__call__(df) | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, OnDemandPandasTransformation): | ||
raise TypeError( | ||
"Comparisons should only involve OnDemandPandasTransformation class objects." | ||
) | ||
|
||
if not super().__eq__(other): | ||
return False | ||
|
||
if ( | ||
self.udf_string != other.udf_string | ||
or self.udf.__code__.co_code != other.udf.__code__.co_code | ||
): | ||
return False | ||
|
||
return True | ||
|
||
def to_proto(self) -> UserDefinedFunctionProto: | ||
return UserDefinedFunctionProto( | ||
name=self.udf.__name__, | ||
body=dill.dumps(self.udf, recurse=True), | ||
body_text=self.udf_string, | ||
) | ||
|
||
@classmethod | ||
def from_proto(cls, user_defined_function_proto: UserDefinedFunctionProto): | ||
return OnDemandPandasTransformation( | ||
udf=dill.loads(user_defined_function_proto.body), | ||
udf_string=user_defined_function_proto.body_text, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.