(self, target=False, set_feature_def=False, ordered_data=False)
Get samples and targets based on the request and an existing model's feature definitions.
        If target=False, just return the samples.
        If set_feature_def=True, set the feature definitions for the model.
        If ordered_data=True, the request is expected to have a key field which will be used as an index. 
        The index will be stored in its original and sorted form in instance variables self.original_index and self.sorted_index
Get samples and targets based on the request and an existing model's feature definitions.
        If target=False, just return the samples.
        If set_feature_def=True, set the feature definitions for the model.
        If ordered_data=True, the request is expected to have a key field which will be used as an index. 
        The index will be stored in its original and sorted form in instance variables self.original_index and self.sorted_index
Get samples and targets based on the request and an existing model s feature definitions . If target = False just return the samples . If set_feature_def = True set the feature definitions for the model . If ordered_data = True the request is expected to have a key field which will be used as an index . The index will be stored in its original and sorted form in instance variables self . original_index and self . sorted_index
def _get_model_and_data(self, target=False, set_feature_def=False, ordered_data=False):
        """
        Get samples and targets based on the request and an existing model's feature definitions.
        If target=False, just return the samples.
        If set_feature_def=True, set the feature definitions for the model.
        If ordered_data=True, the request is expected to have a key field which will be used as an index. 
        The index will be stored in its original and sorted form in instance variables self.original_index and self.sorted_index
        """
    
        # Interpret the request data based on the expected row and column structure
        row_template = ['strData', 'strData']
        col_headers = ['model_name', 'n_features']
        features_col_num = 1

        # If True, the request is expected to have a key field which will be used as an index.
        if ordered_data:
            row_template.append('strData')
            col_headers.insert(1, 'key')
            features_col_num = 2
        
        # Create a Pandas Data Frame for the request data
        self.request_df = utils.request_df(self.request, row_template, col_headers)

        if ordered_data:
            # Set the key column as the index
            self.request_df.set_index("key", drop=False, inplace=True)
            # Store this index so we can reset the data to its original sort order
            self.original_index = self.request_df.index.copy()
        
        # Initialize the persistent model
        self.model = PersistentModel()
        
        # Get the model name from the request dataframe
        self.model.name = self.request_df.iloc[0, 0]
        
        # Get the model from cache or disk
        self._get_model()
        
        # Debug information is printed to the terminal and logs if the paramater debug = true
        if self.model.debug:
            self._print_log(3)

        # If the model requires lag targets, the data is always expected to contain targets
        if not target:
            target = self.model.lag_target
        
        # Get the expected features for this request
        features_df = self.model.original_features_df.copy()
        
        # Set features that are not expected in the current request
        if not set_feature_def:
            exclude = ["excluded"]

            if not target:
                exclude.append("target")
            if not ordered_data:
                exclude.append("identifier")

            # Exclude columns that are not expected in the request data
            exclusions = features_df['variable_type'].isin(exclude)
            features_df = features_df.loc[~exclusions]
        
        try:
            # Split the features provided as a string into individual columns
            samples_df = pd.DataFrame([x[features_col_num].split("|") for x in self.request_df.values.tolist()],\
                                            columns=features_df.loc[:,"name"].tolist(),\
                                            index=self.request_df.index)
        except AssertionError as ae:
            err = "The number of input columns do not match feature definitions. Ensure you are using the | delimiter and providing the correct features."
            err += "\n\nSample rows:\n{}\n\nExpected Features:\n{}\n".format(self.request_df.head(3), features_df.loc[:,"name"].tolist())
            raise AssertionError(err) from ae
        
        # Convert the data types based on feature definitions and sort by the unique identifier (if defined in the definitions)
        samples_df = utils.convert_types(samples_df, features_df, sort=True)

        if ordered_data:
            # Store the sorted index 
            self.sorted_index = samples_df.index.copy()
        
        if target:
            # Get the target feature
            target_name = self.model.original_features_df.loc[self.model.original_features_df["variable_type"] == "target"].index[0]

            # Get the target data
            target_df = samples_df.loc[:,[target_name]]
        
        # Update the feature definitions dataframe
        if set_feature_def:
            # Get the features to be excluded from the model
            exclusions = features_df['variable_type'].isin(["excluded", "target", "identifier"])
            # Store the featuer definitions except exclusions
            features_df = features_df.loc[~exclusions]
            self.model.features_df = features_df
        
        # Remove excluded features, target and identifier from the data
        samples_df = samples_df[features_df.index.tolist()]
        
        if target:
            return [samples_df, target_df]
        else:
            return samples_df
def _get_model_and_data ( self , target = False , set_feature_def = False , ordered_data = False ) : # Interpret the request data based on the expected row and column structure row_template = [ 'strData' , 'strData' ] col_headers = [ 'model_name' , 'n_features' ] features_col_num = 1 # If True, the request is expected to have a key field which will be used as an index. if ordered_data : row_template . append ( 'strData' ) col_headers . insert ( 1 , 'key' ) features_col_num = 2 # Create a Pandas Data Frame for the request data self . request_df = utils . request_df ( self . request , row_template , col_headers ) if ordered_data : # Set the key column as the index self . request_df . set_index ( "key" , drop = False , inplace = True ) # Store this index so we can reset the data to its original sort order self . original_index = self . request_df . index . copy ( ) # Initialize the persistent model self . model = PersistentModel ( ) # Get the model name from the request dataframe self . model . name = self . request_df . iloc [ 0 , 0 ] # Get the model from cache or disk self . _get_model ( ) # Debug information is printed to the terminal and logs if the paramater debug = true if self . model . debug : self . _print_log ( 3 ) # If the model requires lag targets, the data is always expected to contain targets if not target : target = self . model . lag_target # Get the expected features for this request features_df = self . model . original_features_df . copy ( ) # Set features that are not expected in the current request if not set_feature_def : exclude = [ "excluded" ] if not target : exclude . append ( "target" ) if not ordered_data : exclude . append ( "identifier" ) # Exclude columns that are not expected in the request data exclusions = features_df [ 'variable_type' ] . isin ( exclude ) features_df = features_df . loc [ ~ exclusions ] try : # Split the features provided as a string into individual columns samples_df = pd . DataFrame ( [ x [ features_col_num ] . split ( "|" ) for x in self . request_df . values . tolist ( ) ] , columns = features_df . loc [ : , "name" ] . tolist ( ) , index = self . request_df . index ) except AssertionError as ae : err = "The number of input columns do not match feature definitions. Ensure you are using the | delimiter and providing the correct features." err += "\n\nSample rows:\n{}\n\nExpected Features:\n{}\n" . format ( self . request_df . head ( 3 ) , features_df . loc [ : , "name" ] . tolist ( ) ) raise AssertionError ( err ) from ae # Convert the data types based on feature definitions and sort by the unique identifier (if defined in the definitions) samples_df = utils . convert_types ( samples_df , features_df , sort = True ) if ordered_data : # Store the sorted index  self . sorted_index = samples_df . index . copy ( ) if target : # Get the target feature target_name = self . model . original_features_df . loc [ self . model . original_features_df [ "variable_type" ] == "target" ] . index [ 0 ] # Get the target data target_df = samples_df . loc [ : , [ target_name ] ] # Update the feature definitions dataframe if set_feature_def : # Get the features to be excluded from the model exclusions = features_df [ 'variable_type' ] . isin ( [ "excluded" , "target" , "identifier" ] ) # Store the featuer definitions except exclusions features_df = features_df . loc [ ~ exclusions ] self . model . features_df = features_df # Remove excluded features, target and identifier from the data samples_df = samples_df [ features_df . index . tolist ( ) ] if target : return [ samples_df , target_df ] else : return samples_df