
    `Vg%              	         d 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ZddlmZ ddlmZ ddlmZ 	 d	 	 	 dd	Zdd
ZddZeej                  ddeeej0                  ej0                  dZddZ G d d      Zy)z
Module for scope operations
    )annotationsN)StringIO)	Timestamp)DeepChainMap)UndefinedVariableError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   kwargss         ^/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/computation/scope.pyensure_scoper      s$     	     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   "   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_idr#   2   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)r!   sios     r   _get_pretty_stringr0   E   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   r2   r   dictr3   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copyr2   r   
isinstancer   update_updatesys	_getframe	new_child	f_globalsf_localsr(   r   mapsr3   )	selfr   r   r   r   r   framescope_globalscope_locals	            r   __init__zScope.__init__s   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=))r0   r'   r2   keysr   type__name__)rB   
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   rB   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)r2   rS   r   KeyErrorr3   r   )rB   key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)rS   r   rA   r2   appendr3   )rB   old_keynew_key	new_valuerA   mappings         r   swapkeyzScope.swapkey   sj     >>&&8D::??DDJJ 	G'!#, 	r   c                    t        j                  ||      }|D ]F  \  }\  }}}}}}	 t        |d|z         }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   r2   r>   )rB   stackscopes	variablesr2   rC   _ds           r   	_get_varszScope._get_vars   ss     %%fe4	-6 	)E)E1aAqE4%<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)rg   )inspectrf   rk   )rB   r   slrf   s       r   r;   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.
        ri   )rJ   rK   ntempsr#   r3   )rB   value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)rQ   r3   rR   s    r   rq   zScope.ntemps1  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.
        )r3   r   rA   r2   r   )rB   rA   s     r   
full_scopezScope.full_scope6  sA      ZZLnn!!"jjoo 	
 T""r   NN N)r   r4   returnNonerz   str)rz   rP   )rV   r}   rW   rP   )N)r\   r}   r]   r}   rz   r{   )rg   z	list[str]rz   r{   )rz   r4   )rz   r   )rK   
__module____qualname____doc__	__slots____annotations__rF   rN   propertyrS   rY   r`   rk   r;   rt   rq   rw   ry   r   r   r   r   X   s    ( CIJK SW&&	&PR
 ) )%EN2. (0   # #r   rx   )r   r4   rz   r   r|   )r   
__future__r   r$   rn   ior   rc   r-   r   r<   numpynppandas._libs.tslibsr   pandas.compat.chainmapr   pandas.errorsr   r   r   r#   r'   r(   r)   r7   r0   r   ry   r   r   <module>r      s    #       
  ) / 0 IM



 3 !!6666	&r# r#r   