a
    OfUG                  
   @  s  d dl mZ d dlmZmZmZ d dlZd dlmZ d dl	Z
d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlZd dlm  mZ d dlmZ d dlm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z(m)Z) er(d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 dddddddZ4G dd de Z5dddd Z6d1ddd#d$d%d&Z7d2d'd(dd#d)d*d+Z8d3d'd(dd#d)d,d-Z9d4dd'd(dd#ddd.d/d0Z:dS )5    )annotations)TYPE_CHECKINGLiteral
NamedTupleN)setp)lib)cache_readonly)find_stack_level)is_dict_like)	ABCSeriesremove_na_arraylikepprint_thing)LinePlotMPLPlot)create_iter_data_given_by)get_standard_colors)create_subplotsflatten_axesmaybe_adjust_figure)
Collection)Axes)Figure)Line2D)MatplotlibColorr   z	list[str]boolNone)axlabelsis_verticalreturnc                 K  s   |r|   n|  }t|t|krRtt|t|\}}|dksJJ |||9 }|rj| j|fi | n| j|fi | dS )zSet the tick labels of a given axis.

    Due to https://github.com/matplotlib/matplotlib/pull/17266, we need to handle the
    case of repeated ticks (due to `FixedLocator`) and thus we duplicate the number of
    labels.
    r   N)Z
get_xticksZ
get_ytickslendivmodZset_xticklabelsZset_yticklabels)r   r   r    kwargsZticksi	remainder r'   \/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/plotting/_matplotlib/boxplot.py_set_ticklabels/   s    r)   c                      s  e Zd ZeddddZdZdZG dd deZd6d
ddddZ	e
d7ddd
dddZdd Zedd Zedd Zedd Zedd Zedd  Zd8d"dd#d$d%Zddd&d'Zd(dd)d*d+Zddd,d-Zddd.d/d0Zed1dd2d3Ze fd4d5Z  ZS )9BoxPlotzLiteral['box']r!   c                 C  s   dS )Nboxr'   selfr'   r'   r(   _kindB   s    zBoxPlot._kind
horizontal)Naxesdictbothc                   @  s   e Zd ZU ded< ded< dS )z
BoxPlot.BPr   r   zdict[str, list[Line2D]]linesN)__name__
__module____qualname____annotations__r'   r'   r'   r(   BPJ   s   
r9   r1   strr   )return_typer!   c                 K  sN   || j vrtd|| _tj| |fi | | jrJ| jdkrDd| _nd| _d S )Nz2return_type must be {None, 'axes', 'dict', 'both'}verticalF)	_valid_return_types
ValueErrorr;   r   __init__subplotsorientationsharexsharey)r.   datar;   r$   r'   r'   r(   r?   O   s    

zBoxPlot.__init__Nr   z
np.ndarray)r   yr;   c                 K  sx   |j dkr(dd |D }dd |D }nt|}|j|fi |}|dkrR||fS |dkrl| j||d|fS ||fS d S )N   c                 S  s   g | ]}t |qS r'   r   .0vr'   r'   r(   
<listcomp>f       z!BoxPlot._plot.<locals>.<listcomp>c                 S  s(   g | ] }|j d kr|nttjgqS )r   )sizenparraynanrG   r'   r'   r(   rJ   j   rK   r2   r3   r   r4   )ndimr   boxplotr9   )clsr   rE   
column_numr;   kwdsZysbpr'   r'   r(   _plot`   s    
zBoxPlot._plotc                 C  sb   |t ju rd S |d ur&tjdt d t|tr^g d}|D ] }||vr<td| d| q<|S )NzC'color' and 'colormap' cannot be used simultaneously. Using 'color')
stacklevelboxeswhiskersmedianscaps!color dict contains invalid key ''. The key must be either )r   Z
no_defaultwarningswarnr	   
isinstancer2   r>   )r.   colorcolormap
valid_keyskeyr'   r'   r(   _validate_color_argsv   s"    

zBoxPlot._validate_color_argsc                 C  s   t d| jd dS )N   )
num_colorsrd   rc   )r   rd   r-   r'   r'   r(   _color_attrs   s    zBoxPlot._color_attrsc                 C  s
   | j d S Nr   rj   r-   r'   r'   r(   _boxes_c   s    zBoxPlot._boxes_cc                 C  s
   | j d S rk   rl   r-   r'   r'   r(   _whiskers_c   s    zBoxPlot._whiskers_cc                 C  s
   | j d S )NrF   rl   r-   r'   r'   r(   
_medians_c   s    zBoxPlot._medians_cc                 C  s
   | j d S rk   rl   r-   r'   r'   r(   _caps_c   s    zBoxPlot._caps_crc   zQdict[str, MatplotlibColor] | MatplotlibColor | Collection[MatplotlibColor] | None)
color_kwdsr!   c                 C  s   d S Nr'   )r.   ri   rq   r'   r'   r(   _get_colors   s    zBoxPlot._get_colorsc                 C  s   t | jtrN| jd| j}| jd| j}| jd| j}| jd| j}n0| jpX| j}| jpd| j}| jpp| j}| jp|| j}||||f}t|fd|i| j	 d S )NrZ   r[   r\   r]   	color_tup)
rb   rc   r2   getrm   rn   ro   rp   maybe_color_bprU   )r.   rV   rZ   r[   r\   r]   rt   r'   r'   r(   rv      s    zBoxPlot.maybe_color_bpr   )figr!   c                 C  s  | j rtjtd| _| jd ur,t| j| jn| j}t	| j
|dD ]\}\}}| |}| j }| jd ur|j}|t| | jjj}dd |d D }	n
t|g}	| j||f|| jd|\}
}| | |
| j|< t||	| jdkd qBn| jjj}| d}| j }| j||fd| jd|\}
}| | |
| _d	d | jjD }| jsrd
d tt|D }t||| jdkd d S )NZdtype)rD   c                 S  s   g | ]}t |qS r'   r   )rH   colr'   r'   r(   rJ      rK   z&BoxPlot._make_plot.<locals>.<listcomp>r   )rT   r;   r<   )r   r   r    c                 S  s   g | ]}t |qS r'   r   )rH   leftr'   r'   r(   rJ      rK   c                 S  s   g | ]}t |qS r'   r   )rH   rf   r'   r'   r(   rJ      rK   )r@   pdSeriesobject_return_objbyr   rD   r/   	enumerateZ
_iter_dataZ_get_axrU   copyT	set_titler   columnslevelsrW   r;   rv   r)   rA   valuesZ	use_indexranger"   )r.   rw   rD   r%   labelrE   r   rU   r   Z
ticklabelsretrV   r   r'   r'   r(   
_make_plot   sZ    	













zBoxPlot._make_plotc                 C  s   d S rr   r'   r-   r'   r'   r(   _make_legend   s    zBoxPlot._make_legend)r   r!   c                 C  s0   | j r|t| j  | jr,|t| j d S rr   )xlabel
set_xlabelr   ylabel
set_ylabel)r.   r   rD   r'   r'   r(   _post_plot_logic   s    zBoxPlot._post_plot_logicz!Literal['horizontal', 'vertical']c                 C  s   | j ddrdS dS d S )NvertTr<   r0   )rU   ru   r-   r'   r'   r(   rA     s    zBoxPlot.orientationc                   s   | j d u rt jS | jS d S rr   )r;   superresultr~   r-   	__class__r'   r(   r   	  s    
zBoxPlot.result)r1   )Nr1   )Nrc   )r5   r6   r7   propertyr/   Z_layout_typer=   r   r9   r?   classmethodrW   rg   r   rj   rm   rn   ro   rp   rs   rv   r   r   r   rA   r   __classcell__r'   r'   r   r(   r*   A   s>    




  
:r*   r+   c                 K  s   | ds t| d |d dd | ds@t| d |d dd | ds`t| d	 |d
 dd | dst| d |d dd d S )NZboxpropsrZ   r      )rc   alphaZwhiskerpropsr[   Zmedianpropsr\   rF   Zcappropsr]   rh   )ru   r   )rV   rt   rU   r'   r'   r(   rv     s    



rv   TFztuple[float, float] | None)numeric_onlygridfigsizec
                 K  st  |j |dd}|d u r:t|ttfs*|g}| j|}t|}t||
	dd|
	dd|||d\}}t
|}|
	dd |
	dd  }}|
d	dr|p|}n|p|}g }t|D ]\\}}|| }|| }t| \}}| |||f||d
|
}|| || || qtj||dd}|	d u r2|}t|dkrH|d n|}|d|  t|dddddd |S )NF)ZobservedrB   TrC   )naxesrB   rC   r   r   layoutr   r   r   )r   r   )indexr   r   r   zBoxplot grouped by 333333??皙?皙?bottomtoprz   rightZwspace)groupbyrb   listtuple_get_numeric_datar   
differencer"   r   popr   ru   r   zipr   appendr   r{   r|   Zsuptitler   )ZplotfrD   r   r   r   r   r   r   r   r;   r$   groupedr   rw   r1   Z_axesr   r   Z	ax_valuesr%   ry   Zgp_colkeysr   Zre_plotfr   Zbyliner'   r'   r(   _grouped_plot_by_column  sF    


	



r   z
int | Noneint)fontsizerotr   r   c
              
     s  dd l m} tjvrtdt| tr6| d} d}fdd}dd fdd	}|  |d u rnd }nt|tt	fr|}n|g}|d urt
|| f||||||d
}nΈd u rd|d urtd|d u r"|d urd|ini }|| | }W d    n1 s0    Y  |  } t| j}|dkrFtd|d u rX| j}n| | } ||| jj|fi }|| |S )Nr   z,return_type must be {'axes', 'dict', 'both'}xc                    s   t dd} t| g d} t| d}  dd }|rt|rg d}tt|td}|	 D ]2\}}||v r~|| || < q`t
d| d	| q`n
| | | S )
Nrh   )ri   )r   r   rF   krc   rY      r^   r_   )r   rM   Ztaker   r   r
   r2   r   r   itemsr>   fill)r   colorsre   Zkey_to_indexrf   value)rU   r'   r(   rs   r  s$    

zboxplot.<locals>._get_colorsr   )r   c                   s   | dd | dd  }}|r,|t| |r>|t| dd | D } dd |D }|j|fi |}d ur|jdd t|| |dd	d
 t|fd i| dkr|S dkrt	j
||dS |S d S )Nr   r   c                 S  s   g | ]}t |qS r'   r   )rH   r   r'   r'   r(   rJ     rK   z/boxplot.<locals>.plot_group.<locals>.<listcomp>c                 S  s   g | ]}t jt|td qS )rx   )rM   Zasarrayr   r}   rG   r'   r'   r(   rJ     rK   r3   )axisZ	labelsizer   T)r   r   r    Zrotationrt   r2   rP   )r   r   r   r   rR   Ztick_paramsr)   ru   rv   r*   r9   )r   r   r   rU   r   r   rV   )r   r   r;   r   r'   r(   
plot_group  s&    zboxplot.<locals>.plot_group)r   r   r   r   r   r   r;   r1   z7The 'layout' keyword is not supported when 'by' is Nonezfigure.figsizez;boxplot method requires numerical columns, nothing to plot.)matplotlib.pyplotpyplotr*   r=   r>   rb   r   Zto_framer   r   r   Z
rc_contextZgcar   r"   r   r   r   r   )rD   columnr   r   r   r   r   r   r   r;   rU   pltrs   r   r   r   rcr   r'   )r   r   rU   r;   r   r(   rR   [  sb    




(



rR   c
                 K  s<   dd l m} t| f|||||||||	d	|
}|  |S )Nr   )	r   r   r   r   r   r   r   r   r;   )r   r   rR   Zdraw_if_interactive)r.   r   r   r   r   r   r   r   r   r;   rU   r   r'   r'   r(   boxplot_frame  s$    r   )r@   r   r   r   r   rB   rC   c              
   K  sF  |du rt | }t|d||	|
||d\}}t|}tjtd}t| |D ]@\\}}}|jf |||||d|}|t	| ||j
|< qHt|ddddd	d
 nt|  \}}| jdkrtj||dd}n,t |dkr|d |dd  }n|d }|d ur"t|}tj||g}t|j}|jf |||||||d|}|S )NTF)r   Zsqueezer   rB   rC   r   r   rx   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r   r   r   r   r   r   r   )r"   r   r   r{   r|   r}   r   rR   r   r   locr   r   concatjoincomZconvert_to_list_likeZ
MultiIndexZfrom_productr   r   )r   r@   r   r   r   r   r   r   r   rB   rC   rU   r   rw   r1   r   rf   groupdr   framesZdfZ	multi_keyr'   r'   r(   boxplot_frame_groupby  sX    
	





r   )NNTFNNNN)	NNNNr   TNNN)	NNNNr   TNNN)
TNNr   TNNNFT);
__future__r   typingr   r   r   r`   Zmatplotlib.artistr   numpyrM   Zpandas._libsr   Zpandas.util._decoratorsr   Zpandas.util._exceptionsr	   Zpandas.core.dtypes.commonr
   Zpandas.core.dtypes.genericr   Zpandas.core.dtypes.missingr   Zpandasr{   Zpandas.core.commoncorecommonr   Zpandas.io.formats.printingr   Z pandas.plotting._matplotlib.corer   r   Z#pandas.plotting._matplotlib.groupbyr   Z!pandas.plotting._matplotlib.styler   Z!pandas.plotting._matplotlib.toolsr   r   r   collections.abcr   Zmatplotlib.axesr   Zmatplotlib.figurer   Zmatplotlib.linesr   Zpandas._typingr   r)   r*   rv   r   rR   r   r   r'   r'   r'   r(   <module>   s    Q        ?                   "          