
    Dj9                         d dl mZmZ d dlmZ d dlZg dZ G d d      Z e       Z G d de      Z	 G d	 d
e      Z
 G d de
      Z G d d      Zy)    )ABCabstractmethod)EnumN)AbstractContextContextStoreContextTypec                       e Zd ZdZi Zy)_CtxSingletonz,Singleton class to store context informationN)__name__
__module____qualname____doc__store     [C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\pmdarima/arima/_context.pyr
   r
      s
    6Er   r
   c                       e Zd ZdZdZdZy)r   zaContext Type Enumeration

    An enumeration of Context Types known to :class:`ContextStore`
    r      N)r   r   r   r   EMPTYSTEPWISEr   r   r   r   r      s     EHr   r   c                   h    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zed        Zy)r   a  An abstract context manager to store execution context.

    A generic, re-entrant, reusable context manager to store
    execution context. Has helper methods to iterate over the context info
    and provide a string representation of the context info.
    c                 |    |r-|j                         D ci c]  \  }}|	|| c}}| _        y i | _        y c c}}w N)itemsprops)selfkwargskvs       r   __init__zAbstractContext.__init__(   s:      (.||~Gtq!adG
 	
Gs   
88c                 .    t         j                  |        y r   )r   _add_contextr   s    r   	__enter__zAbstractContext.__enter__.   s    !!$'r   c                 .    t         j                  |        y r   )r   _remove_context)r   exc_typeexc_valexc_tbs       r   __exit__zAbstractContext.__exit__1   s    $$T*r   c                 @    || j                   v r| j                   |   S dS )z@Lets us access, e.g., ``ctx.max_steps`` even if not in a contextNr   r   items     r   __getattr__zAbstractContext.__getattr__4   s!    #'4::#5tzz$?4?r   c                     || j                   v S r   r,   r-   s     r   __contains__zAbstractContext.__contains__8   s    tzz!!r   c                 @    || j                   v r| j                   |   S d S r   r,   r-   s     r   __getitem__zAbstractContext.__getitem__;   s!    #'4::#5tzz$?4?r   c                 ,    t        | j                        S r   )iterr   r#   s    r   __iter__zAbstractContext.__iter__>   s    DJJr   c                 6    | j                   j                         S r   )r   keysr#   s    r   r8   zAbstractContext.keysA   s    zz  r   c                 6    | j                   j                         S r   )r   valuesr#   s    r   r:   zAbstractContext.valuesD   s    zz  ""r   c                 6    | j                   j                         S r   )r   r   r#   s    r   r   zAbstractContext.itemsG   s    zz!!r   c                 ^    t        |      }|j                  | j                         || _        y r   )dictupdater   )r   otherparent_propss      r   r>   zAbstractContext.updateJ   s$    E{DJJ'!
r   c                 6    | j                   j                         S r   )r   __repr__r#   s    r   rB   zAbstractContext.__repr__O   s    zz""$$r   c                      y)zGet the ContextTypeNr   r#   s    r   get_typezAbstractContext.get_typeR   s    r   N)r   r   r   r   r    r$   r*   r/   r1   r3   r6   r8   r:   r   r>   rB   r   rD   r   r   r   r   r   !   sY    (+@"@ !#""
% " "r   r   c                   (     e Zd ZdZ fdZd Z xZS )_emptyContextz$An empty context for convenience usec                 *    t         t        |           y r   )superrF   r    )r   	__class__s    r   r    z_emptyContext.__init__Z   s    mT+-r   c                 "    t         j                  S )z)Indicates we are not in a context manager)r   r   r#   s    r   rD   z_emptyContext.get_type]   s       r   )r   r   r   r   r    rD   __classcell__)rI   s   @r   rF   rF   W   s    ..!r   rF   c                   `    e Zd ZdZed        Zed        Zed        Zed        Zed        Z	y)r   zA class to wrap access to the global context store

    This class hosts static methods to wrap access to and encapsulate the
    singleton content store instance
    c                     t        | t              st        d      | t        j                  v r5t        t        j                  |          dkD  rt        j                  |    d   S y)a<  Returns most recently added instance of given Context Type

        Parameters
        ----------
        context_type : ContextType
            Context type to retrieve from the store

        Returns
        -------
        res : AbstractContext
            An instance of AbstractContext subclass or None
        z/context_type must be an instance of ContextTyper   N)
isinstancer   
ValueError_ctxr   lencontext_types    r   get_contextzContextStore.get_contexth   sT     ,4NOO4::%#djj.F*G!*K::l+B// r   c                 8    t         j                  |       }|r|S |S )a  Returns most recent instance of given Context Type or default

        Parameters
        ----------
        context_type : ContextType
            Context type to retrieve from the store

        default : AbstractContext
            Value to return in case given context does not exist

        Returns
        -------
        ctx : AbstractContext
            An instance of AbstractContext subclass or default
        )r   rU   )rT   defaultctxs      r   get_or_defaultzContextStore.get_or_default   s!    " &&|4s&w&r   c                 >    t         j                  | t                     S )a;  Returns recent instance of given Context Type or an empty context

        Parameters
        ----------
        context_type : ContextType
            Context type to retrieve from the store

        Returns
        -------
        res : AbstractContext
            An instance of AbstractContext subclass
        )r   rY   rF   rS   s    r   get_or_emptyzContextStore.get_or_empty   s     **<IIr   c                    t        | t              st        d      | j                         }|t        j
                  vr%t        j                         t        j
                  |<   t        t        j
                  |         dkD  r't        j
                  |   d   }| j                  |       t        j
                  |   j                  |        y)aD  Add given instance of AbstractContext subclass to context store

        This private member is only called by ``AbstractContext.__init__()``

        if the given ctx is nested, merge parent context, to support
        following usage:

        Examples
        --------
        >>> from pmdarima.arima import StepwiseContext, auto_arima
        >>> with StepwiseContext(max_steps=10):
        ...     with StepwiseContext(max_dur=30):
        ...         auto_arima(samp,...)

        This is identical to:
        >>> from contextlib import ExitStack
        ... stack = ExitStack()
        ... outer_ctx = StepwiseContext(max_steps=10)
        ... inner_ctx = StepwiseContext(max_dur=30)
        ... stack.enter_context(outer_ctx)
        ... stack.enter_context(inner_ctx)
        ... with stack:
        ...     auto_arima(samp, ...)


        However, the nested context can override parent context. In the
        example below, the effective context for inner most call to
        ``auto_arima(...)`` is: ``max_steps=15, max_dur=30``. The effective
        context for the second call to ``auto_arima(..)`` is: ``max_steps=10``

        >>> with StepwiseContext(max_steps=10):
        ...     with StepwiseContext(max_steps=15, max_dur=30):
        ...         auto_arima(samp,...)
        ...
        ...     auto_arima(samp,...)
        -ctx must be be an instance of AbstractContextr   rN   N)rO   r   rP   rD   rQ   r   collectionsdequerR   r>   append)rX   rT   parents      r   r"   zContextStore._add_context   s    L #/LMM ||~tzz)'2'8'8':DJJ|$ tzz,'(1,ZZ-b1FJJv

< '',r   c                     t        | t              st        d      | j                         }|t        j
                  vst        t        j
                  |         dk(  ryt        j
                  |   j                          y)zRemoves the most recently added context of given Context Type

        This private member is only used by ``AbstractContext``
        :param ctx:
        :return: None
        r]   r   N)rO   r   rP   rD   rQ   r   rR   pop)rX   rT   s     r   r&   zContextStore._remove_context   s_     #/LMM||~tzz)DJJ|,-2

< $$&r   N)
r   r   r   r   staticmethodrU   rY   r[   r"   r&   r   r   r   r   r   b   sn    
  , ' '& J J 2- 2-h ' 'r   r   )abcr   r   enumr   r^   __all__r
   rQ   r   r   rF   r   r   r   r   <module>rh      sY    $  
< 
 $ 3"c 3"l!O !G' G'r   