
    q-Ph                    P   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z
 d dlmZ d dlmZ  ej        e          5  d dlmZ ddd           n# 1 swxY w Y   erd dlmZ d dlmZmZ d d	lmZ d
d
d
ddd2dZd3dZd
dd4d Zd
d!d5d#Zd6d&Zd7d(Zd
d!d8d+Zd9d/Z d:d0Z!d;d1Z"dS )<    )annotationsN)Iterable)TYPE_CHECKINGAny)	functions)ComputeError)Expr)IntoExprPolarsDataType)PyExprF)
str_as_litlist_as_series	structifydtypeinputr
   r   boolr   r   r   PolarsDataType | Nonereturnr   c               p   t          | t          j                  r| }|rt          |          }nt          | t                    r|st          j        |           }nVt          | t                    r+|r)t          j        t          j	        |           |          }nt          j        | |          }|j
        S )a  
    Parse a single input into an expression.

    Parameters
    ----------
    input
        The input to be parsed as an expression.
    str_as_lit
        Interpret string input as a string literal. If set to `False` (default),
        strings are parsed as column names.
    list_as_series
        Interpret list input as a Series literal. If set to `False` (default),
        lists are parsed as list literals.
    structify
        Convert multi-column expressions to a single struct expression.
    dtype
        If the input is expected to resolve to a literal with a known dtype, pass
        this to the `lit` constructor.

    Returns
    -------
    PyExpr
    )r   )
isinstanceplr	   _structify_expressionstrFcollistlitSeries_pyexpr)r   r   r   r   r   exprs         X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/_utils/parse/expr.pyparse_into_expressionr"      s    > %!! 
) 	/(..D	E3		 )
 )uU||	E4	 	  )^ )uRYu%%U333uU%(((<    r    r	   c                6   | j                                         }|j                                         rf	 | j                                         }t	          j        |                              |          } n$# t          $ r t	          j        |           } Y nw xY w| S N)metaundo_aliaseshas_multiple_outputsoutput_namer   structaliasr   )r    unaliased_expr	expr_names      r!   r   r   B   s    Y++--N//11 =	=	--//I 8N++11)<<DD  	" 	" 	"8D>>DDD	" Ks   A5 5BB)__structifyinputsIntoExpr | Iterable[IntoExpr]r.   named_inputslist[PyExpr]c                x    t          ||           }|r&t          ||           }|                    |           |S )a  
    Parse multiple inputs into a list of expressions.

    Parameters
    ----------
    *inputs
        Inputs to be parsed as expressions, specified as positional arguments.
    **named_inputs
        Additional inputs to be parsed as expressions, specified as keyword arguments.
        The expressions will be renamed to the keyword used.
    __structify
        Convert multi-column expressions to a single struct expression.

    Returns
    -------
    list of PyExpr
    r   )_parse_positional_inputs_parse_named_inputsextend)r.   r/   r1   exprsnamed_exprss        r!   parse_into_list_of_expressionsr:   N   sG    , %V{CCCE "),+NNN[!!!Lr#   r4   0tuple[IntoExpr, ...] | tuple[Iterable[IntoExpr]]c               >    t          |           }fd|D             S )Nc                2    g | ]}t          |           S )r4   )r"   ).0er   s     r!   
<listcomp>z,_parse_positional_inputs.<locals>.<listcomp>r   s'    OOOa!!y999OOOr#   )_parse_inputs_as_iterable)r/   r   inputs_iters    ` r!   r5   r5   l   s,    
 ,F33KOOOO;OOOOr#   &tuple[Any, ...] | tuple[Iterable[Any]]Iterable[Any]c                n    | sg S t          |           dk    rt          | d                   r| d         S | S )N   r   )len_is_iterable)r/   s    r!   rA   rA   u   sD      	 6{{aL33ayMr#   Any | Iterable[Any]c                |    t          | t                    o't          | t          t          t          j        f           S r%   )r   r   r   bytesr   r   )r   s    r!   rH   rH      s8    eX&& zUBI&0 0 , r#   dict[str, IntoExpr]Iterable[PyExpr]c             #     K   |                                  D ]+\  }}t          ||                              |          V  ,d S )Nr4   )itemsr"   r+   )r1   r   namer   s       r!   r6   r6      s_       $))++ L Le#EY???EEdKKKKKKL Lr#   
predicatesconstraintsr   c                     t          |           }|r$t          |          }|                    |           t          |          S )a  
    Parse predicates and constraints into a single expression.

    The result is an AND-reduction of all inputs.

    Parameters
    ----------
    *predicates
        Predicates to be parsed, specified as positional arguments.
    **constraints
        Constraints to be parsed, specified as keyword arguments.
        These will be converted to predicates of the form "keyword equals input value".

    Returns
    -------
    PyExpr
    )r5   _parse_constraintsr7   _combine_predicates)rQ   rR   all_predicatesconstraint_predicatess       r!   ,parse_predicates_constraints_into_expressionrX      sJ    * .j99N 5 2; ? ?3444~...r#   c              #     K   |                                  D ]3\  }}t          j        |                              |          j        V  4d S r%   )rO   r   r   eqr   )rR   rP   values      r!   rT   rT      sU      "((** , ,eeDkknnU##+++++, ,r#   c                    | sd}t          |          t          |           dk    r| d         S t          j        |           S )Nz5at least one predicate or constraint must be providedrF   r   )	TypeErrorrG   plrall_horizontal)rQ   msgs     r!   rU   rU      sG     Enn
:!!}j)))r#   )r   r
   r   r   r   r   r   r   r   r   r   r   )r    r	   r   r	   )r/   r0   r.   r   r1   r
   r   r2   )r/   r;   r   r   r   r2   )r/   rC   r   rD   )r   rI   r   r   )r1   rL   r   r   r   rM   )rQ   r0   rR   r   r   r   )rR   rL   r   rM   )rQ   r2   r   r   )#
__future__r   
contextlibcollections.abcr   typingr   r   polars._reexport	_reexportr   polarsr   r   polars.exceptionsr   suppressImportErrorpolars.polarsr^   r	   polars._typingr
   r   r   r"   r   r:   r5   rA   rH   r6   rX   rT   rU    r#   r!   <module>rn      si   " " " " " "     $ $ $ $ $ $ % % % % % % % %       ! ! ! ! ! ! * * * * * *Z%%                                   %77777777$$$$$$  #'+ + + + + +\	 	 	 	      B P P P P P P
 
 
 
    =BL L L L L L/ / / /<, , , ,
* * * * * *s   AAA