HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/core/computation/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/core/computation/__pycache__/scope.cpython-36.pyc
3

���h�#�	@s�dZddlZddlZddlmZddlZddlZddlZddlZddl	m
Z
ddlZddl
mZddlmZddfdfedd�d	d
�Zed�dd
�Zed�dd�Zeejddeeejejd�Zed�dd�ZGdd�d�ZdS)z
Module for scope operations
�N)�StringIO)�List)�	Timestamp)�DeepChainMap�Scope)�level�returncKst|d||||d�S)z.Ensure that we are grabbing the correct scope.�)�global_dict�
local_dict�	resolvers�target)r)rr
rrr
�kwargs�r�?/tmp/pip-build-5_djhm0z/pandas/pandas/core/computation/scope.py�ensure_scopesr)rcCs.yt|�}Wntk
r$|}YnXt|�S)z�
    Replace a number with its hexadecimal representation. Used to tag
    temporary variables with their calling scope's id.
    )�ord�	TypeError�hex)�xZhexinrrr�	_replacer!s

rcCs$tjdt|��}djdd�|D��S)z,Return the padded hexadecimal id of ``obj``.z@P�css|]}t|�VqdS)N)r)�.0rrrr�	<genexpr>5sz_raw_hex_id.<locals>.<genexpr>)�struct�pack�id�join)�obj�packedrrr�_raw_hex_id1sr TF)r�datetime�True�False�list�tuple�infZInfcCst�}tj||d�|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�siorrr�_get_pretty_stringDsr+c@s�eZdZdZdddddgZddfdfdd	�Zed
�dd�Zee	d
�d
d��Z
ee	d�dd�Zd!eed�dd�Ze
ed�dd�Zed�dd�Zed
�dd�Zeed
�dd��Zedd ��ZdS)"ra�
    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�tempsNcCs�|d|_ttj��|_||_t|t�rT|jj|j�|jdk	rH|j|_|j	|j�t
j|j�}z>|jj|pp|j
j��|_t|t�s�|jj|p�|jj��|_Wd~Xt|t�r�|t|jj�7}t|�|_i|_dS)Nr	)rr�_DEFAULT_GLOBALS�copyr,r
�
isinstancer�update�_update�sys�	_getframe�	new_child�	f_globals�f_localsr%r�mapsr-)�selfrr
rrr
�framerrr�__init__ns$





zScope.__init__)rcCsDtt|jj���}tt|jj���}t|�j�d|�d|�d�}|S)Nz(scope=z, resolvers=�))r+r$r,�keysr�type�__name__)r9Z
scope_keysZres_keysZunicode_strrrr�__repr__�szScope.__repr__cCstt|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)r9rrr�
has_resolvers�szScope.has_resolvers)�key�is_localcCs�y:|r|j|S|jr |j|S|r.|js2t�|j|Stk
r�y
|j|Stk
r�}zddlm}|||�|�WYdd}~XnXYnXdS)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
        r)�UndefinedVariableErrorN)r,rCr�AssertionError�KeyErrorr-Zpandas.core.computation.opsrF)r9rDrE�errrFrrr�resolve�s



z
Scope.resolve)�old_key�new_keycCsR|jr|jj|jj}n|jj}|j|j�x |D]}||kr2|||<dSq2WdS)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)rCrr8r,�appendr-)r9rKrLZ	new_valuer8�mappingrrr�swapkey�s

z
Scope.swapkey)�scopescCsTtj||�}xB|D]:\}\}}}}}}z t|d|�}|jj|�|_Wd~XqWdS)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')
        Zf_N)�	itertools�product�getattrr,r5)r9�stackrP�	variablesr,r:�_�drrr�	_get_vars�szScope._get_vars)rcCs@|d}tj�}z|j|d|�dgd�Wd|dd�=~XdS)z�
        Update the current scope by going back `level` levels.

        Parameters
        ----------
        level : int
        r	N�locals)rP)�inspectrTrX)r9r�slrTrrrr2�s
z
Scope._updatecCsJt|�j�d|j�dt|���}||jks.t�||j|<||jksFt�|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.
        rV)r>r?�ntempsr r-rG)r9�value�namerrr�add_tmps
 
z
Scope.add_tmpcCs
t|j�S)z/The number of temporary variables in this scope)rBr-)r9rrrr\*szScope.ntempscCs |jg|jj|jj}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.
        )r-rr8r,r)r9r8rrr�
full_scope/szScope.full_scope)N)r?�
__module__�__qualname__�__doc__�	__slots__r;�strr@�propertyrArCrJrOrrX�intr2r_r\r`rrrrrWs!
*)rcr!rZ�iorrQr(rr3ZtypingrZnumpy�npZpandas._libs.tslibsrZpandas.compat.chainmaprrgrrerr r$r%r&r.r+rrrrr�<module>s2