1313from great_expectations .core import ExpectationSuite , ExpectationConfiguration
1414import ads
1515import os
16- from ads .feature_store .common .enums import FeatureType
16+ from ads .feature_store .common .enums import FeatureType , TransformationMode
1717from ads .feature_store .dataset import Dataset
1818from ads .feature_store .feature_group import FeatureGroup
1919from ads .feature_store .input_feature_detail import FeatureDetail
2020from ads .feature_store .statistics_config import StatisticsConfig
2121
22-
2322client_kwargs = dict (
2423 retry_strategy = oci .retry .NoneRetryStrategy ,
2524 service_endpoint = os .getenv ("service_endpoint" ),
3534SLEEP_INTERVAL = 60
3635
3736
37+ def transformation_with_kwargs (data_frame , ** kwargs ):
38+ is_area_enabled = kwargs .get ('is_area_enabled' )
39+
40+ if is_area_enabled :
41+ # Calculate petal area and sepal area
42+ data_frame ["petal_area" ] = data_frame ["petal_length" ] * data_frame ["petal_width" ]
43+ data_frame ["sepal_area" ] = data_frame ["sepal_length" ] * data_frame ["sepal_width" ]
44+
45+ # Return the updated DataFrame
46+ return data_frame
47+
48+
3849class FeatureStoreTestCase :
3950 # networks compartment in feature store
40- TIME_NOW = str .format ("{}_{}" ,datetime .utcnow ().strftime ("%Y_%m_%d_%H_%M_%S" ),int (random ()* 1000 ))
51+ TIME_NOW = str .format ("{}_{}" , datetime .utcnow ().strftime ("%Y_%m_%d_%H_%M_%S" ), int (random () * 1000 ))
4152 TENANCY_ID = "ocid1.tenancy.oc1..aaaaaaaa462hfhplpx652b32ix62xrdijppq2c7okwcqjlgrbknhgtj2kofa"
4253 COMPARTMENT_ID = "ocid1.tenancy.oc1..aaaaaaaa462hfhplpx652b32ix62xrdijppq2c7okwcqjlgrbknhgtj2kofa"
4354 METASTORE_ID = "ocid1.datacatalogmetastore.oc1.iad.amaaaaaabiudgxyap7tizm4gscwz7amu7dixz7ml3mtesqzzwwg3urvvdgua"
@@ -363,8 +374,15 @@ def create_entity_resource(self, feature_store) -> "Entity":
363374 entity = feature_store .create_entity (display_name = self .get_name ("entity" ))
364375 return entity
365376
377+ def create_transformation_resource (self , feature_store ) -> "Transformation" :
378+ transformation = feature_store .create_transformation (source_code_func = transformation_with_kwargs ,
379+ display_name = "transformation_with_kwargs" ,
380+ transformation_mode = TransformationMode .PANDAS )
381+
382+ return transformation
383+
366384 def define_feature_group_resource (
367- self , entity_id , feature_store_id
385+ self , entity_id , feature_store_id
368386 ) -> "FeatureGroup" :
369387 feature_group_resource = (
370388 FeatureGroup ()
@@ -382,7 +400,7 @@ def define_feature_group_resource(
382400 return feature_group_resource
383401
384402 def define_dataset_resource (
385- self , entity_id , feature_store_id , feature_group_name
403+ self , entity_id , feature_store_id , feature_group_name
386404 ) -> "Dataset" :
387405 name = self .get_name ("petals_ds" )
388406 dataset_resource = (
@@ -452,6 +470,13 @@ def clean_up_feature_group(feature_group):
452470 except Exception as ex :
453471 print ("Failed to delete feature group: " , str (ex ))
454472 exit (1 )
473+ @staticmethod
474+ def clean_up_transformation (transformation ):
475+ try :
476+ transformation .delete ()
477+ except Exception as ex :
478+ print ("Failed to delete transformation: " , str (ex ))
479+ exit (1 )
455480
456481 @staticmethod
457482 def clean_up_dataset (dataset ):
0 commit comments