§
    θj³)  γ                  σ   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  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 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dS )ι    )ΪannotationsN)ΪTYPE_CHECKING)Ϊparse_into_list_of_expressions©Ϊ	wrap_expr)ΪIterable)ΪExpr)ΪIntoExprΪexprsϊIntoExpr | Iterable[IntoExpr]Ϊreturnr	   c                 σV    t          |  }t          t          j        |¦  «        ¦  «        S )u  
    Compute the logical 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©r   Ϊpyexprss     ϊl/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/polars/functions/aggregation/horizontal.pyr   r      σ(    υR -¨eΠ4GέSΤ'¨Ρ0Τ0Ρ1Τ1Π1σ    c                 σV    t          |  }t          t          j        |¦  «        ¦  «        S )u
  
    Compute the logical 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   A   r   r   c                 σV    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   n   σ'    υ> -¨eΠ4GέSΤ'¨Ρ0Τ0Ρ1Τ1Π1r   c                 σV    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_nullsr   Ϊboolc                σX    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                σX    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 |D ¦   «         }t          j        t          j        d¦  «                             t          j        t          j        t          | ¦  «        ¦  «        ¦  «        ¦  «        d |¦  «                             d¦  «        S )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}  β
    βββββββ΄βββββββ΄ββββββ΄ββββββββββββ
    c                σ,    g | ]}t          |¦  «        S © r   )Ϊ.0Ϊes     r   ϊ
<listcomp>z&cum_sum_horizontal.<locals>.<listcomp>$  s    Π3Π3Π3 aYq\\Π3Π3Π3r   r   c                σ    | |z   S )Nr&   )ΪaΪbs     r   ϊ<lambda>z$cum_sum_horizontal.<locals>.<lambda>(  s
    QU r   Ϊcum_sum)	r   ΪFΪcum_foldΪlitΪcastΪdtype_ofr    ΪlistΪalias)r   r   Ϊexprs_wrappeds      r   Ϊcum_sum_horizontalr7     s    υ> -¨eΠ4GΨ3Π3¨7Π3Ρ3Τ3Mε:έ	aaj₯Τ!1΅$°u±+΄+Ρ!>Τ!>Ρ?Τ?Ρ@Τ@ΨΠΨρτ χ eIΡΤπ	r   )r   r   r   r	   )r   r   r   r   r   r	   )Ϊ
__future__r   Ϊ
contextlibΪtypingr   Ϊpolars.functionsΪ	functionsr/   Ϊpolars._utils.parser   Ϊpolars._utils.wrapr   ΪsuppressΪImportErrorΪpolars._plrΪ_plrr   Ϊcollections.abcr   Ϊpolarsr	   Ϊpolars._typingr
   r   r   r   r   r    r#   r7   r&   r   r   ϊ<module>rF      sο  πΨ "Π "Π "Π "Π "Π "ΰ Π Π Π Ψ  Π  Π  Π  Π  Π  ΰ Π Π Π Π Π Ψ >Π >Π >Π >Π >Π >Ψ (Π (Π (Π (Π (Π (ΰZΤΡ%Τ%π π ΨΠΠΠΠΠππ π ρ τ π π π π π π ψψψπ π π π π π (Ψ(Π(Π(Π(Π(Π(ΰΠΠΠΠΠΨ'Π'Π'Π'Π'Π'π*2π *2π *2π *2πZ*2π *2π *2π *2πZ 2π  2π  2π  2πF 2π  2π  2π  2πH AEπ%@π %@π %@π %@π %@π %@πR AEπ%Aπ %Aπ %Aπ %Aπ %Aπ %AπP&π &π &π &π &π &s   ³AΑA
ΑA
