Λ
    »―ei7  γ                  σ    d dl mZ d dlmZmZmZ d dlmZmZ erd dl	m
Z
 d dlmZ  edd¬«      Z G d	 d
ee   «      Zy)ι    )Ϊannotations)ΪTYPE_CHECKINGΪGenericΪTypeVar)ΪExprKindΪExprNode)ΪExpr)ΪNonNestedLiteralΪExprTr	   )Ϊboundc                  σl    e Zd ZddZddZddZddZddZddZddZ	ddZ
dd	Zdd
ZdddddZy)ΪExprListNamespacec                σ    || _         y )N)Ϊ_expr)ΪselfΪexprs     ϊT/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/narwhals/expr_list.pyΪ__init__zExprListNamespace.__init__   s	    Ψ
σ    c                σh    | j                   j                  t        t        j                  d«      «      S )uι  Return the number of elements in each list.

        Null values count towards the total.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [[1, 2], [3, 4, None], None, []]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_len=nw.col("a").list.len())
            ββββββββββββββββββββββββββ
            |   Narwhals DataFrame   |
            |------------------------|
            |shape: (4, 2)           |
            |ββββββββββββββββ¬ββββββββ|
            |β a            β a_len β|
            |β ---          β ---   β|
            |β list[i64]    β u32   β|
            |ββββββββββββββββͺββββββββ‘|
            |β [1, 2]       β 2     β|
            |β [3, 4, null] β 3     β|
            |β null         β null  β|
            |β []           β 0     β|
            |ββββββββββββββββ΄ββββββββ|
            ββββββββββββββββββββββββββ
        zlist.len©r   Ϊ_append_noder   r   ΪELEMENTWISE©r   s    r   ΪlenzExprListNamespace.len   s&    π6 zzΧ&Ρ&€x΄Χ0DΡ0DΐjΣ'QΣRΠRr   c                σh    | j                   j                  t        t        j                  d«      «      S )u  Get the unique/distinct values in the list.

        Null values are included in the result. The order of unique values is not guaranteed.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [[1, 1, 2], [3, 3, None], None, []]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_unique=nw.col("a").list.unique())
            ββββββββββββββββββββββββββββββ
            |     Narwhals DataFrame     |
            |----------------------------|
            |shape: (4, 2)               |
            |ββββββββββββββββ¬ββββββββββββ|
            |β a            β a_unique  β|
            |β ---          β ---       β|
            |β list[i64]    β list[i64] β|
            |ββββββββββββββββͺββββββββββββ‘|
            |β [1, 1, 2]    β [1, 2]    β|
            |β [3, 3, null] β [null, 3] β|
            |β null         β null      β|
            |β []           β []        β|
            |ββββββββββββββββ΄ββββββββββββ|
            ββββββββββββββββββββββββββββββ
        zlist.uniquer   r   s    r   ΪuniquezExprListNamespace.unique/   s&    π6 zzΧ&Ρ&€x΄Χ0DΡ0DΐmΣ'TΣUΠUr   c                σl    | j                   j                  t        t        j                  d|¬«      «      S )u;  Check if sublists contain the given item.

        Arguments:
            item: Item that will be checked for membership.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [[1, 2], None, []]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_contains_1=nw.col("a").list.contains(1))
            ββββββββββββββββββββββββββββββ
            |     Narwhals DataFrame     |
            |----------------------------|
            |shape: (3, 2)               |
            |βββββββββββββ¬βββββββββββββββ|
            |β a         β a_contains_1 β|
            |β ---       β ---          β|
            |β list[i64] β bool         β|
            |βββββββββββββͺβββββββββββββββ‘|
            |β [1, 2]    β true         β|
            |β null      β null         β|
            |β []        β false        β|
            |βββββββββββββ΄βββββββββββββββ|
            ββββββββββββββββββββββββββββββ
        zlist.contains)Ϊitemr   )r   r   s     r   ΪcontainszExprListNamespace.containsL   s-    π6 zzΧ&Ρ&άXΧ)Ρ)¨?ΐΤFσ
π 	
r   c                σ    t        |t        «      s$dt        |«      j                   d}t	        |«      |dk  rd| d}t        |«      | j                  j                  t        t        j                  d|¬«      «      S )uκ  Return the value by index in each list.

        Negative indices are not accepted.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [[1, 2], [3, 4, None], [None, 5]]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_first=nw.col("a").list.get(0))
            ββββββββββββββββββββββββββββ
            |    Narwhals DataFrame    |
            |--------------------------|
            |shape: (3, 2)             |
            |ββββββββββββββββ¬ββββββββββ|
            |β a            β a_first β|
            |β ---          β ---     β|
            |β list[i64]    β i64     β|
            |ββββββββββββββββͺββββββββββ‘|
            |β [1, 2]       β 1       β|
            |β [3, 4, null] β 3       β|
            |β [null, 5]    β null    β|
            |ββββββββββββββββ΄ββββββββββ|
            ββββββββββββββββββββββββββββ
        z'Index must be of type 'int'. Got type 'z
' instead.r   zIndex z8 is out of bounds: should be greater than or equal to 0.zlist.get)Ϊindex)Ϊ
isinstanceΪintΪtypeΪ__name__Ϊ	TypeErrorΪ
ValueErrorr   r   r   r   r   )r   r"   Ϊmsgs      r   ΪgetzExprListNamespace.getk   s    τ4 %€Τ%ΰ9Ό$Έu»+Χ:NΡ:NΠ9OΘzΠZπ τ C.Π ΰ19Ψ5'Π!YΠZCάS/Π!ΰzzΧ&Ρ&άXΧ)Ρ)¨:ΈUΤCσ
π 	
r   c                σh    | j                   j                  t        t        j                  d«      «      S )u  Compute the min value of the lists in the array.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql("SELECT * FROM VALUES ([1]), ([3, 4, NULL]) df(a)")
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_min=nw.col("a").list.min())
            ββββββββββββββββββββββββββ
            |   Narwhals LazyFrame   |
            |------------------------|
            |ββββββββββββββββ¬ββββββββ|
            |β      a       β a_min β|
            |β   int32[]    β int32 β|
            |ββββββββββββββββΌββββββββ€|
            |β [1]          β     1 β|
            |β [3, 4, NULL] β     3 β|
            |ββββββββββββββββ΄ββββββββ|
            ββββββββββββββββββββββββββ
        zlist.minr   r   s    r   ΪminzExprListNamespace.min   s&    π* zzΧ&Ρ&€x΄Χ0DΡ0DΐjΣ'QΣRΠRr   c                σh    | j                   j                  t        t        j                  d«      «      S )uY  Compute the max value of the lists in the array.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [[1], [3, 4, None]]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_max=nw.col("a").list.max())
            ββββββββββββββββββββββββββ
            |   Narwhals DataFrame   |
            |------------------------|
            |shape: (2, 2)           |
            |ββββββββββββββββ¬ββββββββ|
            |β a            β a_max β|
            |β ---          β ---   β|
            |β list[i64]    β i64   β|
            |ββββββββββββββββͺββββββββ‘|
            |β [1]          β 1     β|
            |β [3, 4, null] β 4     β|
            |ββββββββββββββββ΄ββββββββ|
            ββββββββββββββββββββββββββ
        zlist.maxr   r   s    r   ΪmaxzExprListNamespace.maxͺ   σ&    π. zzΧ&Ρ&€x΄Χ0DΡ0DΐjΣ'QΣRΠRr   c                σh    | j                   j                  t        t        j                  d«      «      S )u?  Compute the mean value of the lists in the array.

        Examples:
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> df_native = pa.table({"a": [[1], [3, 4, None]]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_mean=nw.col("a").list.mean())
            ββββββββββββββββββββββββ
            |  Narwhals DataFrame  |
            |----------------------|
            |pyarrow.Table         |
            |a: list<item: int64>  |
            |  child 0, item: int64|
            |a_mean: double        |
            |----                  |
            |a: [[[1],[3,4,null]]] |
            |a_mean: [[1,3.5]]     |
            ββββββββββββββββββββββββ
        z	list.meanr   r   s    r   ΪmeanzExprListNamespace.meanΓ   s&    π* zzΧ&Ρ&€x΄Χ0DΡ0DΐkΣ'RΣSΠSr   c                σh    | j                   j                  t        t        j                  d«      «      S )u]  Compute the median value of the lists in the array.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql("SELECT * FROM VALUES ([1]), ([3, 4, NULL]) df(a)")
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_median=nw.col("a").list.median())
            βββββββββββββββββββββββββββββ
            |    Narwhals LazyFrame     |
            |---------------------------|
            |ββββββββββββββββ¬βββββββββββ|
            |β      a       β a_median β|
            |β   int32[]    β  double  β|
            |ββββββββββββββββΌβββββββββββ€|
            |β [1]          β      1.0 β|
            |β [3, 4, NULL] β      3.5 β|
            |ββββββββββββββββ΄βββββββββββ|
            βββββββββββββββββββββββββββββ
        zlist.medianr   r   s    r   ΪmedianzExprListNamespace.medianΪ   s&    π* zzΧ&Ρ&€x΄Χ0DΡ0DΐmΣ'TΣUΠUr   c                σh    | j                   j                  t        t        j                  d«      «      S )uY  Compute the sum value of the lists in the array.

        Examples:
            >>> import polars as pl
            >>> import narwhals as nw
            >>> df_native = pl.DataFrame({"a": [[1], [3, 4, None]]})
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_sum=nw.col("a").list.sum())
            ββββββββββββββββββββββββββ
            |   Narwhals DataFrame   |
            |------------------------|
            |shape: (2, 2)           |
            |ββββββββββββββββ¬ββββββββ|
            |β a            β a_sum β|
            |β ---          β ---   β|
            |β list[i64]    β i64   β|
            |ββββββββββββββββͺββββββββ‘|
            |β [1]          β 1     β|
            |β [3, 4, null] β 7     β|
            |ββββββββββββββββ΄ββββββββ|
            ββββββββββββββββββββββββββ
        zlist.sumr   r   s    r   ΪsumzExprListNamespace.sumρ   r/   r   F©Ϊ
descendingΪ
nulls_lastc               σn    | j                   j                  t        t        j                  d||¬«      «      S )uk  Sort the lists of the expression.

        Arguments:
            descending: Sort in descending order.
            nulls_last: Place null values last.

        Examples:
            >>> import duckdb
            >>> import narwhals as nw
            >>> df_native = duckdb.sql(
            ...     "SELECT * FROM VALUES ([2, -1, 1]), ([3, -4, NULL]) df(a)"
            ... )
            >>> df = nw.from_native(df_native)
            >>> df.with_columns(a_sorted=nw.col("a").list.sort())
            βββββββββββββββββββββββββββββββββββ
            |       Narwhals LazyFrame        |
            |---------------------------------|
            |βββββββββββββββββ¬ββββββββββββββββ|
            |β       a       β   a_sorted    β|
            |β    int32[]    β    int32[]    β|
            |βββββββββββββββββΌββββββββββββββββ€|
            |β [2, -1, 1]    β [-1, 1, 2]    β|
            |β [3, -4, NULL] β [NULL, -4, 3] β|
            |βββββββββββββββββ΄ββββββββββββββββ|
            βββββββββββββββββββββββββββββββββββ
        z	list.sortr6   r   )r   r7   r8   s      r   ΪsortzExprListNamespace.sort
  s5    π6 zzΧ&Ρ&άάΧ$Ρ$ΨΨ%Ψ%τ	σ
π 	
r   N)r   r   ΪreturnΪNone)r;   r   )r   r
   r;   r   )r"   r$   r;   r   )r7   Ϊboolr8   r=   r;   r   )r&   Ϊ
__module__Ϊ__qualname__r   r   r   r    r*   r,   r.   r1   r3   r5   r:   © r   r   r   r      sH    σσSσ:Vσ:
σ>&
σPSσ.Sσ2Tσ.Vσ.Sπ2 */ΐ5φ "
r   r   N)Ϊ
__future__r   Ϊtypingr   r   r   Ϊnarwhals._expression_parsingr   r   Ϊnarwhals.exprr	   Ϊnarwhals.typingr
   r   r   r@   r   r   ϊ<module>rF      s8   πέ "η 2Ρ 2η ;αέ"έ0αvΤ&τ^
 υ ^
r   