Λ
    θΛhε)  γ                  σ.   d dl mZ d dlZd dlmZ d dl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 d d	lmZ dd
ZddZddZddZdd	 	 	 	 	 ddZdd	 	 	 	 	 ddZddZy# 1 sw Y   JxY w)ι    )ΪannotationsN)ΪTYPE_CHECKING)Ϊparse_into_list_of_expressions)Ϊ	wrap_expr)ΪUInt32)ΪIterable)ΪExpr)ΪIntoExprc                 σN    t        |  }t        t        j                  |«      «      S )u  
    Compute the bitwise AND horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.

    Notes
    -----
    `Kleene logic`_ is used to deal with nulls: if the column contains any null values
    and no `False` values, the output is null.

    .. _Kleene logic: https://en.wikipedia.org/wiki/Three-valued_logic

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [False, False, True, True, False, None],
    ...         "b": [False, True, True, None, None, None],
    ...         "c": ["u", "v", "w", "x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(all=pl.all_horizontal("a", "b"))
    shape: (6, 4)
    βββββββββ¬ββββββββ¬ββββββ¬ββββββββ
    β a     β b     β c   β all   β
    β ---   β ---   β --- β ---   β
    β bool  β bool  β str β bool  β
    βββββββββͺββββββββͺββββββͺββββββββ‘
    β false β false β u   β false β
    β false β true  β v   β false β
    β true  β true  β w   β true  β
    β true  β null  β x   β null  β
    β false β null  β y   β false β
    β null  β null  β z   β null  β
    βββββββββ΄ββββββββ΄ββββββ΄ββββββββ
    )r   r   ΪplrΪall_horizontal©ΪexprsΪpyexprss     ϊ/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/functions/aggregation/horizontal.pyr   r      σ%    τR -¨eΠ4GάSΧ'Ρ'¨Σ0Σ1Π1σ    c                 σN    t        |  }t        t        j                  |«      «      S )u
  
    Compute the bitwise OR horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.

    Notes
    -----
    `Kleene logic`_ is used to deal with nulls: if the column contains any null values
    and no `True` values, the output is null.

    .. _Kleene logic: https://en.wikipedia.org/wiki/Three-valued_logic

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [False, False, True, True, False, None],
    ...         "b": [False, True, True, None, None, None],
    ...         "c": ["u", "v", "w", "x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(any=pl.any_horizontal("a", "b"))
    shape: (6, 4)
    βββββββββ¬ββββββββ¬ββββββ¬ββββββββ
    β a     β b     β c   β any   β
    β ---   β ---   β --- β ---   β
    β bool  β bool  β str β bool  β
    βββββββββͺββββββββͺββββββͺββββββββ‘
    β false β false β u   β false β
    β false β true  β v   β true  β
    β true  β true  β w   β true  β
    β true  β null  β x   β true  β
    β false β null  β y   β null  β
    β null  β null  β z   β null  β
    βββββββββ΄ββββββββ΄ββββββ΄ββββββββ
    )r   r   r   Ϊany_horizontalr   s     r   r   r   B   r   r   c                 σN    t        |  }t        t        j                  |«      «      S )u  
    Get the maximum value horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, None],
    ...         "c": ["x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(max=pl.max_horizontal("a", "b"))
    shape: (3, 4)
    βββββββ¬βββββββ¬ββββββ¬ββββββ
    β a   β b    β c   β max β
    β --- β ---  β --- β --- β
    β i64 β i64  β str β i64 β
    βββββββͺβββββββͺββββββͺββββββ‘
    β 1   β 4    β x   β 4   β
    β 8   β 5    β y   β 8   β
    β 3   β null β z   β 3   β
    βββββββ΄βββββββ΄ββββββ΄ββββββ
    )r   r   r   Ϊmax_horizontalr   s     r   r   r   o   σ$    τ> -¨eΠ4GάSΧ'Ρ'¨Σ0Σ1Π1r   c                 σN    t        |  }t        t        j                  |«      «      S )u  
    Get the minimum value horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, None],
    ...         "c": ["x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(min=pl.min_horizontal("a", "b"))
    shape: (3, 4)
    βββββββ¬βββββββ¬ββββββ¬ββββββ
    β a   β b    β c   β min β
    β --- β ---  β --- β --- β
    β i64 β i64  β str β i64 β
    βββββββͺβββββββͺββββββͺββββββ‘
    β 1   β 4    β x   β 1   β
    β 8   β 5    β y   β 5   β
    β 3   β null β z   β 3   β
    βββββββ΄βββββββ΄ββββββ΄ββββββ
    )r   r   r   Ϊmin_horizontalr   s     r   r   r      r   r   T)Ϊignore_nullsc                σP    t        | }t        t        j                  || «      «      S )u  
    Sum all values horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.
    ignore_nulls
        Ignore null values (default).
        If set to `False`, any null value in the input will lead to a null output.

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, None],
    ...         "c": ["x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(sum=pl.sum_horizontal("a", "b"))
    shape: (3, 4)
    βββββββ¬βββββββ¬ββββββ¬ββββββ
    β a   β b    β c   β sum β
    β --- β ---  β --- β --- β
    β i64 β i64  β str β i64 β
    βββββββͺβββββββͺββββββͺββββββ‘
    β 1   β 4    β x   β 5   β
    β 8   β 5    β y   β 13  β
    β 3   β null β z   β 3   β
    βββββββ΄βββββββ΄ββββββ΄ββββββ
    )r   r   r   Ϊsum_horizontal©r   r   r   s      r   r   r   ΅   s'    τH -¨eΠ4GάSΧ'Ρ'¨°Σ>Σ?Π?r   c                σP    t        | }t        t        j                  || «      «      S )u°  
    Compute the mean of all values horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.
    ignore_nulls
        Ignore null values (default).
        If set to `False`, any null value in the input will lead to a null output.

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, None],
    ...         "c": ["x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(mean=pl.mean_horizontal("a", "b"))
    shape: (3, 4)
    βββββββ¬βββββββ¬ββββββ¬βββββββ
    β a   β b    β c   β mean β
    β --- β ---  β --- β ---  β
    β i64 β i64  β str β f64  β
    βββββββͺβββββββͺββββββͺβββββββ‘
    β 1   β 4    β x   β 2.5  β
    β 8   β 5    β y   β 6.5  β
    β 3   β null β z   β 3.0  β
    βββββββ΄βββββββ΄ββββββ΄βββββββ
    )r   r   r   Ϊmean_horizontalr   s      r   r    r    έ   s'    τH -¨eΠ4GάSΧ(Ρ(¨°,Σ?Σ@Π@r   c                 σζ    t        |  }|D cg c]  }t        |«       }}t        j                  t        j                  d«      j                  t        «      d |«      j                  d«      S c c}w )ul  
    Cumulatively sum all values horizontally across columns.

    Parameters
    ----------
    *exprs
        Column(s) to use in the aggregation. Accepts expression input. Strings are
        parsed as column names, other non-expression inputs are parsed as literals.

    Examples
    --------
    >>> df = pl.DataFrame(
    ...     {
    ...         "a": [1, 8, 3],
    ...         "b": [4, 5, None],
    ...         "c": ["x", "y", "z"],
    ...     }
    ... )
    >>> df.with_columns(pl.cum_sum_horizontal("a", "b"))
    shape: (3, 4)
    βββββββ¬βββββββ¬ββββββ¬ββββββββββββ
    β a   β b    β c   β cum_sum   β
    β --- β ---  β --- β ---       β
    β i64 β i64  β str β struct[2] β
    βββββββͺβββββββͺββββββͺββββββββββββ‘
    β 1   β 4    β x   β {1,5}     β
    β 8   β 5    β y   β {8,13}    β
    β 3   β null β z   β {3,null}  β
    βββββββ΄βββββββ΄ββββββ΄ββββββββββββ
    r   c                σ    | |z   S )N© )ΪaΪbs     r   ϊ<lambda>z$cum_sum_horizontal.<locals>.<lambda>(  s
    Έ!ΈaΉ% r   Ϊcum_sum)r   r   ΪFΪcum_foldΪlitΪcastr   Ϊalias)r   r   ΪeΪexprs_wrappeds       r   Ϊcum_sum_horizontalr/     sa    τ> -¨eΠ4GΨ+2Φ3 aYq\Π3MΠ3τ ::aeeAhmm€FΣ+Ρ-?ΐΣOΧUΡUΨσπ ως 4s   A.)r   ϊIntoExpr | Iterable[IntoExpr]Ϊreturnr	   )r   r0   r   Ϊboolr1   r	   )Ϊ
__future__r   Ϊ
contextlibΪtypingr   Ϊpolars.functionsΪ	functionsr(   Ϊpolars._utils.parser   Ϊpolars._utils.wrapr   Ϊpolars.datatypesr   ΪsuppressΪImportErrorΪpolars.polarsΪpolarsr   Ϊcollections.abcr   r	   Ϊpolars._typingr
   r   r   r   r   r   r    r/   r#   r   r   ϊ<module>rA      sΐ   πέ "γ έ  ε έ >έ (έ #ΰZΧΡΣ%ρ  έχ ρ έ(εέ'σ*2σZ*2σZ 2σF 2πH AEρ%@Ψ)π%@Ψ9=π%@ΰ	σ%@πR AEρ%AΨ)π%AΨ9=π%Aΰ	σ%AτP%χu π  ϊs   »BΒB