MCPcopy Index your code
hub / github.com/feast-dev/feast / Transformation

Class Transformation

sdk/python/feast/transformation/base.py:20–116  ·  view source on GitHub ↗

Base Transformation class. Can be used to define transformations that can be applied to FeatureViews. Also encapsulates the logic to serialize and deserialize the transformation to and from proto. This is important for the future transformation lifecycle management. E.g.: pandas

Source from the content-addressed store, hash-verified

18
19
20class Transformation(ABC):
21 """
22 Base Transformation class. Can be used to define transformations that can be applied to FeatureViews.
23 Also encapsulates the logic to serialize and deserialize the transformation to and from proto. This is
24 important for the future transformation lifecycle management.
25 E.g.:
26 pandas_transformation = Transformation(
27 mode=TransformationMode.PANDAS,
28 udf=lambda df: df.assign(new_column=df['column1'] + df['column2']),
29 )
30 """
31
32 udf: Callable[[Any], Any]
33 udf_string: str
34
35 def __new__(
36 cls,
37 mode: Union[TransformationMode, str],
38 udf: Callable[[Any], Any],
39 udf_string: str,
40 name: Optional[str] = None,
41 tags: Optional[Dict[str, str]] = None,
42 description: str = "",
43 owner: str = "",
44 *args,
45 **kwargs,
46 ) -> "Transformation":
47 """
48 Creates a Transformation object.
49 Args:
50 mode: (required) The mode of the transformation. Choose one from TransformationMode.
51 udf: (required) The user-defined transformation function.
52 udf_string: (required) The string representation of the udf. The dill get source doesn't
53 work for all cases when extracting the source code from the udf. So it's better to pass
54 the source code as a string.
55 name: (optional) The name of the transformation.
56 tags: (optional) Metadata tags for the transformation.
57 description: (optional) A description of the transformation.
58 owner: (optional) The owner of the transformation.
59 """
60 if cls is Transformation:
61 if isinstance(mode, TransformationMode):
62 mode = mode.value
63
64 if mode.lower() in TRANSFORMATION_CLASS_FOR_TYPE:
65 subclass = get_transformation_class_from_type(mode.lower())
66 return super().__new__(subclass)
67
68 raise ValueError(
69 f"Invalid mode: {mode}. Choose one from TransformationMode."
70 )
71
72 return super().__new__(cls)
73
74 def __init__(
75 self,
76 mode: Union[TransformationMode, str],
77 udf: Callable[[Any], Any],

Callers 6

__deepcopy__Method · 0.85
decoratorFunction · 0.85

Calls

no outgoing calls

Tested by 1