o
    L¾±hX  ã                   @  s`   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dZ
G dd	„ d	ee
 ƒZd
S )é    )Úannotations)ÚTYPE_CHECKINGÚGenericÚTypeVar)ÚExpr)ÚNonNestedLiteralÚExprTr   )Úboundc                   @  s>   e Zd Zddd„Zddd„Zdd	d
„Zddd„Zddd„ZdS )ÚExprListNamespaceÚexprr   ÚreturnÚNonec                 C  s
   || _ d S ©N)Ú_expr)Úselfr   © r   úS/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/narwhals/expr_list.pyÚ__init__   s   
zExprListNamespace.__init__c                   ó   ˆ j  ‡ fd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 ¡ S r   )r   Ú_to_compliant_exprÚlistÚlen©Úplx©r   r   r   Ú<lambda>,   ó    z'ExprListNamespace.len.<locals>.<lambda>©r   Ú_with_elementwiser   r   r   r   r      ó   
ÿzExprListNamespace.lenc                   r   )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                   r   r   )r   r   r   Úuniquer   r   r   r   r   K   r   z*ExprListNamespace.unique.<locals>.<lambda>r   r   r   r   r   r!   /   r    zExprListNamespace.uniqueÚitemr   c                   s   ˆj  ‡ ‡fd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                   ó   ˆj  | ¡j ˆ ¡S r   )r   r   r   Úcontainsr   ©r"   r   r   r   r   j   ó    z,ExprListNamespace.contains.<locals>.<lambda>r   )r   r"   r   r%   r   r$   N   s   ÿzExprListNamespace.containsÚindexÚintc                   sV   t ˆ tƒsdtˆ ƒj› d}t|ƒ‚ˆ dk r dˆ › d}t|ƒ‚ˆj ‡ ‡fd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                   r#   r   )r   r   r   Úgetr   ©r'   r   r   r   r   •   r&   z'ExprListNamespace.get.<locals>.<lambda>)Ú
isinstancer(   ÚtypeÚ__name__Ú	TypeErrorÚ
ValueErrorr   r   )r   r'   Úmsgr   r*   r   r)   m   s   
ÿÿzExprListNamespace.getN)r   r   r   r   )r   r   )r"   r   r   r   )r'   r(   r   r   )r-   Ú
__module__Ú__qualname__r   r   r!   r$   r)   r   r   r   r   r
      s    



r
   N)Ú
__future__r   Útypingr   r   r   Únarwhals.exprr   Únarwhals.typingr   r   r
   r   r   r   r   Ú<module>   s    