
    Dj                         d dl ZddlmZmZ ddlmZ ddlmZ d dl	m
Z
 dgZddd	Zdej                  d
Zd Zd Z	 	 ddZy)    N   )ccheck_endog)get_callable)DTYPE)C_Approxapprox   )constantlinear)orderedmeanc                     | S N )ts    YC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\pmdarima/arima/approx.py<lambda>r   $   s    q     c                      fD cg c]  }t        |t        d       c}\    j                  d   }|j                  d   k7  rt        d|j                  d   fz        |dk7  rt	        j
                         } |    |   t	        j                         }|j                  d   |k  r> fd}t        j                  |t              } t	        j                  |      ||      |  fS c c}w )a  Regularize the values, make them ordered and remove duplicates.
    If the ``ties`` parameter is explicitly set to 'ordered' then order
    is already assumed. Otherwise, the removal process will happen.

    Parameters
    ----------
    x : array-like, shape=(n_samples,)
        The x vector.

    y : array-like, shape=(n_samples,)
        The y vector.

    ties : str
        One of {'ordered', 'mean'}, handles the ties.
    F)dtypepreserve_seriesr   zarray dim mismatch: %i != %ir   c                 $    |k(     } | |      S r   r   )fu_valvalsxys      r   	tie_applyz_regularize.<locals>.tie_applyP   s    e}wr   )r   r   shape
ValueErrornpargsortunique
VALID_TIESget	_identity	vectorize)	r   r   tiesarrnxouxr   funcs	   ``       r   _regularizer/   '   s    $ q6 	Cue<DAq
 
B	QWWQZ72qwwqz:JJKK yJJqM aDaD YYq\88A;

 >>$	2D
 (Y'b1A Aa4KQs   C3c	           	         |t         vrt        dt         z        t        |      j                  t        j
                        }|}	t        |	t               }t        | ||      \  } }| j                  d   }
|
dk(  r|	dk(  rt        d      ||dk7  r|d   nt        j                  }||dk7  r|d   nt        j                  }t        | ||||||      }|t	        j                  |      fS )a  Linearly interpolate points.

    Return a list of points which (linearly) interpolate given data points,
    or a function performing the linear (or constant) interpolation.

    Parameters
    ----------
    x : array-like, shape=(n_samples,)
        Numeric vector giving the coordinates of the points
        to be interpolated.

    y : array-like, shape=(n_samples,)
        Numeric vector giving the coordinates of the points
        to be interpolated.

    xout : int, float or iterable
        A scalar or iterable of numeric values specifying where
        interpolation is to take place.

    method : str, optional (default='linear')
        Specifies the interpolation method to be used.
        Choices are "linear" or "constant".

    rule : int, optional (default=1)
        An integer describing how interpolation is to take place
        outside the interval ``[min(x), max(x)]``. If ``rule`` is 1 then
        np.nans are returned for such points and if it is 2, the value at the
        closest data extreme is used.

    f : int, optional (default=0)
        For ``method`` = "constant" a number between 0 and 1 inclusive,
        indicating a compromise between left- and right-continuous step
        functions. If y0 and y1 are the values to the left and right of the
        point then the value is y0 if f == 0, y1 if f == 1, and y0*(1-f)+y1*f
        for intermediate values. In this way the result is right-continuous
        for f == 0 and left-continuous for f == 1, even for non-finite
        ``y`` values.

    yleft : float, optional (default=None)
        The value to be returned when input ``x`` values are less than
        ``min(x)``. The default is defined by the value of rule given below.

    yright : float, optional (default=None)
        The value to be returned when input ``x`` values are greater than
        ``max(x)``. The default is defined by the value of rule given below.

    ties : str, optional (default='mean')
        Handling of tied ``x`` values. Choices are "mean" or "ordered".
    zmethod must be one of %rr   r
   r   z0need at least two points to linearly interpolate)VALID_APPROXr!   r   astyper"   float64r   r/   r    nanr   asarray)r   r   xoutmethodruler   yleftyrightr)   
method_keyr+   youts               r   r	   r	   b   s    f \!3lBCC T7>>"**%D J *l3F q!T"DAq	
B 
Qw! 4 5 5 }	!rvv~!)2 Aq$5&9DD!!!r   )r   r
   r   NNr   )numpyr"   utils.arrayr   r   utilsr   compat.numpyr   pmdarima.arima._arimar   __all__r2   averager%   r'   r/   r	   r   r   r   <module>rE      sb     (    
 +   JJ
 	8v <@#R"r   