
    Owg'              	      X   d Z ddlmZ ddlmZ ddlZddlZddlmZ ddl	Z	ddl
Z
ddlZddlZddlmZ ddlZddlmZ ddlmZ  ed	      Z ed
      Z G d deeef         Z	 d	 	 	 ddZddZddZeej
                  ddeeej:                  ej:                  dZddZ G d d      Z y)z
Module for scope operations
    )annotations)ChainMapN)StringIO)TypeVar)	Timestamp)UndefinedVariableError_KT_VTc                       e Zd ZdZddZddZy)DeepChainMapz~
    Variant of ChainMap that allows direct updates to inner scopes.

    Only works when all passed mapping are mutable.
    c                `    | j                   D ]  }||v s|||<    y  || j                   d   |<   y )Nr   )maps)selfkeyvaluemappings       T/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/computation/scope.py__setitem__zDeepChainMap.__setitem__!   s<    yy 	Gg~$	 "		!S    c                L    | j                   D ]  }||v s||=  y t        |      )z\
        Raises
        ------
        KeyError
            If `key` doesn't exist.
        N)r   KeyError)r   r   r   s      r   __delitem__zDeepChainMap.__delitem__(   s4     yy 	Gg~CL	 smr   N)r   r	   r   r
   returnNone)r   r	   r   r   )__name__
__module____qualname____doc__r   r    r   r   r   r      s    "r   r   Scopec                (    t        | dz   ||||      S )z.Ensure that we are grabbing the correct scope.   )global_dict
local_dict	resolverstarget)r    )levelr#   r$   r%   r&   s        r   ensure_scoper(   6   s$     	 r   c                f    	 t        |       }t        |      S # t        $ r | }Y t        |      S w xY w)z
    Replace a number with its hexadecimal representation. Used to tag
    temporary variables with their calling scope's id.
    )ord	TypeErrorhex)xhexins     r   	_replacerr/   C   s<    A
 u:	  u:	s    00c                    t        j                  dt        |             }dj                  |D cg c]  }t	        |       c}      S c c}w )z,Return the padded hexadecimal id of ``obj``.z@P )structpackidjoinr/   )objpackedr-   s      r   _raw_hex_idr8   S   s9     [[r#w'F77&1QIaL1221s   ATF)r   datetimeTrueFalselisttupleinfInfc                d    t               }t        j                  | |       |j                         S )z
    Return a prettier version of obj.

    Parameters
    ----------
    obj : object
        Object to pretty print

    Returns
    -------
    str
        Pretty print object repr
    )stream)r   pprintgetvalue)r6   sios     r   _get_pretty_stringrE   f   s%     *C
MM#c"<<>r   c                      e Zd ZU dZg dZded<   ded<   ded<   ded	<   	 d	 	 	 ddZddZedd       Z	ddZ
dddZddZddZddZedd       Zedd       Zy
)r    a  
    Object to hold scope, with a few bells to deal with some custom syntax
    and contexts added by pandas.

    Parameters
    ----------
    level : int
    global_dict : dict or None, optional, default None
    local_dict : dict or Scope or None, optional, default None
    resolvers : list-like or None, optional, default None
    target : object

    Attributes
    ----------
    level : int
    scope : DeepChainMap
    target : object
    temps : dict
    )r'   scoper&   r%   tempsintr'   r   rG   r%   dictrH   Nc                Z   |dz   | _         t        t        j                               | _        || _        t        |t              r]| j                  j                  |j                         |j
                  |j
                  | _        | j                  |j                          t        j                  | j                         }	 | j                  j                  ||n|j                  j                               }t        |      | _        t        |t              sG| j                  j                  ||n|j                  j                               }t        |      | _        ~t        |t              r"|t        |j                   j"                        z  }t        | | _        i | _        y # ~w xY w)Nr"   )r'   r   DEFAULT_GLOBALScopyrG   r&   
isinstancer    update_updatesys	_getframe	new_child	f_globalsf_localsr=   r%   r   rH   )	r   r'   r#   r$   r%   r&   framescope_globalscope_locals	            r   __init__zScope.__init__   sS    QY
 "/"6"6"89
j%(JJj../  ,(//LL))*djj)	  ::// + 7U__RRTL &l3DJj%0"jj22#-#9Zu~~SSU *+6
 j%(z338899I%y1
 s   BF' 'F*c                    t        t        | j                  j                                     }t        t        | j                  j                                     }t        |       j                   d| d| dS )Nz(scope=z, resolvers=))rE   r<   rG   keysr%   typer   )r   
scope_keysres_keyss      r   __repr__zScope.__repr__   s\    'TZZ__->(?@
%d4>>+>+>+@&ABt*%%&gj\hZqQQr   c                >    t        t        | j                              S )z
        Return whether we have any extra scope.

        For example, DataFrames pass Their columns as resolvers during calls to
        ``DataFrame.eval()`` and ``DataFrame.query()``.

        Returns
        -------
        hr : bool
        )boollenr%   r   s    r   has_resolverszScope.has_resolvers   s     C'((r   c                   	 |r| j                   |   S | j                  r| j                  |   S |s| j                  rJ | j                   |   S # t        $ r1 	 | j                  |   cY S # t        $ r}t        ||      |d}~ww xY ww xY w)a  
        Resolve a variable name in a possibly local context.

        Parameters
        ----------
        key : str
            A variable name
        is_local : bool
            Flag indicating whether the variable is local or not (prefixed with
            the '@' symbol)

        Returns
        -------
        value : object
            The value of a particular variable
        N)rG   re   r%   r   rH   r   )r   r   is_localerrs       r   resolvezScope.resolve   s    "	Ezz#& !!~~c**  (:(:::::c?" 	EE zz#& E,S(;DE	Es9   A A A 	BA(%B(	B1A>>BBc                    | j                   r.| j                  j                  | j                  j                  z   }n| j                  j                  }|j	                  | j
                         |D ]  }||v s|||<    y y)a]  
        Replace a variable name, with a potentially new value.

        Parameters
        ----------
        old_key : str
            Current variable name to replace
        new_key : str
            New variable name to replace `old_key` with
        new_value : object
            Value to be replaced along with the possible renaming
        N)re   r%   r   rG   appendrH   )r   old_keynew_key	new_valuer   r   s         r   swapkeyzScope.swapkey   sj     >>&&8D::??DDJJ 	G'!#, 	r   c                    t        j                  ||      }|D ]F  \  }\  }}}}}}	 t        |d|       }t        | j                  j                  |            | _        ~H y# ~w xY w)a  
        Get specifically scoped variables from a list of stack frames.

        Parameters
        ----------
        stack : list
            A list of stack frames as returned by ``inspect.stack()``
        scopes : sequence of strings
            A sequence containing valid stack frame attribute names that
            evaluate to a dictionary. For example, ('locals', 'globals')
        f_N)	itertoolsproductgetattrr   rG   rS   )r   stackscopes	variablesrG   rV   _ds           r   	_get_varszScope._get_vars  su     %%fe4	-6 	)E)E1aAqERw<0)$***>*>q*AB

 	 s   8A##A&c                    |dz   }t        j                         }	 | j                  |d| dg       |dd= ~y# |dd= ~w xY w)z
        Update the current scope by going back `level` levels.

        Parameters
        ----------
        level : int
        r"   Nlocals)rv   )inspectru   rz   )r   r'   slru   s       r   rP   zScope._update&  sJ     QY
 	 NN5":xjN9a%a%s	   9 Ac                    t        |      j                   d| j                   dt        |        }|| j                  vsJ || j                  |<   || j                  v sJ |S )a#  
        Add a temporary variable to the scope.

        Parameters
        ----------
        value : object
            An arbitrary object to be assigned to a temporary variable.

        Returns
        -------
        str
            The name of the temporary variable created.
        rx   )r]   r   ntempsr8   rH   )r   r   names      r   add_tmpzScope.add_tmp:  sj     u+&&'qQ{47H6IJ 4::%%% 

4tzz!!! r   c                ,    t        | j                        S )z/The number of temporary variables in this scope)rc   rH   rd   s    r   r   zScope.ntempsR  s     4::r   c                    | j                   g| j                  j                  z   | j                  j                  z   }t	        | S )z
        Return the full scope for use with passing to engines transparently
        as a mapping.

        Returns
        -------
        vars : DeepChainMap
            All variables in this scope.
        )rH   r%   r   rG   r   )r   r   s     r   
full_scopezScope.full_scopeW  s6     

|dnn111DJJOOCT""r   NNr   N)r'   rI   r   r   r   str)r   rb   )r   r   rg   rb   )N)rl   r   rm   r   r   r   )rv   z	list[str]r   r   )r   rI   )r   r   )r   r   r   r   	__slots____annotations__rY   r`   propertyre   ri   ro   rz   rP   r   r   r   r   r   r   r    r    y   s    ( CIJK SW&&	&PR
 ) )%EN2. (0   # #r   r   )r'   rI   r   r    r   )!r   
__future__r   collectionsr   r9   r}   ior   rr   rB   r2   rQ   typingr   numpynppandas._libs.tslibsr   pandas.errorsr   r	   r
   r   r(   r/   r8   r<   r=   r>   rL   rE   r    r   r   r   <module>r      s    #         
   ) 0enen8CH% : IM



 3 !!6666	&j# j#r   