Ë
    ý�Djv?  ã                   ó˜   — d dl mZ d dlZd dlZddlmZ ddl	m
Z
 g d¢Zd„ Zd	„ Zed
dd
fd„Zed
d
fd„Zd„ Zd„ Zdd„Zd„ Zd„ Zdd„Zd„ Zy)é    )Ú
validationNé   )ÚDTYPEé   )ÚC_intgrt_vec)Ú	as_seriesÚcÚcheck_endogÚ
check_exogÚdiffÚdiff_invÚis_iterablec                 óŒ   — t        | t        j                  «      r| S t        j                  t        j                  | «      fi |¤ŽS )aÖ  Cast as pandas Series.

    Cast an iterable to a Pandas Series object. Note that the index
    will simply be a positional ``arange`` and cannot be set in this
    function.

    Parameters
    ----------
    x : array-like, shape=(n_samples,)
        The 1d array on which to compute the auto correlation.

    Examples
    --------
    >>> as_series([1, 2, 3])
    0    1
    1    2
    2    3
    dtype: int64

    >>> as_series(as_series((1, 2, 3)))
    0    1
    1    2
    2    3
    dtype: int64

    >>> import pandas as pd
    >>> as_series(pd.Series([4, 5, 6], index=['a', 'b', 'c']))
    a    4
    b    5
    c    6
    dtype: int64

    Returns
    -------
    s : pd.Series
        A pandas Series object.
    )Ú
isinstanceÚpdÚSeriesÚskvalÚcolumn_or_1d)ÚxÚkwargss     úXC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\pmdarima/utils/array.pyr   r      s7   € ôL �!”R—Y‘YÔØˆÜ�9‰9”U×'Ñ'¨Ó*Ñ5¨fÑ5Ð5ó    c                  ó  — | syt        | «      dk(  r;| d   }t        |«      rt        j                  |«      S t        j                  |g«      S t        j                  | D �cg c]  }t        |«      r|n|g‘Œ c}«      S c c}w )a½  Imitates the ``c`` function from R.

    Since this whole library is aimed at re-creating in
    Python what R has already done so well, the ``c`` function was created to
    wrap ``numpy.concatenate`` and mimic the R functionality. Similar to R,
    this works with scalars, iterables, and any mix therein.

    Note that using the ``c`` function on multi-nested lists or iterables
    will fail!

    Examples
    --------
    Using ``c`` with varargs will yield a single array:

    >>> c(1, 2, 3, 4)
    array([1, 2, 3, 4])

    Using ``c`` with nested lists and scalars will also yield a single array:

    >>> c([1, 2], 4, c(5, 4))
    array([1, 2, 4, 5, 4])

    However, using ``c`` with multi-level lists will fail!

    >>> c([1, 2, 3], [[1, 2]])  # doctest: +SKIP
    ValueError: all the input arrays must have same number of dimensions

    References
    ----------
    .. [1] https://stat.ethz.ch/R-manual/R-devel/library/base/html/c.html
    Nr   r   )Úlenr   ÚnpÚasarrayÚconcatenate)ÚargsÚelementÚas      r   r	   r	   E   sy   € ñB Øô ˆ4ƒy�A‚~Ø�q‘'ˆô �wÔÜ—:‘:˜gÓ&Ð&ô �z‰z˜7˜)Ó$Ð$ô0 �>‰>ÀÖF¸A¤¨A¤™1°Q°CÑ7ÒFÓGÐGùÒFs   Á A>TFc                 ó6  — t        j                  | d|||¬«      }t        j                  |«      }|s|S t        | t        j
                  «      r| j                  «       } t        | t        j                  «      r!t	        j                  || j                  ¬«      }|S )a+  Wrapper for ``check_array`` and ``column_or_1d`` from sklearn

    Parameters
    ----------
    y : array-like, shape=(n_samples,)
        The 1d endogenous array.

    dtype : string, type or None (default=np.float64)
        Data type of result. If None, the dtype of the input is preserved.
        If "numeric", dtype is preserved unless array.dtype is object.

    copy : bool, optional (default=False)
        Whether a forced copy will be triggered. If copy=False, a copy might
        still be triggered by a conversion.

    force_all_finite : bool, optional (default=False)
        Whether to raise an error on np.inf and np.nan in an array. The
        possibilities are:

        - True: Force all values of array to be finite.
        - False: accept both np.inf and np.nan in array.

    preserve_series : bool, optional
        Whether to preserve a ``pd.Series`` object. Will also attempt to
        squeeze a dataframe into a ``pd.Series``.

    Returns
    -------
    y : np.ndarray or pd.Series, shape=(n_samples,)
        A 1d numpy ndarray
    F)Ú	ensure_2dÚforce_all_finiteÚcopyÚdtype)Úindex)	r   Úcheck_arrayr   r   r   Ú	DataFrameÚsqueezer   r&   )Úyr%   r$   r#   Úpreserve_seriesÚendogs         r   r
   r
   �   s€   € ôL ×ÑØ	ØØ)ØØô€Eô ×Ñ˜uÓ%€EÙØˆô �!”R—\‘\Ô"Ø�I‰I‹Kˆä�!”R—Y‘YÔÜ—	‘	˜% q§w¡wÔ/ˆØ€Lr   c                 ó~  — t        | d«      r| j                  dk7  rt        d«      ‚t        | t        j
                  «      r`|r|�| j                  |«      } |rG| j                  t        j                  «       j                  «       j                  «       rt        d«      ‚| S t        j                  | dt        ||¬«      S )a  A wrapper for ``check_array`` for 2D arrays

    Parameters
    ----------
    X : array-like, shape=(n_samples, n_features)
        The exogenous array. If a Pandas frame, a Pandas frame will be returned
        as well. Otherwise, a numpy array will be returned.

    dtype : string, type or None (default=np.float64)
        Data type of result. If None, the dtype of the input is preserved.
        If "numeric", dtype is preserved unless array.dtype is object.

    copy : bool, optional (default=True)
        Whether a forced copy will be triggered. If copy=False, a copy might
        still be triggered by a conversion.

    force_all_finite : bool, optional (default=True)
        Whether to raise an error on np.inf and np.nan in an array. The
        possibilities are:

        - True: Force all values of array to be finite.
        - False: accept both np.inf and np.nan in array.

    Returns
    -------
    X : pd.DataFrame or np.ndarray, shape=(n_samples, n_features)
        Either a 2-d numpy array or pd.DataFrame
    Úndimr   z Must be a 2-d array or dataframez$Found non-finite values in dataframeT)r"   r%   r$   r#   )Úhasattrr.   Ú
ValueErrorr   r   r(   ÚastypeÚapplyr   ÚisfiniteÚanyr   r'   r   )ÚXr%   r$   r#   s       r   r   r   É   s£   € ô: ˆq�&Ô˜aŸf™f¨škÜÐ;Ó<Ð<ä�!”R—\‘\Ô"á�EÐ%Ø—‘˜“ˆAÙ !§'¡'¬"¯+©+Ó"6Ð!6× ;Ñ ;Ó =× AÑ AÔ CÜÐCÓDÐDØˆô ×ÑØ	ØÜØØ)ôð r   c                 óT   — | j                   d   }t        ||«      }| || | d ||z
   z
  S )Nr   ©ÚshapeÚmin)r   ÚlagÚns      r   Ú_diff_vectorr<   û   s5   € à	�‰�‰
€AÜ
ˆa�‹+€CØˆS�!ˆ9�q˜˜1˜S™5�zÑ!Ð!r   c                 ól   — | j                   \  }}t        ||«      }| ||…d d …f   | d ||z
  …d d …f   z
  S )Nr7   )r   r:   ÚmÚ_s       r   Ú_diff_matrixr@     sA   € à�7‰7�D€A€qÜ
ˆa�‹+€CØˆS�!ˆV’QˆY‰<˜!˜G˜a ™e˜G¢Q˜J™-Ñ'Ð'r   c                 ó  — t        d„ ||fD «       «      rt        d«      ‚t        j                  | dt        d¬«      } | j
                  dk(  rt        nt        }| }t        |«      D ]  } |||«      }|j                  d   rŒ|c S  |S )aÑ  Difference an array.

    A python implementation of the R ``diff`` function [1]. This computes lag
    differences from an array given a ``lag`` and ``differencing`` term.

    If ``x`` is a vector of length :math:`n`, ``lag=1`` and ``differences=1``,
    then the computed result is equal to the successive differences
    ``x[lag:n] - x[:n-lag]``.

    Examples
    --------
    Where ``lag=1`` and ``differences=1``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff(x, 1, 1)
    array([ -6.,  -2.,   7.,  25.], dtype=float32)

    Where ``lag=1`` and ``differences=2``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff(x, 1, 2)
    array([  4.,   9.,  18.], dtype=float32)

    Where ``lag=3`` and ``differences=1``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff(x, 3, 1)
    array([ -1.,  30.], dtype=float32)

    Where ``lag=6`` (larger than the array is) and ``differences=1``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff(x, 6, 1)
    array([], dtype=float32)

    For a 2d array with ``lag=1`` and ``differences=1``:

    >>> import numpy as np
    >>>
    >>> x = np.arange(1, 10).reshape((3, 3)).T
    >>> diff(x, 1, 1)
    array([[ 1.,  1.,  1.],
           [ 1.,  1.,  1.]], dtype=float32)

    Parameters
    ----------
    x : array-like, shape=(n_samples, [n_features])
        The array to difference.

    lag : int, optional (default=1)
        An integer > 0 indicating which lag to use.

    differences : int, optional (default=1)
        An integer > 0 indicating the order of the difference.

    Returns
    -------
    res : np.ndarray, shape=(n_samples, [n_features])
        The result of the differenced arrays.

    References
    ----------
    .. [1] https://stat.ethz.ch/R-manual/R-devel/library/base/html/diff.html
    c              3   ó&   K  — | ]	  }|d k  –— Œ y­w©r   N© ©Ú.0Úvs     r   ú	<genexpr>zdiff.<locals>.<genexpr>J  ó   è ø€ Ò
-�Qˆ1ˆq�5Ñ
-ùó   ‚ú3lag and differences must be positive (> 0) integersF)r"   r%   r$   r   r   )
r4   r0   r   r'   r   r.   r<   r@   Úranger8   )r   r:   ÚdifferencesÚfunÚresÚis         r   r   r   	  sˆ   € ôB Ñ
-˜3 Ð,Ô
-Ô-ÜÐNÓOÐOä×Ñ˜! u´EÀÔF€AØŸ&™& Aš+�,¬<€CØ
€Cô �;Óò ˆÙ�#�s‹mˆà�y‰y˜‹|ØŠJð	ð €Jr   c                 óT  — |€t        j                  ||z  t        ¬«      }n4t        |t        ddd¬«      }|j                  d   ||z  k7  rt        d«      ‚|dk(  r!t        j                  t        | ||¬«      «      S t        t        | ||dz
  t        ||d¬«      ¬	«      |d|d | ¬	«      S )
N©r%   F)r%   r$   r#   r+   r   z#"xi" does not have the right lengthr   )r   Úxir:   )r   r:   rM   ©r   r:   rM   rS   )
r   Úzerosr   r
   r8   Ú
IndexErrorr   r   r   r   rT   s       r   Ú_diff_inv_vectorrW   [  s¶   € ð 
€zÜ�X‰X�c˜KÑ'¬uÔ5‰äØÜØØ"Ø!ô
ˆð �8‰8�A‰;˜# Ñ+Ò+ÜÐBÓCÐCà�aÒÜ�z‰zœ,¨¨r°sÔ;Ó<Ð<ô
 Ü˜ °¸q±Ü ¨¸!Ô<ô>àØØ�$�3ˆxô
ð 	
r   c           	      óš  — | j                   \  }}t        j                  |||z  z   |ft        ¬«      }|dk\  r“|€!t        j                  ||z  |ft        ¬«      }n=t	        j
                  |t        ddd¬«      }|j                   ||z  |fk7  rt        d«      ‚t        |«      D ]%  }t        | d d …|f   |||d d …|f   «      |d d …|f<   Œ' |S )NrR   r   FT©r%   r$   r#   r"   z""xi" does not have the right shape)	r8   r   rU   r   r   r'   rV   rL   rW   )r   r:   rM   rS   r;   r>   r*   rP   s           r   Ú_diff_inv_matrixrZ   {  sÝ   € Ø�7‰7�D€A€qÜ
�‰�!�c˜KÑ'Ñ'¨Ð+´5Ô9€AàˆA‚vàˆ:Ü—‘˜3 Ñ,¨aÐ0¼Ô>‰Bä×"Ñ"ØÜØØ!&ØôˆBð �x‰x˜C +Ñ-¨qÐ1Ò1Ü Ð!EÓFÐFô �q“ò 	LˆAÜ& qª¨A¨¡w°°[À"ÂQÈÀTÁ(ÓKˆAŠa�ˆdŠGð	Lð €Hr   c                 ó  — t        j                  | t        ddd¬«      } t        d„ ||fD «       «      rt	        d«      ‚| j
                  dk(  rt        | |||«      S | j
                  dk(  rt        | |||«      S t	        d«      ‚)a–  
    Inverse the difference of an array.

    A python implementation of the R ``diffinv`` function [1]. This computes
    the inverse of lag differences from an array given a ``lag``
    and ``differencing`` term.

    If ``x`` is a vector of length :math:`n`, ``lag=1`` and ``differences=1``,
    then the computed result is equal to the cumulative sum plus left-padding
    of zeros equal to ``lag * differences``.

    Examples
    --------
    Where ``lag=1`` and ``differences=1``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff_inv(x, 1, 1)
    array([ 0., 10., 14., 16., 25., 59.])

    Where ``lag=1`` and ``differences=2``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff_inv(x, 1, 2)
    array([  0.,   0.,  10.,  24.,  40.,  65., 124.])

    Where ``lag=3`` and ``differences=1``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff_inv(x, 3, 1)
    array([ 0.,  0.,  0., 10.,  4.,  2., 19., 38.])

    Where ``lag=6`` (larger than the array is) and ``differences=1``:

    >>> x = c(10, 4, 2, 9, 34)
    >>> diff_inv(x, 6, 1)
    array([ 0.,  0.,  0.,  0.,  0.,  0., 10.,  4.,  2.,  9., 34.])

    For a 2d array with ``lag=1`` and ``differences=1``:

    >>> import numpy as np
    >>>
    >>> x = np.arange(1, 10).reshape((3, 3)).T
    >>> diff_inv(x, 1, 1)
    array([[ 0.,  0.,  0.],
           [ 1.,  4.,  7.],
           [ 3.,  9., 15.],
           [ 6., 15., 24.]])

    Parameters
    ----------
    x : array-like, shape=(n_samples, [n_features])
        The array to difference.

    lag : int, optional (default=1)
        An integer > 0 indicating which lag to use.

    differences : int, optional (default=1)
        An integer > 0 indicating the order of the difference.

    Returns
    -------
    res : np.ndarray, shape=(n_samples, [n_features])
        The result of the inverse of the difference arrays.

    References
    ----------
    .. [1] https://stat.ethz.ch/R-manual/R-devel/library/stats/html/diffinv.html
    FrY   c              3   ó&   K  — | ]	  }|d k  –— Œ y­wrC   rD   rE   s     r   rH   zdiff_inv.<locals>.<genexpr>ä  rI   rJ   rK   r   r   z9only vector and matrix inverse differencing are supported)r   r'   r   r4   r0   r.   rW   rZ   rT   s       r   r   r   •  s�   € ôJ 	×ÑØ	ÜØØØô	€Aô Ñ
-˜3 Ð,Ô
-Ô-ÜÐNÓOÐOà‡v�v�‚{Ü  3¨°RÓ8Ð8Ø	
�‰�1ŠÜ  3¨°RÓ8Ð8Ü
ð %ó &ð &r   c                 ó<   — t        | t        «      ryt        | d«      S )aå  Test a variable for iterability.

    Determine whether an object ``x`` is iterable. In Python 2, this
    was as simple as checking for the ``__iter__`` attribute. However, in
    Python 3, strings became iterable. Therefore, this function checks for the
    ``__iter__`` attribute, returning True if present (except for strings,
    for which it will return False).

    Parameters
    ----------
    x : str, iterable or object
        The object in question.

    Examples
    --------
    Strings and other objects are not iterable:

    >>> x = "not me"
    >>> y = 123
    >>> any(is_iterable(v) for v in (x, y))
    False

    Tuples, lists and other structures with ``__iter__`` are:

    >>> x = ('a', 'tuple')
    >>> y = ['a', 'list']
    >>> all(is_iterable(v) for v in (x, y))
    True

    This even applies to numpy arrays:

    >>> import numpy as np
    >>> is_iterable(np.arange(10))
    True

    Returns
    -------
    isiter : bool
        True if iterable, else False.
    FÚ__iter__)r   Ústrr/   )r   s    r   r   r   ï  s   € ôR �!”SÔØÜ�1�jÓ!Ð!r   )r   r   )r   r   N)Úsklearn.utilsr   r   Únumpyr   Úpandasr   Úcompatr   Ú_arrayr   Ú__all__r   r	   r
   r   r<   r@   r   rW   rZ   r   r   rD   r   r   ú<module>rf      sv   ðõ .ã Û å Ý  ò€ò(6òVEHðT Ø	ØØó9ðx  D¸4ó /òd"ò(óOòd
ò@ó4W&ót+"r   