88
99import pandas
1010from great_expectations .core import ExpectationSuite
11+ from oci .feature_store .models import (
12+ DatasetFeatureGroupCollection ,
13+ DatasetFeatureGroupSummary ,
14+ )
15+
1116from ads .common import utils
1217from ads .common .oci_mixin import OCIModelMixin
1318from ads .feature_store .common .enums import (
2631 OciExecutionStrategyProvider ,
2732)
2833from ads .feature_store .feature import DatasetFeature
34+ from ads .feature_store .feature_group import FeatureGroup
2935from ads .feature_store .feature_group_expectation import Expectation
3036from ads .feature_store .feature_option_details import FeatureOptionDetails
3137from ads .feature_store .service .oci_dataset import OCIDataset
@@ -113,6 +119,7 @@ class Dataset(Builder):
113119 CONST_ITEMS = "items"
114120 CONST_LAST_JOB_ID = "jobId"
115121 CONST_MODEL_DETAILS = "modelDetails"
122+ CONST_FEATURE_GROUP = "datasetFeatureGroups"
116123
117124 attribute_map = {
118125 CONST_ID : "id" ,
@@ -130,6 +137,7 @@ class Dataset(Builder):
130137 CONST_LIFECYCLE_STATE : "lifecycle_state" ,
131138 CONST_MODEL_DETAILS : "model_details" ,
132139 CONST_PARTITION_KEYS : "partition_keys" ,
140+ CONST_FEATURE_GROUP : "dataset_feature_groups" ,
133141 }
134142
135143 def __init__ (self , spec : Dict = None , ** kwargs ) -> None :
@@ -503,6 +511,44 @@ def with_model_details(self, model_details: ModelDetails) -> "Dataset":
503511
504512 return self .set_spec (self .CONST_MODEL_DETAILS , model_details .to_dict ())
505513
514+ @property
515+ def feature_groups (self ) -> List ["FeatureGroup" ]:
516+ collection : "DatasetFeatureGroupCollection" = self .get_spec (
517+ self .CONST_FEATURE_GROUP
518+ )
519+ feature_groups : List ["FeatureGroup" ] = []
520+ if collection and collection .items :
521+ for datasetFGSummary in collection .items :
522+ feature_groups .append (
523+ FeatureGroup .from_id (datasetFGSummary .feature_group_id )
524+ )
525+
526+ return feature_groups
527+
528+ @feature_groups .setter
529+ def feature_groups (self , feature_groups : List ["FeatureGroup" ]):
530+ self .with_feature_groups (feature_groups )
531+
532+ def with_feature_groups (self , feature_groups : List ["FeatureGroup" ]) -> "Dataset" :
533+ """Sets the model details for the dataset.
534+
535+ Parameters
536+ ----------
537+ feature_groups: List of feature groups
538+ Returns
539+ -------
540+ Dataset
541+ The Dataset instance (self).
542+
543+ """
544+ collection : List ["DatasetFeatureGroupSummary" ] = []
545+ for group in feature_groups :
546+ collection .append (DatasetFeatureGroupSummary (feature_group_id = group .id ))
547+
548+ return self .set_spec (
549+ self .CONST_FEATURE_GROUP , DatasetFeatureGroupCollection (items = collection )
550+ )
551+
506552 @property
507553 def partition_keys (self ) -> List [str ]:
508554 return self .get_spec (self .CONST_PARTITION_KEYS )
@@ -560,7 +606,9 @@ def add_models(self, model_details: ModelDetails) -> "Dataset":
560606 f"Dataset update Failed with : { type (ex )} with error message: { ex } "
561607 )
562608 if existing_model_details :
563- self .with_model_details (ModelDetails ().with_items (existing_model_details ["items" ]))
609+ self .with_model_details (
610+ ModelDetails ().with_items (existing_model_details ["items" ])
611+ )
564612 else :
565613 self .with_model_details (ModelDetails ().with_items ([]))
566614 return self
@@ -652,6 +700,7 @@ def create(self, **kwargs) -> "Dataset":
652700 # Create dataset
653701 logger .info ("Saving dataset." )
654702 self .oci_dataset = self ._to_oci_dataset (** kwargs ).create ()
703+ self ._update_from_oci_dataset_model (self .oci_dataset )
655704 self .with_id (self .oci_dataset .id )
656705 return self
657706
@@ -729,11 +778,10 @@ def _update_from_oci_dataset_model(self, oci_dataset: OCIDataset) -> "Dataset":
729778
730779 # Update the main properties
731780 self .oci_dataset = oci_dataset
732- dataset_details = oci_dataset .to_dict ()
733781
734782 for infra_attr , dsc_attr in self .attribute_map .items ():
735- if infra_attr in dataset_details :
736- self .set_spec (infra_attr , dataset_details [ infra_attr ] )
783+ if dsc_attr in self . oci_dataset . attribute_map :
784+ self .set_spec (infra_attr , getattr ( self . oci_dataset , dsc_attr ) )
737785
738786 return self
739787
@@ -1013,6 +1061,10 @@ def to_dict(self) -> Dict:
10131061 for key , value in spec .items ():
10141062 if hasattr (value , "to_dict" ):
10151063 value = value .to_dict ()
1064+ if hasattr (value , "attribute_map" ):
1065+ value = self .oci_dataset .client .base_client .sanitize_for_serialization (
1066+ value
1067+ )
10161068 spec [key ] = value
10171069
10181070 return {
0 commit comments