
    ˀh/                       d dl mZ d dlZd dlmZ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       erd dlmZ d dlmZmZ d d	lmZ d
d
d
dd	 	 	 	 	 	 	 	 	 	 	 ddZddZd
d	 	 	 	 	 	 	 ddZd
d	 	 	 	 	 ddZ	 	 	 	 ddZddZd
d	 	 	 	 	 ddZ 	 	 	 	 	 	 ddZ!d dZ"d!dZ#y# 1 sw Y   }xY w)"    )annotationsN)IterableMapping)TYPE_CHECKINGAny)	functions)ComputeError)Expr)IntoExprPolarsDataType)PyExprF)
str_as_litlist_as_series	structifydtypec                  t        | t        j                        r| }|rt        |      }|j                  S t        | t              r#|s!t        j                  |       }|j                  S t        | t              r8|r6t        j                  t        j                  |       |      }|j                  S 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)inputr   r   r   r   exprs         t/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/_utils/parse/expr.pyparse_into_expressionr       s    > %!(.D << 
E3	
uuU| << 
E4	 ^uuRYYu%U3 << uuU%(<<    c                :   | j                   j                         }|j                   j                         rA	 | j                   j                         }t	        j
                  |      j                  |      } | S | S # t        $ r t	        j
                  |       } Y | S w xY wN)metaundo_aliaseshas_multiple_outputsoutput_namer   structaliasr	   )r   unaliased_expr	expr_names      r   r   r   B   s    YY++-N//1	=		--/I 88N+11)<DK4K	  	"88D>D K		"s   A8 8BB)__structifyc                `    t        ||       }|rt        ||       }|j                  |       |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,   inputsnamed_inputsexprsnamed_exprss        r   parse_into_list_of_expressionsr6   N   s0    , %V{CE),+N[!Lr!   r.   c               X    t        |       }|D cg c]  }t        ||       c}S c c}w Nr.   )_parse_inputs_as_iterabler    )r2   r   inputs_iteres       r   r/   r/   l   s*    
 ,F3KCNOa!!y9OOOs   'c                    | sg S t        |       dk(  r t        | d   t              rd}t        |      t        |       dk(  rt	        | d         r| d   S | S )N   r   u8  Cannot pass a dictionary as a single positional argument.
If you merely want the *keys*, use:
  • df.method(*your_dict.keys())
If you need the key value pairs, use one of:
  • unpack as keywords:    df.method(**your_dict)
  • build expressions:     df.method(expr.alias(k) for k, expr in your_dict.items()))lenr   r   	TypeError_is_iterable)r2   msgs     r   r9   r9   u   sf     	 6{aJvay':e 	 n 6{aL3ayMr!   c                r    t        | t              xr& t        | t        t        t        j
                  f       S r#   )r   r   r   bytesr   r   )r   s    r   r@   r@      s2    eX& zUBII&0 , r!   c             #  x   K   | j                         D ]#  \  }}t        ||      j                  |       % y wr8   )itemsr    r)   )r3   r   namer   s       r   r0   r0      s>      $))+ Le#EY?EEdKKLs   8:c                 j    t        |       }|rt        |      }|j                  |       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
    )r/   _parse_constraintsr1   _combine_predicates)
predicatesconstraintsall_predicatesconstraint_predicatess       r   ,parse_predicates_constraints_into_expressionrN      s6    * .j9N 2; ?34~..r!   c              #     K   | j                         D ]5  \  }}t        j                  |      j                  |      j                   7 y wr#   )rE   r   r   eqr   )rK   rF   values      r   rH   rH      s?     "((* ,eeeDknnU#+++,s   A
Ac                p    | sd}t        |      t        |       dk(  r| d   S t        j                  |       S )Nz5at least one predicate or constraint must be providedr=   r   )r?   r>   plrall_horizontal)rJ   rA   s     r   rI   rI      s;    En
:!!}j))r!   )r   r   r   boolr   rU   r   rU   r   zPolarsDataType | Nonereturnr   )r   r
   rV   r
   )r2   IntoExpr | Iterable[IntoExpr]r,   rU   r3   r   rV   list[PyExpr])r2   z0tuple[IntoExpr, ...] | tuple[Iterable[IntoExpr]]r   rU   rV   rX   )r2   z&tuple[Any, ...] | tuple[Iterable[Any]]rV   zIterable[Any])r   zAny | Iterable[Any]rV   rU   )r3   dict[str, IntoExpr]r   rU   rV   Iterable[PyExpr])rJ   rW   rK   r   rV   r   )rK   rY   rV   rZ   )rJ   rX   rV   r   )$
__future__r   
contextlibcollections.abcr   r   typingr   r   polars._reexport	_reexportr   polarsr   r   polars.exceptionsr	   suppressImportErrorpolars.polarsrS   r
   polars._typingr   r   r   r    r   r6   r/   r9   r@   r0   rN   rH   rI    r!   r   <module>rh      sg   "  - %  ! *Z%    7$  #'++ + 	+
 + !+ +\	 *  	B P<P P 	P22 =BL%L59LL/.// /<,
*g   s   CC