zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
U
¬ý°d6)ã    @sdZddlmZddlZddlZddlmZddlZddlZddl    Z    ddl
Z
ddl m Z m Z ddlZddlmZddlmZe dƒZe d    ƒZGd
d „d e eefƒZdd ddœdd„Zddœdd„Zddœdd„ZeejddeeejejdœZddœdd„ZGdd„dƒZdS)z
Module for scope operations
é)Ú annotationsN)ÚStringIO)ÚChainMapÚTypeVar)Ú    Timestamp)ÚUndefinedVariableErrorÚ_KTÚ_VTc@s2eZdZdZddddœdd„Zdddœd    d
„Zd S) Ú DeepChainMapz~
    Variant of ChainMap that allows direct updates to inner scopes.
 
    Only works when all passed mapping are mutable.
    rr    ÚNone)ÚkeyÚvalueÚreturncCs4|jD]}||kr|||<dSq||jd|<dS)Nr)Úmaps)Úselfr r Úmapping©rúTd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/computation/scope.pyÚ __setitem__#s
 
zDeepChainMap.__setitem__)r rcCs,|jD]}||kr||=dSqt|ƒ‚dS)z\
        Raises
        ------
        KeyError
            If `key` doesn't exist.
        N)rÚKeyError)rr rrrrÚ __delitem__*s
 
zDeepChainMap.__delitem__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrrrrr
sr
rÚintÚScope©ÚlevelrcCst|d||||dS)z.Ensure that we are grabbing the correct scope.é)Ú global_dictÚ
local_dictÚ    resolversÚtarget)r)rr r!r"r#rrrÚ ensure_scope8sûr$Ústr©rcCs.z 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Ú    _replacerEs
 
r+cCs$t dt|ƒ¡}d dd„|Dƒ¡S)z,Return the padded hexadecimal id of ``obj``.z@PÚcSsg|] }t|ƒ‘qSr)r+)Ú.0r*rrrÚ
<listcomp>Ysz_raw_hex_id.<locals>.<listcomp>)ÚstructÚpackÚidÚjoin)ÚobjÚpackedrrrÚ _raw_hex_idUsr5TF)rÚdatetimeÚTrueÚFalseÚlistÚtupleÚinfZInfcCstƒ}tj||d| ¡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)r3ÚsiorrrÚ_get_pretty_stringhsr@c@sèeZdZUdZdddddgZded<ded<ded<d    ed<d)dd d œdd„Zddœdd„Zeddœdd„ƒZ    dddœdd„Z
d*ddd dœdd„Z dd dœdd „Z dd d œd!d"„Z ddœd#d$„Zeddœd%d&„ƒZeddœd'd(„ƒZd
S)+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"Útempsrr
ÚdictNrr rc    Csò|d|_tt ¡ƒ|_||_t|tƒrT|j |j¡|jdk    rH|j|_|     |j¡t
  |j¡}z^|j  |dk    rt|n|j  ¡¡}t|ƒ|_t|tƒs¼|j  |dk    r¦|n|j ¡¡}t|ƒ|_W5~Xt|tƒrÞ|t|jjƒ7}t|Ž|_i|_dS)Nr)rr
ÚDEFAULT_GLOBALSÚcopyrAr#Ú
isinstancerÚupdateÚ_updateÚsysÚ    _getframeÚ    new_childÚ    f_globalsÚf_localsr:r"rrB)    rrr r!r"r#ÚframeZ scope_globalZ scope_localrrrÚ__init__–s0
 
 
  ÿ
 
ÿ
 
zScope.__init__r%r&cCs@tt|j ¡ƒƒ}tt|j ¡ƒƒ}t|ƒj›d|›d|›dS)Nz(scope=z , resolvers=ú))r@r9rAÚkeysr"Útyper)rZ
scope_keysZres_keysrrrÚ__repr__¾szScope.__repr__ÚboolcCstt|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
        )rTÚlenr"©rrrrÚ has_resolversÃs zScope.has_resolvers)r Úis_localc Cs–z<|r|j|WS|jr$|j|WS|s.|jr2t‚|j|WStk
rz|j|WYStk
rŠ}zt||ƒ|‚W5d}~XYnXYnXdS)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)rArWr"ÚAssertionErrorrrBr)rr rXÚerrrrrÚresolveÑs   z Scope.resolve)Úold_keyÚnew_keyrcCsP|jr|jj|jj}n|jj}| |j¡|D]}||kr0|||<dSq0dS)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)rWr"rrAÚappendrB)rr\r]Ú    new_valuerrrrrÚswapkeyøs  z Scope.swapkeyz    list[str])ÚscopesrcCsVt ||¡}|D]@\}\}}}}}}z&t|d|›ƒ}t|j |¡ƒ|_W5~XqdS)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
rArK)rÚstackraÚ    variablesrArNÚ_ÚdrrrÚ    _get_varss zScope._get_varsc    Cs@|d}t ¡}z|j|d|…dgdW5|dd…=~XdS)zƒ
        Update the current scope by going back `level` levels.
 
        Parameters
        ----------
        level : int
        rNÚlocals)ra)Úinspectreri)rrÚslrerrrrH(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.
        rg)rRrÚntempsr5rBrY)rr ÚnamerrrÚadd_tmp<s
 
z Scope.add_tmpcCs
t|jƒS)z/The number of temporary variables in this scope)rUrBrVrrrrmTsz 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.
        )rBr"rrAr
)rrrrrÚ
full_scopeYs zScope.full_scope)NNrN)N)rrrrÚ    __slots__Ú__annotations__rOrSÚpropertyrWr[r`rirHrormrprrrrr{s.
ÿ( ')NNrN) rÚ
__future__rr6rkÚiorrbr=r/rIÚtypingrrÚnumpyÚnpZpandas._libs.tslibsrZ pandas.errorsrrr    r
r$r+r5r9r:r;rDr@rrrrrÚ<module>sB    ÿ ø