(n_samples, features_df, sort=True)
return n_samples
Convert data in n_samples to the correct data type based on the feature definitions.
    Optionally sort the data by the feature with "variable_type" set to "identifier". 
    Both n_samples and features_df must be supplied as dataframes. The columns in n_samples must be equal to rows in features_df.
    The features_df dataframe must have "name", "data_type" and "variable_type" columns.
    Accepted data_types are int, float, str, bool.
Convert data in n_samples to the correct data type based on the feature definitions.
    Optionally sort the data by the feature with "variable_type" set to "identifier". 
    Both n_samples and features_df must be supplied as dataframes. The columns in n_samples must be equal to rows in features_df.
    The features_df dataframe must have "name", "data_type" and "variable_type" columns.
    Accepted data_types are int, float, str, bool.
Convert data in n_samples to the correct data type based on the feature definitions . Optionally sort the data by the feature with variable_type set to identifier . Both n_samples and features_df must be supplied as dataframes . The columns in n_samples must be equal to rows in features_df . The features_df dataframe must have name data_type and variable_type columns . Accepted data_types are int float str bool .
def convert_types(n_samples, features_df, sort=True):
    """
    Convert data in n_samples to the correct data type based on the feature definitions.
    Optionally sort the data by the feature with "variable_type" set to "identifier". 
    Both n_samples and features_df must be supplied as dataframes. The columns in n_samples must be equal to rows in features_df.
    The features_df dataframe must have "name", "data_type" and "variable_type" columns.
    Accepted data_types are int, float, str, bool.
    """
    
    # Transpose the features dataframe and keep the data_types for each feature
    features_df_t = features_df.T
    features_df_t.columns = features_df_t.loc["name",:].tolist()
    dtypes = features_df_t.loc["data_type",:]
    
    # Dictionary used to convert argument values to the correct type
    types = {"boolean":ast.literal_eval, "bool":ast.literal_eval, "integer":atoi, "int":atoi,\
             "float":atof, "string":str, "str":str}
    
    # Convert columns by the corresponding data type
    for col in n_samples.columns:
        # Handle conversion from string to boolean
        if dtypes[col] in ("boolean", "bool"):
            n_samples.loc[:, col] = n_samples.loc[:, col].astype("str").apply(str.capitalize)
        
        # Convert this column to the correct type
        n_samples.loc[:, col] = n_samples.loc[:, col].apply(types[dtypes[col]])     

    # Get the unique identifier from the feature definitions
    identifier = features_df.loc[features_df["variable_type"] == "identifier"]

    # Ensure the data is sorted by the identifier if available
    if sort and len(identifier) == 1:
        n_samples = n_samples.sort_values(by=[identifier.index[0]], ascending=True)

    return n_samples
def convert_types ( n_samples , features_df , sort = True ) : # Transpose the features dataframe and keep the data_types for each feature features_df_t = features_df . T features_df_t . columns = features_df_t . loc [ "name" , : ] . tolist ( ) dtypes = features_df_t . loc [ "data_type" , : ] # Dictionary used to convert argument values to the correct type types = { "boolean" : ast . literal_eval , "bool" : ast . literal_eval , "integer" : atoi , "int" : atoi , "float" : atof , "string" : str , "str" : str } # Convert columns by the corresponding data type for col in n_samples . columns : # Handle conversion from string to boolean if dtypes [ col ] in ( "boolean" , "bool" ) : n_samples . loc [ : , col ] = n_samples . loc [ : , col ] . astype ( "str" ) . apply ( str . capitalize ) # Convert this column to the correct type n_samples . loc [ : , col ] = n_samples . loc [ : , col ] . apply ( types [ dtypes [ col ] ] ) # Get the unique identifier from the feature definitions identifier = features_df . loc [ features_df [ "variable_type" ] == "identifier" ] # Ensure the data is sorted by the identifier if available if sort and len ( identifier ) == 1 : n_samples = n_samples . sort_values ( by = [ identifier . index [ 0 ] ] , ascending = True ) return n_samples