(cls, request, context)
return instance
Alternative initialization method for this class
        Used when the request contains the timeseries as a contatenated string, repeated for every row
        This is used when the number of input data points differs from the output rows required for seasonality plots
Alternative initialization method for this class
        Used when the request contains the timeseries as a contatenated string, repeated for every row
        This is used when the number of input data points differs from the output rows required for seasonality plots
Alternative initialization method for this class Used when the request contains the timeseries as a contatenated string repeated for every row This is used when the number of input data points differs from the output rows required for seasonality plots
def init_seasonality(cls, request, context):
        """
        Alternative initialization method for this class
        Used when the request contains the timeseries as a contatenated string, repeated for every row
        This is used when the number of input data points differs from the output rows required for seasonality plots
        """
                
        # The rows are duplicates in this kind of request, so inputs are simply taken from the first row
        # First we store the correct number of rows to be output.
        request_row_count = len([row for request_rows in request for row in request_rows.rows])
        # The timeseries is accepted as a string from the second column of the first row
        timeseries = request[0].rows[0].duals[1].strData
        # The holidays are taken from the third column of the first row
        holidays = request[0].rows[0].duals[2].strData
        
        # Get the number of columns in the request
        cols = len(request[0].rows[0].duals)

        # If additional regressors are included we extract them from the request as well
        if cols > 4:
            regressors = request[0].rows[0].duals[3].strData
            regressor_args = request[0].rows[0].duals[4]
        
        # The key word arguments are taken from the last column of the first row
        args = request[0].rows[0].duals[cols-1]
        
        # The data may be sent unsorted by Qlik, so we have to store the order to use when sending the results
        sort_order = pd.DataFrame([(row.duals[0].numData, row.duals[0].strData) \
                                        for request_rows in request \
                                        for row in request_rows.rows], \
                                       columns=['seasonality_num', 'seasonality_str'])
        
        # We ignore Null values here as these are handled separately in the response
        sort_order = sort_order.loc[sort_order.seasonality_num.notnull()]
        
        # Re-create the request with ds and y columns
        pairs = timeseries.split(";")
        request_df = pd.DataFrame([p.split(":") for p in pairs], columns=['ds', 'y'])
        
        # Convert strings to numeric values, replace conversion errors with Null values
        request_df = request_df.applymap(lambda s: utils.atof(s) if s else np.NaN)      
        
        # Check if the holidays column is populated
        if len(holidays) > 0:
            # Create a holidays data frame
            pairs = holidays.split(";")
            holiday_df = pd.DataFrame([p.split(":") for p in pairs], columns=['ds', 'holiday'])
            
            # Workaround for Pandas not converting the ds column to floats like it does for request_df
            holiday_df.loc[:,'ds'] = holiday_df.loc[:,'ds'].astype('float64')
            
            # Merge the holidays with the request data frame using column ds as key
            request_df = pd.merge(request_df, holiday_df, on='ds', how='left')
            
            # Replace null values in the holiday column with empty strings
            request_df = request_df.fillna(value={'holiday': ''})
        
        # If additional regressors are included in the request
        if cols > 4:
            # Create a regressors data frame
            pairs = regressors.split(";")
            regressors_df = pd.DataFrame([p.split(":") for p in pairs], columns=['ds', 'regressors'])
            
            # Merge the holidays with the request data frame using column ds as key
            request_df = pd.merge(request_df, regressors_df, on='ds', how='left')
            
            # Replace null values in the holiday column with empty strings
            request_df = request_df.fillna(value={'regressors': ''})

            # Add keyword arguments for the additional regressors to the request data frame as well
            request_df.loc[:, 'regressor_args'] = regressor_args

        # Values in the data frame are converted to type SSE.Dual
        request_df.loc[:,'ds'] = request_df.loc[:,'ds'].apply(lambda result: SSE.Dual(numData=result))
        request_df.loc[:,'y'] = request_df.loc[:,'y'].apply(lambda result: SSE.Dual(numData=result))
        if 'holiday' in request_df.columns:
            request_df.loc[:,'holiday'] = request_df.loc[:,'holiday'].apply(lambda result: SSE.Dual(strData=result))
        if 'regressors' in request_df.columns:
            request_df.loc[:,'regressors'] = request_df.loc[:,'regressors'].apply(lambda result: SSE.Dual(strData=result))
        
        # Add the keyword arguments to the data frame as well, already of type SSE.Dual
        request_df.loc[:, 'args'] = args
        
        # Create the updated request list and convert to SSE data types
        request_list = request_df.values.tolist()
        request_list = [SSE.Row(duals=duals) for duals in request_list]
        updated_request = [SSE.BundledRows(rows=request_list)]
                
        # Call the default initialization method
        instance = ProphetForQlik(updated_request, context)
        
        # Handle null value row in the request dataset
        instance.NaT_df = request_df.loc[request_df.ds.isnull()].copy()
        
        # If such a row exists it will be sliced off and then added back to the response
        if len(instance.NaT_df) > 0:
            instance.NaT_df.loc[:,'y'] = 0         
        
        # Set a property that lets us know this instance was created for seasonality forecasts
        instance.is_seasonality_request = True
        
        # Set a property that lets us know the row count in the original request as this will be different from request_df
        instance.request_row_count = request_row_count
        
        # Update the default result type if this was not passed in arguments
        if instance.result_type == 'yhat':
            instance.result_type = instance.seasonality
        
        if instance.seasonality == 'weekly':
            # For weekly seasonlity the return sort order is based on the day number from 0-6, with 0 being Monday
            instance.sort_order = sort_order.set_index(sort_order.seasonality_num)
        else:
            # Else the return sort order is based on the data frame's index after sorting on the seasonality field
            instance.sort_order = sort_order.sort_values('seasonality_num')
        
        # Return the initialized ProphetForQlik instance
        return instance
def init_seasonality ( cls , request , context ) : # The rows are duplicates in this kind of request, so inputs are simply taken from the first row # First we store the correct number of rows to be output. request_row_count = len ( [ row for request_rows in request for row in request_rows . rows ] ) # The timeseries is accepted as a string from the second column of the first row timeseries = request [ 0 ] . rows [ 0 ] . duals [ 1 ] . strData # The holidays are taken from the third column of the first row holidays = request [ 0 ] . rows [ 0 ] . duals [ 2 ] . strData # Get the number of columns in the request cols = len ( request [ 0 ] . rows [ 0 ] . duals ) # If additional regressors are included we extract them from the request as well if cols > 4 : regressors = request [ 0 ] . rows [ 0 ] . duals [ 3 ] . strData regressor_args = request [ 0 ] . rows [ 0 ] . duals [ 4 ] # The key word arguments are taken from the last column of the first row args = request [ 0 ] . rows [ 0 ] . duals [ cols - 1 ] # The data may be sent unsorted by Qlik, so we have to store the order to use when sending the results sort_order = pd . DataFrame ( [ ( row . duals [ 0 ] . numData , row . duals [ 0 ] . strData ) for request_rows in request for row in request_rows . rows ] , columns = [ 'seasonality_num' , 'seasonality_str' ] ) # We ignore Null values here as these are handled separately in the response sort_order = sort_order . loc [ sort_order . seasonality_num . notnull ( ) ] # Re-create the request with ds and y columns pairs = timeseries . split ( ";" ) request_df = pd . DataFrame ( [ p . split ( ":" ) for p in pairs ] , columns = [ 'ds' , 'y' ] ) # Convert strings to numeric values, replace conversion errors with Null values request_df = request_df . applymap ( lambda s : utils . atof ( s ) if s else np . NaN ) # Check if the holidays column is populated if len ( holidays ) > 0 : # Create a holidays data frame pairs = holidays . split ( ";" ) holiday_df = pd . DataFrame ( [ p . split ( ":" ) for p in pairs ] , columns = [ 'ds' , 'holiday' ] ) # Workaround for Pandas not converting the ds column to floats like it does for request_df holiday_df . loc [ : , 'ds' ] = holiday_df . loc [ : , 'ds' ] . astype ( 'float64' ) # Merge the holidays with the request data frame using column ds as key request_df = pd . merge ( request_df , holiday_df , on = 'ds' , how = 'left' ) # Replace null values in the holiday column with empty strings request_df = request_df . fillna ( value = { 'holiday' : '' } ) # If additional regressors are included in the request if cols > 4 : # Create a regressors data frame pairs = regressors . split ( ";" ) regressors_df = pd . DataFrame ( [ p . split ( ":" ) for p in pairs ] , columns = [ 'ds' , 'regressors' ] ) # Merge the holidays with the request data frame using column ds as key request_df = pd . merge ( request_df , regressors_df , on = 'ds' , how = 'left' ) # Replace null values in the holiday column with empty strings request_df = request_df . fillna ( value = { 'regressors' : '' } ) # Add keyword arguments for the additional regressors to the request data frame as well request_df . loc [ : , 'regressor_args' ] = regressor_args # Values in the data frame are converted to type SSE.Dual request_df . loc [ : , 'ds' ] = request_df . loc [ : , 'ds' ] . apply ( lambda result : SSE . Dual ( numData = result ) ) request_df . loc [ : , 'y' ] = request_df . loc [ : , 'y' ] . apply ( lambda result : SSE . Dual ( numData = result ) ) if 'holiday' in request_df . columns : request_df . loc [ : , 'holiday' ] = request_df . loc [ : , 'holiday' ] . apply ( lambda result : SSE . Dual ( strData = result ) ) if 'regressors' in request_df . columns : request_df . loc [ : , 'regressors' ] = request_df . loc [ : , 'regressors' ] . apply ( lambda result : SSE . Dual ( strData = result ) ) # Add the keyword arguments to the data frame as well, already of type SSE.Dual request_df . loc [ : , 'args' ] = args # Create the updated request list and convert to SSE data types request_list = request_df . values . tolist ( ) request_list = [ SSE . Row ( duals = duals ) for duals in request_list ] updated_request = [ SSE . BundledRows ( rows = request_list ) ] # Call the default initialization method instance = ProphetForQlik ( updated_request , context ) # Handle null value row in the request dataset instance . NaT_df = request_df . loc [ request_df . ds . isnull ( ) ] . copy ( ) # If such a row exists it will be sliced off and then added back to the response if len ( instance . NaT_df ) > 0 : instance . NaT_df . loc [ : , 'y' ] = 0 # Set a property that lets us know this instance was created for seasonality forecasts instance . is_seasonality_request = True # Set a property that lets us know the row count in the original request as this will be different from request_df instance . request_row_count = request_row_count # Update the default result type if this was not passed in arguments if instance . result_type == 'yhat' : instance . result_type = instance . seasonality if instance . seasonality == 'weekly' : # For weekly seasonlity the return sort order is based on the day number from 0-6, with 0 being Monday instance . sort_order = sort_order . set_index ( sort_order . seasonality_num ) else : # Else the return sort order is based on the data frame's index after sorting on the seasonality field instance . sort_order = sort_order . sort_values ( 'seasonality_num' ) # Return the initialized ProphetForQlik instance return instance