Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/core/groupby/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/core/groupby/__pycache__/groupby.cpython-312.pyc

�

Mٜg�����dZddlmZddlmZmZmZmZddlZddl	m
Z
mZddlZddl
mZddlmZmZmZmZmZmZmZddlZddlZddlmZdd	lmZmZdd
lm Z ddl!m"cm#Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4dd
l5m6Z7ddl8m9Z9m:Z:ddl;m<Z<m=Z=m>Z>m?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPddlQmRZRmSZSmTZTddlUmVZVmWZWddlXmYZYddlZm[Z[ddl\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcddldmeZeddlfmgZgmhZhddlimjZjmkZkddllmmcmnZoddlpmqZqddlrmsZsddltmuZumvZvmwZwddlxmyZyddlzm{Z{m|Z|dd l}m~Z~mZm�Z�m�Z�m�Z�dd!l�m�Z�dd"l�m�Z�dd#l�m�Z�dd$l�m�Z�m�Z�erdd%lm�Z�dd&l�m�Z�dd'l�m�Z�m�Z�m�Z�d(Z�d)d*d+d,�Z�d-Z�d.Z�d/Z�d0Z�d1Z�d2Z�eGd3�d4ej��Z�eee�eeegefe�eegefeeeffZ�Gd5�d6ejeke/e{�Z�ed7es�8�Z�Gd9�d:e�e/�Z�e?e��				d>											d?d;��Z�d@d<�Z�d=Z�y)Aa
Provide the groupby split-apply-combine paradigm. Define the GroupBy
class providing the base-class of operations.

The SeriesGroupBy and DataFrameGroupBy sub-class
(defined in pandas.core.groupby.generic)
expose these user-facing objects to provide specific functionality.
�)�annotations)�Hashable�Iterator�Mapping�SequenceN)�partial�wraps)�dedent)�
TYPE_CHECKING�Callable�Literal�TypeVar�Union�cast�final)�option_context)�	Timestamp�lib)�rank_1d)�NA)
�AnyArrayLike�	ArrayLike�Axis�AxisInt�DtypeObj�
FillnaOptions�
IndexLabel�NDFrameT�PositionalIndexer�RandomState�Scalar�T�npt)�function)�AbstractMethodError�	DataError)�Appender�Substitution�cache_readonly�doc)�find_stack_level)�coerce_indexer_dtype�ensure_dtype_can_hold_na)�
is_bool_dtype�is_float_dtype�is_hashable�
is_integer�is_integer_dtype�is_list_like�is_numeric_dtype�is_object_dtype�	is_scalar�needs_i8_conversion�pandas_dtype)�isna�na_value_for_dtype�notna)�
algorithms�sample)�executor)�warn_alias_replacement)�ArrowExtensionArray�BaseMaskedArray�Categorical�ExtensionArray�
FloatingArray�IntegerArray�SparseArray)�StringDtype)�ArrowStringArray�ArrowStringArrayNumpySemantics)�PandasObject�SelectionMixin)�	DataFrame)�NDFrame)�base�numba_�ops)�get_grouper)�GroupByIndexingMixin�GroupByNthSelector)�CategoricalIndex�Index�
MultiIndex�
RangeIndex�
default_index)�ensure_block_shape)�Series)�get_group_index_sorter)�get_jit_arguments�maybe_use_numba)�Any)�	Resampler)�ExpandingGroupby�ExponentialMovingWindowGroupby�RollingGroupbyz�
        See Also
        --------
        Series.%(name)s : Apply a function %(name)s to a Series.
        DataFrame.%(name)s : Apply a function %(name)s
            to each row or column of a DataFrame.
al	
    Apply function ``func`` group-wise and combine the results together.

    The function passed to ``apply`` must take a {input} as its first
    argument and return a DataFrame, Series or scalar. ``apply`` will
    then take care of combining the results back together into a single
    dataframe or series. ``apply`` is therefore a highly flexible
    grouping method.

    While ``apply`` is a very flexible method, its downside is that
    using it can be quite a bit slower than using more specific methods
    like ``agg`` or ``transform``. Pandas offers a wide range of method that will
    be much faster than using ``apply`` for their specific purposes, so try to
    use them before reaching for ``apply``.

    Parameters
    ----------
    func : callable
        A callable that takes a {input} as its first argument, and
        returns a dataframe, a series or a scalar. In addition the
        callable may take positional and keyword arguments.
    include_groups : bool, default True
        When True, will attempt to apply ``func`` to the groupings in
        the case that they are columns of the DataFrame. If this raises a
        TypeError, the result will be computed with the groupings excluded.
        When False, the groupings will be excluded when applying ``func``.

        .. versionadded:: 2.2.0

        .. deprecated:: 2.2.0

           Setting include_groups to True is deprecated. Only the value
           False will be allowed in a future version of pandas.

    args, kwargs : tuple and dict
        Optional positional and keyword arguments to pass to ``func``.

    Returns
    -------
    Series or DataFrame

    See Also
    --------
    pipe : Apply function to the full GroupBy object instead of to each
        group.
    aggregate : Apply aggregate function to the GroupBy object.
    transform : Apply function column-by-column to the GroupBy object.
    Series.apply : Apply a function to a Series.
    DataFrame.apply : Apply a function to each row or column of a DataFrame.

    Notes
    -----

    .. versionchanged:: 1.3.0

        The resulting dtype will reflect the return value of the passed ``func``,
        see the examples below.

    Functions that mutate the passed object can produce unexpected
    behavior or errors and are not supported. See :ref:`gotchas.udf-mutation`
    for more details.

    Examples
    --------
    {examples}
    a?
    >>> df = pd.DataFrame({'A': 'a a b'.split(),
    ...                    'B': [1, 2, 3],
    ...                    'C': [4, 6, 5]})
    >>> g1 = df.groupby('A', group_keys=False)
    >>> g2 = df.groupby('A', group_keys=True)

    Notice that ``g1`` and ``g2`` have two groups, ``a`` and ``b``, and only
    differ in their ``group_keys`` argument. Calling `apply` in various ways,
    we can get different grouping results:

    Example 1: below the function passed to `apply` takes a DataFrame as
    its argument and returns a DataFrame. `apply` combines the result for
    each group together into a new DataFrame:

    >>> g1[['B', 'C']].apply(lambda x: x / x.sum())
              B    C
    0  0.333333  0.4
    1  0.666667  0.6
    2  1.000000  1.0

    In the above, the groups are not part of the index. We can have them included
    by using ``g2`` where ``group_keys=True``:

    >>> g2[['B', 'C']].apply(lambda x: x / x.sum())
                B    C
    A
    a 0  0.333333  0.4
      1  0.666667  0.6
    b 2  1.000000  1.0

    Example 2: The function passed to `apply` takes a DataFrame as
    its argument and returns a Series.  `apply` combines the result for
    each group together into a new DataFrame.

    .. versionchanged:: 1.3.0

        The resulting dtype will reflect the return value of the passed ``func``.

    >>> g1[['B', 'C']].apply(lambda x: x.astype(float).max() - x.min())
         B    C
    A
    a  1.0  2.0
    b  0.0  0.0

    >>> g2[['B', 'C']].apply(lambda x: x.astype(float).max() - x.min())
         B    C
    A
    a  1.0  2.0
    b  0.0  0.0

    The ``group_keys`` argument has no effect here because the result is not
    like-indexed (i.e. :ref:`a transform <groupby.transform>`) when compared
    to the input.

    Example 3: The function passed to `apply` takes a DataFrame as
    its argument and returns a scalar. `apply` combines the result for
    each group together into a Series, including setting the index as
    appropriate:

    >>> g1.apply(lambda x: x.C.max() - x.B.min(), include_groups=False)
    A
    a    5
    b    2
    dtype: int64a�
    >>> s = pd.Series([0, 1, 2], index='a a b'.split())
    >>> g1 = s.groupby(s.index, group_keys=False)
    >>> g2 = s.groupby(s.index, group_keys=True)

    From ``s`` above we can see that ``g`` has two groups, ``a`` and ``b``.
    Notice that ``g1`` have ``g2`` have two groups, ``a`` and ``b``, and only
    differ in their ``group_keys`` argument. Calling `apply` in various ways,
    we can get different grouping results:

    Example 1: The function passed to `apply` takes a Series as
    its argument and returns a Series.  `apply` combines the result for
    each group together into a new Series.

    .. versionchanged:: 1.3.0

        The resulting dtype will reflect the return value of the passed ``func``.

    >>> g1.apply(lambda x: x * 2 if x.name == 'a' else x / 2)
    a    0.0
    a    2.0
    b    1.0
    dtype: float64

    In the above, the groups are not part of the index. We can have them included
    by using ``g2`` where ``group_keys=True``:

    >>> g2.apply(lambda x: x * 2 if x.name == 'a' else x / 2)
    a  a    0.0
       a    2.0
    b  b    1.0
    dtype: float64

    Example 2: The function passed to `apply` takes a Series as
    its argument and returns a scalar. `apply` combines the result for
    each group together into a Series, including setting the index as
    appropriate:

    >>> g1.apply(lambda x: x.max() - x.min())
    a    1
    b    0
    dtype: int64

    The ``group_keys`` argument has no effect here because the result is not
    like-indexed (i.e. :ref:`a transform <groupby.transform>`) when compared
    to the input.

    >>> g2.apply(lambda x: x.max() - x.min())
    a    1
    b    0
    dtype: int64)�template�dataframe_examples�series_examplesa
Compute {fname} of group values.

Parameters
----------
numeric_only : bool, default {no}
    Include only float, int, boolean columns.

    .. versionchanged:: 2.0.0

        numeric_only no longer accepts ``None``.

min_count : int, default {mc}
    The required number of valid values to perform the operation. If fewer
    than ``min_count`` non-NA values are present the result will be NA.

Returns
-------
Series or DataFrame
    Computed {fname} of values within each group.

Examples
--------
{example}
a:
Compute {fname} of group values.

Parameters
----------
numeric_only : bool, default {no}
    Include only float, int, boolean columns.

    .. versionchanged:: 2.0.0

        numeric_only no longer accepts ``None``.

min_count : int, default {mc}
    The required number of valid values to perform the operation. If fewer
    than ``min_count`` non-NA values are present the result will be NA.

engine : str, default None {e}
    * ``'cython'`` : Runs rolling apply through C-extensions from cython.
    * ``'numba'`` : Runs rolling apply through JIT compiled code from numba.
        Only available when ``raw`` is set to ``True``.
    * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``

engine_kwargs : dict, default None {ek}
    * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
    * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
        and ``parallel`` dictionary keys. The values must either be ``True`` or
        ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
        ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
        applied to both the ``func`` and the ``apply`` groupby aggregation.

Returns
-------
Series or DataFrame
    Computed {fname} of values within each group.

Examples
--------
{example}
a�
Apply a ``func`` with arguments to this %(klass)s object and return its result.

Use `.pipe` when you want to improve readability by chaining together
functions that expect Series, DataFrames, GroupBy or Resampler objects.
Instead of writing

>>> h = lambda x, arg2, arg3: x + 1 - arg2 * arg3
>>> g = lambda x, arg1: x * 5 / arg1
>>> f = lambda x: x ** 4
>>> df = pd.DataFrame([["a", 4], ["b", 5]], columns=["group", "value"])
>>> h(g(f(df.groupby('group')), arg1=1), arg2=2, arg3=3)  # doctest: +SKIP

You can write

>>> (df.groupby('group')
...    .pipe(f)
...    .pipe(g, arg1=1)
...    .pipe(h, arg2=2, arg3=3))  # doctest: +SKIP

which is much more readable.

Parameters
----------
func : callable or tuple of (callable, str)
    Function to apply to this %(klass)s object or, alternatively,
    a `(callable, data_keyword)` tuple where `data_keyword` is a
    string indicating the keyword of `callable` that expects the
    %(klass)s object.
args : iterable, optional
       Positional arguments passed into `func`.
kwargs : dict, optional
         A dictionary of keyword arguments passed into `func`.

Returns
-------
the return type of `func`.

See Also
--------
Series.pipe : Apply a function with arguments to a series.
DataFrame.pipe: Apply a function with arguments to a dataframe.
apply : Apply function to each group instead of to the
    full %(klass)s object.

Notes
-----
See more `here
<https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#piping-function-calls>`_

Examples
--------
%(examples)s
a�

Call function producing a same-indexed %(klass)s on each group.

Returns a %(klass)s having the same indexes as the original object
filled with the transformed values.

Parameters
----------
f : function, str
    Function to apply to each group. See the Notes section below for requirements.

    Accepted inputs are:

    - String
    - Python function
    - Numba JIT function with ``engine='numba'`` specified.

    Only passing a single function is supported with this engine.
    If the ``'numba'`` engine is chosen, the function must be
    a user defined function with ``values`` and ``index`` as the
    first and second arguments respectively in the function signature.
    Each group's index will be passed to the user defined function
    and optionally available for use.

    If a string is chosen, then it needs to be the name
    of the groupby method you want to use.
*args
    Positional arguments to pass to func.
engine : str, default None
    * ``'cython'`` : Runs the function through C-extensions from cython.
    * ``'numba'`` : Runs the function through JIT compiled code from numba.
    * ``None`` : Defaults to ``'cython'`` or the global setting ``compute.use_numba``

engine_kwargs : dict, default None
    * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
    * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
      and ``parallel`` dictionary keys. The values must either be ``True`` or
      ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
      ``{'nopython': True, 'nogil': False, 'parallel': False}`` and will be
      applied to the function

**kwargs
    Keyword arguments to be passed into func.

Returns
-------
%(klass)s

See Also
--------
%(klass)s.groupby.apply : Apply function ``func`` group-wise and combine
    the results together.
%(klass)s.groupby.aggregate : Aggregate using one or more
    operations over the specified axis.
%(klass)s.transform : Call ``func`` on self producing a %(klass)s with the
    same axis shape as self.

Notes
-----
Each group is endowed the attribute 'name' in case you need to know
which group you are working on.

The current implementation imposes three requirements on f:

* f must return a value that either has the same shape as the input
  subframe or can be broadcast to the shape of the input subframe.
  For example, if `f` returns a scalar it will be broadcast to have the
  same shape as the input subframe.
* if this is a DataFrame, f must support application column-by-column
  in the subframe. If f also supports application to the entire subframe,
  then a fast path is used starting from the second chunk.
* f must not mutate groups. Mutation is not supported and may
  produce unexpected results. See :ref:`gotchas.udf-mutation` for more details.

When using ``engine='numba'``, there will be no "fall back" behavior internally.
The group data and group index will be passed as numpy arrays to the JITed
user defined function, and no alternative execution attempts will be tried.

.. versionchanged:: 1.3.0

    The resulting dtype will reflect the return value of the passed ``func``,
    see the examples below.

.. versionchanged:: 2.0.0

    When using ``.transform`` on a grouped DataFrame and the transformation function
    returns a DataFrame, pandas now aligns the result's index
    with the input's index. You can call ``.to_numpy()`` on the
    result of the transformation function to avoid alignment.

Examples
--------
%(example)saP
Aggregate using one or more operations over the specified axis.

Parameters
----------
func : function, str, list, dict or None
    Function to use for aggregating the data. If a function, must either
    work when passed a {klass} or when passed to {klass}.apply.

    Accepted combinations are:

    - function
    - string function name
    - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
    - None, in which case ``**kwargs`` are used with Named Aggregation. Here the
      output has one column for each element in ``**kwargs``. The name of the
      column is keyword, whereas the value determines the aggregation used to compute
      the values in the column.

      Can also accept a Numba JIT function with
      ``engine='numba'`` specified. Only passing a single function is supported
      with this engine.

      If the ``'numba'`` engine is chosen, the function must be
      a user defined function with ``values`` and ``index`` as the
      first and second arguments respectively in the function signature.
      Each group's index will be passed to the user defined function
      and optionally available for use.

    .. deprecated:: 2.1.0

        Passing a dictionary is deprecated and will raise in a future version
        of pandas. Pass a list of aggregations instead.
*args
    Positional arguments to pass to func.
engine : str, default None
    * ``'cython'`` : Runs the function through C-extensions from cython.
    * ``'numba'`` : Runs the function through JIT compiled code from numba.
    * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``

engine_kwargs : dict, default None
    * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
    * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
      and ``parallel`` dictionary keys. The values must either be ``True`` or
      ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
      ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
      applied to the function

**kwargs
    * If ``func`` is None, ``**kwargs`` are used to define the output names and
      aggregations via Named Aggregation. See ``func`` entry.
    * Otherwise, keyword arguments to be passed into func.

Returns
-------
{klass}

See Also
--------
{klass}.groupby.apply : Apply function func group-wise
    and combine the results together.
{klass}.groupby.transform : Transforms the Series on each group
    based on the given function.
{klass}.aggregate : Aggregate using one or more
    operations over the specified axis.

Notes
-----
When using ``engine='numba'``, there will be no "fall back" behavior internally.
The group data and group index will be passed as numpy arrays to the JITed
user defined function, and no alternative execution attempts will be tried.

Functions that mutate the passed object can produce unexpected
behavior or errors and are not supported. See :ref:`gotchas.udf-mutation`
for more details.

.. versionchanged:: 1.3.0

    The resulting dtype will reflect the return value of the passed ``func``,
    see the examples below.
{examples}a�
Aggregate using one or more operations over the specified axis.

Parameters
----------
func : function, str, list, dict or None
    Function to use for aggregating the data. If a function, must either
    work when passed a {klass} or when passed to {klass}.apply.

    Accepted combinations are:

    - function
    - string function name
    - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
    - dict of axis labels -> functions, function names or list of such.
    - None, in which case ``**kwargs`` are used with Named Aggregation. Here the
      output has one column for each element in ``**kwargs``. The name of the
      column is keyword, whereas the value determines the aggregation used to compute
      the values in the column.

      Can also accept a Numba JIT function with
      ``engine='numba'`` specified. Only passing a single function is supported
      with this engine.

      If the ``'numba'`` engine is chosen, the function must be
      a user defined function with ``values`` and ``index`` as the
      first and second arguments respectively in the function signature.
      Each group's index will be passed to the user defined function
      and optionally available for use.

*args
    Positional arguments to pass to func.
engine : str, default None
    * ``'cython'`` : Runs the function through C-extensions from cython.
    * ``'numba'`` : Runs the function through JIT compiled code from numba.
    * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``

engine_kwargs : dict, default None
    * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
    * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
      and ``parallel`` dictionary keys. The values must either be ``True`` or
      ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
      ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
      applied to the function

**kwargs
    * If ``func`` is None, ``**kwargs`` are used to define the output names and
      aggregations via Named Aggregation. See ``func`` entry.
    * Otherwise, keyword arguments to be passed into func.

Returns
-------
{klass}

See Also
--------
{klass}.groupby.apply : Apply function func group-wise
    and combine the results together.
{klass}.groupby.transform : Transforms the Series on each group
    based on the given function.
{klass}.aggregate : Aggregate using one or more
    operations over the specified axis.

Notes
-----
When using ``engine='numba'``, there will be no "fall back" behavior internally.
The group data and group index will be passed as numpy arrays to the JITed
user defined function, and no alternative execution attempts will be tried.

Functions that mutate the passed object can produce unexpected
behavior or errors and are not supported. See :ref:`gotchas.udf-mutation`
for more details.

.. versionchanged:: 1.3.0

    The resulting dtype will reflect the return value of the passed ``func``,
    see the examples below.
{examples}c�&�eZdZdZdd�Zd�Zdd�Zy)�GroupByPlotzE
    Class implementing the .plot attribute for groupby objects.
    c��||_y�N)�_groupby)�self�groupbys  �F/usr/local/lib/python3.12/site-packages/pandas/core/groupby/groupby.py�__init__zGroupByPlot.__init__�s	����
�c������fd�}d|_|jj||jj�S)Nc�(��|j�i���Sri)�plot)rk�args�kwargss ��rm�fzGroupByPlot.__call__.<locals>.f�s����4�9�9�d�-�f�-�-rorr)�__name__rj�_python_apply_general�
_selected_obj)rkrsrtrus `` rm�__call__zGroupByPlot.__call__�s2���	.���
��}�}�2�2�1�d�m�m�6Q�6Q�R�Rroc������fd�}|S)Nc�v�������fd�}�jj|�jj�S)Nc�<��t|j���i���Sri)�getattrrr)rkrsrt�names ���rmruz0GroupByPlot.__getattr__.<locals>.attr.<locals>.f�s ���/�w�t�y�y�$�/��@��@�@ro)rjrwrx)rsrtrur~rks`` ��rm�attrz%GroupByPlot.__getattr__.<locals>.attr�s,���
A��=�=�6�6�q�$�-�-�:U�:U�V�Vro�)rkr~rs`` rm�__getattr__zGroupByPlot.__getattr__�s���	W��roN)rl�GroupBy�return�None�r~�str)rv�
__module__�__qualname__�__doc__rnryr�r�rormrgrg�s��� �S�rorgc��eZdZUejhd�zZded<ded<dZded<dZd	ed
<ded<edd
��Z	edd��Z
eedd���Zeed d���Z
eedd���Zeed!d���Zed��Zed��Zeed���Zed"d��Zeded���ee�				d#d���Zed$d%d��Zed&d��Zy)'�BaseGroupBy>�obj�axis�keys�sort�level�dropna�grouper�as_index�observed�
exclusions�
group_keysrr��ops.BaseGrouper�_grouperN�_KeysArgType | Noner��IndexLabel | Noner��boolr�c�,�t|j�Sri)�len�groups�rks rm�__len__zBaseGroupBy.__len__s���4�;�;��roc�,�tj|�Sri)�object�__repr__r�s rmr�zBaseGroupBy.__repr__s�����t�$�$roc��tjt|�j�d�tt���|jS)NzI.grouper is deprecated and will be removed in a future version of pandas.)�category�
stacklevel)�warnings�warn�typerv�
FutureWarningr+r�r�s rmr�zBaseGroupBy.groupers?��	�
�
��D�z�"�"�#�$(�
(�"�'�)�		
��}�}�roc�.�|jjS)aI
        Dict {group name -> group labels}.

        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 3], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        dtype: int64
        >>> ser.groupby(level=0).groups
        {'a': ['a', 'a'], 'b': ['b']}

        For DataFrameGroupBy:

        >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"])
        >>> df
           a  b  c
        0  1  2  3
        1  1  5  6
        2  7  8  9
        >>> df.groupby(by=["a"]).groups
        {1: [0, 1], 7: [2]}

        For Resampler:

        >>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
        ...                 ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
        >>> ser
        2023-01-01    1
        2023-01-15    2
        2023-02-01    3
        2023-02-15    4
        dtype: int64
        >>> ser.resample('MS').groups
        {Timestamp('2023-01-01 00:00:00'): 2, Timestamp('2023-02-01 00:00:00'): 4}
        )r�r�r�s rmr�zBaseGroupBy.groups%s��\�}�}�#�#�#roc�.�|jjSri)r��ngroupsr�s rmr�zBaseGroupBy.ngroupsUs���}�}�$�$�$roc�.�|jjS)a�
        Dict {group name -> group indices}.

        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 3], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        dtype: int64
        >>> ser.groupby(level=0).indices
        {'a': array([0, 1]), 'b': array([2])}

        For DataFrameGroupBy:

        >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["owl", "toucan", "eagle"])
        >>> df
                a  b  c
        owl     1  2  3
        toucan  1  5  6
        eagle   7  8  9
        >>> df.groupby(by=["a"]).indices
        {1: array([0, 1]), 7: array([2])}

        For Resampler:

        >>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
        ...                 ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
        >>> ser
        2023-01-01    1
        2023-01-15    2
        2023-02-01    3
        2023-02-15    4
        dtype: int64
        >>> ser.resample('MS').indices
        defaultdict(<class 'list'>, {Timestamp('2023-01-01 00:00:00'): [0, 1],
        Timestamp('2023-02-01 00:00:00'): [2, 3]})
        )r��indicesr�s rmr�zBaseGroupBy.indicesZs��`�}�}�$�$�$roc��	�
�d�}t|�dk(rgSt|j�dkDrtt|j��}nd}|d}t	|t
�rtt	|t
�s
d}t
|��t|�t|�k(s	|D�cgc]}|j|��c}S|D�cgc]
}||���c}�
�
fd�|D�}n||��	�	fd�|D�}|D�cgc]}|jj|g��� c}Scc}w#t$r}d}t
|�|�d}~wwxYwcc}wcc}w)zd
        Safe get multiple indices, translate keys for
        datelike to underlying repr.
        c�|�t|tj�rd�St|tj�rd�Sd�S)Nc��t|�Sri)r��keys rm�<lambda>zABaseGroupBy._get_indices.<locals>.get_converter.<locals>.<lambda>�s��9�S�>roc�,�t|�jSri)r�asm8r�s rmr�zABaseGroupBy._get_indices.<locals>.get_converter.<locals>.<lambda>�s��9�S�>�#6�#6roc��|Srir�r�s rmr�zABaseGroupBy._get_indices.<locals>.get_converter.<locals>.<lambda>�s��3ro)�
isinstance�datetime�np�
datetime64)�ss rm�
get_converterz/BaseGroupBy._get_indices.<locals>.get_converter�s4���!�X�.�.�/�1�1��A�r�}�}�-�6�6�&�&rorNz<must supply a tuple to get_group with multiple grouping keyszHmust supply a same-length tuple to get_group with multiple grouping keysc3�V�K�|] }td�t�|�D�����"y�w)c3�2K�|]\}}||����y�wrir�)�.0ru�ns   rm�	<genexpr>z5BaseGroupBy._get_indices.<locals>.<genexpr>.<genexpr>�s����B�,A�D�A�q�1�Q�4�,A�s�N)�tuple�zip)r�r~�
converterss  �rmr�z+BaseGroupBy._get_indices.<locals>.<genexpr>�s$�����U�u�t�U�B�C�
�D�,A�B�B�u�s�&)c3�.�K�|]}�|����y�wrir�)r�r~�	converters  �rmr�z+BaseGroupBy._get_indices.<locals>.<genexpr>�s�����7���Y�t�_��s�)	r�r��next�iterr�r��
ValueError�KeyError�get)rk�namesr��index_sample�name_sample�msgr~�errr�r�r�s         @@rm�_get_indiceszBaseGroupBy._get_indices�s>���	'��u�:��?��I��t�|�|��q� ���T�\�\� 2�3�L��L��A�h���l�E�*��k�5�1�T�� ��o�%��{�#�s�<�'8�8�	3�;@�A�5�4�D�L�L��.�5�A�A�5A�A�L�q�-��*�L�A�J�U�u�U�E�&�l�3�I�7��7�E�7<�=�u�t���� � ��r�*�u�=�=��!B���3�6��%�S�/�s�2��
3��B��>s6�D�D�3D�:D9�/#D>�D�	D6�#D1�1D6c�,�|j|g�dS)zQ
        Safe get index, translate keys for datelike to underlying repr.
        r)r�)rkr~s  rm�
_get_indexzBaseGroupBy._get_index�s��
� � �$��(��+�+roc���t|jt�r|jS|j�:t	|j�r|j|jS|j
S|jSri)r�r�rZ�
_selectionr0�_obj_with_exclusionsr�s rmrxzBaseGroupBy._selected_obj�s]���d�h�h��'��8�8�O��?�?�&��4�?�?�+��x�x����0�0�
�,�,�,��x�x�roc�6�|jj�Sri)r��_dir_additionsr�s rmr�zBaseGroupBy._dir_additions�s���x�x�&�&�(�(ror�a�        >>> df = pd.DataFrame({'A': 'a b a b'.split(), 'B': [1, 2, 3, 4]})
        >>> df
           A  B
        0  a  1
        1  b  2
        2  a  3
        3  b  4

        To get the difference between each groups maximum and minimum value in one
        pass, you can do

        >>> df.groupby('A').pipe(lambda x: x.max() - x.min())
           B
        A
        a  2
        b  2)�klass�examplesc�6�tj||g|��i|��Sri)�com�pipe)rk�funcrsrts    rmr�zBaseGroupBy.pipe�s��:�x�x��d�4�T�4�V�4�4roc��|j}|j}t|�rt|�dk(st|�rft|�dk(rXt	|t
�rt|�dk(r|d}n4t	|t
�s$t
jdtt���|j|�}t|�st|��|�7|jdk(r|ntd�|f}|jj|St
jdtt���|j!||j��S)aA
        Construct DataFrame from group with provided name.

        Parameters
        ----------
        name : object
            The name of the group to get as a DataFrame.
        obj : DataFrame, default None
            The DataFrame to take the DataFrame out of.  If
            it is None, the object groupby was called on will
            be used.

            .. deprecated:: 2.1.0
                The obj is deprecated and will be removed in a future version.
                Do ``df.iloc[gb.indices.get(name)]``
                instead of ``gb.get_group(name, obj=df)``.

        Returns
        -------
        same type as obj

        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 3], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        dtype: int64
        >>> ser.groupby(level=0).get_group("a")
        a    1
        a    2
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["owl", "toucan", "eagle"])
        >>> df
                a  b  c
        owl     1  2  3
        toucan  1  5  6
        eagle   7  8  9
        >>> df.groupby(by=["a"]).get_group((1,))
                a  b  c
        owl     1  2  3
        toucan  1  5  6

        For Resampler:

        >>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
        ...                 ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
        >>> ser
        2023-01-01    1
        2023-01-15    2
        2023-02-01    3
        2023-02-15    4
        dtype: int64
        >>> ser.resample('MS').get_group('2023-01-01')
        2023-01-01    1
        2023-01-15    2
        dtype: int64
        �rz�When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group in a future version of pandas. Pass `(name,)` instead of `name` to silence this warning.�r�Nz�obj is deprecated and will be removed in a future version. Do ``df.iloc[gb.indices.get(name)]`` instead of ``gb.get_group(name, obj=df)``.�r�)r�r�r3r�r�r�r�r�r�r+r�r�r��slicerx�iloc�_take_with_is_copy)rkr~r�r�r��inds�indexers       rm�	get_groupzBaseGroupBy.get_group�s��L�y�y���
�
�����C��J�!�O����3�t�9��>��$��&�3�t�9��>��A�w����e�,��
�
�$�"�/�1�
����t�$���4�y��4�.� ��;�"�i�i�1�n�d�5��;��2E�G��%�%�*�*�7�3�3��M�M�=��+�-�
��)�)�$�T�Y�Y�)�?�?roc�`�|j}|j}|jj|j|j
��}t
|�r2t|�dk(r$tjdtt���t|t�rt|�dk(r	d�|D�}|S)aB
        Groupby iterator.

        Returns
        -------
        Generator yielding sequence of (name, subsetted object)
        for each group

        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 3], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        dtype: int64
        >>> for x, y in ser.groupby(level=0):
        ...     print(f'{x}\n{y}\n')
        a
        a    1
        a    2
        dtype: int64
        b
        b    3
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"])
        >>> df
           a  b  c
        0  1  2  3
        1  1  5  6
        2  7  8  9
        >>> for x, y in df.groupby(by=["a"]):
        ...     print(f'{x}\n{y}\n')
        (1,)
           a  b  c
        0  1  2  3
        1  1  5  6
        (7,)
           a  b  c
        2  7  8  9

        For Resampler:

        >>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
        ...                 ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
        >>> ser
        2023-01-01    1
        2023-01-15    2
        2023-02-01    3
        2023-02-15    4
        dtype: int64
        >>> for x, y in ser.resample('MS'):
        ...     print(f'{x}\n{y}\n')
        2023-01-01 00:00:00
        2023-01-01    1
        2023-01-15    2
        dtype: int64
        2023-02-01 00:00:00
        2023-02-01    3
        2023-02-15    4
        dtype: int64
        r�r�z�Creating a Groupby object with a length-1 list-like level parameter will yield indexes as tuples in a future version. To keep indexes as scalars, create Groupby objects with a scalar level parameter instead.r�c3�,K�|]\}}|f|f���y�wrir�)r�r��groups   rmr�z'BaseGroupBy.__iter__.<locals>.<genexpr>�s����?��*�#�u��v�u�o��s�)r�r�r��get_iteratorrxr�r3r�r�r�r�r+r��list)rkr�r��results    rm�__iter__zBaseGroupBy.__iter__is���P�y�y���
�
�����+�+�D�,>�,>�T�Y�Y�+�O�����3�u�:��?��M�M�4��+�-�

��d�D�!�c�$�i�1�n�?��?�F��
ro)r��int)r�r�)r�r�)r�zdict[Hashable, np.ndarray])r�z$dict[Hashable, npt.NDArray[np.intp]])r�zset[str])r�z/Callable[..., T] | tuple[Callable[..., T], str]r�r"ri�r��DataFrame | Series)r�z#Iterator[tuple[Hashable, NDFrameT]])rvr�r�rJ�
_hidden_attrs�__annotations__r�r�rr�r��propertyr�r�r�r�r�r�r)rxr�r(r
r'�_pipe_templater�r�r�r�rormr�r��s��� �.�.�2��M��M��� $�D�
�$�#�E��#���
� �� ��%��%��
������
�,$���,$�\�
�%���%��
�.%���.%�`�0>��0>�d�,��,�������&�)��)����
�
��,�n��5�=�5�

�5��-�.5��h@��h@�T�X��Xror��OutputFrameOrSeries)�boundc��eZdZUdZded<ded<edddddddddejdf																									did	��Zdjd
�Z	edkd��Z
edld��Ze		dm			dnd��Ze				dod��Z
edpd��Zedqd��Ze	dr			dsd��Z		dm					dtd�Zedud��Z						dvd�Zedd�d��Zedd�d��Zeedj1ded���dd�dwd��Ze			dx											dyd��Ze		dzdd!�							d{d"��Z										d|d#�Ze			d}							d~d$��Z	d					d�d%�Zeddd&�d'��Zedqd(��Z ed)��Z!ed�d�d*��Z"ee#d�d+���Z$ee%d,�-�e%e&�.�d�d�d/����Z'ee%d,�-�e%e&�.�d�d�d0����Z(ee%d,�-�e%e&�.�d�d1����Z)ee%d,�-�e%e&�.�			d�					d�d2����Z*ed�d�d3��Z+ee%d,�-�e%e&�.�				d�							d�d5����Z,ee%d,�-�e%e&�.�				d�							d�d6����Z-e					d�											d�d7��Z.ed�d�d8��Z/ee%d,�-�e%e&�.�d�d9����Z0ee1e2d:d
ddde3d;��<�				d�							d�d=���Z4ee1e5d>d
de3d?��@�dd�dA���Z6ee1e2dBd
d dde3dC��<�				d�							d�dD���Z7ee1e2dEd
d dde3dF��<�				d�							d�dG���Z8e	d�							d�dH��Z9e	d�							d�dI��Z:ed�dJ��Z;e1e<jz�			d�	d�dK��Z=edd�d�dL��Z>ed�dM��Z?ee%d,�-�ee&�d�dN����Z@ee%d,�-�ee&�d�dO����ZAedrd�dP��ZBee%d,�-�drd�dQ���ZCee%d,�-�drd�dR���ZDee#e%d,�-�e%e&�.�d�dS�����ZE	dr					d�dT�ZFe			d�					d�dU��ZGee%d,�-�d�d�dV���ZHee%d,�-�d�d�dW���ZIee%d,�-�e%e&�.�dXddYd
ejf											d�dZ����ZJee%d,�-�e%e&�.�ejf			d�d[����ZKee%d,�-�e%e&�.�ejf			d�d\����ZLee%d,�-�e%e&�.�ejd
f					d�d]����ZMee%d,�-�e%e&�.�ejd
f					d�d^����ZNee%d,�-�d4dejejdf					d�d_���ZOee%d,�-�e%e&�.�d4ejf					d�d`����ZPee%d,�-�e%e&�.�d4ejejdejf							d�da����ZQee%d,�-�e%e&�.�d�d�db����ZRee%d,�-�e%e&�.�d�d�dc����ZSed�dd��ZTeeUj�df							d�de��ZWe					d�									d�df��ZXd
ejdd
f											d�dg�ZYd�dh�ZZy)�r�a�
    Class for grouping and aggregating relational data.

    See aggregate, transform, and apply functions on this object.

    It's easiest to use obj.groupby(...) to use GroupBy, but you can also do:

    ::

        grouped = groupby(obj, ...)

    Parameters
    ----------
    obj : pandas object
    axis : int, default 0
    level : int, default None
        Level of MultiIndex
    groupings : list of Grouping objects
        Most users should ignore this
    exclusions : array-like, optional
        List of columns to exclude
    name : str
        Most users should ignore this

    Returns
    -------
    **Attributes**
    groups : dict
        {group name -> group labels}
    len(grouped) : int
        Number of groups

    Notes
    -----
    After grouping, see aggregate, apply, and transform functions. Here are
    some other brief notes about usage. When grouping by multiple groups, the
    result index will be a MultiIndex (hierarchical) by default.

    Iteration produces (key, group) tuples, i.e. chunking the data by group. So
    you can write code like:

    ::

        grouped = obj.groupby(keys, axis=axis)
        for key, group in grouped:
            # do something with the data

    Function calls on GroupBy, if not specially implemented, "dispatch" to the
    grouped data. So if you group a DataFrame and wish to invoke the std()
    method on each group, you can simply do:

    ::

        df.groupby(mapper).std()

    rather than

    ::

        df.groupby(mapper).aggregate(np.std)

    You can pass arguments to these "wrapped" functions, too.

    See the online documentation for full exposition on these topics and much
    more
    r�r�r�r�NrTc
	�x�||_t|t�sJt|���||_|s|dk7rtd��||_||_|	|_|
|_	||_
|�4t|||||	|tjurdn||j��\}}}|tjurBtd�|jD��r$t!j"dt$t'���d}||_||_|j-|�|_||_|rt3|�|_yt3�|_y)Nrz$as_index=False only valid for axis=0F)r�r�r�r�r�c3�4K�|]}|j���y�wri��_passed_categorical�r��pings  rmr�z#GroupBy.__init__.<locals>.<genexpr><s����J�8I��4�+�+�8I���z�The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.r�)r�r�rMr�r�r�r�r�r�r�r�rQr�
no_default�any�	groupingsr�r�r�r+r�r��_get_axis_numberr�r��	frozensetr�)
rkr�r�r�r�r�r��	selectionr�r�r�r�r�s
             rmrnzGroupBy.__init__s"�� $����#�w�'�2��c��2�'���
���q�y� �!G�H�H� ��
���	���	�$�������?�'2������"*�c�n�n�"<��(��{�{�(�$�G�Z���s�~�~�%��J��8I�8I�J�J��
�
�8�"�/�1�
��H� ��
�����(�(��.��	���
�3=�)�J�/���9�;��roc��||jvrtj||�S||jvr||St	dt|�j�d|�d���)N�'z' object has no attribute ')�_internal_names_setr��__getattribute__r��AttributeErrorr�rv)rkrs  rmr�zGroupBy.__getattr__Msd���4�+�+�+��*�*�4��6�6��4�8�8����:�����T�
�#�#�$�$?��v�Q�G�
�	
roc��|dk(r>tjt|�j�d|�d�tt���ytjdt|�j�d|�d�tt���y)Nr��.zo with axis=1 is deprecated and will be removed in a future version. Operate on the un-grouped DataFrame insteadr�zThe 'axis' keyword in z\ is deprecated and will be removed in a future version. Call without passing 'axis' instead.)r�r�r�rvr�r+)rkr�r~s   rm�_deprecate_axiszGroupBy._deprecate_axisWs|���1�9��M�M���:�&�&�'�q���/$�$��+�-�
�
�M�M�(��d��)<�)<�(=�Q�t�f�E7�7��+�-�
roc�
���	�tt|j�|��	tj�	�}d�vrF�dt
jur1|jj�d�}|j||�nd�vr|dk(rn|dk(rd�d<nd�d<d|jvrB�jdd��!�jd�t
jur|j�d<��	�fd�}||_
|tjvr|j!||j"�S|tj$v}|j!||j||��}|j&j(r|r|j+|�}|S)z<Compute the result of an operation by using GroupBy's apply.r��skew�fillnaNrc����|g���i���Srir�)�xrsrurts ���rm�curriedz&GroupBy._op_via_apply.<locals>.curried�s����Q�(��(��(�(ro)�is_transform�not_indexed_same)r}r�r��inspect�	signaturerrr�rr�
parametersr�r�rvrN�plotting_methodsrwrx�transformation_kernelsr��has_dropped_na�_set_result_index_ordered)
rkr~rsrt�sigr�rrr�rus
  ``     @rm�
_op_via_applyzGroupBy._op_via_applyjss���
�D��2�2�3�T�:������"���V���v��c�n�n� D��8�8�,�,�V�F�^�<�D�� � ��t�,�
�v�
��v�~����!�!%��v��!"��v���S�^�^�#��z�z�&�$�'�/�6�:�:�f�3E����3W�!%����v��	)�
 ����4�(�(�(��-�-�g�t�7I�7I�J�J��t�:�:�:���+�+���%�%�%�!-�-�	,�
���=�=�'�'�L��3�3�F�;�F��
roFc��ddlm}|jr�|s�|jr\|jj
}|jj}|jj}|||j|||d��}�nattt|���}	|||j|	��}�n-|�s|||j��}|jj|j�}
|jr#|jjd}|dk7}|
|}
|
j r�|j"|jj%|
�s[t'j(|
j*�}
|j,j/|
�\}}|j1||j��}n3|j3|
|jd��}n|||j��}|j4j6d	k(r|j4j8}n$t;|j<�r
|j<}nd}t?|t@�r	|�||_|S)
Nr��concatF)r�r��levelsr�r�)r�r�r�����r��copyr�)!�pandas.core.reshape.concatr$r�r�r��result_indexr%r�r�r��ranger�rx�	_get_axisr��
group_info�has_duplicates�axes�equalsr<�unique1d�_values�index�get_indexer_non_unique�take�reindexr��ndimr~r0r�r�rZ)rk�valuesrrr$r��group_levels�group_namesr�r��ax�labels�mask�targetr��_r~s                 rm�_concat_objectszGroupBy._concat_objects�s���	6��?�?�<��}�}�!�]�]�7�7�
�#�}�}�3�3��"�m�m�1�1�������#�'�%��
���E�#�f�+�.�/����T�Y�Y�T�B��!��F����3�F��#�#�-�-�d�i�i�8�B��{�{����1�1�!�4����|����X��� � ����T�Y�Y�)?�)F�)F�r�)J�#�,�,�R�Z�Z�8��#�\�\�@�@��H�
������W�4�9�9��=�����������G���F����3�F��8�8�=�=�A���8�8�=�=�D�
����
)��?�?�D��D��f�f�%�$�*:��F�K��
roc�h�|jj|j�}|jjr6|jj
s |j
||jd��}|St|jj��}|j
||jd��}|j|j��}|jj
r/|jtt|��|j��}|j
||jd��}|S)NFr'r�)
r�r,r�r��is_monotonicr�set_axisrU�result_ilocs�
sort_indexr6rWr�)rkr��obj_axis�original_positionss    rmrz!GroupBy._set_result_index_ordered�s����8�8�%�%�d�i�i�0���=�=�%�%�d�m�m�.J�.J��_�_�X�D�I�I�E�_�J�F��M�#�4�=�=�#=�#=�#?�@�����!3�$�)�)�%��P���"�"��	�	�"�2���=�=�'�'��^�^�J�s�8�}�$=�D�I�I�^�N�F������	�	���F���
roc
��t|t�r|j�}|j}t	t|jj�t|jj��t|jjD�cgc]}|j��c}��D]G\}}}||vs�|r|jd||��"d}tj|tt����I|Scc}w)Nrz�A grouping was used that is not in the columns of the DataFrame and so was excluded from the result. This grouping will be included in a future version of pandas. Add the grouping as a column of the DataFrame to silence this warning.��messager�r�)r�rZ�to_frame�columnsr��reversedr�r��get_group_levelsr�in_axis�insertr�r�r�r+)rkr�rL�grpr~�levrOr�s        rm�_insert_inaxis_grouperzGroupBy._insert_inaxis_grouper�s����f�f�%��_�_�&�F��.�.��"%��T�]�]�(�(�)��T�]�]�3�3�5�6��T�]�]�-D�-D�E�-D�c�c�k�k�-D�E�F�#
��D�#�w��7�"���M�M�!�T�3�/�Y���M�M� #�!.�#3�#5��##
�.�
��)Fs�C9c���|jdk(rd|j}|jj|jj�r)|jjj�|_|S)Nr�)r�r"r3r0r�r()rkr�s  rm�_maybe_transpose_resultzGroupBy._maybe_transpose_resultsO���9�9��>��X�X�F��|�|�"�"�4�8�8�>�>�2� $�x�x�~�~�2�2�4����
roc�L�|jsJ|j|�}|j�}tt	|j
j��}n|j
j}|�t||�}||_	|j|�}|j||��S)z�
        Wraps the output of GroupBy aggregations into the expected result.

        Parameters
        ----------
        result : Series, DataFrame

        Returns
        -------
        Series or DataFrame
        ��qs)r�rS�_consolidaterUr+r�r�r*�_insert_quantile_levelr3rU�_reindex_output)rkr�rXr3�ress     rm�_wrap_aggregated_outputzGroupBy._wrap_aggregated_output*s���(�}�}��0�0��8�F��(�(�*�F��%��
�
� 5� 5�6�7�E��M�M�.�.�E�
�>�+�5�"�5�E�����*�*�6�2���#�#�C�B�#�/�/roc��t|��ri�r%)rk�datar8rrs     rm�_wrap_applied_outputzGroupBy._wrap_applied_outputTs��"�$�'�'roc�Z�|jj\}}}|jj}|jj}|j	||j
��j
�}|j}t|t�rat|jj�dkDrtd��|jjdj}	|j|	�}|j	|�j
�}
tj ||�\}}|||
|fS)Nr�r�z_Grouping with more than 1 grouping labels and a MultiIndex is not supported with engine='numba'r)r�r-�	_sort_idx�_sorted_idsr5r��to_numpyr3r�rVr�r�NotImplementedErrorr~�get_level_valuesr�generate_slices)
rkr`�idsr?r��sorted_index�
sorted_ids�sorted_data�
index_data�	group_key�sorted_index_data�starts�endss
             rm�_numba_prepzGroupBy._numba_prep`s���-�-�2�2���Q���}�}�.�.���]�]�.�.�
��i�i��4�9�9�i�=�F�F�H���Z�Z�
��j�*�-��4�=�=�*�*�+�a�/�)�H����
�
�/�/��2�7�7�I�#�4�4�Y�?�J�&�O�O�L�9�B�B�D���*�*�:�w�?��������	
�	
roc��|jstd��|jdk(rtd��|j}|jdk(r|n|j�}t
j||dfit|���}|jj\}}	}	|jj}
|jj|f||
d�|��}|jj|jd<|j!||j��}|jdk(r$|j#d�}|j$|_|S|j&|_|S)	zp
        Perform groupby with a standard numerical aggregation function (e.g. mean)
        with Numba.
        z<as_index=False is not supported. Use .reset_index() instead.r�zaxis=1 is not supported.�T)r<r�)r/rL)r�rfr�r�r7rKr>�generate_shared_aggregatorr\r�r-r��_mgr�applyr*r/�_constructor_from_mgr�squeezer~rL)
rkr��
dtype_mapping�
engine_kwargs�aggregator_kwargsr`�df�
aggregatorrir?r��res_mgrr�s
             rm�_numba_agg_generalzGroupBy._numba_agg_general{s<���}�}�%�N��
��9�9��>�%�&@�A�A��(�(���Y�Y�!�^�T�������8�8����
� �
�.�	
�
��M�M�,�,�	��Q���-�-�'�'���"�'�'�-�-��
�"�G�
�7H�
���-�-�4�4����Q���)�)�'����)�E���9�9��>��^�^�I�.�F��)�)�F�K��
�"�\�\�F�N��
ro)r{c	�8�|j}|jdk(r|n|j�}|j|�\}}}	}
t	j
|�t	j|fit||���}||
|	||t|j�g|���}|jtj|	�d��}|j}
|jdk(rd|ji}|j�}nd|ji}|j |fd|
i|��S)a(
        Perform groupby transform routine with the numba engine.

        This routine mimics the data splitting routine of the DataSplitter class
        to generate the indices of each group in the sorted data and then passes the
        data and indices into a Numba jitted function.
        rtrr�r�r~rLr3)r�r7rKrrrO�validate_udf�generate_numba_transform_funcr\r�rLr5r��argsortr3r~�ravel�_constructor)rkr�r{rsrtr`r}rprqrjrl�numba_transform_funcr�r3�
result_kwargss               rm�_transform_with_numbazGroupBy._transform_with_numba�s���(�(���Y�Y�!�^�T������26�2B�2B�2�2F�/���l�K����D�!�%�C�C�� 
�%�m�V�<� 
��&�������
�
�O�
��

�����R�Z�Z��5�A��>���
�
���9�9��>�#�T�Y�Y�/�M��\�\�^�F�&����5�M� �t� � ��F�u�F�
�F�Froc	�p�|j}|jdk(r|n|j�}|j|�\}}}	}
t	j
|�t	j|fit||���}||
|	||t|j�g|���}|jj}
|jdk(rd|ji}|j�}nd|ji}|j|fd|
i|��}|js*|j!|�}t#t|��|_|S)a*
        Perform groupby aggregation routine with the numba engine.

        This routine mimics the data splitting routine of the DataSplitter class
        to generate the indices of each group in the sorted data and then passes the
        data and indices into a Numba jitted function.
        rtr�r~rLr3)r�r7rKrrrOr��generate_numba_agg_funcr\r�rLr�r*r~r�r�r�rSrXr3)rkr�r{rsrtr`r}rprqrjrl�numba_agg_funcr�r3r�r\s                rm�_aggregate_with_numbazGroupBy._aggregate_with_numba�s'���(�(���Y�Y�!�^�T������26�2B�2B�2�2F�/���l�K����D�!��7�7��
�%�m�V�<�
�� �������
�
�O�
��

���
�
�*�*���9�9��>�#�T�Y�Y�/�M��\�\�^�F�&����5�M��d����E�e�E�}�E���}�}��-�-�c�2�C�%�c�#�h�/�C�I��
rorc�	dataframerd)�inputr�)�include_groupsc������}tj���|�k7r tj|}t|||�t	�t
�rNt
|��r3t|��}t|�r|�i���S�s�rtd�����|Std��d����s�r,t��rt�����fd��}n
td���}|s|j||j�Stdd�5	|j||j�}	t	|j t"�s�|j$�x|jj&|jj&k7rKt)j*t,j/t1|�j2d�t4t7���ddd�|	S#t$r(|j||j�cYcddd�SwxYw#1swY	SxYw)	Nz"Cannot pass arguments to property z$apply func should be callable, not 'r
c����|g���i���Srir�)�grsr�rts ���rmruzGroupBy.apply.<locals>.fs�����3�D�3�F�3�3roz6func must be a callable if args or kwargs are suppliedzmode.chained_assignmentrwrI)r��is_builtin_func�_builtin_table_aliasr?r�r��hasattrr}�callabler��	TypeErrorr	rwr�rrxr�rZr��shaper�r��_apply_groupings_depr�formatr�rv�DeprecationWarningr+)
rkr�r�rsrt�	orig_func�aliasr\rur�s
 ` ``     rmrwz
GroupBy.apply�s�����	��"�"�4�(������,�,�Y�7�E�"�4��E�:��d�C� ��t�T�"��d�D�)���C�=���/��/�/��V�$�'I�$��%P�Q�Q��
� �"F�t�f�A� N�O�O�
�V���~��t��4��4�!�L����A���-�-�a��1J�1J�K�K��5�t�
<�
P��3�3�A�t�7I�7I�J��"�4�8�8�V�4����/��*�*�0�0�D�4M�4M�4S�4S�S��M�M� 5� <� <� ��J�/�/��!�"4�#3�#5��=�4�
���	
P��1�1�!�T�5N�5N�O�O�1=�
<�	
P��=�4�
�s+�:G4�<B:G�%G1�%G4�0G1�1G4�4G>c��|jj|||j�\}}|�|}|j||||�S)a�
        Apply function f in python space

        Parameters
        ----------
        f : callable
            Function to apply
        data : Series or DataFrame
            Data to apply f to
        not_indexed_same: bool, optional
            When specified, overrides the value of not_indexed_same. Apply behaves
            differently when the result index is equal to the input index, but
            this can be coincidental leading to value-dependent behavior.
        is_transform : bool, default False
            Indicator for whether the function is actually a transform
            and should not have group keys prepended.
        is_agg : bool, default False
            Indicator for whether the function is an aggregation. When the
            result is empty, we don't want to warn for this case.
            See _GroupBy._python_agg_general.

        Returns
        -------
        Series or DataFrame
            data after applying f
        )r��apply_groupwiser�ra)rkrur`rr�is_aggr8�mutateds        rmrwzGroupBy._python_apply_general:sP��F�-�-�7�7��4����K�����#�&���(�(�����	
�	
ror&)�npfuncc�j�|jd||||d�|��}|j|jd��S)N)�how�alt�numeric_only�	min_countrl��methodr���_cython_agg_general�__finalize__r�)rkr�r�r�r�rtr�s       rm�_agg_generalzGroupBy._agg_generalhsM��*��)�)�
���%��	
�
�
���"�"�4�8�8�I�"�>�>roc���|�J�|jdk(rt|d��}nHt|j|j��}|j
ddk(sJ�|jdd�df}	|jj||d��}|jtk(r|jtd��}t||��S#t$r*}d	|�d
|j�d�}	t|�|	�|�d}~wwxYw)
zn
        Fallback to pure-python aggregation if _cython_operation raises
        NotImplementedError.
        Nr�F�r(��dtyperT)�preserve_dtypezagg function failed [how->z,dtype->�])r7)r7rZrLr"r�r�r�r��
agg_series�	Exceptionr�r��astyperY)
rkr�r8r7r��serr}�
res_valuesr�r�s
          rm�_agg_py_fallbackzGroupBy._agg_py_fallback{s��������;�;�!����e�,�C��6�8�8�6�<�<�8�B��8�8�A�;�!�#�#�#��'�'�!�Q�$�-�C�
	*����1�1�#�s�4�1�P�J��9�9���#�*�*�6��*�>�J�"�*�4�8�8���	*�.�s�e�8�C�I�I�;�a�H�C��$�s�)�C�.�c�)��	*�s�+C�	C3�	%C.�.C3c� ������
��j|����
d��
����fd�}�
j|�}�j|�}�dvr�j|�}�j	|�}	�j
dk(r|	j
d��}	|	S)N�r�r~c���	�jjd|�f�jdz
�d����}|S#t$r�dvrt	|t
�rn���dvr�YnwxYw��J��j
�|�j���}|S)N�	aggregater��r�r��r�all)rr��std�sem)r7r�)r��_cython_operationr7rfr�rFr�)r8r�r�r`r�rtr�rks  ������rm�
array_funcz/GroupBy._cython_agg_general.<locals>.array_func�s����
�8����8�8��������Q��'���
��&�
��'�	
��.�(�Z���-L���[�C�+G�$G���	
���?�"�?��*�*�3��T�Y�Y�C�*�P�F��Ms�/4�%A�A��idxmin�idxmaxr�Fr��r8rr�r)�_get_data_to_aggregate�grouped_reduce�_wrap_agged_manager�_wrap_idxmax_idxminr]r��
infer_objects)rkr�r�r�r�rtr��new_mgrr\�outr`s``` ``    @rmr�zGroupBy._cython_agg_general�s�����*�*��3�*�O��	�	�6�%�%�j�1���&�&�w�/���&�&��*�*�3�/�C��*�*�3�/���9�9��>��#�#��#�/�C��
roc��t|��rir_)rkr�r�r�rts     rm�_cython_transformzGroupBy._cython_transform�s��"�$�'�'ro)�enginer{c��|}tj|�xs|}||k7r
t|||�t|t�s|j
|||g|��i|��S|tjvrd|�d�}t|��|tjvs|tjvr|�
||d<||d<t||�|i|��Stj|dd�5|dvr+ttd|�}|j|dg|��i|��}n|�
||d<||d<t||�|i|��}ddd�|j!�S#1swY�xYw)Nr
z2' is not a valid function name for transform(name)r�r{r�Tr�)r��get_cython_funcr?r�r��_transform_generalrN�transform_kernel_allowlistr��cythonized_kernelsrr}�temp_setattrrr
�_idxmax_idxmin�_wrap_transform_fast_result)	rkr�r�r{rsrtr�r�r�s	         rm�
_transformzGroupBy._transform�su���	��"�"�4�(�0�D�����"�4��D�9��$��$�*�4�*�*�4���X��X�QW�X�X�
��8�8�
8��d�V�M�N�C��S�/�!�
�T�,�,�
,���8S�8S�0S��!�#)��x� �*7���'�&�7�4��&��7��7�7��!�!�$�
�D�9��/�/���(:� ;�T�B�D�0�T�0�0��t�M�d�M�f�M�F��)�+1��x�(�2?���/�0�W�T�4�0�$�A�&�A�F�:��3�3�F�;�;�:�9�s
�AD9�9Ec�z�|j}|jj\}}}|j|jj|j
d��}|jjdk(rJtj|j|�}|j||j|j��}|S|jdk(rdn|j
}|j|j|�}|j!|||fidd��}|j#|j%|j
�|��}|S)	z7
        Fast transform path for aggregations.
        Fr'r��r3r~rT)�
allow_dupsr(r�)r�r�r-r6r*r�r�r7r<�take_ndr2r�r3r~r/r5�_reindex_with_indexersrCr,)	rkr�r�rir?r��outputr��new_axs	         rmr�z#GroupBy._wrap_transform_fast_results��
�'�'���M�M�,�,�	��Q������
�
� :� :����QV��W���8�8�=�=�A���$�$�V�^�^�S�9�C��%�%�c�������%�J�F��
����q�(�1�d�i�i�D��[�[��&�+�+�C�0�F��2�2����}�%�$�U�3��F��_�_�S�]�]�4�9�9�%=�D�_�I�F��
roc�x�t|�dk(rtjgd��}n(tjtj|��}|r)|j
j
||j��}|Stjt|j
j�t��}|jd�d||jt�<tj|t|j
j dd�dgz�j"}|j
j%|�}|S)Nr�int64r�r�FTr�)r�r��arrayr��concatenaterxr5r��emptyr3r��fillr�r��tiler�r�r"�where)rkr�r��filteredr=s     rm�
_apply_filterzGroupBy._apply_filter%s����w�<�1���h�h�r��1�G��g�g�b�n�n�W�5�6�G���)�)�.�.�w�T�Y�Y�.�G�H���
�8�8�C�� 2� 2� 8� 8�9��F�D��I�I�e��(,�D�����$�%��7�7�4��d�&8�&8�&>�&>�q�r�&B�!C�q�c�!I�J�L�L�D��)�)�/�/��5�H��roc���|jj\}}}t||�}||t|�}}|dk(r%t	j
dtj��Stjd|dd|ddk7f}t	jtjt	j|�d|f�}|j�}	|r|	t	j|	||�z}	n2t	j|	tj|dddf|�|	z
}	|jjrHt	j|dk(tj|	jtj d���}	n!|	jtjd��}	t	j
|tj"��}
t	j$|tj"��|
|<|	|
S)	a.
        Parameters
        ----------
        ascending : bool, default True
            If False, number in reverse, from length of group - 1 to 0.

        Notes
        -----
        this is currently implementing sort=False
        (though the default is sort=True) for groupby in general
        rr�TNr&r�Fr�)r�r-r[r�r�r�r��r_�diff�nonzero�cumsum�repeatrr��nanr��float64�intp�arange)rk�	ascendingrir?r��sorter�count�run�repr��revs           rm�_cumcount_arrayzGroupBy._cumcount_array6sx���-�-�2�2���Q��'��W�5����[�#�c�(�U���A�:��8�8�A�R�X�X�.�.��e�e�D�#�c�r�(�c�!�"�g�-�-�.���g�g�b�e�e�B�J�J�s�O�A�.��5�6�7���t�m�m�o����2�9�9�S��X�s�+�+�C��)�)�C����c�!�"�g�t�m� 4�5�s�;�c�A�C��=�=�'�'��(�(�3�"�9�b�f�f�c�j�j����%�j�.P�Q�C��*�*�R�X�X�E�*�2�C��h�h�u�B�G�G�,���i�i��R�W�W�5��F���3�x�roc���t|jt�r|jjSt|jt�sJ�|jj
Sri)r�r�rL�_constructor_slicedrZr�r�s rm�_obj_1d_constructorzGroupBy._obj_1d_constructor^sF���d�h�h�	�*��8�8�/�/�/��$�(�(�F�+�+�+��x�x�$�$�$rorl�r~)�see_alsoc�2��|jd�fd����S)a�
        Return True if any value in the group is truthful, else False.

        Parameters
        ----------
        skipna : bool, default True
            Flag to ignore nan values during truth testing.

        Returns
        -------
        Series or DataFrame
            DataFrame or Series of boolean values, where a value is True if any element
            is True within its respective group, False otherwise.
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 0], index=lst)
        >>> ser
        a    1
        a    2
        b    0
        dtype: int64
        >>> ser.groupby(level=0).any()
        a     True
        b    False
        dtype: bool

        For DataFrameGroupBy:

        >>> data = [[1, 0, 3], [1, 0, 6], [7, 1, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["ostrich", "penguin", "parrot"])
        >>> df
                 a  b  c
        ostrich  1  0  3
        penguin  1  0  6
        parrot   7  1  9
        >>> df.groupby(by=["a"]).any()
               b      c
        a
        1  False   True
        7   True   True
        rc�>��t|d��j���S�NFr�)�skipna)rZr�rrs �rmr�zGroupBy.any.<locals>.<lambda>�����&���/�3�3�6�3�Bro�r�r�r��rkrs `rmrzGroupBy.anygs'���d�'�'��B��(�
�	
roc�2��|jd�fd����S)a�
        Return True if all values in the group are truthful, else False.

        Parameters
        ----------
        skipna : bool, default True
            Flag to ignore nan values during truth testing.

        Returns
        -------
        Series or DataFrame
            DataFrame or Series of boolean values, where a value is True if all elements
            are True within its respective group, False otherwise.
        %(see_also)s
        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 0], index=lst)
        >>> ser
        a    1
        a    2
        b    0
        dtype: int64
        >>> ser.groupby(level=0).all()
        a     True
        b    False
        dtype: bool

        For DataFrameGroupBy:

        >>> data = [[1, 0, 3], [1, 5, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["ostrich", "penguin", "parrot"])
        >>> df
                 a  b  c
        ostrich  1  0  3
        penguin  1  5  6
        parrot   7  8  9
        >>> df.groupby(by=["a"]).all()
               b      c
        a
        1  False   True
        7   True   True
        r�c�>��t|d��j���Sr)rZr�rs �rmr�zGroupBy.all.<locals>.<lambda>�r	ror
rrs `rmr�zGroupBy.all�s'���f�'�'��B��(�
�	
roc�|���	�
�|j�}|jj\�}�
�dk7�	|jdk(�d	���	�
fd�}|j	|�}|j|�}t
j|dd�5|j|�}ddd�|jd��S#1swY�xYw)
af
        Compute count of group, excluding missing values.

        Returns
        -------
        Series or DataFrame
            Count of values within each group.
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, np.nan], index=lst)
        >>> ser
        a    1.0
        a    2.0
        b    NaN
        dtype: float64
        >>> ser.groupby(level=0).count()
        a    2
        b    0
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, np.nan, 3], [1, np.nan, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["cow", "horse", "bull"])
        >>> df
                a	  b	c
        cow     1	NaN	3
        horse	1	NaN	6
        bull	7	8.0	9
        >>> df.groupby("a").count()
            b   c
        a
        1   0   2
        7   1   1

        For Resampler:

        >>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
        ...                 ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
        >>> ser
        2023-01-01    1
        2023-01-15    2
        2023-02-01    3
        2023-02-15    4
        dtype: int64
        >>> ser.resample('MS').count()
        2023-01-01    2
        2023-02-01    2
        Freq: MS, dtype: int64
        r&r�c�T��|jdk(r �t|�jdd�z}n�t|�z}tj|����}t|t�r@t|dtj|jdtj����St|t�rDt|jt�s*td�}t!|�j#|d|��S�r*|jdk(sJ�|jddk(sJ�|dS|S)	Nr�r&)r<�max_binrr�)r=zint64[pyarrow]rt)r7r9�reshaper�count_level_2dr�rArEr��zerosr��bool_r@r�rGr8r��_from_sequence)�bvalues�masked�countedr�ri�	is_seriesr=r�s    ����rm�hfunczGroupBy.count.<locals>.hfunc	s
����|�|�q� ���g��!6�!6�q�"�!=� =�=����g���.���(�(���W�M�G��'�?�3�#��A�J�R�X�X�g�m�m�A�.>�b�h�h�%O����G�%8�9�*��
�
�{�C�%�%5�6���G�}�3�3�G�A�J�e�3�L�L���|�|�q�(�(�(��}�}�Q�'�1�,�,�,��q�z�!��Nror�TNr��
fill_value)rrr�r)
r�r�r-r7r�r�r�r�r]r[)rkr`r?rr��new_objr�rirr=r�s       @@@@rmr�z
GroupBy.count�s����v�*�*�,���-�-�2�2���Q���b�y���I�I��N�	�	�	�0�%�%�e�,���*�*�7�3���
�
�d�J��
5��1�1�'�:�F�6��#�#�F�q�#�9�9�6�
5�s�B2�2B;c����t|�r)ddlm}|j|tj
|d��S|j
d�fd����}|j|jd��S)	aW
        Compute mean of groups, excluding missing values.

        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns.

            .. versionchanged:: 2.0.0

                numeric_only no longer accepts ``None`` and defaults to ``False``.

        engine : str, default None
            * ``'cython'`` : Runs the operation through C-extensions from cython.
            * ``'numba'`` : Runs the operation through JIT compiled code from numba.
            * ``None`` : Defaults to ``'cython'`` or globally setting
              ``compute.use_numba``

            .. versionadded:: 1.4.0

        engine_kwargs : dict, default None
            * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}``

            .. versionadded:: 1.4.0

        Returns
        -------
        pandas.Series or pandas.DataFrame
        %(see_also)s
        Examples
        --------
        >>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2],
        ...                    'B': [np.nan, 2, 3, 4, 5],
        ...                    'C': [1, 2, 1, 1, 2]}, columns=['A', 'B', 'C'])

        Groupby one column and return the mean of the remaining columns in
        each group.

        >>> df.groupby('A').mean()
             B         C
        A
        1  3.0  1.333333
        2  4.0  1.500000

        Groupby two columns and return the mean of the remaining column.

        >>> df.groupby(['A', 'B']).mean()
                 C
        A B
        1 2.0  2.0
          4.0  1.0
        2 3.0  1.0
          5.0  2.0

        Groupby one column and return the mean of only particular column in
        the group.

        >>> df.groupby('A')['B'].mean()
        A
        1    3.0
        2    4.0
        Name: B, dtype: float64
        r)�grouped_mean��min_periods�meanc�>��t|d��j���S�NFr�)r�)rZr#�rr�s �rmr�zGroupBy.mean.<locals>.<lambda>�	s���f�Q�U�3�8�8�l�8�Sro�r�r�rlr�)	r]�pandas.core._numba.kernelsr r�r>�float_dtype_mappingr�r�r�)rkr�r�r{r r�s `    rmr#zGroupBy.mean=	sw���Z�6�"�?��*�*���,�,���	+��
��-�-��S�)�.��F�
�&�&�t�x�x�	�&�B�Broc�l��|jd�fd����}|j|jd��S)a�
        Compute median of groups, excluding missing values.

        For multiple groupings, the result index will be a MultiIndex

        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns.

            .. versionchanged:: 2.0.0

                numeric_only no longer accepts ``None`` and defaults to False.

        Returns
        -------
        Series or DataFrame
            Median of values within each group.

        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
        >>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
        >>> ser
        a     7
        a     2
        a     8
        b     4
        b     3
        b     3
        dtype: int64
        >>> ser.groupby(level=0).median()
        a    7.0
        b    3.0
        dtype: float64

        For DataFrameGroupBy:

        >>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
        >>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
        ...                   'mouse', 'mouse', 'mouse', 'mouse'])
        >>> df
                 a  b
          dog    1  1
          dog    3  4
          dog    5  8
        mouse    7  4
        mouse    7  4
        mouse    8  2
        mouse    3  1
        >>> df.groupby(level=0).median()
                 a    b
        dog    3.0  4.0
        mouse  7.0  3.0

        For Resampler:

        >>> ser = pd.Series([1, 2, 3, 3, 4, 5],
        ...                 index=pd.DatetimeIndex(['2023-01-01',
        ...                                         '2023-01-10',
        ...                                         '2023-01-15',
        ...                                         '2023-02-01',
        ...                                         '2023-02-10',
        ...                                         '2023-02-15']))
        >>> ser.resample('MS').median()
        2023-01-01    2.0
        2023-02-01    4.0
        Freq: MS, dtype: float64
        �medianc�>��t|d��j���Sr%)rZr+r&s �rmr�z GroupBy.median.<locals>.<lambda>�	s���&���/�6�6�L�6�Qror'rlr�r�)rkr�r�s ` rmr+zGroupBy.median�	s@���R�)�)��Q�%�*�
��
�"�"�4�8�8�I�"�>�>ror�c	����t|�r=ddlm}tj|j|tj|d����S|jd�fd�|���S)a�	
        Compute standard deviation of groups, excluding missing values.

        For multiple groupings, the result index will be a MultiIndex.

        Parameters
        ----------
        ddof : int, default 1
            Degrees of freedom.

        engine : str, default None
            * ``'cython'`` : Runs the operation through C-extensions from cython.
            * ``'numba'`` : Runs the operation through JIT compiled code from numba.
            * ``None`` : Defaults to ``'cython'`` or globally setting
              ``compute.use_numba``

            .. versionadded:: 1.4.0

        engine_kwargs : dict, default None
            * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}``

            .. versionadded:: 1.4.0

        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.

            .. versionadded:: 1.5.0

            .. versionchanged:: 2.0.0

                numeric_only now defaults to ``False``.

        Returns
        -------
        Series or DataFrame
            Standard deviation of values within each group.
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
        >>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
        >>> ser
        a     7
        a     2
        a     8
        b     4
        b     3
        b     3
        dtype: int64
        >>> ser.groupby(level=0).std()
        a    3.21455
        b    0.57735
        dtype: float64

        For DataFrameGroupBy:

        >>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
        >>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
        ...                   'mouse', 'mouse', 'mouse', 'mouse'])
        >>> df
                 a  b
          dog    1  1
          dog    3  4
          dog    5  8
        mouse    7  4
        mouse    7  4
        mouse    8  2
        mouse    3  1
        >>> df.groupby(level=0).std()
                      a         b
        dog    2.000000  3.511885
        mouse  2.217356  1.500000
        r��grouped_var�r"�ddofr�c�>��t|d��j���S�NFr�)r1)rZr��rr1s �rmr�zGroupBy.std.<locals>.<lambda>S
����f�Q�U�3�7�7�T�7�Bro�r�r�r1)	r]r(r/r��sqrtr�r>r)r��rkr1r�r{r�r/s `    rmr�zGroupBy.std�	sp���r�6�"�>��7�7��'�'���0�0�!� !��(���
��+�+��B�)��	,��
roc���t|�r*ddlm}|j|tj
|d���S|j
d�fd�|���S)a	
        Compute variance of groups, excluding missing values.

        For multiple groupings, the result index will be a MultiIndex.

        Parameters
        ----------
        ddof : int, default 1
            Degrees of freedom.

        engine : str, default None
            * ``'cython'`` : Runs the operation through C-extensions from cython.
            * ``'numba'`` : Runs the operation through JIT compiled code from numba.
            * ``None`` : Defaults to ``'cython'`` or globally setting
              ``compute.use_numba``

            .. versionadded:: 1.4.0

        engine_kwargs : dict, default None
            * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}``

            .. versionadded:: 1.4.0

        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.

            .. versionadded:: 1.5.0

            .. versionchanged:: 2.0.0

                numeric_only now defaults to ``False``.

        Returns
        -------
        Series or DataFrame
            Variance of values within each group.
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
        >>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
        >>> ser
        a     7
        a     2
        a     8
        b     4
        b     3
        b     3
        dtype: int64
        >>> ser.groupby(level=0).var()
        a    10.333333
        b     0.333333
        dtype: float64

        For DataFrameGroupBy:

        >>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
        >>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
        ...                   'mouse', 'mouse', 'mouse', 'mouse'])
        >>> df
                 a  b
          dog    1  1
          dog    3  4
          dog    5  8
        mouse    7  4
        mouse    7  4
        mouse    8  2
        mouse    3  1
        >>> df.groupby(level=0).var()
                      a          b
        dog    4.000000  12.333333
        mouse  4.916667   2.250000
        rr.r0�varc�>��t|d��j���Sr3)rZr:r4s �rmr�zGroupBy.var.<locals>.<lambda>�
r5ror6)r]r(r/r�r>r)r�r8s `    rmr:zGroupBy.varX
sd���r�6�"�>��*�*���,�,����+��
��+�+��B�)��	,��
roc	�	�|jdk(rtd��|rdnd}|j}|j}|jj
D�	chc]}	|	js�|	j��}
}	t|t�r|j}||
vrgn|g}n�t|j�}
|�@t|�}|t|
�z}|rtd|�d���||
z
}|rtd|�d���|
}t|j�D��cgc] \}}||
vr||vr|jdd�|f��"}}}t|jj
�}|D]C}t!|||j|j"d	|�
�\}}}|t|j
�z
}�E|j%||j"|j&|j(��}t+t|j-��}||_t/d�|D��r[|D�cgc]}|j0��}}t3j4||D�cgc]}|j��c}�
�}|j7|d��}|r|j9|d��}|j"r�|j:j<}t?tA|��|j:_tt?tA|jj
���}|jC|d	��}||j:_|r�tt?tA|jj
�|j:jD��}|j%|j:jG|�|j"|j(d	��jId�}||z}|jKd�}|jLr|}n�|j:} tOjP| j<�}!||!vrtd|�d���||_| jSt?tA|!���|_|jU�}"|jj
djjjV}#tY|!|#��j[tA|!�|�}$|$|"_|"}|j]|jd��Scc}	wcc}}wcc}wcc}w)z�
        Shared implementation of value_counts for SeriesGroupBy and DataFrameGroupBy.

        SeriesGroupBy additionally supports a bins argument. See the docstring of
        DataFrameGroupBy.value_counts for a description of arguments.
        r�z1DataFrameGroupBy.value_counts only handles axis=0�
proportionr�NzKeys z0 in subset cannot be in the groupby column keys.z) in subset do not exist in the DataFrame.F)r�r�r�r�r�)r�r�r�c3�zK�|]3}t|jttf�xr
|j���5y�wri)r��grouping_vectorrBrT�	_observed)r��groupings  rmr�z(GroupBy._value_counts.<locals>.<genexpr>sC����
�&��
�x�/�/�+�?O�1P�Q�
'��&�&�&�
'�%�s�9;�r�rr�stable)r��kind)r��sort_remaining)r�r�r��sumgzColumn label 'z' is duplicate of result columnr��value_countsr�)/r�rfr�r�r�rrOr~r�rZ�setrLr��	enumerater�r�rQr�rlr�r�r�sizer�
_result_indexrV�from_productr6�sort_valuesr3r�r+r�rE�nlevels�	droplevel�	transformrr�r��fill_missing_names�	set_names�reset_indexr�rUrPr�)%rk�subset�	normalizer�r�r�r~r}r�rA�
in_axis_names�_namer��unique_cols�	subsetted�clashing�doesnt_exist�idxrr�r�r?�gb�
result_seriesr�levels_list�multi_indexr��index_levelr%�indexed_group_sizer�r3rL�result_frame�
orig_dtype�colss%                                     rm�
_value_countszGroupBy._value_counts�
s����9�9��>�%�C��
� )�|�g��
�X�X���'�'��+/�-�-�*A�*A�
�*A�h�X�EU�EU�H�M�M�*A�	�
��c�6�"��H�H�E��-�/�2�c�U�D��c�k�k�*�K��!���K�	�$�s�=�'9�9���$���z�*3�3��� )�;�6���$���~�.2�3���
(�	�
#,�C�K�K�"8��#9�J�C���
�-�%�9�2D�����C�� �"8�
������0�0�1�	��C�'����Y�Y��Y�Y���
�M�G�Q��
��g�/�/�0�0�I���Z�Z������]�]��;�;�	�
���V�R�W�W�Y�/�
�!�
���
�&�
�
�
;D�D�)�$�4�-�-�)�K�D�$�1�1��)�#D�)�$�D�I�I�)�#D��K�*�1�1�+�!�1�L�M��)�5�5�#�(�6��M��9�9�!�'�'�-�-�E�(-�c�%�j�(9�M���%��u�S����)@�)@�%A�B�C�K�)�4�4�!�%�5��M�).�M���%����c�$�-�-�1�1�2�M�4G�4G�4O�4O�P��F�"/�!6�!6��#�#�-�-�f�5��Y�Y��{�{��"7�"��i���

�
�/�/�M�*�0�0��5�M��=�=�"�F�"�'�'�E��,�,�U�[�[�9�G��w�� �>�$��7V�!W�X�X�!%�M��"'�/�/�%��G��2E�"F�M��(�4�4�6�L����0�0��3�7�7�?�?�E�E�J���
�3�:�:�3�w�<��N�D�#'�L� �!�F��"�"�4�8�8�N�"�C�C��m
��2��HE��#Ds�S�#S�
%S�S�0S
c���|rr|jjdk(rYt|jj�s:t	t|�j�d|�d|jj����|jd�fd�|���S)a+
        Compute standard error of the mean of groups, excluding missing values.

        For multiple groupings, the result index will be a MultiIndex.

        Parameters
        ----------
        ddof : int, default 1
            Degrees of freedom.

        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.

            .. versionadded:: 1.5.0

            .. versionchanged:: 2.0.0

                numeric_only now defaults to ``False``.

        Returns
        -------
        Series or DataFrame
            Standard error of the mean of values within each group.

        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([5, 10, 8, 14], index=lst)
        >>> ser
        a     5
        a    10
        b     8
        b    14
        dtype: int64
        >>> ser.groupby(level=0).sem()
        a    2.5
        b    3.0
        dtype: float64

        For DataFrameGroupBy:

        >>> data = [[1, 12, 11], [1, 15, 2], [2, 5, 8], [2, 6, 12]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tuna", "salmon", "catfish", "goldfish"])
        >>> df
                   a   b   c
            tuna   1  12  11
          salmon   1  15   2
         catfish   2   5   8
        goldfish   2   6  12
        >>> df.groupby("a").sem()
              b  c
        a
        1    1.5  4.5
        2    0.5  2.0

        For Resampler:

        >>> ser = pd.Series([1, 3, 2, 4, 3, 8],
        ...                 index=pd.DatetimeIndex(['2023-01-01',
        ...                                         '2023-01-10',
        ...                                         '2023-01-15',
        ...                                         '2023-02-01',
        ...                                         '2023-02-10',
        ...                                         '2023-02-15']))
        >>> ser.resample('MS').sem()
        2023-01-01    0.577350
        2023-02-01    1.527525
        Freq: MS, dtype: float64
        r�z.sem called with numeric_only=z and dtype r�c�>��t|d��j���Sr3)rZr�r4s �rmr�zGroupBy.sem.<locals>.<lambda>�s���&���/�3�3��3�>ror6)r�r7r4r�r�r�rvr�)rkr1r�s ` rmr�zGroupBy.semSs����T�D�H�H�M�M�Q�.�7G������7W����:�&�&�'�( � ,�~�[������8H�J��
��'�'��>�%��	(�
�	
roc�R�|jj�}d}t|jt�r�t|jj
t�rQt|jj
t�rd}nPt|jj
t�rd}n)d}n&t|jj
t�rd}t|jt�r(|j||jj��}n|j|�}|�|jdddd|��}tj|dd�5|j|d	�
�}ddd�|j s|j#d�j%�}|S#1swY�6xYw)a:
        Compute group sizes.

        Returns
        -------
        DataFrame or Series
            Number of rows in each group as a Series if as_index is True
            or a DataFrame if as_index is False.
        %(see_also)s
        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([1, 2, 3], index=lst)
        >>> ser
        a     1
        a     2
        b     3
        dtype: int64
        >>> ser.groupby(level=0).size()
        a    2
        b    1
        dtype: int64

        >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["owl", "toucan", "eagle"])
        >>> df
                a  b  c
        owl     1  2  3
        toucan  1  5  6
        eagle   7  8  9
        >>> df.groupby("a").size()
        a
        1    2
        7    1
        dtype: int64

        For Resampler:

        >>> ser = pd.Series([1, 2, 3], index=pd.DatetimeIndex(
        ...                 ['2023-01-01', '2023-01-15', '2023-02-01']))
        >>> ser
        2023-01-01    1
        2023-01-15    2
        2023-02-01    3
        dtype: int64
        >>> ser.resample('MS').size()
        2023-01-01    2
        2023-02-01    1
        Freq: MS, dtype: int64
        N�numpy_nullable�pyarrowrF)r��convert_string�convert_boolean�convert_floating�
dtype_backendr�TrrrJ)r�rJr�r�rZr�r@rIrHrArr~�convert_dtypesr�r�r[r��renamerS)rkr�ros   rmrJzGroupBy.size�sP��t���#�#�%��EI�
��d�h�h��'��$�(�(�.�.�*=�>��d�h�h�n�n�.L�M�$(�M�������0@�A�$4�M�$-�M��D�H�H�N�N�O�<� 0�
��d�h�h��'��-�-�f�4�8�8�=�=�-�I�F��-�-�f�5�F��$��*�*�#�$� %�!&�+�+��F��
�
�d�J��
5��)�)�&�Q�)�?�F�6��}�}��]�]�6�*�6�6�8�F��
�6�
5�s�F�F&rFa        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([1, 2, 3, 4], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        b    4
        dtype: int64
        >>> ser.groupby(level=0).sum()
        a    3
        b    7
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tiger", "leopard", "cheetah", "lion"])
        >>> df
                  a  b  c
          tiger   1  8  2
        leopard   1  2  5
        cheetah   2  5  8
           lion   2  6  9
        >>> df.groupby("a").sum()
             b   c
        a
        1   10   7
        2   11  17)�fname�no�mc�e�ek�examplec�.�t|�r)ddlm}|j|tj
||��St
j|dd�5|j||dtj��}ddd�|jd��S#1swY�xYw)	Nr)�grouped_sumr!r�TrF�r�r�r�r�r)r]r(ryr�r>�default_dtype_mappingr�r�r�r�rFr[)rkr�r�r�r{ryr�s       rmrFzGroupBy.sum
s���d�6�"�>��*�*���.�.��%�	+��
��!�!�$�
�D�9��*�*�!-�'���6�6�	+���:��'�'��1�'�=�=�:�9�s�$B�B�proda        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([1, 2, 3, 4], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        b    4
        dtype: int64
        >>> ser.groupby(level=0).prod()
        a    2
        b   12
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tiger", "leopard", "cheetah", "lion"])
        >>> df
                  a  b  c
          tiger   1  8  2
        leopard   1  2  5
        cheetah   2  5  8
           lion   2  6  9
        >>> df.groupby("a").prod()
             b    c
        a
        1   16   10
        2   30   72)rrrsrtrwc�H�|j||dtj��S)Nr|rz)r�r�r|)rkr�r�s   rmr|zGroupBy.prodSs-��T� � �%��&�QS�QX�QX�!�
�	
ro�mina        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([1, 2, 3, 4], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        b    4
        dtype: int64
        >>> ser.groupby(level=0).min()
        a    1
        b    3
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tiger", "leopard", "cheetah", "lion"])
        >>> df
                  a  b  c
          tiger   1  8  2
        leopard   1  2  5
        cheetah   2  5  8
           lion   2  6  9
        >>> df.groupby("a").min()
            b  c
        a
        1   2  2
        2   5  8c��t|�r*ddlm}|j|tj
||d��S|j
||dtj��S)Nr��grouped_min_maxF�r"�is_maxr~rz)	r]r(r�r�r>�identity_dtype_mappingr�r�r~�rkr�r�r�r{r�s      rmr~zGroupBy.min�sg��d�6�"�B��*�*���/�/��%��+��
��$�$�)�#���v�v�	%��
ro�maxa        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([1, 2, 3, 4], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        b    4
        dtype: int64
        >>> ser.groupby(level=0).max()
        a    2
        b    4
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tiger", "leopard", "cheetah", "lion"])
        >>> df
                  a  b  c
          tiger   1  8  2
        leopard   1  2  5
        cheetah   2  5  8
           lion   2  6  9
        >>> df.groupby("a").max()
            b  c
        a
        1   8  5
        2   6  9c��t|�r*ddlm}|j|tj
||d��S|j
||dtj��S)Nrr�Tr�r�rz)	r]r(r�r�r>r�r�r�r�r�s      rmr�zGroupBy.max�sg��d�6�"�B��*�*���/�/��%��+��
��$�$�)�#���v�v�	%��
roc�8�ddd�}|j||d||��S)a�
        Compute the first entry of each column within each group.

        Defaults to skipping NA elements.

        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns.
        min_count : int, default -1
            The required number of valid values to perform the operation. If fewer
            than ``min_count`` valid values are present the result will be NA.
        skipna : bool, default True
            Exclude NA/null values. If an entire row/column is NA, the result
            will be NA.

            .. versionadded:: 2.2.1

        Returns
        -------
        Series or DataFrame
            First values within each group.

        See Also
        --------
        DataFrame.groupby : Apply a function groupby to each row or column of a
            DataFrame.
        pandas.core.groupby.DataFrameGroupBy.last : Compute the last non-null entry
            of each column.
        pandas.core.groupby.DataFrameGroupBy.nth : Take the nth row from each group.

        Examples
        --------
        >>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[None, 5, 6], C=[1, 2, 3],
        ...                        D=['3/11/2000', '3/12/2000', '3/13/2000']))
        >>> df['D'] = pd.to_datetime(df['D'])
        >>> df.groupby("A").first()
             B  C          D
        A
        1  5.0  1 2000-03-11
        3  6.0  3 2000-03-13
        >>> df.groupby("A").first(min_count=2)
            B    C          D
        A
        1 NaN  1.0 2000-03-11
        3 NaN  NaN        NaT
        >>> df.groupby("A").first(numeric_only=True)
             B  C
        A
        1  5.0  1
        3  6.0  3
        c��dd�}t|t�r|j||��St|t�r||�St	t|���)Nc��|jt|j�}t|�s |jjjS|dS)z-Helper function for first item that isn't NA.r�r�r;r�r��na_value�r�arrs  rm�firstz2GroupBy.first.<locals>.first_compat.<locals>.firstC
s<���g�g�e�A�G�G�n�-���3�x��7�7�=�=�1�1�1��1�v�
ror��rrZ�r�rLrwrZr�r�)r�r�r�s   rm�first_compatz#GroupBy.first.<locals>.first_compatB
sI��
��#�y�)��y�y��T�y�2�2��C��(��S�z�!���S�	�*�*ror��r�r�r�r�r�r�r�rr�r�r�)rkr�r�rr�s     rmr�z
GroupBy.first	
s1��r
	+�� � �%�����!�
�	
roc�8�ddd�}|j||d||��S)aS
        Compute the last entry of each column within each group.

        Defaults to skipping NA elements.

        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns. If None, will attempt to use
            everything, then use only numeric data.
        min_count : int, default -1
            The required number of valid values to perform the operation. If fewer
            than ``min_count`` valid values are present the result will be NA.
        skipna : bool, default True
            Exclude NA/null values. If an entire row/column is NA, the result
            will be NA.

            .. versionadded:: 2.2.1

        Returns
        -------
        Series or DataFrame
            Last of values within each group.

        See Also
        --------
        DataFrame.groupby : Apply a function groupby to each row or column of a
            DataFrame.
        pandas.core.groupby.DataFrameGroupBy.first : Compute the first non-null entry
            of each column.
        pandas.core.groupby.DataFrameGroupBy.nth : Take the nth row from each group.

        Examples
        --------
        >>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[5, None, 6], C=[1, 2, 3]))
        >>> df.groupby("A").last()
             B  C
        A
        1  5.0  2
        3  6.0  3
        c��dd�}t|t�r|j||��St|t�r||�St	t|���)Nc��|jt|j�}t|�s |jjjS|dS)z,Helper function for last item that isn't NA.r&r�r�s  rm�lastz/GroupBy.last.<locals>.last_compat.<locals>.last�
s<���g�g�e�A�G�G�n�-���3�x��7�7�=�=�1�1�1��2�w�ror�r�r�)r�r�r�s   rm�last_compatz!GroupBy.last.<locals>.last_compat�
sI��
��#�y�)��y�y��D�y�1�1��C��(��C�y� ���S�	�*�*ror�r�r�r�r�)rkr�r�rr�s     rmr�zGroupBy.lastY
s1��\
	+�� � �%�����!�
�	
roc��|jjdk(r�|j}t|j�}|std��|jjd|jddd��}gd�}|jj||jj|�	�}|j|�S|jd
��}|S)a�
        Compute open, high, low and close values of a group, excluding missing values.

        For multiple groupings, the result index will be a MultiIndex

        Returns
        -------
        DataFrame
            Open, high, low and close values within each group.

        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['SPX', 'CAC', 'SPX', 'CAC', 'SPX', 'CAC', 'SPX', 'CAC',]
        >>> ser = pd.Series([3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 0.1, 0.5], index=lst)
        >>> ser
        SPX     3.4
        CAC     9.0
        SPX     7.2
        CAC     5.2
        SPX     8.8
        CAC     9.4
        SPX     0.1
        CAC     0.5
        dtype: float64
        >>> ser.groupby(level=0).ohlc()
             open  high  low  close
        CAC   9.0   9.4  0.5    0.5
        SPX   3.4   8.8  0.1    0.1

        For DataFrameGroupBy:

        >>> data = {2022: [1.2, 2.3, 8.9, 4.5, 4.4, 3, 2 , 1],
        ...         2023: [3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 8.2, 1.0]}
        >>> df = pd.DataFrame(data, index=['SPX', 'CAC', 'SPX', 'CAC',
        ...                   'SPX', 'CAC', 'SPX', 'CAC'])
        >>> df
             2022  2023
        SPX   1.2   3.4
        CAC   2.3   9.0
        SPX   8.9   7.2
        CAC   4.5   5.2
        SPX   4.4   8.8
        CAC   3.0   9.4
        SPX   2.0   8.2
        CAC   1.0   1.0
        >>> df.groupby(level=0).ohlc()
            2022                 2023
            open high  low close open high  low close
        CAC  2.3  4.5  1.0   1.0  9.0  9.4  1.0   1.0
        SPX  1.2  8.9  1.2   2.0  3.4  8.8  3.4   8.2

        For Resampler:

        >>> ser = pd.Series([1, 3, 2, 4, 3, 5],
        ...                 index=pd.DatetimeIndex(['2023-01-01',
        ...                                         '2023-01-10',
        ...                                         '2023-01-15',
        ...                                         '2023-02-01',
        ...                                         '2023-02-10',
        ...                                         '2023-02-15']))
        >>> ser.resample('MS').ohlc()
                    open  high  low  close
        2023-01-01     1     3    1      2
        2023-02-01     4     5    3      5
        r�zNo numeric types to aggregater��ohlcrr&r�)�open�high�low�close)r3rLc�"�|j�Sri)r�)�sgbs rmr�zGroupBy.ohlc.<locals>.<lambda>�
s
��C�H�H�Jro)
r�r7rxr4r�r&r�r�r2�_constructor_expanddimr*r[�_apply_to_column_groupbys)rkr��
is_numericr��	agg_namesr�s      rmr�zGroupBy.ohlc�
s���L�8�8�=�=�A���$�$�C�)�#�)�)�4�J��� ?�@�@����8�8��S�[�[�&�q�B�9��J�9�I��X�X�4�4��$�-�-�"<�"<�i�5��F��'�'��/�/��/�/�0F�G���
roc�F����|j}t|�dk(r]|j�����}|jdk(r|}n|j	�}|j�jjddStj|dd�5|j���fd�|d��}ddd�|jdk(rjSj	�}|js*|j|�}tt|��|_|S#1swY�lxYw)Nr��percentiles�include�excluder�r�Tc�,��|j�����S)Nr�)�describe)rr�r�r�s ���rmr�z"GroupBy.describe.<locals>.<lambda>
s���!�*�*� +�W�g�%�ro�r)r�r�r�r7�unstackrKr"r�r�r�rwr�r�rSrXr3)rkr�r�r�r��	describedr�s ```   rmr�zGroupBy.describe�
s����'�'���s�8�q�=����'��'�%��I��x�x�1�}�"��"�*�*�,���?�?�$�&�&�+�+�B�Q�/�/�
�
�
�d�J��
5��/�/���!%�0��F�6��9�9��>��8�8�O����!���}�}��0�0��8�F�(��V��5�F�L��
�#6�
5�s�D�D c�,�ddlm}|||g|��d|i|��S)a�
        Provide resampling when using a TimeGrouper.

        Given a grouper, the function resamples it according to a string
        "string" -> "frequency".

        See the :ref:`frequency aliases <timeseries.offset_aliases>`
        documentation for more details.

        Parameters
        ----------
        rule : str or DateOffset
            The offset string or object representing target grouper conversion.
        *args
            Possible arguments are `how`, `fill_method`, `limit`, `kind` and
            `on`, and other arguments of `TimeGrouper`.
        include_groups : bool, default True
            When True, will attempt to include the groupings in the operation in
            the case that they are columns of the DataFrame. If this raises a
            TypeError, the result will be computed with the groupings excluded.
            When False, the groupings will be excluded when applying ``func``.

            .. versionadded:: 2.2.0

            .. deprecated:: 2.2.0

               Setting include_groups to True is deprecated. Only the value
               False will be allowed in a future version of pandas.

        **kwargs
            Possible arguments are `how`, `fill_method`, `limit`, `kind` and
            `on`, and other arguments of `TimeGrouper`.

        Returns
        -------
        pandas.api.typing.DatetimeIndexResamplerGroupby,
        pandas.api.typing.PeriodIndexResamplerGroupby, or
        pandas.api.typing.TimedeltaIndexResamplerGroupby
            Return a new groupby object, with type depending on the data
            being resampled.

        See Also
        --------
        Grouper : Specify a frequency to resample with when
            grouping by a key.
        DatetimeIndex.resample : Frequency conversion and resampling of
            time series.

        Examples
        --------
        >>> idx = pd.date_range('1/1/2000', periods=4, freq='min')
        >>> df = pd.DataFrame(data=4 * [range(2)],
        ...                   index=idx,
        ...                   columns=['a', 'b'])
        >>> df.iloc[2, 0] = 5
        >>> df
                            a  b
        2000-01-01 00:00:00  0  1
        2000-01-01 00:01:00  0  1
        2000-01-01 00:02:00  5  1
        2000-01-01 00:03:00  0  1

        Downsample the DataFrame into 3 minute bins and sum the values of
        the timestamps falling into a bin.

        >>> df.groupby('a').resample('3min', include_groups=False).sum()
                                 b
        a
        0   2000-01-01 00:00:00  2
            2000-01-01 00:03:00  1
        5   2000-01-01 00:00:00  1

        Upsample the series into 30 second bins.

        >>> df.groupby('a').resample('30s', include_groups=False).sum()
                            b
        a
        0   2000-01-01 00:00:00  1
            2000-01-01 00:00:30  0
            2000-01-01 00:01:00  1
            2000-01-01 00:01:30  0
            2000-01-01 00:02:00  0
            2000-01-01 00:02:30  0
            2000-01-01 00:03:00  1
        5   2000-01-01 00:02:00  1

        Resample by month. Values are assigned to the month of the period.

        >>> df.groupby('a').resample('ME', include_groups=False).sum()
                    b
        a
        0   2000-01-31  3
        5   2000-01-31  1

        Downsample the series into 3 minute bins as above, but close the right
        side of the bin interval.

        >>> (
        ...     df.groupby('a')
        ...     .resample('3min', closed='right', include_groups=False)
        ...     .sum()
        ... )
                                 b
        a
        0   1999-12-31 23:57:00  1
            2000-01-01 00:00:00  2
        5   2000-01-01 00:00:00  1

        Downsample the series into 3 minute bins and close the right side of
        the bin interval, but label each bin using the right edge instead of
        the left.

        >>> (
        ...     df.groupby('a')
        ...     .resample('3min', closed='right', label='right', include_groups=False)
        ...     .sum()
        ... )
                                 b
        a
        0   2000-01-01 00:00:00  1
            2000-01-01 00:03:00  2
        5   2000-01-01 00:03:00  1
        r)�get_resampler_for_groupingr�)�pandas.core.resampler�)rk�ruler�rsrtr�s      rm�resamplezGroupBy.resamples5��z	D�*��$�
��
�.<�
�@F�
�	
roc�h�ddlm}||jg|��|j|jd�|��S)a�
        Return a rolling grouper, providing rolling functionality per group.

        Parameters
        ----------
        window : int, timedelta, str, offset, or BaseIndexer subclass
            Size of the moving window.

            If an integer, the fixed number of observations used for
            each window.

            If a timedelta, str, or offset, the time period of each window. Each
            window will be a variable sized based on the observations included in
            the time-period. This is only valid for datetimelike indexes.
            To learn more about the offsets & frequency strings, please see `this link
            <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.

            If a BaseIndexer subclass, the window boundaries
            based on the defined ``get_window_bounds`` method. Additional rolling
            keyword arguments, namely ``min_periods``, ``center``, ``closed`` and
            ``step`` will be passed to ``get_window_bounds``.

        min_periods : int, default None
            Minimum number of observations in window required to have a value;
            otherwise, result is ``np.nan``.

            For a window that is specified by an offset,
            ``min_periods`` will default to 1.

            For a window that is specified by an integer, ``min_periods`` will default
            to the size of the window.

        center : bool, default False
            If False, set the window labels as the right edge of the window index.

            If True, set the window labels as the center of the window index.

        win_type : str, default None
            If ``None``, all points are evenly weighted.

            If a string, it must be a valid `scipy.signal window function
            <https://docs.scipy.org/doc/scipy/reference/signal.windows.html#module-scipy.signal.windows>`__.

            Certain Scipy window types require additional parameters to be passed
            in the aggregation function. The additional parameters must match
            the keywords specified in the Scipy window type method signature.

        on : str, optional
            For a DataFrame, a column label or Index level on which
            to calculate the rolling window, rather than the DataFrame's index.

            Provided integer column is ignored and excluded from result since
            an integer index is not used to calculate the rolling window.

        axis : int or str, default 0
            If ``0`` or ``'index'``, roll across the rows.

            If ``1`` or ``'columns'``, roll across the columns.

            For `Series` this parameter is unused and defaults to 0.

        closed : str, default None
            If ``'right'``, the first point in the window is excluded from calculations.

            If ``'left'``, the last point in the window is excluded from calculations.

            If ``'both'``, no points in the window are excluded from calculations.

            If ``'neither'``, the first and last points in the window are excluded
            from calculations.

            Default ``None`` (``'right'``).

        method : str {'single', 'table'}, default 'single'
            Execute the rolling operation per single column or row (``'single'``)
            or over the entire object (``'table'``).

            This argument is only implemented when specifying ``engine='numba'``
            in the method call.

        Returns
        -------
        pandas.api.typing.RollingGroupby
            Return a new grouper with our rolling appended.

        See Also
        --------
        Series.rolling : Calling object with Series data.
        DataFrame.rolling : Calling object with DataFrames.
        Series.groupby : Apply a function groupby to a Series.
        DataFrame.groupby : Apply a function groupby.

        Examples
        --------
        >>> df = pd.DataFrame({'A': [1, 1, 2, 2],
        ...                    'B': [1, 2, 3, 4],
        ...                    'C': [0.362, 0.227, 1.267, -0.562]})
        >>> df
              A  B      C
        0     1  1  0.362
        1     1  2  0.227
        2     2  3  1.267
        3     2  4 -0.562

        >>> df.groupby('A').rolling(2).sum()
            B      C
        A
        1 0  NaN    NaN
          1  3.0  0.589
        2 2  NaN    NaN
          3  7.0  0.705

        >>> df.groupby('A').rolling(2, min_periods=1).sum()
            B      C
        A
        1 0  1.0  0.362
          1  3.0  0.589
        2 2  3.0  1.267
          3  7.0  0.705

        >>> df.groupby('A').rolling(2, on='B').sum()
            B      C
        A
        1 0  1    NaN
          1  2  0.589
        2 2  3    NaN
          3  4  0.705
        r)rb)r��	_as_index)�pandas.core.windowrbrxr�r�)rkrsrtrbs    rm�rollingzGroupBy.rolling�sE��D	6�����
�
�
��]�]��m�m�	
�
�
�	
roc�R�ddlm}||jg|��d|ji|��S)z�
        Return an expanding grouper, providing expanding
        functionality per group.

        Returns
        -------
        pandas.api.typing.ExpandingGroupby
        r)r`r�)r�r`rxr�)rkrsrtr`s    rm�	expandingzGroupBy.expanding/s=��	8�����
�
�
��]�]�
��	
�	
roc�R�ddlm}||jg|��d|ji|��S)z�
        Return an ewm grouper, providing ewm functionality per group.

        Returns
        -------
        pandas.api.typing.ExponentialMovingWindowGroupby
        r)rar�)r�rarxr�)rkrsrtras    rm�ewmzGroupBy.ewmDs>��	F�-����
�
�
��]�]�
��	
�	
roc�0��
�|�d}�jj\}}}tj|d��j	tj
d��}|dk(r|ddd�}t
tj|||�j���
d�
�fd	�}�j�}|j|�}�j|�}	�jd
k(r'|	j}	�jj |	_�jj"|	_|	S)a

        Shared function for `pad` and `backfill` to call Cython method.

        Parameters
        ----------
        direction : {'ffill', 'bfill'}
            Direction passed to underlying Cython function. `bfill` will cause
            values to be filled backwards. `ffill` and any other values will
            default to a forward fill
        limit : int, default None
            Maximum number of consecutive values to fill. If `None`, this
            method will convert to -1 prior to passing to Cython

        Returns
        -------
        `Series` or `DataFrame` with filled values

        See Also
        --------
        pad : Returns Series with minimum number of char in object.
        backfill : Backward fill the missing values in the dataset.
        Nr&�	mergesort)rDFr��bfill)r<�
sorted_labels�limitr�c���t|�}|jdk(rOtj|jtj
��}�||��t
j||�St|tj�rY|j}�jjrt|j�}tj|j|��}n0t|�j|j|j��}t!|�D]a\}}tj|jdtj
��}�|||��t
j||�||dd�f<�c|S)Nr�r�)r�r=)r9r7r�r�r�r�r<r�r��ndarrayr�r�rr-r��_emptyrI)	r8r=r�r�r��i�
value_element�col_funcrks	       ��rm�blk_funczGroupBy._fill.<locals>.blk_func�s�����<�D��{�{�a���(�(�6�<�<�r�w�w�?���W�4�0�!�)�)�&�'�:�:�
�f�b�j�j�1�"�L�L�E��}�}�3�3� 8���� F���(�(�6�<�<�u�=�C��v�,�-�-�f�l�l�&�,�,�-�O�C�(1�&�(9�$�A�}� �h�h�v�|�|�A��b�g�g�F�G���t�A�w�7� *� 2� 2�=�'� J�C��1��I�	):�
�
ror�r�)r�r-r�r�r�r�r�
libgroupby�group_fillna_indexerr�r�rwr�r�r"r�rLr3)rk�	directionr�rir?r�r��mgrrrr�s`         @rm�_fillz
GroupBy._fillXs����2�=��E��M�M�,�,�	��Q���
�
�3�[�9�@�@����u�@�U�
����)�$�B�$�/�M���+�+��'���;�;�
��	�<�)�)�+���)�)�H�%���*�*�7�3���9�9��>��i�i�G�"�h�h�.�.�G�O�������
��roc�(�|jd|��S)a0	
        Forward fill the values.

        Parameters
        ----------
        limit : int, optional
            Limit of how many values to fill.

        Returns
        -------
        Series or DataFrame
            Object with missing values filled.

        See Also
        --------
        Series.ffill: Returns Series with minimum number of char in object.
        DataFrame.ffill: Object with missing values filled or None if inplace=True.
        Series.fillna: Fill NaN values of a Series.
        DataFrame.fillna: Fill NaN values of a DataFrame.

        Examples
        --------

        For SeriesGroupBy:

        >>> key = [0, 0, 1, 1]
        >>> ser = pd.Series([np.nan, 2, 3, np.nan], index=key)
        >>> ser
        0    NaN
        0    2.0
        1    3.0
        1    NaN
        dtype: float64
        >>> ser.groupby(level=0).ffill()
        0    NaN
        0    2.0
        1    3.0
        1    3.0
        dtype: float64

        For DataFrameGroupBy:

        >>> df = pd.DataFrame(
        ...     {
        ...         "key": [0, 0, 1, 1, 1],
        ...         "A": [np.nan, 2, np.nan, 3, np.nan],
        ...         "B": [2, 3, np.nan, np.nan, np.nan],
        ...         "C": [np.nan, np.nan, 2, np.nan, np.nan],
        ...     }
        ... )
        >>> df
           key    A    B   C
        0    0  NaN  2.0 NaN
        1    0  2.0  3.0 NaN
        2    1  NaN  NaN 2.0
        3    1  3.0  NaN NaN
        4    1  NaN  NaN NaN

        Propagate non-null values forward or backward within each group along columns.

        >>> df.groupby("key").ffill()
             A    B   C
        0  NaN  2.0 NaN
        1  2.0  3.0 NaN
        2  NaN  NaN 2.0
        3  3.0  NaN 2.0
        4  3.0  NaN 2.0

        Propagate non-null values forward or backward within each group along rows.

        >>> df.T.groupby(np.array([0, 0, 1, 1])).ffill().T
           key    A    B    C
        0  0.0  0.0  2.0  2.0
        1  0.0  2.0  3.0  3.0
        2  1.0  1.0  NaN  2.0
        3  1.0  3.0  NaN  NaN
        4  1.0  1.0  NaN  NaN

        Only replace the first NaN element within a group along rows.

        >>> df.groupby("key").ffill(limit=1)
             A    B    C
        0  NaN  2.0  NaN
        1  2.0  3.0  NaN
        2  NaN  NaN  2.0
        3  3.0  NaN  2.0
        4  3.0  NaN  NaN
        �ffill�r��r��rkr�s  rmr�z
GroupBy.ffill�s��v�z�z�'��z�/�/roc�(�|jd|��S)a�
        Backward fill the values.

        Parameters
        ----------
        limit : int, optional
            Limit of how many values to fill.

        Returns
        -------
        Series or DataFrame
            Object with missing values filled.

        See Also
        --------
        Series.bfill :  Backward fill the missing values in the dataset.
        DataFrame.bfill:  Backward fill the missing values in the dataset.
        Series.fillna: Fill NaN values of a Series.
        DataFrame.fillna: Fill NaN values of a DataFrame.

        Examples
        --------

        With Series:

        >>> index = ['Falcon', 'Falcon', 'Parrot', 'Parrot', 'Parrot']
        >>> s = pd.Series([None, 1, None, None, 3], index=index)
        >>> s
        Falcon    NaN
        Falcon    1.0
        Parrot    NaN
        Parrot    NaN
        Parrot    3.0
        dtype: float64
        >>> s.groupby(level=0).bfill()
        Falcon    1.0
        Falcon    1.0
        Parrot    3.0
        Parrot    3.0
        Parrot    3.0
        dtype: float64
        >>> s.groupby(level=0).bfill(limit=1)
        Falcon    1.0
        Falcon    1.0
        Parrot    NaN
        Parrot    3.0
        Parrot    3.0
        dtype: float64

        With DataFrame:

        >>> df = pd.DataFrame({'A': [1, None, None, None, 4],
        ...                    'B': [None, None, 5, None, 7]}, index=index)
        >>> df
                  A	    B
        Falcon	1.0	  NaN
        Falcon	NaN	  NaN
        Parrot	NaN	  5.0
        Parrot	NaN	  NaN
        Parrot	4.0	  7.0
        >>> df.groupby(level=0).bfill()
                  A	    B
        Falcon	1.0	  NaN
        Falcon	NaN	  NaN
        Parrot	4.0	  5.0
        Parrot	4.0	  7.0
        Parrot	4.0	  7.0
        >>> df.groupby(level=0).bfill(limit=1)
                  A	    B
        Falcon	1.0	  NaN
        Falcon	NaN	  NaN
        Parrot	NaN	  5.0
        Parrot	4.0	  7.0
        Parrot	4.0	  7.0
        r�r�r�r�s  rmr�z
GroupBy.bfill	s��\�z�z�'��z�/�/roc��t|�S)a�
        Take the nth row from each group if n is an int, otherwise a subset of rows.

        Can be either a call or an index. dropna is not available with index notation.
        Index notation accepts a comma separated list of integers and slices.

        If dropna, will take the nth non-null row, dropna is either
        'all' or 'any'; this is equivalent to calling dropna(how=dropna)
        before the groupby.

        Parameters
        ----------
        n : int, slice or list of ints and slices
            A single nth value for the row or a list of nth values or slices.

            .. versionchanged:: 1.4.0
                Added slice and lists containing slices.
                Added index notation.

        dropna : {'any', 'all', None}, default None
            Apply the specified dropna operation before counting which row is
            the nth row. Only supported if n is an int.

        Returns
        -------
        Series or DataFrame
            N-th value within each group.
        %(see_also)s
        Examples
        --------

        >>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2],
        ...                    'B': [np.nan, 2, 3, 4, 5]}, columns=['A', 'B'])
        >>> g = df.groupby('A')
        >>> g.nth(0)
           A   B
        0  1 NaN
        2  2 3.0
        >>> g.nth(1)
           A   B
        1  1 2.0
        4  2 5.0
        >>> g.nth(-1)
           A   B
        3  1 4.0
        4  2 5.0
        >>> g.nth([0, 1])
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0
        4  2 5.0
        >>> g.nth(slice(None, -1))
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0

        Index notation may also be used

        >>> g.nth[0, 1]
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0
        4  2 5.0
        >>> g.nth[:-1]
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0

        Specifying `dropna` allows ignoring ``NaN`` values

        >>> g.nth(0, dropna='any')
           A   B
        1  1 2.0
        2  2 3.0

        When the specified ``n`` is larger than any of the groups, an
        empty DataFrame is returned

        >>> g.nth(3, dropna='any')
        Empty DataFrame
        Columns: [A, B]
        Index: []
        )rSr�s rm�nthzGroupBy.nthYs��x"�$�'�'roc��|sF|j|�}|jj\}}}||dk7z}|j|�}|St	|�std��|dvrtd|�d���t
t|�}|jj||j��}t|�t|j�k(r
|j}n�|jj}	|jj|	j|j�}|jjr-|dk(}
t!j"|
t$|�}t'|d��}|jd	k(r3|j(j+||j,|j.�
�}n(|j+||j,|j.�
�}|j1|�S)Nr&z4dropna option only supported for an integer argumentr�z_For a DataFrame or Series groupby.nth, dropna must be either None, 'any' or 'all', (was passed z).)r�r��Int64r�r�)r�r�)�"_make_mask_from_positional_indexerr�r-�_mask_selected_objr1r�rr�rxr�r�r��
codes_info�isinr3rr�r�rrUr"rlr�r�r�)
rkr�r�r=rir?r��droppedr�r��nullsr8�grbs
             rm�_nthzGroupBy._nth�s���
��:�:�1�=�D��
�
�0�0�I�C��A��3�"�9�%�D��)�)�$�/�C��J��!�}��S�T�T���'���%�h�b�*��
�
��a�L���$�$�+�+��T�Y�Y�+�G���w�<�3�t�1�1�2�2��m�m�G�
�=�=�%�%�D��m�m�.�.�t�y�y����/G�H�G��}�}�+�+��2�
�����%��W�5����g�6���9�9��>��)�)�#�#�G�d�m�m�$�)�)�#�T�C��/�/�'�D�M�M��	�	�/�R�C��w�w�q�z�roc����������j|d��}�j|�}�jdk(rH�jj	|j
�j��}|jj
}n3�jj	|�j��}|j}tj|j|j�\}}	d�fd��										d
�fd��tj|tj��}
|
}t|�r(tj|gtj��}
d}�jj\}}
�t!|
��t#t$j&||
�||	�	��d�����fd
�}|j(j+|�}�j|�}�j-||��S)a
        Return group values at the given quantile, a la numpy.percentile.

        Parameters
        ----------
        q : float or array-like, default 0.5 (50% quantile)
            Value(s) between 0 and 1 providing the quantile(s) to compute.
        interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
            Method to use when the desired quantile falls between two points.
        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.

            .. versionadded:: 1.5.0

            .. versionchanged:: 2.0.0

                numeric_only now defaults to ``False``.

        Returns
        -------
        Series or DataFrame
            Return type determined by caller of GroupBy object.

        See Also
        --------
        Series.quantile : Similar method for Series.
        DataFrame.quantile : Similar method for DataFrame.
        numpy.percentile : NumPy method to compute qth percentile.

        Examples
        --------
        >>> df = pd.DataFrame([
        ...     ['a', 1], ['a', 2], ['a', 3],
        ...     ['b', 1], ['b', 3], ['b', 5]
        ... ], columns=['key', 'val'])
        >>> df.groupby('key').quantile()
            val
        key
        a    2.0
        b    3.0
        �quantiler�r�r�c���t|j�rtd��d}t|t�rJt|j�r5|j
ttj��}|j}||fSt|j�r_t|t�r&|j
ttj��}n|}tjtj�}||fSt|j�r9t|t�r)|j
ttj��}||fSt|j�rTtjdt!��j"�d�t$t'���tj(|�}||fSt+|j�r|j}||fSt|t�rat-|j�rLtjtj.�}|j
ttj��}||fStj(|�}||fS)Nz7'quantile' cannot be performed against 'object' dtypes!)r�r�zAllowing bool dtype in z�.quantile is deprecated and will raise in a future version, matching the Series/DataFrame behavior. Cast to uint8 dtype before calling quantile instead.r�)r5r�r�r�rAr4re�floatr�r�r2rCr�r.r�r�r�rvr�r+�asarrayr7r/r�)�vals�	inferencer�rks   �rm�
pre_processorz'GroupBy.quantile.<locals>.pre_processor,s�����t�z�z�*��M���*.�I��$��0�5E�d�j�j�5Q��m�m�%�"�&�&�m�A�� �J�J�	�F�	�>�!�E"�$�*�*�-��d�N�3��-�-�e�b�f�f�-�E�C��C��H�H�R�X�X�.�	�:�	�>�!�9�t�z�z�*�z�$��/O��m�m�%�"�&�&�m�A��6�	�>�!�5�t�z�z�*��
�
�-�d�4�j�.A�.A�-B�C0�0�"�/�1�
��j�j��&�� �	�>�!�%�T�Z�Z�0� �J�J�	��Y��&��D�.�1�n�T�Z�Z�6P��H�H�R�Z�Z�0�	��m�m�%�"�&�&�m�A���	�>�!��j�j��&���	�>�!roc�f��|�rt|t�r�|�J��dvrt|�st||�St	j
�5t	jdt��t|�|j|j�|�cddd�St|�r�dvs}t|�rE|jd�j|jj�}|j!|�St|t"j�sJ�|j|�S|S#1swY|SxYw)N>�linear�midpoint�ignore)r��i8)r�rAr/rDr��catch_warnings�filterwarnings�RuntimeWarningr�r��numpy_dtyper2r7�view�_ndarrayr��_from_backing_datar�)r�r��result_mask�	orig_vals�
interpolations    �rm�post_processorz(GroupBy.quantile.<locals>.post_processorZs#�����i��9�&�2�2�2�$�(>�>�~�!�H� -�T�;�?�?�
&�4�4�6�$�3�3�H�~�V�#2�4�	�?� $���$-�$9�$9�!"�!,�	$�7�6�%�Y�/�%�)?�?�*�9�5� $�{�{�4�0�5�5�%�.�.�4�4� ��
 )�;�;� � ��&�i����:�:�:��;�;�y�1�1��K�;7�:�K�s
�AD&�&D0r�N)r<rXr�rprqc����|}t|t�r4|j}tj��ftj
��}n
t
|�}d}t|j�}�|�\}}d}|jdk(r|jd}tj|��ftj��}|r|jd�}|jdk(r�
|d||||��n&t|�D]}	�
||	||	||	d|���|jdk(r%|jd�}|�'|jd�}n|j!|��z�}�
||||�S)Nr�r�rtrr�)r8r=r��is_datetimelike�K)r�rA�_maskr�rrr9r7r�r7r�r�r�r�r+r�r)r8r�r=r�r�r�r��ncolsr�r�r�r��nqsr�r�s          �����rmr�z"GroupBy.quantile.<locals>.blk_func�sS����I��&�/�2��|�|�� �h�h���~�R�X�X�F���F�|��"��1�&�,�,�?�O�+�F�3�O�D�)��E��y�y�A�~��
�
�1�
���(�(�E�7�C�0��
�
�C�C���y�y�����y�y�A�~����F��� +�$3���u��A���A��#�A�w�!�!�W�$(�(7��&��y�y�A�~��i�i��n���*�"-�"3�"3�C�"8�K��k�k�%��3��7��!�#�y�+�y�I�IrorW)r�rr�z"tuple[np.ndarray, DtypeObj | None])
r��
np.ndarrayr�zDtypeObj | Noner�znp.ndarray | Noner�rr�rr�)r�r�r�r��
_get_splitterr"�_sorted_datarrh�_slabelsr�r�r�r�r6r-r�rr��group_quantilervr�r])rk�qr�r�r�r��splitter�sdatarprqrX�pass_qsrir?r�rr\r�r�r�r�r�s` `              @@@@@rmr�zGroupBy.quantile�s����`�)�)�|�*�)�U���&�&�s�+���9�9��>��}�}�2�2�3�5�5�t�y�y�2�I�H��)�)�+�+�E��}�}�2�2�3�T�Y�Y�2�G�H��)�)�E��*�*�8�+<�+<�h�>N�>N�O����,	"�\0	��0	�&�0	�+�0	�!�	0	�
�0	�d�X�X�a�r�z�z�
*��%'���Q�<����1�#�R�Z�Z�0�B��G��-�-�2�2���Q���"�g����%�%���'���

��0	J�0	J�d�*�*�+�+�H�5���&�&�w�/���+�+�C�G�+�<�<roc��|j}|j|j�}|jjd}|jj
r9t
j|dk(tj|�}tj}ntj}td�|jjD��rt|d��dz
}|j|||��}|s|jdz
|z
}|S)a
        Number each group from 0 to the number of groups - 1.

        This is the enumerative complement of cumcount.  Note that the
        numbers given to the groups match the order in which the groups
        would be seen when iterating over the groupby object, not the
        order they are first observed.

        Groups with missing keys (where `pd.isna()` is True) will be labeled with `NaN`
        and will be skipped from the count.

        Parameters
        ----------
        ascending : bool, default True
            If False, number in reverse, from number of group - 1 to 0.

        Returns
        -------
        Series
            Unique numbers for each group.

        See Also
        --------
        .cumcount : Number the rows in each group.

        Examples
        --------
        >>> df = pd.DataFrame({"color": ["red", None, "red", "blue", "blue", "red"]})
        >>> df
           color
        0    red
        1   None
        2    red
        3   blue
        4   blue
        5    red
        >>> df.groupby("color").ngroup()
        0    1.0
        1    NaN
        2    1.0
        3    0.0
        4    0.0
        5    1.0
        dtype: float64
        >>> df.groupby("color", dropna=False).ngroup()
        0    1
        1    2
        2    1
        3    0
        4    0
        5    1
        dtype: int64
        >>> df.groupby("color", dropna=False).ngroup(ascending=False)
        0    1
        1    0
        2    1
        3    2
        4    2
        5    1
        dtype: int64
        rr&c3�4K�|]}|j���y�wrir�rs  rmr�z!GroupBy.ngroup.<locals>.<genexpr> s����L�4K�D�t�'�'�4K�r�dense)�ties_methodr�r�)r�r,r�r�r-rr�r�r�r�r�rrrrr�)rkr�r�r3�comp_idsr�r�s       rm�ngroupzGroupBy.ngroup�s���@�'�'���
�
�d�i�i�(���=�=�+�+�A�.���=�=�'�'��x�x��B������A�H��J�J�E��H�H�E��L�D�M�M�4K�4K�L�L��x�W�=��A�H��)�)�(�E��)�G����\�\�A�%��.�F��
roc��|jj|j�}|j|��}|j	||�S)a�
        Number each item in each group from 0 to the length of that group - 1.

        Essentially this is equivalent to

        .. code-block:: python

            self.apply(lambda x: pd.Series(np.arange(len(x)), x.index))

        Parameters
        ----------
        ascending : bool, default True
            If False, number in reverse, from length of group - 1 to 0.

        Returns
        -------
        Series
            Sequence number of each element within each group.

        See Also
        --------
        .ngroup : Number the groups themselves.

        Examples
        --------
        >>> df = pd.DataFrame([['a'], ['a'], ['a'], ['b'], ['b'], ['a']],
        ...                   columns=['A'])
        >>> df
           A
        0  a
        1  a
        2  a
        3  b
        4  b
        5  a
        >>> df.groupby('A').cumcount()
        0    0
        1    1
        2    2
        3    0
        4    1
        5    3
        dtype: int64
        >>> df.groupby('A').cumcount(ascending=False)
        0    3
        1    2
        2    1
        3    1
        4    0
        5    0
        dtype: int64
        )r�)r�r,r�r�r)rkr�r3�	cumcountss    rm�cumcountzGroupBy.cumcount)sE��n�)�)�3�3�D�I�I�>���(�(�9�(�=�	��'�'�	�5�9�9ro�average�keepc�d��	�|dvr
d}t|���tjur.|jj	���|j�d�nd�||||d��	�dk7r:�	j
d��	d<��	fd�}|j||jd	�
�}|S|j	d
d�d��	��S)a
        Provide the rank of values within each group.

        Parameters
        ----------
        method : {'average', 'min', 'max', 'first', 'dense'}, default 'average'
            * average: average rank of group.
            * min: lowest rank in group.
            * max: highest rank in group.
            * first: ranks assigned in order they appear in the array.
            * dense: like 'min', but rank always increases by 1 between groups.
        ascending : bool, default True
            False for ranks by high (1) to low (N).
        na_option : {'keep', 'top', 'bottom'}, default 'keep'
            * keep: leave NA values where they are.
            * top: smallest rank if ascending.
            * bottom: smallest rank if descending.
        pct : bool, default False
            Compute percentage rank of data within each group.
        axis : int, default 0
            The axis of the object over which to compute the rank.

            .. deprecated:: 2.1.0
                For axis=1, operate on the underlying object instead. Otherwise
                the axis keyword is not necessary.

        Returns
        -------
        DataFrame with ranking of values within each group
        %(see_also)s
        Examples
        --------
        >>> df = pd.DataFrame(
        ...     {
        ...         "group": ["a", "a", "a", "a", "a", "b", "b", "b", "b", "b"],
        ...         "value": [2, 4, 2, 3, 5, 1, 2, 4, 1, 5],
        ...     }
        ... )
        >>> df
          group  value
        0     a      2
        1     a      4
        2     a      2
        3     a      3
        4     a      5
        5     b      1
        6     b      2
        7     b      4
        8     b      1
        9     b      5
        >>> for method in ['average', 'min', 'max', 'dense', 'first']:
        ...     df[f'{method}_rank'] = df.groupby('group')['value'].rank(method)
        >>> df
          group  value  average_rank  min_rank  max_rank  dense_rank  first_rank
        0     a      2           1.5       1.0       2.0         1.0         1.0
        1     a      4           4.0       4.0       4.0         3.0         4.0
        2     a      2           1.5       1.0       2.0         1.0         2.0
        3     a      3           3.0       3.0       3.0         2.0         3.0
        4     a      5           5.0       5.0       5.0         4.0         5.0
        5     b      1           1.5       1.0       2.0         1.0         1.0
        6     b      2           3.0       3.0       3.0         2.0         3.0
        7     b      4           4.0       4.0       4.0         3.0         4.0
        8     b      1           1.5       1.0       2.0         1.0         2.0
        9     b      5           5.0       5.0       5.0         4.0         5.0
        >�topr�bottomz3na_option must be one of 'keep', 'top', or 'bottom'�rankr)rr��	na_option�pctrr�c�.��|jd�dd����S)NF)r�r�r��r�rr�rts ��rmr�zGroupBy.rank.<locals>.<lambda>�s���&�!�&�&�I�d��I�&�IroT�rF)r�r�r)
r�rrr�rr�poprwrxr�)
rkr�r�rrr�r�rur�rts
     `   @rmrzGroupBy.rankds����X�5�5�G�C��S�/�!��s�~�~�%��8�8�,�,�T�2�D�� � ��v�.��D�"�"�"��	
���1�9�%�z�z�-�8�F�8��I�A��/�/��4�%�%�D�0��F��M�%�t�%�%��
���
��	
�	
roc�4���tjd|�ddg��tjur.|jj���|j
�d�nd��dk7r$��fd�}|j||jd��S|jdi���S)	a�
        Cumulative product for each group.

        Returns
        -------
        Series or DataFrame
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([6, 2, 0], index=lst)
        >>> ser
        a    6
        a    2
        b    0
        dtype: int64
        >>> ser.groupby(level=0).cumprod()
        a    6
        a   12
        b    0
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 2, 5], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["cow", "horse", "bull"])
        >>> df
                a   b   c
        cow     1   8   2
        horse   1   2   5
        bull    2   6   9
        >>> df.groupby("a").groups
        {1: ['cow', 'horse'], 2: ['bull']}
        >>> df.groupby("a").cumprod()
                b   c
        cow     8   2
        horse  16  10
        bull    6   9
        �cumprodr�rrc�,��|jdd�i���S�Nr�r��r rs ��rmr�z!GroupBy.cumprod.<locals>.<lambda>s���)�!�)�)�8��8��8roTrr#�
�nv�validate_groupby_funcrrr�rrrwrxr��rkr�rsrtrus ` ` rmr zGroupBy.cumprod�s����`	� � ��D�&�>�8�:T�U��s�~�~�%��8�8�,�,�T�2�D�� � ��y�1��D��1�9�8�A��-�-�a��1C�1C�RV�-�W�W�%�t�%�%�:�6�:�:roc�4���tjd|�ddg��tjur.|jj���|j
�d�nd��dk7r$��fd�}|j||jd��S|jdi���S)	a�
        Cumulative sum for each group.

        Returns
        -------
        Series or DataFrame
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b']
        >>> ser = pd.Series([6, 2, 0], index=lst)
        >>> ser
        a    6
        a    2
        b    0
        dtype: int64
        >>> ser.groupby(level=0).cumsum()
        a    6
        a    8
        b    0
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 2, 5], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["fox", "gorilla", "lion"])
        >>> df
                  a   b   c
        fox       1   8   2
        gorilla   1   2   5
        lion      2   6   9
        >>> df.groupby("a").groups
        {1: ['fox', 'gorilla'], 2: ['lion']}
        >>> df.groupby("a").cumsum()
                  b   c
        fox       8   2
        gorilla  10   7
        lion      6   9
        r�r�rrc�,��|jdd�i���Sr"�r�rs ��rmr�z GroupBy.cumsum.<locals>.<lambda>Es���(�!�(�(�7��7��7roTrr*r$r's ` ` rmr�zGroupBy.cumsum
s����`	� � ��4��.�(�9S�T��s�~�~�%��8�8�,�,�T�2�D�� � ��x�0��D��1�9�7�A��-�-�a��1C�1C�RV�-�W�W�%�t�%�%�9�&�9�9roc�L��|jdd�}�tjur.|jj	���|j�d�nd��dk7r7�fd�}|j}|r|j�}|j||d��S|jd||��S)a`
        Cumulative min for each group.

        Returns
        -------
        Series or DataFrame
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
        >>> ser = pd.Series([1, 6, 2, 3, 0, 4], index=lst)
        >>> ser
        a    1
        a    6
        a    2
        b    3
        b    0
        b    4
        dtype: int64
        >>> ser.groupby(level=0).cummin()
        a    1
        a    1
        a    1
        b    3
        b    0
        b    0
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 0, 2], [1, 1, 5], [6, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["snake", "rabbit", "turtle"])
        >>> df
                a   b   c
        snake   1   0   2
        rabbit  1   1   5
        turtle  6   6   9
        >>> df.groupby("a").groups
        {1: ['snake', 'rabbit'], 6: ['turtle']}
        >>> df.groupby("a").cummin()
                b   c
        snake   0   2
        rabbit  0   2
        turtle  6   9
        rT�cumminrc�D��tjj|��Sri)r��minimum�
accumulate�rr�s �rmr�z GroupBy.cummin.<locals>.<lambda>�����"�*�*�/�/��4�8ror�r�r�
r�rrr�rrrx�_get_numeric_datarwr��rkr�r�rtrrur�s `     rmr,zGroupBy.cumminJ����r���H�d�+���s�~�~�%��8�8�,�,�T�2�D�� � ��x�0��D��1�9�8�A��$�$�C���+�+�-���-�-�a��4�-�H�H��%�%��<��&�
�	
roc�L��|jdd�}�tjur.|jj	���|j�d�nd��dk7r7�fd�}|j}|r|j�}|j||d��S|jd||��S)aV
        Cumulative max for each group.

        Returns
        -------
        Series or DataFrame
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
        >>> ser = pd.Series([1, 6, 2, 3, 1, 4], index=lst)
        >>> ser
        a    1
        a    6
        a    2
        b    3
        b    1
        b    4
        dtype: int64
        >>> ser.groupby(level=0).cummax()
        a    1
        a    6
        a    6
        b    3
        b    3
        b    4
        dtype: int64

        For DataFrameGroupBy:

        >>> data = [[1, 8, 2], [1, 1, 0], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["cow", "horse", "bull"])
        >>> df
                a   b   c
        cow     1   8   2
        horse   1   1   0
        bull    2   6   9
        >>> df.groupby("a").groups
        {1: ['cow', 'horse'], 2: ['bull']}
        >>> df.groupby("a").cummax()
                b   c
        cow     8   2
        horse   8   2
        bull    6   9
        rT�cummaxrc�D��tjj|��Sri)r��maximumr/r0s �rmr�z GroupBy.cummax.<locals>.<lambda>�r1rorr2r3r5s `     rmr8zGroupBy.cummax�r6roc	�0������tjur.|jj���|j	�d�nd�t|�rB�dk(rt
d��tt|�}t|�dk(rt
d��ddl
m}d}nFt|�std|�d	t|��d
���|rt
d��tt|�g}d}g}|D�]��t��std��d	t���d
���tt������dk7r'����fd�}	|j!|	|j"d��}
n��tjurd
�|j$j&\}}}
t)j*t|�t(j,��}t/j0|||
��|j2}|j5|j6|j8|j6|fi�d��}
|rKt;|
t<�rtt>|
jA��}
|
jC|r|�d���nd����}
|jEttFt<tHf|
�����t|�dk(r|dS|d��S)aY
        Shift each group by periods observations.

        If freq is passed, the index will be increased using the periods and the freq.

        Parameters
        ----------
        periods : int | Sequence[int], default 1
            Number of periods to shift. If a list of values, shift each group by
            each period.
        freq : str, optional
            Frequency string.
        axis : axis to shift, default 0
            Shift direction.

            .. deprecated:: 2.1.0
                For axis=1, operate on the underlying object instead. Otherwise
                the axis keyword is not necessary.

        fill_value : optional
            The scalar value to use for newly introduced missing values.

            .. versionchanged:: 2.1.0
                Will raise a ``ValueError`` if ``freq`` is provided too.

        suffix : str, optional
            A string to add to each shifted column if there are multiple periods.
            Ignored otherwise.

        Returns
        -------
        Series or DataFrame
            Object shifted within each group.

        See Also
        --------
        Index.shift : Shift values of Index.

        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([1, 2, 3, 4], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        b    4
        dtype: int64
        >>> ser.groupby(level=0).shift(1)
        a    NaN
        a    1.0
        b    NaN
        b    3.0
        dtype: float64

        For DataFrameGroupBy:

        >>> data = [[1, 2, 3], [1, 5, 6], [2, 5, 8], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tuna", "salmon", "catfish", "goldfish"])
        >>> df
                   a  b  c
            tuna   1  2  3
          salmon   1  5  6
         catfish   2  5  8
        goldfish   2  6  9
        >>> df.groupby("a").shift(1)
                      b    c
            tuna    NaN  NaN
          salmon    2.0  3.0
         catfish    NaN  NaN
        goldfish    5.0  8.0
        �shiftrr�z:If `periods` contains multiple shifts, `axis` cannot be 1.z0If `periods` is an iterable, it cannot be empty.r#TzPeriods must be integer, but z is rz/Cannot specify `suffix` if `periods` is an int.FNc�,��|j�����Sri)r<)rr�r�freq�periods ����rmr�zGroupBy.shift.<locals>.<lambda>Ys���a�g�g��D�$�
�rorr�)rr�r?r�)%rrr�rrr3r�rrr�r)r$r1r�r�r�rwrxr�r-r�rr�r��group_shift_indexerr�r�r�r/r�rZrrK�
add_suffix�appendrrL)rk�periodsr>r�r�suffixr$rA�shifted_dataframesru�shiftedrir?r��res_indexerr�r?s  ```           @rmr<z
GroupBy.shift�s����l�s�~�~�%��8�8�,�,�T�2�D�� � ��w�/��D��� ��q�y� �P����8�W�-�G��7�|�q� � �!S�T�T�9��J��g�&��3�G�9�D��g���q�Q���� �!R�S�S��C��)�*�G��J����F��f�%��3�F�8�4��V��~�Q�O����#�v�&�F���4�1�9����4�4��t�)�)��5�������/�!%�J�"&�-�-�":�":���Q�� �h�h�s�3�x�r�x�x�@���.�.�{�C��&�Q��/�/���4�4��Y�Y����$�)�)�!4�k� B�C�)�#�5�����g�v�.�"�8�W�-=�-=�-?�@�G�!�,�,�,2�v�h�a��x�(�!�F�8����
�%�%�d�5���1B�+C�W�&M�N�G�N�%�&�!�+�
�q�!�	
��*��3�	
roc�@����tjur.|jj���|j	�d�nd��dk7r|j��fd��S|j}|j���}ddg}|jdk(r$|j|vr|jd�}||z
S|jj�D��cgc]\}}||vs�|��}}}t|�r |j|D�cic]}|d��c}�}||z
Scc}}wcc}w)	a?
        First discrete difference of element.

        Calculates the difference of each element compared with another
        element in the group (default is element in previous row).

        Parameters
        ----------
        periods : int, default 1
            Periods to shift for calculating difference, accepts negative values.
        axis : axis to shift, default 0
            Take difference over rows (0) or columns (1).

            .. deprecated:: 2.1.0
                For axis=1, operate on the underlying object instead. Otherwise
                the axis keyword is not necessary.

        Returns
        -------
        Series or DataFrame
            First differences.
        %(see_also)s
        Examples
        --------
        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
        >>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
        >>> ser
        a     7
        a     2
        a     8
        b     4
        b     3
        b     3
        dtype: int64
        >>> ser.groupby(level=0).diff()
        a    NaN
        a   -5.0
        a    6.0
        b    NaN
        b   -1.0
        b    0.0
        dtype: float64

        For DataFrameGroupBy:

        >>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
        >>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
        ...                   'mouse', 'mouse', 'mouse', 'mouse'])
        >>> df
                 a  b
          dog    1  1
          dog    3  4
          dog    5  8
        mouse    7  4
        mouse    7  4
        mouse    8  2
        mouse    3  1
        >>> df.groupby(level=0).diff()
                 a    b
          dog  NaN  NaN
          dog  2.0  3.0
          dog  2.0  4.0
        mouse  NaN  NaN
        mouse  0.0  0.0
        mouse  1.0 -2.0
        mouse -5.0 -1.0
        r�rc�*��|j����S)N)rCr�)r�)rr�rCs ��rmr�zGroupBy.diff.<locals>.<lambda>�s������w�T��(Jro)rC�int8�int16r��float32)rrr�rrrwr�r<r7r�r��dtypes�itemsr�)	rkrCr�r�rF�
dtypes_to_f32�cr��	to_coerces	 ``      rmr�zGroupBy.diff}s���V�s�~�~�%��8�8�,�,�T�2�D�� � ��v�.��D��1�9��:�:�J�K�K��'�'���*�*�W�*�-�� ��)�
��8�8�q�=��y�y�M�)�!�.�.��3���W�}��	,/�:�:�+;�+;�+=�X�+=�x�q�%��-�AW��+=�I�X��9�~�!�.�.�	�)J�	�1�!�Y�,�	�)J�K���W�}���	Y��)Js�D�D�?
Dc�R�������tjdfvs�tjur;tjdt	|�j
�d�tt����tjura�tjurMtd�|D��r;tjdt	|�j
�d�tt���d��tjurd��tjur.|jj���|j�d	�nd
����d
k7r'�����fd�}|j||jd�
�S��d�d
�t|�����}|jd
k(r2|j!|j"j$|j&��}n;|j(j!|j"j$|j&��}|j+����}	|jdk(r|	j(}	||	zdz
S)a�
        Calculate pct_change of each value to previous entry in group.

        Returns
        -------
        Series or DataFrame
            Percentage changes within each group.
        %(see_also)s
        Examples
        --------

        For SeriesGroupBy:

        >>> lst = ['a', 'a', 'b', 'b']
        >>> ser = pd.Series([1, 2, 3, 4], index=lst)
        >>> ser
        a    1
        a    2
        b    3
        b    4
        dtype: int64
        >>> ser.groupby(level=0).pct_change()
        a         NaN
        a    1.000000
        b         NaN
        b    0.333333
        dtype: float64

        For DataFrameGroupBy:

        >>> data = [[1, 2, 3], [1, 5, 6], [2, 5, 8], [2, 6, 9]]
        >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
        ...                   index=["tuna", "salmon", "catfish", "goldfish"])
        >>> df
                   a  b  c
            tuna   1  2  3
          salmon   1  5  6
         catfish   2  5  8
        goldfish   2  6  9
        >>> df.groupby("a").pct_change()
                    b  c
            tuna    NaN    NaN
          salmon    1.5  1.000
         catfish    NaN    NaN
        goldfish    0.2  0.125
        NzDThe 'fill_method' keyword being not None and the 'limit' keyword in z�.pct_change are deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.r�c3�rK�|]/\}}|j�jj����1y�wri)r9r8r)r�r?rQs   rmr�z%GroupBy.pct_change.<locals>.<genexpr>&s-����/�6:�F�A�s����
�!�!�%�%�'�d�s�57z#The default fill_method='ffill' in z�.pct_change is deprecated and will be removed in a future version. Either fill in any non-leading NA values prior to calling pct_change or specify 'fill_method=None' to not fill NA values.r��
pct_changerc�0��|j�������S)N)rC�fill_methodr�r>r�)rT)rr�rVr>r�rCs �����rmr�z$GroupBy.pct_change.<locals>.<lambda>?s"���!�,�,��'����'�roTrr�)r�)rCr>r�)rrr�r�r�rvr�r+rr�rrrwrxr}r�rlr��codesr�r"r<)
rkrCrVr�r>r�ru�filled�fill_grprFs
 `````    rmrTzGroupBy.pct_change�s����t�s�~�~�t�4�4��S�^�^�8S��M�M�V���:�&�&�'�(��
�+�-�
��#�.�.�(�����&�3�/�6:�/�,��
�
�9��D�z�*�*�+�,H�H�
"�/�1��"�K��C�N�N�"��E��s�~�~�%��8�8�,�,�T�2�D�� � ��|�4��D���t�q�y��A��-�-�a��1C�1C�RV�-�W�W���!�K��E�+���{�+�%�8���9�9��>��~�~�d�m�m�&9�&9�d�o�o�~�V�H��x�x�'�'��
�
�(;�(;����'�X�H��.�.��t�.�<���9�9��>��i�i�G��� �A�%�%roc�Z�|jtd|��}|j|�S)a�
        Return first n rows of each group.

        Similar to ``.apply(lambda x: x.head(n))``, but it returns a subset of rows
        from the original DataFrame with original index and order preserved
        (``as_index`` flag is ignored).

        Parameters
        ----------
        n : int
            If positive: number of entries to include from start of each group.
            If negative: number of entries to exclude from end of each group.

        Returns
        -------
        Series or DataFrame
            Subset of original Series or DataFrame as determined by n.
        %(see_also)s
        Examples
        --------

        >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]],
        ...                   columns=['A', 'B'])
        >>> df.groupby('A').head(1)
           A  B
        0  1  2
        2  5  6
        >>> df.groupby('A').head(-1)
           A  B
        0  1  2
        N�r�r�r��rkr�r=s   rm�headzGroupBy.headUs,��F�6�6�u�T�1�~�F���&�&�t�,�,roc��|r|jt|d��}n|jg�}|j|�S)a�
        Return last n rows of each group.

        Similar to ``.apply(lambda x: x.tail(n))``, but it returns a subset of rows
        from the original DataFrame with original index and order preserved
        (``as_index`` flag is ignored).

        Parameters
        ----------
        n : int
            If positive: number of entries to include from end of each group.
            If negative: number of entries to exclude from start of each group.

        Returns
        -------
        Series or DataFrame
            Subset of original Series or DataFrame as determined by n.
        %(see_also)s
        Examples
        --------

        >>> df = pd.DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]],
        ...                   columns=['A', 'B'])
        >>> df.groupby('A').tail(1)
           A  B
        1  a  2
        3  b  2
        >>> df.groupby('A').tail(-1)
           A  B
        1  a  2
        3  b  2
        Nr[r\s   rm�tailzGroupBy.tail{sA��H
��:�:�5�!��T�?�K�D��:�:�2�>�D��&�&�t�,�,roc��|jjd}||dk7z}|jdk(r|j|S|jjdd�|fS)a
        Return _selected_obj with mask applied to the correct axis.

        Parameters
        ----------
        mask : np.ndarray[bool]
            Boolean mask to apply.

        Returns
        -------
        Series or DataFrame
            Filtered _selected_obj.
        rr&N)r�r-r�rxr�)rkr=ris   rmr�zGroupBy._mask_selected_obj�s]���m�m�&�&�q�)���s�b�y�!���9�9��>��%�%�d�+�+��%�%�*�*�1�d�7�3�3roc���|jj}t|�dk(r|S|jr|St	d�|D��s|S|D�cgc]}|j
��}}|jj}|�|j|�|dgz}tj||��}|jr|j�}|jr=|jj|j�|ddd|i}	|j di|	��St#|�D�
�cgc] \}
}|j$s�|
|j&f��"}}
}t|�dkDr't)|�\}}
|j+t-|
�d�	�}|j/|jj0�j!|d|�
�}t|�dkDr|j3��}|j3d�
�Scc}wcc}}
w)aI
        If we have categorical groupers, then we might want to make sure that
        we have a fully re-indexed output to the levels. This means expanding
        the output space to accommodate all values in the cartesian product of
        our groups, regardless of whether they were observed in the data or
        not. This will expand the output space if there are missing groups.

        The method returns early without modifying the input if the number of
        groupings is less than 2, self.observed == True or none of the groupers
        are categorical.

        Parameters
        ----------
        output : Series or DataFrame
            Object resulting from grouping and applying an operation.
        fill_value : scalar, default np.nan
            Value to use for unobserved categories if self.observed is False.
        qs : np.ndarray[float64] or None, default None
            quantile values, only relevant for quantile.

        Returns
        -------
        Series or DataFrame
            Object (potentially) re-indexed to include all possible groups.
        r�c3�\K�|]$}t|jttf����&y�wri)r�r?rBrTrs  rmr�z*GroupBy._reindex_output.<locals>.<genexpr>�s+����
�!��
�t�+�+�k�;K�-L�M�!�s�*,NrBr(Frr)r<r�)r(r)r�T)�dropr�)r�rr�r�r�_group_indexr�rBrVrLr�rMr�r��_get_axis_namer�r6rIrOr~r�rcr��	set_indexr*rS)rkr�rrXrrr_r�r3�dr��in_axis_grps�g_nums�g_namess              rmr[zGroupBy._reindex_output�s���@�M�M�+�+�	��y�>�Q���M��]�]��M��
�!�
�
��M�5>�?�Y�T�t�(�(�Y��?��
�
�#�#��
�>�
���r�"��T�F�N�E��'�'��5�A���9�9��%�%�'�E��=�=����'�'��	�	�2�E����j��A�
"�6�>�>�&�A�&�&�-6�i�,@�
�,@�y��4�D�L�L�Q��	�	�N�,@�	�
��|��q� �!�<�0�O�F�G��[�[��W�
�A�[�>�F��!�!�$�-�-�"<�"<�=�E�E���*�F�
���|��q� ��'�'�f�'�5�F��!�!�t�!�,�,��a@��>
s�
G!�G&�0G&c��|jjr|jStj|||�}|�,tj|j||j
��}t
j|�}|jj|j|j
�}g}	|D]k\}
}|j|
}t|�}
|�|}n|�J�t||
z�}tj|
|||�dn||��}|	j||��mtj|	�}	|jj!|	|j
��S)ab
        Return a random sample of items from each group.

        You can use `random_state` for reproducibility.

        Parameters
        ----------
        n : int, optional
            Number of items to return for each group. Cannot be used with
            `frac` and must be no larger than the smallest group unless
            `replace` is True. Default is one if `frac` is None.
        frac : float, optional
            Fraction of items to return. Cannot be used with `n`.
        replace : bool, default False
            Allow or disallow sampling of the same row more than once.
        weights : list-like, optional
            Default None results in equal probability weighting.
            If passed a list-like then values must have the same length as
            the underlying DataFrame or Series object and will be used as
            sampling probabilities after normalization within each group.
            Values must be non-negative with at least one positive element
            within each group.
        random_state : int, array-like, BitGenerator, np.random.RandomState, np.random.Generator, optional
            If int, array-like, or BitGenerator, seed for random number generator.
            If np.random.RandomState or np.random.Generator, use as given.

            .. versionchanged:: 1.4.0

                np.random.Generator objects now accepted

        Returns
        -------
        Series or DataFrame
            A new object of same type as caller containing items randomly
            sampled within each group from the caller object.

        See Also
        --------
        DataFrame.sample: Generate random samples from a DataFrame object.
        numpy.random.choice: Generate a random sample from a given 1-D numpy
            array.

        Examples
        --------
        >>> df = pd.DataFrame(
        ...     {"a": ["red"] * 2 + ["blue"] * 2 + ["black"] * 2, "b": range(6)}
        ... )
        >>> df
               a  b
        0    red  0
        1    red  1
        2   blue  2
        3   blue  3
        4  black  4
        5  black  5

        Select one row at random for each distinct value in column a. The
        `random_state` argument can be used to guarantee reproducibility:

        >>> df.groupby("a").sample(n=1, random_state=1)
               a  b
        4  black  4
        2   blue  2
        1    red  1

        Set `frac` to sample fixed proportions rather than counts:

        >>> df.groupby("a")["b"].sample(frac=0.5, random_state=2)
        5    5
        2    2
        0    0
        Name: b, dtype: int64

        Control sample probabilities within groups by setting weights:

        >>> df.groupby("a").sample(
        ...     n=1,
        ...     weights=[1, 1, 1, 0, 0, 1],
        ...     random_state=1,
        ... )
               a  b
        5  black  5
        2   blue  2
        0    red  0
        Nr�)rJ�replace�weights�random_state)rxr�r=�process_sampling_size�preprocess_weightsr�r�rnr�r�r�r��roundrBr�r�r5)rkr��fracrlrmrnrJ�weights_arr�group_iterator�sampled_indicesr<r��grp_indices�
group_size�sample_size�
grp_samples                rmr=zGroupBy.samplesK��|���#�#��%�%�%��+�+�A�t�W�=���� �3�3��"�"�G�$�)�)��K��'�'��5�����3�3�D�4F�4F��	�	�R����)�K�F�C��,�,�v�.�K��[�)�J���"���'�'�'�#�D�:�$5�6������ �� '���[��5M�)��J�
�"�"�;�z�#:�;�!*�$�.�.��9���!�!�&�&��T�Y�Y�&�G�Groc�x������tjur<��|j�|jj	���|j���n|j�|j�sYtd�|jjD���r2tj|jjD�cgc]}t|j���c}�}t|jj�dk(r;t|jjdjj��}nt|jj �}||ksJ�||k}	|xr|	}
|j"}|
r:t%|t&�r*�r|j)�}t|j*�dkD}
|
ryt-d��d����sh|j"j/�jd��r>t1j2dt5|�j6�d	��d
�t8t;����dk(r0	����fd�}�|_|j=||j"d
��}
|
S|jA�d����}
|
Scc}w#t,$r0}�dk(rdnd}d|�d�t?|�vrt-d��d��d��d}~wwxYw)a�Compute idxmax/idxmin.

        Parameters
        ----------
        how : {'idxmin', 'idxmax'}
            Whether to compute idxmin or idxmax.
        axis : {{0 or 'index', 1 or 'columns'}}, default None
            The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
            If axis is not provided, grouper's axis is used.
        numeric_only : bool, default False
            Include only float, int, boolean columns.
        skipna : bool, default True
            Exclude NA/null values. If an entire row/column is NA, the result
            will be NA.
        ignore_unobserved : bool, default False
            When True and an unobserved group is encountered, do not raise. This used
            for transform where unobserved groups do not play an impact on the result.

        Returns
        -------
        Series or DataFrame
            idxmax or idxmin for the groupby operation.
        Nc3�4K�|]}|j���y�wrir�rs  rmr�z)GroupBy._idxmax_idxmin.<locals>.<genexpr>�s����%
�1H��D�$�$�1H�rr�rz
Can't get zZ of an empty group due to unobserved categories. Specify observed=True in groupby instead.r�zThe behavior of rzn with all-NA values, or any-NA and skipna=False, is deprecated. In a future version this will raise ValueErrorr�c�2��t|��}|�����S)N)r�rr�)r})r}r�r�r�r�rs  ����rmr�z$GroupBy._idxmax_idxmin.<locals>.func�s���$�R��-�F�!�t�F��V�VroTr�r��argmax�argminzattempt to get z of an empty sequence)r�r�r�r)!rrr�r�rrr�rr�rr�r|r�rdr?�uniquer*r�r�rLr4rLr�r9r�r�r�rvr�r+rwr�r�)rkr��ignore_unobservedr�rr�r�expected_len�
result_len�has_unobserved�	raise_errr`r�r�r�r~s ` ```          rmr�zGroupBy._idxmax_idxmin�s����>�s�~�~�%��|��y�y���8�8�,�,�T�2�D�� � ��s�+��9�9�D��}�}��%
�15���1H�1H�%
�"
��7�7�48�M�M�4K�4K�L�4K�D��T�&�&�'�4K�L��L��4�=�=�*�*�+�q�0� ����!8�!8��!;�!K�!K�!R�!R�!T�U�
�!����!;�!;�<�
���-�-�-�'�,�6�N�->�)>�)Q�>�I��,�,�D��Z��i�8���1�1�3�D�����-��1�	�� � ���&@�@�����(�(�-�-�/�3�3��3�>��
�
�&�t�D�z�':�':�&;�1�S�E�B9�9�"�/�1���1�9�
�W�!$��
��3�3��$�3�3�d�4����M��"�"�%����	#�
���
��}M��\�
�#&�(�?�x���$�T�F�*?�@�C��H�L�$�$�S�E�*P�P�� � ���
�s�:I;�5-J�	J9�	+J4�4J9c��|jj|j�}|jdk(r|j	|j
�}|St
|t�r|j�}|j}t
|tj�sJ�t|j
d��}t
|t�rF|j|jj!|d|��|j"|j$��}|Si}t'|j(�D]&\}}|jj!|d|��||<�(|jj||j"��}|j*|_|S)NrF)�compatT)�
allow_fillrr�)r3)r�r,r�rJr�r�r�rV�
to_flat_indexr2r�r�r:rZr�r�r5r3r~rIr"rL)	rkr\r3r�r8r�r`�k�
column_valuess	         rmr�zGroupBy._wrap_idxmax_idxminsD�����"�"�4�9�9�-���8�8�q�=��Z�Z����,�F�,�
�)�%��,��+�+�-���[�[�F��f�b�j�j�1�1�1�)�%�+�+�e�D�H��#�v�&��)�)��K�K�$�$�V���$�R��)�)����*����
���(1�&�(�(�(;�$�A�}�#�k�k�.�.�%�$�8�/��D��G�)<����.�.�t�3�9�9�.�E��!$������
ro)r�rr�r�r�rr�r�r��ops.BaseGrouper | Noner�zfrozenset[Hashable] | Nonerr�r�r�r�r�r�r�r�zbool | lib.NoDefaultr�r�r�r�)rr�)r�r�r~r�r�r�r�)FF)rr�rr�)r�r�r�r�)r��Series | DataFramer�rL)r�rr�rri)r�r�rX�npt.NDArray[np.float64] | None)r8r�rr�rr�)r`rL)r�rrzzdict[np.dtype, Any]r{�dict[str, bool] | None)r�r�r�r)NFF)rurr`r�rzbool | Nonerr�r�r�r�r)Fr&)r�r�r�r�r�r�r��Callable | None)
r�r�r8rr7r�r�rr�r)NFr&)r�r�r�r�r�r�r�r�)Fr)r�r�r�r�r�r)T)r�r�r�r)r�r)rr�r�r)r�r)FNN)r�r�r��!Literal['cython', 'numba'] | Noner{r�)F)r�r�r�r)r�NNF)r1r�r�r�r{r�r�r�)NFTFT)rTzSequence[Hashable] | NonerUr�r�r�r�r�r�r�r�r�)r�F)r1r�r�r�r�rr�)FrNN)r�r�r�r�r�r�r{r�)r�r�r�r�r�r)Fr&NN)Fr&T)r�r�r�r�rr�r�r)r�rL)NNN)r�r�r�r_)r�rb)r�r`)r�ra)r�zLiteral['ffill', 'bfill']r��
int | None)r�r�)r�rS)r�zPositionalIndexer | tupler�zLiteral['any', 'all', None]r�r)g�?r�F)rzfloat | AnyArrayLiker�r�r�r�)r�r�)r�r�r�r�rr�rr�r��AxisInt | lib.NoDefaultr�r)r��Axis | lib.NoDefaultr�r)r�r�r�r�r�r)rCzint | Sequence[int]r�r�rDz
str | None)rCr�r�r�r�r)rCr�rVz$FillnaOptions | None | lib.NoDefaultr�zint | None | lib.NoDefaultr�r�)�)r�r�r�r)r=znpt.NDArray[np.bool_]r�r)r�r�rr!rXr�r�r�)NNFNN)
r�r�rrzfloat | Nonerlr�rmzSequence | Series | NonernzRandomState | None)r�zLiteral['idxmax', 'idxmin']r�r�r�zAxis | None | lib.NoDefaultrr�r�r�r�r)r\rr�r)[rvr�r�r�r�rrrrnr�rr!r@rrSrUr]rarrr�r�r�r'�_apply_docsr�rwrwr�r�r�r�r�r�r�r�r�rr(�_common_see_alsorr�r�r#r+r�r:rfr�rJr*�#_groupby_agg_method_engine_templater
rF�_groupby_agg_method_templater|r~r�r�r�r�rLr�r�r�r�r�r�r�r�r�r�r�rrrr r�r,r8r<r�rTr]r_r�r�r�r[r=r�r�r�rormr�r��s���A�F���N�
�%)��#'�*.�15�'+����),����:O�
�:O�"�:O��	:O�
!�:O�(�
:O�/�:O�%�:O��:O��:O��:O�'�:O��:O�
�:O��:O�x
�����$�1��1�l�"'�"�	A��A��	A��A�F��)��	����2����>�����.2�'0�"�'0�
+�'0��'0�Z"'�"�(��(��	(�
�(��
��
�4+��+�+�+�.�	+�Z�?C�!G��!G�F�?C�"��"�N��J��&�&���4H�(I�	'�	
��
9=�?��
?�B�
)-�"��
+
��+
�!�+
�&�	+
�
�+
��
+
�
�+
��+
�Z�#��?�#'�
?��?��?�
�?� �
?��?�$(9��(9� )�(9�14�(9�;C�(9�	�(9�T� $�"��/�
�/��/��	/�
�/��/�dEF�(��(�&*�(�:A�(�
�-1��'<��'<�R����<���� �#��#�N�
�%���%���y�!��+�,�3
�-�"��3
�j��y�!��+�,�4
�-�"��4
�l��y�!��+�,�`:�-�"��`:�D��y�!��+�,�#�48�04�	YC��YC�2�YC�.�	YC�-�"��YC�v�M?��M?�^��y�!��+�,��48�04�"�h��h�2�h�.�	h�
�h�-�"��h�T��y�!��+�,��48�04�"�f��f�2�f�.�	f�
�f�-�"��f�P�-1�����
MD�)�MD��MD��	MD�
�MD��
MD�
�MD��MD�^�S
��S
�j��y�!��+�,�\�-�"��\�|��+����
���
�!
�)�X#��48�04�>��>��>�2�	>�
.�>�U)��V>�<��$�����
�!
�'�P
�Q'��R
�
��+���
�
���
�!
�)�X#��48�04������2�	�
.��U)��V�2��+���
�
���
�!
�)�X#��48�04������2�	�
.��U)��V�2�NR�M
� �M
�58�M
�GK�M
�	�M
��M
�^�NR�B
� �B
�58�B
�GK�B
�	�B
��B
�H�W��W�r	��	�	�����	#�

�#��#�J�;?�B
��B
�H�I
��I
�V��y�!�
���
� �"��
�$��y�!�
���
� �"��
�"�Q��Q�f��y�!�Y0�"��Y0�v��y�!�L0�"��L0�\�
��y�!��+�,�X(�-�"���X(�z/3�8�$�8�,�8�
�	8�t�#&�%�"�	a=��a=��a=��	a=��a=�F��y�!�P�"��P�d��y�!�7:�"��7:�r��y�!��+�,� ����(+���
g
��g
��g
��	g
�
�g
�&�
g
�
�g
�-�"��g
�R��y�!��+�,�+.�>�>�8;�(�8;�	�8;�-�"��8;�t��y�!��+�,�+.�>�>�8:�(�8:�	�8:�-�"��8:�t��y�!��+�,�),���"�F
�%�F
��F
�

�F
�-�"��F
�P��y�!��+�,�),���"�F
�%�F
��F
�

�F
�-�"��F
�P��y�!�()�
�%(�^�^��>�>�!�
Y
�$�Y
�#�	Y
��
Y
�"��Y
�v��y�!��+�,�����_��_�&=�_�	�_�-�"��_�B��y�!��+�,��<?�N�N�,/�N�N�
�%(�^�^�
o&��o&�:�o&�*�	o&�#�
o&�-�"��o&�b��y�!��+�,�!-�-�"��!-�F��y�!��+�,�&-�-�"��&-�P�4��4�,� �V�V�-1�	_-�#�_-��_-�
+�	_-�

�_-��_-�B��!��,0�+/�
~H��~H��~H��	~H�
*�~H�)�
~H��~H�F#(�,/�N�N��"�
i�
(�i� �i�*�	i�
�i��
i�
�i�Vror�c��t|t�r	ddlm}|}n't|t�r	ddlm}|}nt
d|����||||||��S)Nr)�
SeriesGroupBy)�DataFrameGroupByzinvalid type: )r�r�r�r�r�)r�rZ�pandas.core.groupby.genericr�rLr�r�)r��byr�r�r�r�r�r�s        rm�get_groupbyr�'sV���#�v��=���	�C��	#�@� ���.���.�/�/���
�
����roc��t|�}t|�j�\}}t||�}|jr�tt|�}t|j�|gz}|jD�cgc]}tj||���c}tj|t|��gz}t
|||jdgz��}|St|�}	ttj|	�|�}
||g}tj|
|�tj||	�g}t
|||jdg��}|Scc}w)a
    Insert the sequence 'qs' of quantiles as the inner-most level of a MultiIndex.

    The quantile level in the MultiIndex is a repeated copy of 'qs'.

    Parameters
    ----------
    idx : Index
    qs : np.ndarray[float64]

    Returns
    -------
    MultiIndex
    N)r%rWr�)r�rU�	factorizer,�	_is_multirrVr�r%rWr�r�r�r�r�r~)r\rXr��	lev_codesrRr%rrW�mi�nidx�	idx_codess           rmrZrZDs���b�'�C��2�Y�(�(�*�N�I�s�$�Y��4�I�
�}�}��:�s�#���c�j�j�!�S�E�)��,/�I�I�6�I�q����1�c�"�I�6�"�'�'�)�S�QT�X�:V�9W�W��
�v�U�#�)�)�t�f�:L�
M���I�
�3�x��(����4��#�>�	��s������9�c�*�B�G�G�I�t�,D�E��
�v�U�3�8�8�T�:J�
K��
�I��7s�7Ea-{}.{} operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.)NrNT)r�rMr�r�r�rr�r�r�r�r�r�)r\rUrXznpt.NDArray[np.float64]r�rV)�r��
__future__r�collections.abcrrrrr��	functoolsrr	r�textwrapr
�typingrrr
rrrrr��numpyr��pandas._config.configr�pandas._libsrr�pandas._libs.algosr�pandas._libs.groupby�_libsrlr��pandas._libs.missingr�pandas._typingrrrrrrrrrr r!r"r#�pandas.compat.numpyr$r%�
pandas.errorsr%r&�pandas.util._decoratorsr'r(r)r*�pandas.util._exceptionsr+�pandas.core.dtypes.castr,r-�pandas.core.dtypes.commonr.r/r0r1r2r3r4r5r6r7r8�pandas.core.dtypes.missingr9r:r;�pandas.corer<r=�pandas.core._numbar>�pandas.core.applyr?�pandas.core.arraysr@rArBrCrDrErF�pandas.core.arrays.string_rG�pandas.core.arrays.string_arrowrHrI�pandas.core.baserJrK�pandas.core.common�core�commonr��pandas.core.framerL�pandas.core.genericrM�pandas.core.groupbyrNrOrP�pandas.core.groupby.grouperrQ�pandas.core.groupby.indexingrRrS�pandas.core.indexes.apirTrUrVrWrX�pandas.core.internals.blocksrY�pandas.core.seriesrZ�pandas.core.sortingr[�pandas.core.util.numba_r\r]r^r�r_r�r`rarbr�r�r�r�r��_transform_template�_agg_template_series�_agg_template_framergr��_KeysArgTyper�r�r�r�rZr�r�rorm�<module>r�s����#������������0��'�)�)�#�����/����5���������(�4����3���!� �'�'���
4����<�%�6��
��.�����A�D@�B2�Iw��r ��4&'�#�P5��n\��|P��dM��`��,����2����N��h�Z��
!�"���8�*�h�&�	'�(��H�h���	!���F�,��x� 8�:N�F�T�3�7�C��[I�k�(�#�[I�|R�W��#��&*���	������$�	�
��
�
���8�H�ro

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists