Λ
    WΛhX  γ                  σp    d dl mZ d dlmZ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)ΪExpr)ΪNonNestedLiteralΪExprTr   )Ϊboundc                  σ4    e Zd ZddZddZddZd	dZd
dZy)ΪExprListNamespacec                σ    || _         y ©N)Ϊ_expr)ΪselfΪexprs     ϊL/var/www/html/jupyter_env/lib/python3.12/site-packages/narwhals/expr_list.pyΪ__init__zExprListNamespace.__init__   s	    Ψ
σ    c                σ@      j                   j                   f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     β|
            |ββββββββββββββββ΄ββββββββ|
            ββββββββββββββββββββββββββ
        c                σj    j                   j                  | «      j                  j                  «       S r   )r   Ϊ_to_compliant_exprΪlistΪlen©Ϊplxr   s    r   ϊ<lambda>z'ExprListNamespace.len.<locals>.<lambda>,   s%   ψ 

Χ5Ρ5°cΣ:Χ?Ρ?ΧCΡCΣE r   ©r   Ϊ_with_elementwise©r   s   `r   r   zExprListNamespace.len   s   ψ π6 zzΧ+Ρ+ΫEσ
π 	
r   c                σ@      j                   j                   f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      β|
            |β []           β []        β|
            |ββββββββββββββββ΄ββββββββββββ|
            ββββββββββββββββββββββββββββββ
        c                σj    j                   j                  | «      j                  j                  «       S r   )r   r   r   Ϊuniquer   s    r   r   z*ExprListNamespace.unique.<locals>.<lambda>K   s%   ψ 

Χ5Ρ5°cΣ:Χ?Ρ?ΧFΡFΣH r   r   r   s   `r   r"   zExprListNamespace.unique/   s   ψ π6 zzΧ+Ρ+ΫHσ
π 	
r   c                σD      j                   j                   f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        β|
            |βββββββββββββ΄βββββββββββββββ|
            ββββββββββββββββββββββββββββββ
        c                σl    j                   j                  | «      j                  j                  «      S r   )r   r   r   Ϊcontains)r   Ϊitemr   s    r   r   z,ExprListNamespace.contains.<locals>.<lambda>j   s'   ψ 

Χ5Ρ5°cΣ:Χ?Ρ?ΧHΡHΘΣN r   r   )r   r&   s   ``r   r%   zExprListNamespace.containsN   s   ω π6 zzΧ+Ρ+άNσ
π 	
r   c                σΨ     t        t        «      s$dt        «      j                   d}t	        |«      dk  rd d}t        |«       j                  j                   fd«      S )u  Return the value by index in each list.

        Negative indices are not accepted.

        Returns:
            A new expression.

        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.c                σl    j                   j                  | «      j                  j                  «      S r   )r   r   r   Ϊget)r   Ϊindexr   s    r   r   z'ExprListNamespace.get.<locals>.<lambda>   s'   ψ 

Χ5Ρ5°cΣ:Χ?Ρ?ΧCΡCΐEΣJ r   )Ϊ
isinstanceΪintΪtypeΪ__name__Ϊ	TypeErrorΪ
ValueErrorr   r   )r   r*   Ϊmsgs   `` r   r)   zExprListNamespace.getm   sq   ω τ: %€Τ%ΰ9Ό$Έu»+Χ:NΡ:NΠ9OΘzΠZπ τ C.Π ΰ19Ψ5'Π!YΠZCάS/Π!ΰzzΧ+Ρ+άJσ
π 	
r   N)r   r	   ΪreturnΪNone)r2   r	   )r&   r   r2   r	   )r*   r,   r2   r	   )r.   Ϊ
__module__Ϊ__qualname__r   r   r"   r%   r)   © r   r   r   r      s    σσ
σ>
σ>
τ>)
r   r   N)Ϊ
__future__r   Ϊtypingr   r   r   Ϊnarwhals.exprr   Ϊnarwhals.typingr   r	   r   r6   r   r   ϊ<module>r;      s5   πέ "η 2Ρ 2αέ"έ0αvΤ&τJ
 υ J
r   