Ë
    ±.óh£—  ã                  óD  — d dl mZ d dlmZmZ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 d d	lmZ d d
lmZmZmZmZmZmZ ej4                  dk\  rd dlmZ nd dlmZ ej4                  dk\  rd dlmZ nd dlmZ  G d„ d«      Z G d„ d«      Z G d„ d«      Z y)é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚCallable)Ú	functions)Úparse_as_duration_string)Ú
deprecatedN)ÚIterable)Ú	timedelta)Ú	DataFrame)ÚClosedIntervalÚIntoExprÚLabelÚQuantileMethodÚ
SchemaDictÚStartBy)é   é   )ÚSelf)r   é   c                  óò   — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 dd„Zd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
)#ÚGroupByzStarts a new GroupBy operation.c               ó<   — || _         || _        || _        || _        y)aº  
        Utility class for performing a group by operation over the given DataFrame.

        Generated by calling `df.group_by(...)`.

        Parameters
        ----------
        df
            DataFrame to perform the group by operation over.
        *by
            Column or columns to group by. Accepts expression input. Strings are parsed
            as column names.
        maintain_order
            Ensure that the order of the groups is consistent with the input data.
            This is slower than a default group by.
        **named_by
            Additional column(s) to group by, specified as keyword arguments.
            The columns will be named as the keyword used.
        N)ÚdfÚbyÚnamed_byÚmaintain_order)Úselfr   r   r   r   s        úW/var/www/html/ai-service/venv/lib/python3.12/site-packages/polars/dataframe/group_by.pyÚ__init__zGroupBy.__init__&   s!   € ð4 ˆŒØˆŒØ ˆŒØ,ˆÕó    c                ó„  — ddl m} | j                  j                  «       | _        d} | j                  j	                  «       j
                  | j                  i | j                  ¤d| j                  i¤Žj                  t        j                  «       j                  «       j                  |«      «      j                  |j                  «       ¬«      }|j!                  t        j"                  «       j%                  |«      «      j'                  «       | _        |j!                  |«      j+                  «       | _        d| _        | S )u3  
        Allows iteration over the groups of the group by operation.

        Each group is represented by a tuple of `(name, data)`. The group names are
        tuples of the distinct group values that identify each group.

        Examples
        --------
        >>> df = pl.DataFrame({"foo": ["a", "a", "b"], "bar": [1, 2, 3]})
        >>> for name, data in df.group_by("foo"):  # doctest: +SKIP
        ...     print(name)
        ...     print(data)
        (a,)
        shape: (2, 2)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ foo â”† bar â”‚
        â”‚ --- â”† --- â”‚
        â”‚ str â”† i64 â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ a   â”† 1   â”‚
        â”‚ a   â”† 2   â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        (b,)
        shape: (1, 2)
        â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ foo â”† bar â”‚
        â”‚ --- â”† --- â”‚
        â”‚ str â”† i64 â”‚
        â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ b   â”† 3   â”‚
        â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        r   ©ÚQueryOptFlagsÚ__POLARS_GB_GROUP_INDICESr   ©Úoptimizations)Úpolars.lazyframe.opt_flagsr$   r   ÚrechunkÚlazyÚgroup_byr   r   r   ÚaggÚFÚfirstÚ
agg_groupsÚaliasÚcollectÚnoneÚselectÚallÚexcludeÚ	iter_rowsÚ_group_namesÚ	to_seriesÚ_group_indicesÚ_current_index©r   r$   Útemp_colÚ	groups_dfs       r   Ú__iter__zGroupBy.__iter__E   sñ   € õD 	=à—'‘'—/‘/Ó#ˆŒØ.ˆðˆDG‰GL‰L‹Nß‰Xt—w‘wðUØ"&§-¡-ñUØ@D×@SÑ@SòUç‰S”—‘“×%Ñ%Ó'×-Ñ-¨hÓ7Ó8ß‰W =×#5Ñ#5Ó#7ˆWÓ8ð	 	ð &×,Ñ,¬Q¯U©U«W¯_©_¸XÓ-FÓG×QÑQÓSˆÔØ'×.Ñ.¨xÓ8×BÑBÓDˆÔØˆÔàˆr!   c                ó  — | j                   t        | j                  «      k\  rt        ‚t	        | j
                  «      }| j                  | j                  | j                      d d …f   }| xj                   dz  c_         ||fS ©Né   ©r:   Úlenr9   ÚStopIterationÚnextr7   r   ©r   Ú
group_nameÚ
group_datas      r   Ú__next__zGroupBy.__next__x   óq   € Ø×Ñ¤# d×&9Ñ&9Ó":Ò:ÜÐä˜$×+Ñ+Ó,ˆ
Ø—W‘W˜T×0Ñ0°×1DÑ1DÑEÂqÐHÑIˆ
Ø×Ò˜qÑ Õà˜:Ð%Ð%r!   c                ó  — ddl m}   | j                  j                  «       j                  | j
                  i | j                  ¤d| j                  i¤Žj                  |i |¤Žj                  |j                  «       ¬«      S )uÚ  
        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.

        >>> df = pl.DataFrame(
        ...     {
        ...         "a": ["a", "b", "a", "b", "c"],
        ...         "b": [1, 2, 1, 3, 3],
        ...         "c": [5, 4, 3, 2, 1],
        ...     }
        ... )
        >>> df.group_by("a").agg(pl.col("b"), pl.col("c"))  # 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.

        >>> df.group_by("a").agg(pl.col("b").sum())  # 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.

        >>> df.group_by("a").agg([pl.sum("b"), pl.mean("c")])  # 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.

        >>> df.group_by("a").agg(
        ...     pl.sum("b").name.suffix("_sum"),
        ...     (pl.col("c") ** 2).mean().name.suffix("_mean_squared"),
        ... )  # 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.

        >>> df.group_by("a").agg(
        ...     b_sum=pl.sum("b"),
        ...     c_mean_squared=(pl.col("c") ** 2).mean(),
        ... )  # 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   r#   r   r&   )r(   r$   r   r*   r+   r   r   r   r,   r1   r2   ©r   ÚaggsÚ
named_aggsr$   s       r   r,   zGroupBy.agg‚   s{   € õR 	=ðð ˆDG‰GL‰L‹Nß‰Xt—w‘wðUØ"&§-¡-ñUØ@D×@SÑ@SòUç‰S$ð&à$ñ&÷ ‰W =×#5Ñ#5Ó#7ˆWÓ8ð		
r!   c                óF  — | j                   rd}t        |«      ‚t        d„ | j                  D «       «      sd}t        |«      ‚| j                  }| j                  j
                  j                  | j                  j                  j                  ||| j                  «      «      S )u1	  
        Apply a custom/user-defined function (UDF) over the groups as a sub-DataFrame.

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

        Implementing logic using a Python function is almost always *significantly*
        slower and more memory intensive than implementing the same logic using
        the native expression API because:

        - The native expression engine runs in Rust; UDFs run in Python.
        - Use of Python UDFs forces the DataFrame to be materialized in memory.
        - Polars-native expressions can be parallelised (UDFs cannot).
        - Polars-native expressions can be logically optimised (UDFs cannot).

        Wherever possible you should strongly prefer the native expression API
        to achieve the best performance.

        Parameters
        ----------
        function
            Custom function that receives a DataFrame and returns a DataFrame.

        Returns
        -------
        DataFrame

        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.group_by("color").map_groups(
        ...     lambda group_df: group_df.sample(2)
        ... )  # 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.filter(
        ...     pl.int_range(pl.len()).shuffle().over("color") < 2
        ... )  # doctest: +IGNORE_RESULT
        z;cannot call `map_groups` when grouping by named expressionsc              3  ó<   K  — | ]  }t        |t        «      –— Œ y ­w©N)Ú
isinstanceÚstr)Ú.0Úcs     r   ú	<genexpr>z%GroupBy.map_groups.<locals>.<genexpr>4  s   è ø€ Ò7¨!”:˜a¤×%Ñ7ùs   ‚z7cannot call `map_groups` when grouping by an expression)
r   Ú	TypeErrorr4   r   r   Ú	__class__Ú
_from_pydfÚ_dfÚgroup_by_map_groupsr   )r   ÚfunctionÚmsgÚby_strss       r   Ú
map_groupszGroupBy.map_groupsô   s‚   € ðz =Š=ØOˆCÜ˜C“.Ð ÜÑ7¨t¯w©wÔ7Ô7ØKˆCÜ˜C“.Ð à!ŸW™Wˆàw‰w× Ñ ×+Ñ+ØG‰GK‰K×+Ñ+¨G°X¸t×?RÑ?RÓSó
ð 	
r!   c                ó   — ddl m}  | j                  j                  «       j                  | j
                  i | j                  ¤d| j                  i¤Žj                  |«      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#   r   r&   )r(   r$   r   r*   r+   r   r   r   Úheadr1   Ú_eager©r   Únr$   s      r   ra   zGroupBy.head>  si   € õZ 	=ðˆDG‰GL‰L‹Nß‰Xt—w‘wðUØ"&§-¡-ñUØ@D×@SÑ@SòUç‰T!‹Wß‰W =×#7Ñ#7Ó#9ˆWÓ:ð		
r!   c                ó   — ddl m}  | j                  j                  «       j                  | j
                  i | j                  ¤d| j                  i¤Žj                  |«      j                  |j                  «       ¬«      S )um  
        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#   r   r&   )r(   r$   r   r*   r+   r   r   r   Útailr1   r2   rc   s      r   rf   zGroupBy.tailt  si   € õZ 	=ðˆDG‰GL‰L‹Nß‰Xt—w‘wðUØ"&§-¡-ñUØ@D×@SÑ@SòUç‰T!‹Wß‰W =×#5Ñ#5Ó#7ˆWÓ8ð		
r!   c                óH   — | j                  t        j                  «       «      S )uj  
        Aggregate the groups into Series.

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

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

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

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

        Rows containing null values count towards the total.

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "a": ["Apple", "Apple", "Orange"],
        ...         "b": [1, None, 2],
        ...     }
        ... )
        >>> df.group_by("a").count()  # doctest: +SKIP
        shape: (2, 2)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”€â”
        â”‚ a      â”† count â”‚
        â”‚ ---    â”† ---   â”‚
        â”‚ str    â”† u32   â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 2     â”‚
        â”‚ Orange â”† 1     â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”€â”˜
        Úcount)r,   r-   rC   r0   rh   s    r   rm   zGroupBy.countä  s"   € ð: x‰xœŸ™›Ÿ™ gÓ.Ó/Ð/r!   c                ód   — | j                  t        j                  «       j                  «       «      S )uR  
        Aggregate the first values in the group.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).first()
        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,   r-   r4   r.   rh   s    r   r.   zGroupBy.first  s   € ð4 x‰xœŸ™›Ÿ™›Ó(Ð(r!   c                ód   — | j                  t        j                  «       j                  «       «      S )uP  
        Aggregate the last values in the group.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).last()
        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,   r-   r4   Úlastrh   s    r   rp   zGroupBy.last  ó   € ð4 x‰xœŸ™›Ÿ™›Ó'Ð'r!   c                ód   — | j                  t        j                  «       j                  «       «      S )u@  
        Reduce the groups to the maximal value.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).max()
        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,   r-   r4   Úmaxrh   s    r   rs   zGroupBy.max;  ó   € ð4 x‰xœŸ™›Ÿ™›Ó&Ð&r!   c                ód   — | j                  t        j                  «       j                  «       «      S )u·  
        Reduce the groups to the mean values.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).mean()
        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,   r-   r4   Úmeanrh   s    r   rv   zGroupBy.meanW  rq   r!   c                ód   — | j                  t        j                  «       j                  «       «      S )uZ  
        Return the median per group.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).median()
        shape: (2, 3)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b    â”‚
        â”‚ ---    â”† --- â”† ---  â”‚
        â”‚ str    â”† f64 â”† f64  â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
        â”‚ Apple  â”† 2.0 â”† 4.0  â”‚
        â”‚ Banana â”† 4.0 â”† 13.0 â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
        )r,   r-   r4   Úmedianrh   s    r   rx   zGroupBy.medians  s    € ð0 x‰xœŸ™›Ÿ™Ó(Ó)Ð)r!   c                ód   — | j                  t        j                  «       j                  «       «      S )uO  
        Reduce the groups to the minimal value.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).min()
        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,   r-   r4   Úminrh   s    r   rz   zGroupBy.min  rt   r!   c                ód   — | j                  t        j                  «       j                  «       «      S )uV  
        Count the unique values per group.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).n_unique()
        shape: (2, 3)
        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
        â”‚ d      â”† a   â”† b   â”‚
        â”‚ ---    â”† --- â”† --- â”‚
        â”‚ str    â”† u32 â”† u32 â”‚
        â•žâ•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
        â”‚ Apple  â”† 2   â”† 2   â”‚
        â”‚ Banana â”† 3   â”† 3   â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
        )r,   r-   r4   Ún_uniquerh   s    r   r|   zGroupBy.n_unique©  s"   € ð0 x‰xœŸ™›×(Ñ(Ó*Ó+Ð+r!   c                ój   — | j                  t        j                  «       j                  ||¬«      «      S )ui  
        Compute the quantile per group.

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

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).quantile(1)
        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,   r-   r4   Úquantile)r   r   r~   s      r   r   zGroupBy.quantileÃ  s*   € ðD x‰xœŸ™›×(Ñ(¨ÀÐ(ÓOÓPÐPr!   c                ód   — | j                  t        j                  «       j                  «       «      S )u'  
        Reduce the groups to the sum.

        Examples
        --------
        >>> df = 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"],
        ...     }
        ... )
        >>> df.group_by("d", maintain_order=True).sum()
        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,   r-   r4   Úsumrh   s    r   r   zGroupBy.sumç  rt   r!   )
r   r   r   úIntoExpr | Iterable[IntoExpr]r   Úboolr   r   ÚreturnÚNone©r„   r   )r„   z!tuple[tuple[Any, ...], DataFrame]©rM   r‚   rN   r   r„   r   )r\   ú Callable[[DataFrame], DataFrame]r„   r   )é   )rd   Úintr„   r   )r„   r   rQ   )rj   z
str | Noner„   r   )Únearest)r   Úfloatr~   r   r„   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r>   rI   r,   r_   ra   rf   r4   rC   r	   rm   r.   rp   rs   rv   rx   rz   r|   r   r   © r!   r   r   r   #   sõ   „ Ù)ð-àð-ð +ð-ð ð	-ð
 ð-ð 
ó-ó>1óf&ðp
à,ðp
ð ðp
ð 
ó	p
ódH
ôT4
ôl4
ól!ô($"ñL ÐHÓIò0ó Jð0ó<)ó8(ó8'ó8(ó8*ó4'ó8,ð6 @Ið"QØð"QØ.<ð"Qà	ó"QôH'r!   r   c                  ól   — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zd	d„Zd
d„Z	 	 	 	 	 	 dd„Z	 	 	 	 	 	 dd„Zy)ÚRollingGroupByz‰
    A rolling grouper.

    This has an `.agg` method which will allow you to run all polars expressions in a
    group by context.
    c               ó„   — t        |«      }t        |«      }|| _        || _        || _        || _        || _        || _        y rQ   )r   r   Útime_columnÚperiodÚoffsetÚclosedr+   )r   r   Úindex_columnr–   r—   r˜   r+   s          r   r    zRollingGroupBy.__init__  sC   € ô *¨&Ó1ˆÜ)¨&Ó1ˆàˆŒØ'ˆÔØˆŒØˆŒØˆŒØ ˆr!   c                ón  — ddl m} d}| j                  j                  «       j	                  | j
                  | j                  | j                  | j                  | j                  ¬«      j                  t        j                  «       j                  «       j                  |«      «      j                  |j!                  «       ¬«      }|j#                  t        j$                  «       j'                  |«      «      j)                  «       | _        |j#                  |«      j-                  «       | _        d| _        | S )Nr   r#   r%   ©r™   r–   r—   r˜   r+   r&   )r(   r$   r   r*   Úrollingr•   r–   r—   r˜   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   s       r   r>   zRollingGroupBy.__iter__   sá   € Ý<à.ˆàG‰GL‰L‹Nß‰WØ!×-Ñ-Ø—{‘{Ø—{‘{Ø—{‘{ØŸ™ð ó ÷ ‰S”—‘“×%Ñ%Ó'×-Ñ-¨hÓ7Ó8ß‰W =×#5Ñ#5Ó#7ˆWÓ8ð 	ð &×,Ñ,¬Q¯U©U«W¯_©_¸XÓ-FÓG×QÑQÓSˆÔØ'×.Ñ.¨xÓ8×BÑBÓDˆÔØˆÔàˆr!   c                ó  — | j                   t        | j                  «      k\  rt        ‚t	        | j
                  «      }| j                  | j                  | j                      d d …f   }| xj                   dz  c_         ||fS r@   rB   rF   s      r   rI   zRollingGroupBy.__next__7  rJ   r!   c                ó*  — ddl m}  | j                  j                  «       j	                  | j
                  | j                  | j                  | j                  | j                  ¬«      j                  |i |¤Žj                  |j                  «       ¬«      S )áë  
        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.
        r   r#   r›   r&   )r(   r$   r   r*   rœ   r•   r–   r—   r˜   r+   r,   r1   r2   rL   s       r   r,   zRollingGroupBy.aggA  s€   € õ$ 	=ðˆDG‰GL‰L‹Nß‰WØ!×-Ñ-Ø—{‘{Ø—{‘{Ø—{‘{ØŸ™ð ó ÷ ‰S$ð&ð %ñ&÷ ‰W =×#5Ñ#5Ó#7ˆWÓ8ð	
r!   c                ó*  — ddl m} | j                  j                  «       j	                  | j
                  | j                  | j                  | j                  | j                  ¬«      j                  ||«      j                  |j                  «       ¬«      S )áö  
        Apply a custom/user-defined function (UDF) over the groups as a new DataFrame.

        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]).map_elements(lambda struct_series: ..)`

        Parameters
        ----------
        function
            Function to apply over each group of the `LazyFrame`; it receives
            a DataFrame and should return a DataFrame.
        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.
        r   r#   r›   r&   )r(   r$   r   r*   rœ   r•   r–   r—   r˜   r+   r_   r1   r2   ©r   r\   Úschemar$   s       r   r_   zRollingGroupBy.map_groupsb  sr   € õ: 	=ð G‰GL‰L‹Nß‰WØ!×-Ñ-Ø—{‘{Ø—{‘{Ø—{‘{ØŸ™ð ó ÷ ‰Z˜ &Ó)ß‰W =×#5Ñ#5Ó#7ˆWÓ8ð	
r!   N)r   r   r™   r   r–   ústr | timedeltar—   ústr | timedelta | Noner˜   r   r+   ú$IntoExpr | Iterable[IntoExpr] | Noner„   r…   r†   ©r„   z$tuple[tuple[object, ...], DataFrame]r‡   ©r\   rˆ   r£   zSchemaDict | Noner„   r   ©	r   rŽ   r   r   r    r>   rI   r,   r_   r‘   r!   r   r“   r“     s   „ ñð!àð!ð ð!ð
  ð!ð 'ð!ð ð!ð 7ð!ð 
ó!ó(ó.&ð
à,ð
ð ð
ð 
ó	
ðB*
à2ð*
ð "ð*
ð 
ô	*
r!   r“   c                  ó|   — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zd	d„Zd
d„Z	 	 	 	 	 	 dd„Z	 	 	 	 	 	 dd„Zy)ÚDynamicGroupByz…
    A dynamic grouper.

    This has an `.agg` method which allows you to run all polars expressions in a
    group by context.
    c               óÒ   — t        |«      }t        |«      }t        |«      }|| _        || _        || _        || _        || _        || _        || _        || _        |	| _	        |
| _
        y rQ   )r   r   r•   Úeveryr–   r—   ÚlabelÚinclude_boundariesr˜   r+   Ústart_by)r   r   r™   r­   r–   r—   r¯   r˜   r®   r+   r°   s              r   r    zDynamicGroupBy.__init__—  sj   € ô )¨Ó/ˆÜ)¨&Ó1ˆÜ)¨&Ó1ˆàˆŒØ'ˆÔØˆŒ
ØˆŒØˆŒØˆŒ
Ø"4ˆÔØˆŒØ ˆŒØ ˆr!   c                óÆ  — ddl m} d}| j                  j                  «       j	                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  ¬«	      j                  t        j                   «       j#                  «       j%                  |«      «      j'                  |j)                  «       ¬«      }|j+                  t        j,                  «       j/                  |«      «      j1                  «       | _        |j+                  |«      j5                  «       | _        d| _        | S )Nr   r#   r%   ©	r™   r­   r–   r—   r®   r¯   r˜   r+   r°   r&   )r(   r$   r   r*   Úgroup_by_dynamicr•   r­   r–   r—   r®   r¯   r˜   r+   r°   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   s       r   r>   zDynamicGroupBy.__iter__´  s   € Ý<à.ˆàG‰GL‰L‹NßÑØ!×-Ñ-Ø—j‘jØ—{‘{Ø—{‘{Ø—j‘jØ#'×#:Ñ#:Ø—{‘{ØŸ™ØŸ™ð ó 
÷ ‰S”—‘“×%Ñ%Ó'×-Ñ-¨hÓ7Ó8ß‰W =×#5Ñ#5Ó#7ˆWÓ8ð 	ð" &×,Ñ,¬Q¯U©U«W¯_©_¸XÓ-FÓG×QÑQÓSˆÔØ'×.Ñ.¨xÓ8×BÑBÓDˆÔØˆÔàˆr!   c                ó  — | j                   t        | j                  «      k\  rt        ‚t	        | j
                  «      }| j                  | j                  | j                      d d …f   }| xj                   dz  c_         ||fS r@   rB   rF   s      r   rI   zDynamicGroupBy.__next__Ï  rJ   r!   c                ó‚  — ddl m}  | j                  j                  «       j	                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  ¬«	      j                  |i |¤Žj                  |j!                  «       ¬«      S )rŸ   r   r#   r²   r&   )r(   r$   r   r*   r³   r•   r­   r–   r—   r®   r¯   r˜   r+   r°   r,   r1   r2   rL   s       r   r,   zDynamicGroupBy.aggÙ  sŸ   € õ$ 	=ðˆDG‰GL‰L‹NßÑØ!×-Ñ-Ø—j‘jØ—{‘{Ø—{‘{Ø—j‘jØ#'×#:Ñ#:Ø—{‘{ØŸ™ØŸ™ð ó 
÷ ‰S$ð&ð %ñ&÷ ‰W =×#5Ñ#5Ó#7ˆWÓ8ð	
r!   c           
     ól  — ddl m} | j                  j                  «       j	                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  ¬«      j                  ||«      j                  |j                  «       ¬«      S )r¡   r   r#   )r™   r­   r–   r—   r¯   r˜   r+   r°   r&   )r(   r$   r   r*   r³   r•   r­   r–   r—   r¯   r˜   r+   r°   r_   r1   r2   r¢   s       r   r_   zDynamicGroupBy.map_groupsþ  sŠ   € õ: 	=ð G‰GL‰L‹NßÑØ!×-Ñ-Ø—j‘jØ—{‘{Ø—{‘{Ø#'×#:Ñ#:Ø—{‘{ØŸ™ØŸ™ð ó 	÷ ‰Z˜ &Ó)ß‰W =×#5Ñ#5Ó#7ˆWÓ8ð	
r!   N)r   r   r™   r   r­   r¤   r–   r¥   r—   r¥   r¯   rƒ   r˜   r   r®   r   r+   r¦   r°   r   r„   r…   r†   r§   r‡   r¨   r©   r‘   r!   r   r«   r«     sÅ   „ ñð!àð!ð ð!ð
 ð!ð 'ð!ð 'ð!ð !ð!ð ð!ð ð!ð 7ð!ð ð!ð 
ó!ó:ó6&ð#
à,ð#
ð ð#
ð 
ó	#
ðJ-
à2ð-
ð "ð-
ð 
ô	-
r!   r«   )!Ú
__future__r   Útypingr   r   r   Úpolarsr   r-   Úpolars._utils.convertr   Úpolars._utils.deprecationr	   ÚsysÚcollections.abcr
   Údatetimer   r   Úpolars._typingr   r   r   r   r   r   Úversion_infor   Útyping_extensionsÚwarningsr   r“   r«   r‘   r!   r   ú<module>rÃ      s€   ðÝ "ç /Ñ /å !Ý :Ý 0áÛÝ(Ý"å ÷÷ ð ×Ñ˜7Ò"Þå*à
×Ñ˜7Ò"Þ'å0÷^'ñ ^'÷BH
ñ H
÷V\
ò \
r!   