(self, request, context)
Class initializer.
        :param request: an iterable sequence of RowData
        :Sets up the input data frame and parameters based on the request
Class initializer.
        :param request: an iterable sequence of RowData
        :Sets up the input data frame and parameters based on the request
Class initializer . : param request : an iterable sequence of RowData : Sets up the input data frame and parameters based on the request
def __init__(self, request, context):
        """
        Class initializer.
        :param request: an iterable sequence of RowData
        :Sets up the input data frame and parameters based on the request
        """
        
        # Set the request and context variables for this object instance
        self.request = request
        self.context = context

        # Create a Pandas Data Frame with column ds for the dates and column y for values
        self.request_df = pd.DataFrame([(row.duals[0].numData, row.duals[1].numData) \
                                        for request_rows in self.request \
                                        for row in request_rows.rows], \
                                       columns=['ds','y'])
        
        # Handle null value rows in the request dataset
        self.NaT_df = self.request_df.loc[self.request_df.ds.isnull()].copy()
        
        # If such a row exists it will be sliced off and then added back to the response
        if len(self.NaT_df) > 0:
            self.NaT_df.loc[:,'y'] = 0
            self.request_df = self.request_df.loc[self.request_df.ds.notnull()]               
        
        # Get additional arguments from the third column in the request data
        # Arguments should take the form of a comma separated string: 'arg1=value1, arg2=value2'
        self._set_params()
        
        # Additional information is printed to the terminal and logs if the paramater debug = true
        if self.debug:
            self._print_log(1)
        
        # Convert numerical date values to datetime
        self.request_df.loc[:,'ds'] = pd.to_datetime(self.request_df.loc[:,'ds'], unit=self.qlik_cal_unit,
                                                     origin=self.qlik_cal_start)
        
        # If the request contains holidays, prepare a holidays data frame
        if self.has_holidays:
            self._prep_holidays()
        
        # If the request contains additional regressors, add them to a regressors data frame
        if self.has_regressors:
            self._prep_regressors()
        
        # Sort the Request Data Frame based on dates, as Qlik may send unordered data
        self.request_df = self.request_df.sort_values('ds')
        
        # Store the original indexes for re-ordering output later
        self.request_index = self.request_df.loc[:,'ds']
        
        # Add additional regressors to the request data frame
        if self.has_regressors:
            self.request_df = self.request_df.merge(self.regressors_df, how='left', left_index=True, right_index=True)

        # Ignore the placeholder rows which will be filled with forecasted figures later
        self.input_df = self.request_df.iloc[:-self.periods].copy()
        
        # Reset the indexes for the input data frame. 
        # Not doing this interferes with correct ordering of the output from Prophet
        self.input_df = self.input_df.reset_index(drop=True)
        
        # If the input data frame contains less than 2 non-Null rows, prediction is not possible
        if len(self.input_df) - self.input_df.y.isnull().sum() >= 2:
            # If take_log = true take logarithm of relevant input values.
            # This is usually to make the timeseries more stationary
            if self.take_log:
                self.input_df.loc[:,'y'] = np.log(self.input_df.loc[:,'y'])
                
                if self.cap is not None:
                    self.cap = np.log(self.cap)
                
                    if self.floor is not None:
                        self.floor = np.log(self.floor)
            
            # If a logistic growth model is applied add the cap and floor columns to the input data frame
            if self.cap is not None:
                self.input_df.loc[:,'cap'] = self.cap
                
                if self.floor is not None:
                    self.input_df.loc[:,'floor'] = self.floor
            
        if self.debug:
            self._print_log(2)
def __init__ ( self , request , context ) : # Set the request and context variables for this object instance self . request = request self . context = context # Create a Pandas Data Frame with column ds for the dates and column y for values self . request_df = pd . DataFrame ( [ ( row . duals [ 0 ] . numData , row . duals [ 1 ] . numData ) for request_rows in self . request for row in request_rows . rows ] , columns = [ 'ds' , 'y' ] ) # Handle null value rows in the request dataset self . NaT_df = self . request_df . loc [ self . request_df . ds . isnull ( ) ] . copy ( ) # If such a row exists it will be sliced off and then added back to the response if len ( self . NaT_df ) > 0 : self . NaT_df . loc [ : , 'y' ] = 0 self . request_df = self . request_df . loc [ self . request_df . ds . notnull ( ) ] # Get additional arguments from the third column in the request data # Arguments should take the form of a comma separated string: 'arg1=value1, arg2=value2' self . _set_params ( ) # Additional information is printed to the terminal and logs if the paramater debug = true if self . debug : self . _print_log ( 1 ) # Convert numerical date values to datetime self . request_df . loc [ : , 'ds' ] = pd . to_datetime ( self . request_df . loc [ : , 'ds' ] , unit = self . qlik_cal_unit , origin = self . qlik_cal_start ) # If the request contains holidays, prepare a holidays data frame if self . has_holidays : self . _prep_holidays ( ) # If the request contains additional regressors, add them to a regressors data frame if self . has_regressors : self . _prep_regressors ( ) # Sort the Request Data Frame based on dates, as Qlik may send unordered data self . request_df = self . request_df . sort_values ( 'ds' ) # Store the original indexes for re-ordering output later self . request_index = self . request_df . loc [ : , 'ds' ] # Add additional regressors to the request data frame if self . has_regressors : self . request_df = self . request_df . merge ( self . regressors_df , how = 'left' , left_index = True , right_index = True ) # Ignore the placeholder rows which will be filled with forecasted figures later self . input_df = self . request_df . iloc [ : - self . periods ] . copy ( ) # Reset the indexes for the input data frame.  # Not doing this interferes with correct ordering of the output from Prophet self . input_df = self . input_df . reset_index ( drop = True ) # If the input data frame contains less than 2 non-Null rows, prediction is not possible if len ( self . input_df ) - self . input_df . y . isnull ( ) . sum ( ) >= 2 : # If take_log = true take logarithm of relevant input values. # This is usually to make the timeseries more stationary if self . take_log : self . input_df . loc [ : , 'y' ] = np . log ( self . input_df . loc [ : , 'y' ] ) if self . cap is not None : self . cap = np . log ( self . cap ) if self . floor is not None : self . floor = np . log ( self . floor ) # If a logistic growth model is applied add the cap and floor columns to the input data frame if self . cap is not None : self . input_df . loc [ : , 'cap' ] = self . cap if self . floor is not None : self . input_df . loc [ : , 'floor' ] = self . floor if self . debug : self . _print_log ( 2 )