o
    $&]i”7  ã                   @  sp   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dZG d	d
„ d
ee ƒZdS )é    )Úannotations)ÚTYPE_CHECKINGÚGenericÚTypeVar)ÚExprKindÚExprNode)Ú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&dd„Zd&dd„Z	d&dd„Z
d&dd„Zd&dd„Zdddœd)d"d#„Zd$S )*ÚExprListNamespaceÚexprr
   ÚreturnÚNonec                 C  s
   || _ d S )N)Ú_expr)Úselfr   © r   úP/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/narwhals/expr_list.pyÚ__init__   s   
zExprListNamespace.__init__c                 C  ó   | 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   r   r   r   Úlen   ó   zExprListNamespace.lenc                 C  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      â”‚|
            |â”‚ []           â”† []        â”‚|
            |â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜|
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
        zlist.uniquer   r   r   r   r   Úunique/   r   zExprListNamespace.uniqueÚitemr	   c                 C  s   | j  ttj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        â”‚|
            |â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜|
            â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
        zlist.contains)r   r   )r   r   r   r   r   ÚcontainsL   s   ÿzExprListNamespace.containsÚindexÚintc                 C  sX   t |tƒsdt|ƒj› d}t|ƒ‚|dk r d|› d}t|ƒ‚| j tt	j
d|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)r   )Ú
isinstancer    ÚtypeÚ__name__Ú	TypeErrorÚ
ValueErrorr   r   r   r   r   )r   r   Úmsgr   r   r   Úgetk   s   
ÿÿzExprListNamespace.getc                 C  r   )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   r   r   r   Úmin“   ó   zExprListNamespace.minc                 C  r   )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   r   r   r   Úmaxª   ó   zExprListNamespace.maxc                 C  r   )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   r   r   r   ÚmeanÃ   r)   zExprListNamespace.meanc                 C  r   )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   r   r   r   ÚmedianÚ   r)   zExprListNamespace.medianc                 C  r   )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   r   r   r   Úsumñ   r+   zExprListNamespace.sumF©Ú
descendingÚ
nulls_lastr0   Úboolr1   c                C  s   | j  ttjd||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.sortr/   r   )r   r0   r1   r   r   r   Úsort
  s   üÿzExprListNamespace.sortN)r   r
   r   r   )r   r
   )r   r	   r   r
   )r   r    r   r
   )r0   r2   r1   r2   r   r
   )r#   Ú
__module__Ú__qualname__r   r   r   r   r'   r(   r*   r,   r-   r.   r3   r   r   r   r   r      s    





(



r   N)Ú
__future__r   Útypingr   r   r   Únarwhals._expression_parsingr   r   Únarwhals.exprr   Únarwhals.typingr	   r
   r   r   r   r   r   Ú<module>   s    