§
    tŠtjæ  ã                  ó–   — d dl mZ d dlmZ d dlZd dlmZ d dlm	Z	m
Z
 d dlmZ erd dlmZ d dlmZ d d	lmZmZ 	 ddd„Zdd„Zdd„ZdS )é    )Úannotations)ÚTYPE_CHECKINGN©Úremove_na_arraylike)Ú
MultiIndexÚconcat)Úunpack_single_str_list)ÚHashable)Ú
IndexLabel)Ú	DataFrameÚSeriesÚhistÚdatar   ÚkindÚstrÚreturnú"dict[Hashable, DataFrame | Series]c                ó’   ‡ ‡— |dk    rdŠndŠt          ‰ j        t          ¦  «        sJ ‚ˆ ˆfd„‰ j        j        ‰         D ¦   «         S )am  
    Create data for iteration given `by` is assigned or not, and it is only
    used in both hist and boxplot.

    If `by` is assigned, return a dictionary of DataFrames in which the key of
    dictionary is the values in groups.
    If `by` is not assigned, return input as is, and this preserves current
    status of iter_data.

    Parameters
    ----------
    data : reformatted grouped data from `_compute_plot_data` method.
    kind : str, plot kind. This function is only used for `hist` and `box` plots.

    Returns
    -------
    iter_data : DataFrame or Dictionary of DataFrames

    Examples
    --------
    If `by` is assigned:

    >>> import numpy as np
    >>> tuples = [("h1", "a"), ("h1", "b"), ("h2", "a"), ("h2", "b")]
    >>> mi = pd.MultiIndex.from_tuples(tuples)
    >>> value = [[1, 3, np.nan, np.nan], [3, 4, np.nan, np.nan], [np.nan, np.nan, 5, 6]]
    >>> data = pd.DataFrame(value, columns=mi)
    >>> create_iter_data_given_by(data)
    {'h1':     h1
         a    b
    0  1.0  3.0
    1  3.0  4.0
    2  NaN  NaN, 'h2':     h2
         a    b
    0  NaN  NaN
    1  NaN  NaN
    2  5.0  6.0}
    r   r   é   c                ól   •— i | ]0}|‰j         d d …‰j                             ‰¦  «        |k    f         “Œ1S )N)ÚlocÚcolumnsÚget_level_values)Ú.0Úcolr   Úlevels     €€úa/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/pandas/plotting/_matplotlib/groupby.pyú
<dictcomp>z-create_iter_data_given_by.<locals>.<dictcomp>Q   sP   ø€ ð ð ð àð 	ˆTŒX�a�a�a˜œ×6Ò6°uÑ=Ô=ÀÒDÐDÔEðð ð ó    )Ú
isinstancer   r   Úlevels)r   r   r   s   ` @r   Úcreate_iter_data_given_byr"      sp   øø€ ð\ ˆv‚~€~Øˆˆàˆõ �d”l¥JÑ/Ô/Ð/Ð/Ð/ðð ð ð ð à”<Ô& uÔ-ðñ ô ð r   Úbyr   Úcolsc                óú   — t          |¦  «        }|                      |¦  «        }g }|D ]@\  }}t          j        |g|g¦  «        }||         }	||	_        |                     |	¦  «         ŒAt          |d¬¦  «        } | S )al  
    Internal function to group data, and reassign multiindex column names onto the
    result in order to let grouped data be used in _compute_plot_data method.

    Parameters
    ----------
    data : Original DataFrame to plot
    by : grouped `by` parameter selected by users
    cols : columns of data set (excluding columns used in `by`)

    Returns
    -------
    Output is the reconstructed DataFrame with MultiIndex columns. The first level
    of MI is unique values of groups, and second level of MI is the columns
    selected by users.

    Examples
    --------
    >>> d = {"h": ["h1", "h1", "h2"], "a": [1, 3, 5], "b": [3, 4, 6]}
    >>> df = pd.DataFrame(d)
    >>> reconstruct_data_with_by(df, by="h", cols=["a", "b"])
       h1      h2
       a     b     a     b
    0  1.0   3.0   NaN   NaN
    1  3.0   4.0   NaN   NaN
    2  NaN   NaN   5.0   6.0
    r   )Úaxis)r	   Úgroupbyr   Úfrom_productr   Úappendr   )
r   r#   r$   Úby_modifiedÚgroupedÚ	data_listÚkeyÚgroupr   Ú	sub_groups
             r   Úreconstruct_data_with_byr0   W   s‘   € õ< )¨Ñ,Ô,€KØ�lŠl˜;Ñ'Ô'€Gà€IØð $ð $‰
ˆˆUõ Ô)¨C¨5°$¨-Ñ8Ô8ˆØ˜$”Kˆ	Ø#ˆ	ÔØ×Ò˜Ñ#Ô#Ð#Ð#å�) !Ð$Ñ$Ô$€DØ€Kr   Úyú
np.ndarrayúIndexLabel | Nonec                ó¤   — |�@t          | j        ¦  «        dk    r(t          j        d„ | j        D ¦   «         ¦  «        j        S t          | ¦  «        S )zàInternal function to reformat y given `by` is applied or not for hist plot.

    If by is None, input y is 1-d with NaN removed; and if by is not None, groupby
    will take place and input y is multi-dimensional array.
    Nr   c                ó,   — g | ]}t          |¦  «        ‘ŒS © r   )r   r   s     r   ú
<listcomp>z,reformat_hist_y_given_by.<locals>.<listcomp>Œ   s!   € ÐAÐAÐA°cÕ,¨SÑ1Ô1ÐAÐAÐAr   )ÚlenÚshapeÚnpÚarrayÚTr   )r1   r#   s     r   Úreformat_hist_y_given_byr=   …   sM   € ð 
€~�#˜aœg™,œ,¨Ò*Ð*ÝŒxÐAÐA¸Q¼SÐAÑAÔAÑBÔBÔDÐDÝ˜qÑ!Ô!Ð!r   )r   )r   r   r   r   r   r   )r   r   r#   r   r$   r   r   r   )r1   r2   r#   r3   r   r2   )Ú
__future__r   Útypingr   Únumpyr:   Úpandas.core.dtypes.missingr   Úpandasr   r   Ú pandas.plotting._matplotlib.miscr	   Úcollections.abcr
   Úpandas._typingr   r   r   r"   r0   r=   r6   r   r   ú<module>rF      s*  ðØ "Ð "Ð "Ð "Ð "Ð "à  Ð  Ð  Ð  Ð  Ð  à Ð Ð Ð à :Ð :Ð :Ð :Ð :Ð :ðð ð ð ð ð ð ð ð
 DÐ CÐ CÐ CÐ CÐ Càð Ø(Ð(Ð(Ð(Ð(Ð(à)Ð)Ð)Ð)Ð)Ð)ðð ð ð ð ð ð ð ð "(ð9ð 9ð 9ð 9ð 9ðx+ð +ð +ð +ð\"ð "ð "ð "ð "ð "r   