Ë
    èË€hid  ã                  óä   — d dl mZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ er>d dlZd dlmZ d d	lmZmZ d d
lmZmZmZ d dlmZ ej2                  dk\  rd dlm	Z	 nd dlm	Z	  G d„ d«      Zy)é    )Úannotations)ÚTYPE_CHECKINGÚCallable)Ú	functions)Ú
deprecated)Úparse_into_list_of_expressions)Úwrap_ldfN)ÚIterable)Ú	DataFrameÚ	LazyFrame)ÚIntoExprÚQuantileMethodÚ
SchemaDict)ÚPyLazyGroupBy)é   é   c                  óÚ   — e Zd ZdZdd„Z	 	 	 	 	 	 dd„Z	 	 	 	 	 	 dd„Zddd„Zddd„Zdd„Z	ddd	„Z
 ed
«      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„Zdd„Zy)ÚLazyGroupByz‡
    Utility class for performing a group by operation over a lazy DataFrame.

    Generated by calling `df.lazy().group_by(...)`.
    c                ó   — || _         y ©N)Úlgb)Úselfr   s     úu/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/lazyframe/group_by.pyÚ__init__zLazyGroupBy.__init__   s	   € Øˆó    c                ó¤   — |r t        |d   t        «      rd}t        |«      ‚t        |i |¤Ž}t	        | j
                  j                  |«      «      S )uu  
        Compute aggregations for each group of a group by operation.

        Parameters
        ----------
        *aggs
            Aggregations to compute for each group of the group by operation,
            specified as positional arguments.
            Accepts expression input. Strings are parsed as column names.
        **named_aggs
            Additional aggregations, specified as keyword arguments.
            The resulting columns will be renamed to the keyword used.

        Examples
        --------
        Compute the aggregation of the columns for each group.

        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": ["a", "b", "a", "b", "c"],
        ...         "b": [1, 2, 1, 3, 3],
        ...         "c": [5, 4, 3, 2, 1],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("a").agg(
        ...     [pl.col("b"), pl.col("c")]
        ... ).collect()  # doctest: +IGNORE_RESULT
        shape: (3, 3)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ a   â”† b         â”† c         â”‚
        â”‚ --- â”† ---       â”† ---       â”‚
        â”‚ str â”† list[i64] â”† list[i64] â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•â•¡
        â”‚ a   â”† [1, 1]    â”† [5, 3]    â”‚
        â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
        â”‚ b   â”† [2, 3]    â”† [4, 2]    â”‚
        â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
        â”‚ c   â”† [3]       â”† [1]       â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        Compute the sum of a column for each group.

        >>> ldf.group_by("a").agg(
        ...     pl.col("b").sum()
        ... ).collect()  # doctest: +IGNORE_RESULT
        shape: (3, 2)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ a   â”† b   â”‚
        â”‚ --- â”† --- â”‚
        â”‚ str â”† i64 â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ a   â”† 2   â”‚
        â”‚ b   â”† 5   â”‚
        â”‚ c   â”† 3   â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜

        Compute multiple aggregates at once by passing a list of expressions.

        >>> ldf.group_by("a").agg(
        ...     [pl.sum("b"), pl.mean("c")]
        ... ).collect()  # doctest: +IGNORE_RESULT
        shape: (3, 3)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ a   â”† b   â”† c   â”‚
        â”‚ --- â”† --- â”† --- â”‚
        â”‚ str â”† i64 â”† f64 â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ c   â”† 3   â”† 1.0 â”‚
        â”‚ a   â”† 2   â”† 4.0 â”‚
        â”‚ b   â”† 5   â”† 3.0 â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜

        Or use positional arguments to compute multiple aggregations in the same way.

        >>> ldf.group_by("a").agg(
        ...     pl.sum("b").name.suffix("_sum"),
        ...     (pl.col("c") ** 2).mean().name.suffix("_mean_squared"),
        ... ).collect()  # doctest: +IGNORE_RESULT
        shape: (3, 3)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ a   â”† b_sum â”† c_mean_squared â”‚
        â”‚ --- â”† ---   â”† ---            â”‚
        â”‚ str â”† i64   â”† f64            â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡
        â”‚ a   â”† 2     â”† 17.0           â”‚
        â”‚ c   â”† 3     â”† 1.0            â”‚
        â”‚ b   â”† 5     â”† 10.0           â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        Use keyword arguments to easily name your expression inputs.

        >>> ldf.group_by("a").agg(
        ...     b_sum=pl.sum("b"),
        ...     c_mean_squared=(pl.col("c") ** 2).mean(),
        ... ).collect()  # doctest: +IGNORE_RESULT
        shape: (3, 3)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ a   â”† b_sum â”† c_mean_squared â”‚
        â”‚ --- â”† ---   â”† ---            â”‚
        â”‚ str â”† i64   â”† f64            â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•¡
        â”‚ a   â”† 2     â”† 17.0           â”‚
        â”‚ c   â”† 3     â”† 1.0            â”‚
        â”‚ b   â”† 5     â”† 10.0           â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
        r   z“specifying aggregations as a dictionary is not supported

Try unpacking the dictionary to take advantage of the keyword syntax of the `agg` method.)Ú
isinstanceÚdictÚ	TypeErrorr   r	   r   Úagg)r   ÚaggsÚ
named_aggsÚmsgÚpyexprss        r   r    zLazyGroupBy.agg"   sR   € ñ^ ”J˜t A™w¬Ô-ð(ð ô
 ˜C“.Ð ä0°$ÐE¸*ÑEˆÜ˜Ÿ™Ÿ™ WÓ-Ó.Ð.r   c                óL   — t        | j                  j                  ||«      «      S )u­	  
        Apply a custom/user-defined function (UDF) over the groups as a new DataFrame.

        .. warning::
            This method is much slower than the native expressions API.
            Only use it if you cannot implement your logic otherwise.

        Using this is considered an anti-pattern as it will be very slow because:

        - it forces the engine to materialize the whole `DataFrames` for the groups.
        - it is not parallelized
        - it blocks optimizations as the passed python function is opaque to the
          optimizer

        The idiomatic way to apply custom functions over multiple columns is using:

        `pl.struct([my_columns]).apply(lambda struct_series: ..)`

        Parameters
        ----------
        function
            Function to apply over each group of the `LazyFrame`.
        schema
            Schema of the output function. This has to be known statically. If the
            given schema is incorrect, this is a bug in the caller's query and may
            lead to errors. If set to None, polars assumes the schema is unchanged.

        Examples
        --------
        For each color group sample two rows:

        >>> df = pl.DataFrame(
        ...     {
        ...         "id": [0, 1, 2, 3, 4],
        ...         "color": ["red", "green", "green", "red", "red"],
        ...         "shape": ["square", "triangle", "square", "triangle", "square"],
        ...     }
        ... )
        >>> (
        ...     df.lazy()
        ...     .group_by("color")
        ...     .map_groups(lambda group_df: group_df.sample(2), schema=None)
        ...     .collect()
        ... )  # doctest: +IGNORE_RESULT
        shape: (4, 3)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ id  â”† color â”† shape    â”‚
        â”‚ --- â”† ---   â”† ---      â”‚
        â”‚ i64 â”† str   â”† str      â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•¡
        â”‚ 1   â”† green â”† triangle â”‚
        â”‚ 2   â”† green â”† square   â”‚
        â”‚ 4   â”† red   â”† square   â”‚
        â”‚ 3   â”† red   â”† triangle â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        It is better to implement this with an expression:

        >>> df.lazy().filter(
        ...     pl.int_range(pl.len()).shuffle().over("color") < 2
        ... ).collect()  # doctest: +IGNORE_RESULT
        )r	   r   Ú
map_groups)r   ÚfunctionÚschemas      r   r&   zLazyGroupBy.map_groupsœ   s!   € ôF ˜Ÿ™×+Ñ+¨H°fÓ=Ó>Ð>r   c                óJ   — t        | j                  j                  |«      «      S )un  
        Get the first `n` rows of each group.

        Parameters
        ----------
        n
            Number of rows to return.

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "letters": ["c", "c", "a", "c", "a", "b"],
        ...         "nrs": [1, 2, 3, 4, 5, 6],
        ...     }
        ... )
        >>> df
        shape: (6, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ letters â”† nrs â”‚
        â”‚ ---     â”† --- â”‚
        â”‚ str     â”† i64 â”‚
        â•žâ•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ c       â”† 1   â”‚
        â”‚ c       â”† 2   â”‚
        â”‚ a       â”† 3   â”‚
        â”‚ c       â”† 4   â”‚
        â”‚ a       â”† 5   â”‚
        â”‚ b       â”† 6   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        >>> df.group_by("letters").head(2).sort("letters")
        shape: (5, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ letters â”† nrs â”‚
        â”‚ ---     â”† --- â”‚
        â”‚ str     â”† i64 â”‚
        â•žâ•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ a       â”† 3   â”‚
        â”‚ a       â”† 5   â”‚
        â”‚ b       â”† 6   â”‚
        â”‚ c       â”† 1   â”‚
        â”‚ c       â”† 2   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        )r	   r   Úhead©r   Úns     r   r*   zLazyGroupBy.headá   ó   € ôZ ˜Ÿ™Ÿ™ aÓ(Ó)Ð)r   c                óJ   — t        | j                  j                  |«      «      S )un  
        Get the last `n` rows of each group.

        Parameters
        ----------
        n
            Number of rows to return.

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "letters": ["c", "c", "a", "c", "a", "b"],
        ...         "nrs": [1, 2, 3, 4, 5, 6],
        ...     }
        ... )
        >>> df
        shape: (6, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ letters â”† nrs â”‚
        â”‚ ---     â”† --- â”‚
        â”‚ str     â”† i64 â”‚
        â•žâ•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ c       â”† 1   â”‚
        â”‚ c       â”† 2   â”‚
        â”‚ a       â”† 3   â”‚
        â”‚ c       â”† 4   â”‚
        â”‚ a       â”† 5   â”‚
        â”‚ b       â”† 6   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        >>> df.group_by("letters").tail(2).sort("letters")
         shape: (5, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ letters â”† nrs â”‚
        â”‚ ---     â”† --- â”‚
        â”‚ str     â”† i64 â”‚
        â•žâ•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ a       â”† 3   â”‚
        â”‚ a       â”† 5   â”‚
        â”‚ b       â”† 6   â”‚
        â”‚ c       â”† 2   â”‚
        â”‚ c       â”† 4   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        )r	   r   Útailr+   s     r   r/   zLazyGroupBy.tail  r-   r   c                óH   — | j                  t        j                  «       «      S )uÖ  
        Aggregate the groups into Series.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": ["one", "two", "one", "two"],
        ...         "b": [1, 2, 3, 4],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("a", maintain_order=True).all().collect()
        shape: (2, 2)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ a   â”† b         â”‚
        â”‚ --- â”† ---       â”‚
        â”‚ str â”† list[i64] â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•â•¡
        â”‚ one â”† [1, 3]    â”‚
        â”‚ two â”† [2, 4]    â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
        )r    ÚFÚall©r   s    r   r2   zLazyGroupBy.all?  s   € ð. x‰xœŸ™›Ó Ð r   Nc                ór   — t        j                  «       }||j                  |«      }| j                  |«      S )u‡  
        Return the number of rows in each group.

        Parameters
        ----------
        name
            Assign a name to the resulting column; if unset, defaults to "len".

        Examples
        --------
        >>> lf = pl.LazyFrame({"a": ["Apple", "Apple", "Orange"], "b": [1, None, 2]})
        >>> lf.group_by("a").len().collect()  # doctest: +IGNORE_RESULT
        shape: (2, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ a      â”† len â”‚
        â”‚ ---    â”† --- â”‚
        â”‚ str    â”† u32 â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ Apple  â”† 2   â”‚
        â”‚ Orange â”† 1   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        >>> lf.group_by("a").len(name="n").collect()  # doctest: +IGNORE_RESULT
        shape: (2, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ a      â”† n   â”‚
        â”‚ ---    â”† --- â”‚
        â”‚ str    â”† u32 â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ Apple  â”† 2   â”‚
        â”‚ Orange â”† 1   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        )r1   ÚlenÚaliasr    )r   ÚnameÚlen_exprs      r   r5   zLazyGroupBy.lenX  s3   € ôB —5‘5“7ˆØÐØ—~‘~ dÓ+ˆHØx‰x˜Ó!Ð!r   z&`count` was renamed; use `len` insteadc                óf   — | j                  t        j                  «       j                  d«      «      S )uh  
        Return the number of rows in each group.

        .. deprecated:: 0.20.5
            This method has been renamed to :func:`LazyGroupBy.len`.

        Rows containing null values count towards the total.

        Examples
        --------
        >>> lf = pl.LazyFrame(
        ...     {
        ...         "a": ["Apple", "Apple", "Orange"],
        ...         "b": [1, None, 2],
        ...     }
        ... )
        >>> lf.group_by("a").count().collect()  # doctest: +SKIP
        shape: (2, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ a      â”† count â”‚
        â”‚ ---    â”† ---   â”‚
        â”‚ str    â”† u32   â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 2     â”‚
        â”‚ Orange â”† 1     â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”˜
        Úcount)r    r1   r5   r6   r3   s    r   r:   zLazyGroupBy.count~  s"   € ð: x‰xœŸ™›Ÿ™ gÓ.Ó/Ð/r   c                ód   — | j                  t        j                  «       j                  «       «      S )ue  
        Aggregate the first values in the group.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "c": [True, True, True, False, False, True],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).first().collect()
        shape: (3, 4)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”† c     â”‚
        â”‚ ---    â”† --- â”† ---  â”† ---   â”‚
        â”‚ str    â”† i64 â”† f64  â”† bool  â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 1   â”† 0.5  â”† true  â”‚
        â”‚ Orange â”† 2   â”† 0.5  â”† true  â”‚
        â”‚ Banana â”† 4   â”† 13.0 â”† false â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úfirstr3   s    r   r<   zLazyGroupBy.first  s   € ð4 x‰xœŸ™›Ÿ™›Ó(Ð(r   c                ód   — | j                  t        j                  «       j                  «       «      S )uc  
        Aggregate the last values in the group.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 14, 13],
        ...         "c": [True, True, True, False, False, True],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).last().collect()
        shape: (3, 4)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”† c     â”‚
        â”‚ ---    â”† --- â”† ---  â”† ---   â”‚
        â”‚ str    â”† i64 â”† f64  â”† bool  â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 3   â”† 10.0 â”† false â”‚
        â”‚ Orange â”† 2   â”† 0.5  â”† true  â”‚
        â”‚ Banana â”† 5   â”† 13.0 â”† true  â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úlastr3   s    r   r>   zLazyGroupBy.last¹  ó   € ð4 x‰xœŸ™›Ÿ™›Ó'Ð'r   c                ód   — | j                  t        j                  «       j                  «       «      S )uS  
        Reduce the groups to the maximal value.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "c": [True, True, True, False, False, True],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).max().collect()
        shape: (3, 4)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”† c    â”‚
        â”‚ ---    â”† --- â”† ---  â”† ---  â”‚
        â”‚ str    â”† i64 â”† f64  â”† bool â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 3   â”† 10.0 â”† true â”‚
        â”‚ Orange â”† 2   â”† 0.5  â”† true â”‚
        â”‚ Banana â”† 5   â”† 14.0 â”† true â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úmaxr3   s    r   rA   zLazyGroupBy.maxÕ  ó   € ð4 x‰xœŸ™›Ÿ™›Ó&Ð&r   c                ód   — | j                  t        j                  «       j                  «       «      S )uÊ  
        Reduce the groups to the mean values.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "c": [True, True, True, False, False, True],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).mean().collect()
        shape: (3, 4)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b        â”† c        â”‚
        â”‚ ---    â”† --- â”† ---      â”† ---      â”‚
        â”‚ str    â”† f64 â”† f64      â”† f64      â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 2.0 â”† 4.833333 â”† 0.666667 â”‚
        â”‚ Orange â”† 2.0 â”† 0.5      â”† 1.0      â”‚
        â”‚ Banana â”† 4.5 â”† 13.5     â”† 0.5      â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úmeanr3   s    r   rD   zLazyGroupBy.meanñ  r?   r   c                ód   — | j                  t        j                  «       j                  «       «      S )um  
        Return the median per group.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "d": ["Apple", "Banana", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).median().collect()
        shape: (2, 3)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”‚
        â”‚ ---    â”† --- â”† ---  â”‚
        â”‚ str    â”† f64 â”† f64  â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 2.0 â”† 4.0  â”‚
        â”‚ Banana â”† 4.0 â”† 13.0 â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úmedianr3   s    r   rF   zLazyGroupBy.median  s    € ð0 x‰xœŸ™›Ÿ™Ó(Ó)Ð)r   c                ód   — | j                  t        j                  «       j                  «       «      S )ub  
        Reduce the groups to the minimal value.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "c": [True, True, True, False, False, True],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).min().collect()
        shape: (3, 4)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”† c     â”‚
        â”‚ ---    â”† --- â”† ---  â”† ---   â”‚
        â”‚ str    â”† i64 â”† f64  â”† bool  â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 1   â”† 0.5  â”† false â”‚
        â”‚ Orange â”† 2   â”† 0.5  â”† true  â”‚
        â”‚ Banana â”† 4   â”† 13.0 â”† false â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úminr3   s    r   rH   zLazyGroupBy.min'  rB   r   c                ód   — | j                  t        j                  «       j                  «       «      S )ui  
        Count the unique values per group.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 1, 3, 4, 5],
        ...         "b": [0.5, 0.5, 0.5, 10, 13, 14],
        ...         "d": ["Apple", "Banana", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).n_unique().collect()
        shape: (2, 3)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b   â”‚
        â”‚ ---    â”† --- â”† --- â”‚
        â”‚ str    â”† u32 â”† u32 â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ Apple  â”† 2   â”† 2   â”‚
        â”‚ Banana â”† 3   â”† 3   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Ún_uniquer3   s    r   rJ   zLazyGroupBy.n_uniqueC  s"   € ð0 x‰xœŸ™›×(Ñ(Ó*Ó+Ð+r   c                ój   — | j                  t        j                  «       j                  ||¬«      «      S )u|  
        Compute the quantile per group.

        Parameters
        ----------
        quantile
            Quantile between 0.0 and 1.0.
        interpolation : {'nearest', 'higher', 'lower', 'midpoint', 'linear', 'equiprobable'}
            Interpolation method.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).quantile(1).collect()
        shape: (3, 3)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”‚
        â”‚ ---    â”† --- â”† ---  â”‚
        â”‚ str    â”† f64 â”† f64  â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 3.0 â”† 10.0 â”‚
        â”‚ Orange â”† 2.0 â”† 0.5  â”‚
        â”‚ Banana â”† 5.0 â”† 14.0 â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
        )Úinterpolation)r    r1   r2   Úquantile)r   rM   rL   s      r   rM   zLazyGroupBy.quantile]  s*   € ðD x‰xœŸ™›×(Ñ(¨ÀÐ(ÓOÓPÐPr   c                ód   — | j                  t        j                  «       j                  «       «      S )u:  
        Reduce the groups to the sum.

        Examples
        --------
        >>> ldf = pl.DataFrame(
        ...     {
        ...         "a": [1, 2, 2, 3, 4, 5],
        ...         "b": [0.5, 0.5, 4, 10, 13, 14],
        ...         "c": [True, True, True, False, False, True],
        ...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
        ...     }
        ... ).lazy()
        >>> ldf.group_by("d", maintain_order=True).sum().collect()
        shape: (3, 4)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”† c   â”‚
        â”‚ ---    â”† --- â”† ---  â”† --- â”‚
        â”‚ str    â”† i64 â”† f64  â”† u32 â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ Apple  â”† 6   â”† 14.5 â”† 2   â”‚
        â”‚ Orange â”† 2   â”† 0.5  â”† 1   â”‚
        â”‚ Banana â”† 9   â”† 27.0 â”† 1   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        )r    r1   r2   Úsumr3   s    r   rO   zLazyGroupBy.sum  rB   r   )r   r   ÚreturnÚNone)r!   zIntoExpr | Iterable[IntoExpr]r"   r   rP   r   )r'   z Callable[[DataFrame], DataFrame]r(   zSchemaDict | NonerP   r   )é   )r,   ÚintrP   r   )rP   r   r   )r7   z
str | NonerP   r   )Únearest)rM   ÚfloatrL   r   rP   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r&   r*   r/   r2   r5   r   r:   r<   r>   rA   rD   rF   rH   rJ   rM   rO   © r   r   r   r      sÚ   „ ñóðx/à,ðx/ð ðx/ð 
ó	x/ðtC?à2ðC?ð "ðC?ð 
ó	C?ôJ-*ô^-*ó^!ô2$"ñL Ð8Ó9ò0ó :ð0ó<)ó8(ó8'ó8(ó8*ó4'ó8,ð6 @Ið"QØð"QØ.<ð"Qà	ó"QôH'r   r   )Ú
__future__r   Útypingr   r   Úpolarsr   r1   Úpolars._utils.deprecationr   Úpolars._utils.parser   Úpolars._utils.wrapr	   ÚsysÚcollections.abcr
   r   r   Úpolars._typingr   r   r   Úpolars.polarsr   Úversion_infoÚwarningsÚtyping_extensionsr   rZ   r   r   ú<module>rh      sL   ðÝ "ç *å !Ý 0Ý >Ý 'áÛÝ(ç+ßCÑCÝ+à
×Ñ˜7Ò"Þ'å0÷C
'ò C
'r   