
    Eg'              	      T   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 dS )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d
S )DeepChainMapz~
    Variant of ChainMap that allows direct updates to inner scopes.

    Only works when all passed mapping are mutable.
    keyr	   valuer
   returnNonec                R    | j         D ]}||v r|||<    d S || j         d         |<   d S )Nr   )maps)selfr   r   mappings       R/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/core/computation/scope.py__setitem__zDeepChainMap.__setitem__!   sI    y 	 	Gg~~$  "	!S    c                H    | j         D ]}||v r||=  dS t          |          )z\
        Raises
        ------
        KeyError
            If `key` doesn't exist.
        N)r   KeyError)r   r   r   s      r   __delitem__zDeepChainMap.__delitem__(   s?     y 	 	Gg~~CL  smmr   N)r   r	   r   r
   r   r   )r   r	   r   r   )__name__
__module____qualname____doc__r   r    r   r   r   r      sF         " " " "     r   r   r   levelintr   Scopec                0    t          | dz   ||||          S )z.Ensure that we are grabbing the correct scope.   )global_dict
local_dict	resolverstarget)r"   )r    r%   r&   r'   r(   s        r   ensure_scoper)   6   s.     	   r   strc                f    	 t          |           }n# t          $ r | }Y nw xY wt          |          S )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   	_replacerr1   C   sF    A    u::s    !!c                    t          j        dt          |                     }d                    d |D                       S )z,Return the padded hexadecimal id of ``obj``.z@P c                ,    g | ]}t          |          S r   )r1   ).0r/   s     r   
<listcomp>z_raw_hex_id.<locals>.<listcomp>W   s    111QIaLL111r   )structpackidjoin)objpackeds     r   _raw_hex_idr=   S   s<     [r#ww''F7711&111222r   TF)r   datetimeTrueFalselisttupleinfInfc                r    t                      }t          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)r;   sios     r   _get_pretty_stringrJ   f   s0     **C
M#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d
S )*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'   tempsr!   r    r   rL   r'   dictrM   Nr   r   r   c                ^   |dz   | _         t          t                                                    | _        || _        t          |t                    rL| j                            |j                   |j        |j        | _        | 	                    |j                    t          j        | j                   }	 | j                            ||n|j                                                  }t          |          | _        t          |t                    sI| j                            ||n|j                                                  }t          |          | _        ~n# ~w xY wt          |t                    r|t          |j        j                  z  }t          | | _        i | _        d S )Nr$   )r    r   DEFAULT_GLOBALScopyrL   r(   
isinstancer"   update_updatesys	_getframe	new_child	f_globalsf_localsrB   r'   r   rM   )	r   r    r%   r&   r'   r(   framescope_globalscope_locals	            r   __init__zScope.__init__   s    QY
 "/"6"6"8"899
j%(( 	+Jj./// ,(/LL)***dj))	  :// + 7U_RRTT L &l33DJj%00 7"j22#-#9ZZu~SSUU  *+66
IIII j%(( 	:z38999I%y1


s   8B'E! !E$r*   c                   t          t          | j                                                            }t          t          | j                                                            }t          |           j         d| d| dS )Nz(scope=z, resolvers=))rJ   rA   rL   keysr'   typer   )r   
scope_keysres_keyss      r   __repr__zScope.__repr__   sn    'TZ__->->(?(?@@
%d4>+>+>+@+@&A&ABBt**%QQjQQhQQQQr   boolc                D    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
        )re   lenr'   r   s    r   has_resolverszScope.has_resolvers   s     C''(((r   r   is_localc                    	 |r| j         |         S | j        r| j        |         S |s| j        rJ | j         |         S # t          $ r4 	 | 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)rL   ri   r'   r   rM   r   )r   r   rj   errs       r   resolvezScope.resolve   s    "	E 'z#& ! +~c**  :(:::::c?" 	E 	E 	EE z#&&& E E E,S(;;DE	Es5   = = = 
A;AA;
A7!A22A77A;old_keynew_keyc                    | j         r| j        j        | j        j        z   }n| j        j        }|                    | j                   |D ]}||v r|||<    dS dS )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)ri   r'   r   rL   appendrM   )r   rn   ro   	new_valuer   r   s         r   swapkeyzScope.swapkey   s{      	#>&8DD:?DDJ 	 	G'!!#,  "	 	r   scopes	list[str]c                    t          j        ||          }|D ]S\  }\  }}}}}}	 t          |d|           }t          | j                            |                    | _        ~N# ~w xY wdS )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   rL   rW   )r   stackrt   	variablesrL   rZ   _ds           r   	_get_varszScope._get_vars  s     %fe44	-6 	 	)E)E1aAqE<<<00)$**>*>q*A*ABB

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

        Parameters
        ----------
        level : int
        r$   Nlocals)rt   )inspectr{   r   )r   r    slr{   s       r   rT   zScope._update&  si     QY
 	 NN5":xjN999aaa%%%aaa%s    A 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.
        r}   )ra   r   ntempsr=   rM   )r   r   names      r   add_tmpzScope.add_tmp:  sm     u++&JJJJ{47H7HJJ 4:%%%% 
4tz!!!! r   c                *    t          | j                  S )z/The number of temporary variables in this scope)rg   rM   rh   s    r   r   zScope.ntempsR  s     4:r   c                X    | 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.
        )rM   r'   r   rL   r   )r   r   s     r   
full_scopezScope.full_scopeW  s+     
|dn11DJOCT""r   NNr   N)r    r!   r   r   r   r*   )r   re   )r   r*   rj   re   )N)rn   r*   ro   r*   r   r   )rt   ru   r   r   )r   r!   )r   r   )r   r   r   r   	__slots____annotations__r]   rd   propertyri   rm   rs   r   rT   r   r   r   r   r   r   r"   r"   y   s_         ( CBBIJJJKKK SW& & & & &PR R R R
 ) ) ) X)%E %E %E %EN    2   .       (   0    X # # # X# # #r   r   )r    r!   r   r"   r   )!r   
__future__r   collectionsr   r>   r   ior   rx   rG   r7   rU   typingr   numpynppandas._libs.tslibsr   pandas.errorsr   r	   r
   r   r)   r1   r=   rA   rB   rC   rP   rJ   r"   r   r   r   <module>r      s    # " " " " "                           



           ) ) ) ) ) ) 0 0 0 0 0 0genngenn    8CH%   : IM
 
 
 
 
    3 3 3 3 !66	 	   &j# j# j# j# j# j# j# j# j# j#r   