Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/core/computation/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/core/computation/__pycache__/eval.cpython-312.pyc

�

Mٜg�6���dZddlmZddlZddlmZddlZddlmZddl	m
Z
ddlmZddl
mZdd	lmZmZdd
lmZddlmZddlmZdd
lmZerddlmZdd�Zdd�Zd�Zd�Zdd�Z dd�Z!								d									dd�Z"y)z
Top level ``eval`` module.
�)�annotationsN)�
TYPE_CHECKING)�find_stack_level)�validate_bool_kwarg��is_extension_array_dtype)�ENGINES)�PARSERS�Expr)�tokenize_string)�ensure_scope)�NDFrame)�pprint_thing)�BinOpc��ddlm}ddlm}|�|rdnd}|tvr.tt	j��}td|�d|����|dk(r
|std��|S)	a?
    Make sure a valid engine is passed.

    Parameters
    ----------
    engine : str
        String to validate.

    Raises
    ------
    KeyError
      * If an invalid engine is passed.
    ImportError
      * If numexpr was requested but doesn't exist.

    Returns
    -------
    str
        Engine name.
    r)�NUMEXPR_INSTALLED)�USE_NUMEXPR�numexpr�pythonzInvalid engine 'z' passed, valid engines are z~'numexpr' is not installed or an unsupported version. Cannot use engine='numexpr' for query/eval if 'numexpr' is not installed)	�pandas.core.computation.checkr�#pandas.core.computation.expressionsrr	�list�keys�KeyError�ImportError)�enginerr�
valid_enginess    �G/usr/local/lib/python3.12/site-packages/pandas/core/computation/eval.py�
_check_enginersv��*@�?�
�~�)��x��
�W���W�\�\�^�,�
���v�h�&B�=�/�R�
�	
����#4��
L�
�	
�
�M�c�Z�|tvr#td|�dtj�����y)z�
    Make sure a valid parser is passed.

    Parameters
    ----------
    parser : str

    Raises
    ------
    KeyError
      * If an invalid parser is passed
    zInvalid parser 'z' passed, valid parsers are N)r
rr)�parsers r�
_check_parserr#Ks6���W����v�h�&B�7�<�<�>�BR�S�
�	
�r c�x�|�8|D]2}t|d�r�t|�j}td|�d���yy)N�__getitem__zResolver of type 'z+' does not implement the __getitem__ method)�hasattr�type�__name__�	TypeError)�	resolvers�resolver�names   r�_check_resolversr-^sN����!�H��8�]�3��H�~�.�.���(���/7�7���"�r c��|std��y)z�
    Make sure an expression is not an empty string

    Parameters
    ----------
    expr : object
        An object that can be converted to a string

    Raises
    ------
    ValueError
      * If expr is an empty string
    zexpr cannot be an empty stringN)�
ValueError)�exprs r�_check_expressionr1is����9�:�:�r c�2�t|�}t|�|S)a&
    Convert an object to an expression.

    This function converts an object to an expression (a unicode string) and
    checks to make sure it isn't empty after conversion. This is used to
    convert operators to their string representation for recursive calls to
    :func:`~pandas.eval`.

    Parameters
    ----------
    expr : object
        The object to be converted to a string.

    Returns
    -------
    str
        The string representation of an object.

    Raises
    ------
    ValueError
      * If the expression is empty.
    )rr1)r0�ss  r�_convert_expressionr4{s��0	�T��A��a���Hr c��|dk(}|dk7}|rd}n|rd}|s|r8t|�D])\}}|tjk(s�|dk(s� t��yy)Nr�pandasz5The '@' prefix is only supported by the pandas parserzuThe '@' prefix is not allowed in top-level eval calls.
please refer to your variables by name without the '@' prefix.�@)r�tokenize�OP�SyntaxError)r0�stack_levelr"�at_top_of_stack�not_pandas_parser�msg�toknum�tokvals        r�_check_for_localsrA�sj��!�Q�&�O��(�*���E��	�
M�	�
�+�-�d�3�N�F�F�����$��3��!�#�&�&�4�,r c	��t|d�}t|t�rKt|�|j	�D�	cgc]&}	|	j�dk7s�|	j���(}
}	n|g}
t
|
�dkD}|r
|�td��t|�}t|�t|�d}d}
d}|
D�]�}t|�}t|||�t|dz||||��}t||||�	�}|d
k(r�t|j j"�s=t%|j dd��Lt'd�|j j(D��r&t+j,d
t.t1���d}t2|}||�}|j5�}|j6�|rtd��|rtd��|j6}|j8���&|���*d}|sC|
rA	|j8}t|t:�r|j=d��}n|j=�}n|j8}	|r$t|t:�r||j@dd�|f<n|||<|s||if}n|D]
}||vs�|||<n	|||ifz
}d}d}
���|dur|r|S|Sycc}	w#t>$r}td�|�d}~wwxYw#tBtDf$r}td�|�d}~wwxYw)a'
    Evaluate a Python expression as a string using various backends.

    The following arithmetic operations are supported: ``+``, ``-``, ``*``,
    ``/``, ``**``, ``%``, ``//`` (python engine only) along with the following
    boolean operations: ``|`` (or), ``&`` (and), and ``~`` (not).
    Additionally, the ``'pandas'`` parser allows the use of :keyword:`and`,
    :keyword:`or`, and :keyword:`not` with the same semantics as the
    corresponding bitwise operators.  :class:`~pandas.Series` and
    :class:`~pandas.DataFrame` objects are supported and behave as they would
    with plain ol' Python evaluation.

    Parameters
    ----------
    expr : str
        The expression to evaluate. This string cannot contain any Python
        `statements
        <https://docs.python.org/3/reference/simple_stmts.html#simple-statements>`__,
        only Python `expressions
        <https://docs.python.org/3/reference/simple_stmts.html#expression-statements>`__.
    parser : {'pandas', 'python'}, default 'pandas'
        The parser to use to construct the syntax tree from the expression. The
        default of ``'pandas'`` parses code slightly different than standard
        Python. Alternatively, you can parse an expression using the
        ``'python'`` parser to retain strict Python semantics.  See the
        :ref:`enhancing performance <enhancingperf.eval>` documentation for
        more details.
    engine : {'python', 'numexpr'}, default 'numexpr'

        The engine used to evaluate the expression. Supported engines are

        - None : tries to use ``numexpr``, falls back to ``python``
        - ``'numexpr'`` : This default engine evaluates pandas objects using
          numexpr for large speed ups in complex expressions with large frames.
        - ``'python'`` : Performs operations as if you had ``eval``'d in top
          level python. This engine is generally not that useful.

        More backends may be available in the future.
    local_dict : dict or None, optional
        A dictionary of local variables, taken from locals() by default.
    global_dict : dict or None, optional
        A dictionary of global variables, taken from globals() by default.
    resolvers : list of dict-like or None, optional
        A list of objects implementing the ``__getitem__`` special method that
        you can use to inject an additional collection of namespaces to use for
        variable lookup. For example, this is used in the
        :meth:`~DataFrame.query` method to inject the
        ``DataFrame.index`` and ``DataFrame.columns``
        variables that refer to their respective :class:`~pandas.DataFrame`
        instance attributes.
    level : int, optional
        The number of prior stack frames to traverse and add to the current
        scope. Most users will **not** need to change this parameter.
    target : object, optional, default None
        This is the target object for assignment. It is used when there is
        variable assignment in the expression. If so, then `target` must
        support item assignment with string keys, and if a copy is being
        returned, it must also support `.copy()`.
    inplace : bool, default False
        If `target` is provided, and the expression mutates `target`, whether
        to modify `target` inplace. Otherwise, return a copy of `target` with
        the mutation.

    Returns
    -------
    ndarray, numeric scalar, DataFrame, Series, or None
        The completion value of evaluating the given code or None if ``inplace=True``.

    Raises
    ------
    ValueError
        There are many instances where such an error can be raised:

        - `target=None`, but the expression is multiline.
        - The expression is multiline, but not all them have item assignment.
          An example of such an arrangement is this:

          a = b + 1
          a + 2

          Here, there are expressions on different lines, making it multiline,
          but the last line has no variable assigned to the output of `a + 2`.
        - `inplace=True`, but the expression is missing item assignment.
        - Item assignment is provided, but the `target` does not support
          string item assignment.
        - Item assignment is provided and `inplace=False`, but the `target`
          does not support the `.copy()` method

    See Also
    --------
    DataFrame.query : Evaluates a boolean expression to query the columns
            of a frame.
    DataFrame.eval : Evaluate a string describing operations on
            DataFrame columns.

    Notes
    -----
    The ``dtype`` of any objects involved in an arithmetic ``%`` operation are
    recursively cast to ``float64``.

    See the :ref:`enhancing performance <enhancingperf.eval>` documentation for
    more details.

    Examples
    --------
    >>> df = pd.DataFrame({"animal": ["dog", "pig"], "age": [10, 20]})
    >>> df
      animal  age
    0    dog   10
    1    pig   20

    We can add a new column using ``pd.eval``:

    >>> pd.eval("double_age = df.age * 2", target=df)
      animal  age  double_age
    0    dog   10          20
    1    pig   20          40
    �inplace��NzPmulti-line expressions are only valid in the context of data, use DataFrame.evalTF)�global_dict�
local_dictr*�target)rr"�envr�
operand_typesc3�2K�|]}t|����y�w)Nr)�.0�elems  r�	<genexpr>zeval.<locals>.<genexpr>Us�����;�D�)��.�;�s�z�Engine has switched to 'python' because numexpr does not support extension array dtypes. Please set your engine to python manually.)�
stacklevelrzNMulti-line expressions are only valid if all expressions contain an assignmentz0Cannot operate inplace if there is no assignment)�deepz"Cannot return a copy of the targetz)Cannot assign expression output to target)#r�
isinstance�strr1�
splitlines�strip�lenr/rr#r-r4rAr
rr�terms�return_type�getattr�anyrJ�warnings�warn�RuntimeWarningrr	�evaluate�assignerrHr�copy�AttributeError�locr)�
IndexError)r0r"rrGrFr*�levelrHrC�e�exprs�
multi_line�ret�
first_expr�target_modifiedrI�parsed_expr�eng�eng_instr^�errr+s                      r�evalrn�s��B"�'�9�5�G��$����$��$(�O�O�$5�I�$5�q�����b������$5��I�����U��a��J��f�n��
2�
�	
��6�
"�F��&���Y��
�C��J��O���"�4�(���$��v�.���A�I�#�!���
���4��v�3�G���Y��$�[�%6�%6�%B�%B�C��{�(�(�/�4�@�L���'�-�-�;�;���

�M�M�U��+�-�	
��F��f�o���{�#�����!�����'�� �?���� �!S�T�T��'�'���:�:�!�h�&:�"�O��z�T� �Z�Z�F�!�&�'�2�!'���$��!7��!'����������
W��z�&�'�:�.1�F�J�J�q�(�{�+�'*�F�8�$��&��_�.�	�!*�H��8�+�-0���*��!*�
�8�S�/�!3�3�I��C��J�q�v�%��(�v�1�c�1���]J��Z&�T�$�%I�J�PS�S��T���z�*�
W� �!L�M�SV�V��
W�s;�J�J�"?J�/+J0�	J-�J(�(J-�0K�?K�K)r�
str | None�returnrR)r"rR)rprR)r0rRr;�intr"rR)r6NNN�rNF)
r0zstr | BinOpr"rRrrorcrqrC�bool)#�__doc__�
__future__rr8�typingrrZ�pandas.util._exceptionsr�pandas.util._validatorsr�pandas.core.dtypes.commonr�pandas.core.computation.enginesr	�pandas.core.computation.exprr
r�pandas.core.computation.parsingr�pandas.core.computation.scoper
�pandas.core.genericr�pandas.io.formats.printingr�pandas.core.computation.opsrrr#r-r1r4rArnrrr r�<module>r�s����#�� ��4�7�>�3��<�6�'�3��1�*�Z
�&�;�$
�:'�(��������u2�
�u2��u2�
�u2��u2��u2r 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists