a
    é´«jçA  ã                   @  sF  d Z ddlmZ ddl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 erlddlmZ ddlmZ d=d
d„Zd>dd„Zdd„ Zd?dd„Zd@ddddœdd„Zdd„ ZdAdd„Zdd„ ZdBdd„ZdCd!d"„ZdDd#d$„Zdd%d&œd'd(„ZdEd)d*„ZdFd+d,„Z i fd-d.„Z!dGd0d1„Z"d2d3„ Z#d4d5„ Z$dHd7d8„Z%d9d:„ Z&d;d<„ Z'dS )IzF
Module consolidating common testing functions for checking plotting.
é    )Úannotations)ÚTYPE_CHECKINGN)Úis_list_like)ÚSeries)ÚSequence©ÚAxesTc                 C  sb   |r|du rt dƒ‚t| ƒ} | D ]<}|rL| ¡ dus8J ‚t| ¡  ¡ |ƒ q | ¡ du s J ‚q dS )a)  
    Check each axes has expected legend labels

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like
    labels : list-like
        expected legend labels
    visible : bool
        expected legend visibility. labels are checked only when visible is
        True
    Nz-labels must be specified when visible is True)Ú
ValueErrorÚ_flatten_visibleÚ
get_legendÚ_check_text_labelsZ	get_texts)ÚaxesÚlabelsÚvisibleÚax© r   ú[/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/pandas/tests/plotting/common.pyÚ_check_legend_labels   s    r   c                 C  sT   |r|du rt dƒ‚|r@|  ¡ \}}dd„ |D ƒ}||ksPJ ‚n|  ¡ du sPJ ‚dS )a  
    Check ax has expected legend markers

    Parameters
    ----------
    ax : matplotlib Axes object
    expected_markers : list-like
        expected legend markers
    visible : bool
        expected legend visibility. labels are checked only when visible is
        True
    Nz.Markers must be specified when visible is Truec                 S  s   g | ]}|  ¡ ‘qS r   )Z
get_marker)Ú.0Úhandler   r   r   Ú
<listcomp>@   ó    z(_check_legend_marker.<locals>.<listcomp>)r	   Zget_legend_handles_labelsr   )r   Zexpected_markersr   ZhandlesÚ_Úmarkersr   r   r   Ú_check_legend_marker/   s    r   c           	      C  sn   ddl m} |  ¡ }| ¡ }t|ƒt|ƒks0J ‚t||ƒD ]$\}}| ¡ }| ¡ }t ||¡ q:| d¡ dS )zŒ
    Check each axes has identical lines

    Parameters
    ----------
    xp : matplotlib Axes object
    rs : matplotlib Axes object
    r   NÚall)	Úmatplotlib.pyplotÚpyplotÚ	get_linesÚlenÚzipZ
get_xydataÚtmÚassert_almost_equalÚclose)	ZxpÚrsÚpltZxp_linesZrs_linesZxplÚrslZxpdataZrsdatar   r   r   Ú_check_dataF   s    	r'   c                 C  sB   ddl m} t| |ƒs$t| ƒs$| g} | D ]}| ¡ |ks(J ‚q(dS )zà
    Check each artist is visible or not

    Parameters
    ----------
    collections : matplotlib Artist or its list-like
        target Artist or its list or collection
    visible : bool
        expected visibility
    r   )Ú
CollectionN)Úmatplotlib.collectionsr(   Ú
isinstancer   Úget_visible)Úcollectionsr   r(   Úpatchr   r   r   Ú_check_visible]   s
    r.   zAxes | Sequence[Axes]ÚboolÚNone)r   ÚfilledÚreturnc                 C  s0   t | ƒ} | D ]}|jD ]}|j|ksJ ‚qqdS )z¹
    Check for each artist whether it is filled or not

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like
    filled : bool
        expected filling
    N)r
   ZpatchesÚfill)r   r1   r   r-   r   r   r   Ú_check_patches_all_filledq   s    
r4   c                   s*   |   ¡ }tt||ƒƒ‰ ‡ fdd„| jD ƒS )Nc                   s   g | ]}ˆ | ‘qS r   r   ©r   Úv©Zmappedr   r   r   ‡   r   z&_get_colors_mapped.<locals>.<listcomp>)ÚuniqueÚdictr    Úvalues)ZseriesÚcolorsr8   r   r7   r   Ú_get_colors_mapped‚   s    r<   c                 C  sŽ  ddl m} ddlm}m}m} ddlm} |j}	|durà|dur\t	||ƒ}|dt
| ƒ… }t
| ƒt
|ƒkspJ ‚t| |ƒD ]d\}
}t|
|ƒr |
 ¡ }|	 |¡}n(t|
||fƒrÀt|
 ¡ d ƒ}n|
 ¡ }|	 |¡}||kszJ ‚qz|du�rŠ|du�rt	||ƒ}|dt
| ƒ… }t
| ƒt
|ƒk�s$J ‚t| |ƒD ]Z\}
}t|
|ƒ�rP|
 ¡ d }n|
 ¡ }t|tjƒ�rnt|ƒ}|	 |¡}||k�s.J ‚�q.dS )aÿ  
    Check each artist has expected line colors and face colors

    Parameters
    ----------
    collections : list-like
        list or collection of target artist
    linecolors : list-like which has the same length as collections
        list of expected line colors
    facecolors : list-like which has the same length as collections
        list of expected face colors
    mapping : Series
        Series used for color grouping key
        used for andrew_curves, parallel_coordinates, radviz test
    r   )r;   )r(   ÚLineCollectionÚPolyCollection)ÚLine2DN)Ú
matplotlibr;   r)   r(   r=   r>   Zmatplotlib.linesr?   ZColorConverterr<   r   r    r*   Ú	get_colorZto_rgbaÚtupleZget_edgecolorZget_facecolorÚnpZndarray)r,   Z
linecolorsZ
facecolorsÚmappingr;   r(   r=   r>   r?   Úconvr-   ÚcolorÚresultÚexpectedr   r   r   Ú_check_colorsŠ   s>    






rI   c                 C  s`   t | ƒs|  ¡ |ks\J ‚nBdd„ | D ƒ}t|ƒt|ƒks<J ‚t||ƒD ]\}}||ksFJ ‚qFdS )a  
    Check each text has expected labels

    Parameters
    ----------
    texts : matplotlib Text object, or its list-like
        target text, or its list
    expected : str or list-like which has the same length as texts
        expected text label, or its list
    c                 S  s   g | ]}|  ¡ ‘qS r   )Úget_text)r   Útr   r   r   r   Ø   r   z&_check_text_labels.<locals>.<listcomp>N)r   rJ   r   r    )ZtextsrH   r   ÚlabelÚer   r   r   r   Ê   s    r   c           	      C  s  ddl m} t| ƒ} | D ]ô}|dus,|dur”t|j ¡ |ƒrF| ¡ }n| ¡ |jdd� }|D ]4}|durzt | 	¡ |¡ |dur^t | 
¡ |¡ q^|dus¤|durt|j ¡ |ƒr¾| ¡ }n| ¡ |jdd� }|D ]4}|duròt | 	¡ |¡ |durÖt | 
¡ |¡ qÖqdS )ac  
    Check each axes has expected tick properties

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like
    xlabelsize : number
        expected xticks font size
    xrot : number
        expected xticks rotation
    ylabelsize : number
        expected yticks font size
    yrot : number
        expected yticks rotation
    r   )ÚNullFormatterNT)Úminor)Zmatplotlib.tickerrN   r
   r*   ÚxaxisZget_minor_formatterZget_xticklabelsr!   r"   Zget_fontsizeZget_rotationÚyaxisZget_yticklabels)	r   Z
xlabelsizeZxrotZ
ylabelsizeZyrotrN   r   r   rL   r   r   r   Ú_check_ticks_propsÞ   s*    

rR   Úlinearc                 C  s:   t | ƒ} | D ](}|j ¡ |ks"J ‚|j ¡ |ksJ ‚qdS )zö
    Check each axes has expected scales

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like
    xaxis : {'linear', 'log'}
        expected xaxis scale
    yaxis : {'linear', 'log'}
        expected yaxis scale
    N)r
   rP   Z	get_scalerQ   )r   rP   rQ   r   r   r   r   Ú_check_ax_scales  s    rT   c                 C  sê   ddl m} |du rd}t| ƒ}|durVt|ƒ|ks8J ‚|D ]}t| ¡ ƒdks<J ‚q<|durÄtƒ }tƒ }|| ƒD ]4}| ¡  ¡ }	| |	d d ¡ | |	d d ¡ qrt|ƒt|ƒf}
|
|ksÄJ ‚t	 
|d j ¡ tj|tjd�¡ dS )až  
    Check expected number of axes is drawn in expected layout

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like
    axes_num : number
        expected number of axes. Unnecessary axes should be set to
        invisible.
    layout : tuple
        expected layout, (expected number of rows , columns)
    figsize : tuple
        expected figsize. default is matplotlib default
    r   ©Úflatten_axesN)gš™™™™™@g333333@é   )Zdtype)Ú!pandas.plotting._matplotlib.toolsrV   r
   r   Zget_childrenÚsetÚget_positionZ
get_pointsÚaddr!   Zassert_numpy_array_equalÚfigureZget_size_inchesrC   ÚarrayZfloat64)r   Zaxes_numZlayoutZfigsizerV   Zvisible_axesr   Zx_setZy_setZpointsrG   r   r   r   Ú_check_axes_shape  s*    þr^   zSequence[Axes])r   r2   c                 C  s&   ddl m} || ƒ}dd„ |D ƒ} | S )zƒ
    Flatten axes, and filter only visible

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like

    r   rU   c                 S  s   g | ]}|  ¡ r|‘qS r   )r+   )r   r   r   r   r   r   W  r   z$_flatten_visible.<locals>.<listcomp>)rX   rV   )r   rV   Zaxes_ndarrayr   r   r   r
   K  s    	r
   c           
      C  sv   t | ƒ} | D ]d}|j}d}d}|D ]4}t|ddƒ}t|ddƒ}	|rJ|d7 }|	r"|d7 }q"||ksdJ ‚||ksJ ‚qdS )zø
    Check axes has expected number of errorbars

    Parameters
    ----------
    axes : matplotlib Axes object, or its list-like
    xerr : number
        expected number of x errorbar
    yerr : number
        expected number of y errorbar
    r   Úhas_xerrFÚhas_yerrrW   N)r
   Ú
containersÚgetattr)
r   ZxerrZyerrr   ra   Z
xerr_countZ
yerr_countÚcr_   r`   r   r   r   Ú_check_has_errorbars[  s    
rd   c                 C  s‚  ddl m} t|tdœ}|du rj|du r,d}t| || ƒs>J ‚|dkrft| j|ƒsVJ ‚t| jtƒsfJ ‚�n|du r’t| ƒD ]}t||ƒszJ ‚qzdS t| tƒs J ‚t	|  
¡ ƒt	|ƒks¸J ‚|  ¡ D ]¼\}}t||| ƒsÚJ ‚|dkrø|rö| ¡ |ksöJ ‚qÀ|dk�rB|�r|j ¡ |k�sJ ‚t|j|ƒ�s.J ‚t|jtƒ�s|J ‚qÀ|dk�rx|d d }	|	j}
|�r||
 ¡ |k�s|J ‚qÀt‚qÀdS )	a<  
    Check box returned type is correct

    Parameters
    ----------
    returned : object to be tested, returned from boxplot
    return_type : str
        return_type passed to boxplot
    expected_keys : list-like, optional
        group labels in subplot case. If not passed,
        the function checks assuming boxplot uses single ax
    check_ax_title : bool
        Whether to check the ax.title is the same as expected_key
        Intended to be checked by calling from ``boxplot``.
        Normal ``plot`` doesn't attach ``ax.title``, it must be disabled.
    r   r   )r9   r   ÚbothNr9   re   r   Zmedians)Úmatplotlib.axesr   r9   rB   r*   r   Úlinesr
   r   ÚsortedÚkeysÚitemsZ	get_titler   ÚAssertionError)ÚreturnedÚreturn_typeZexpected_keysZcheck_ax_titler   ÚtypesÚrÚkeyÚvalueÚliner   r   r   r   Ú_check_box_return_typew  s>    

rs   c                   s�  dd l ‰ ‡ fdd„}d}|D �]l}ˆ j ddt|ƒ |¡ |d7 }ˆ jddd� | jf d	|i|¤Ž |ƒ rnJ ‚ˆ j ¡  ˆ j ddt|ƒ |¡ |d7 }ˆ jdd
d� | jf |ddœ|¤Ž |ƒ rÆJ ‚ˆ j ¡  |dvrˆ j ddt|ƒ |¡ |d7 }ˆ jdd
d� | jf d	|i|¤Ž |ƒ �s&J ‚ˆ j ¡  ˆ j ddt|ƒ |¡ |d7 }ˆ jddd� | jf |d
dœ|¤Ž |ƒ �s€J ‚ˆ j ¡  qd S )Nr   c                    sN   ˆ j  ¡ j ¡ } ˆ j  ¡ j ¡ }tdd„ | D ƒƒ}tdd„ |D ƒƒ}|oJ| S )Nc                 s  s   | ]}|j  ¡  V  qd S ©N©Zgridliner+   ©r   Úgr   r   r   Ú	<genexpr>¼  r   z;_check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>c                 s  s   | ]}|j  ¡  V  qd S rt   ru   rv   r   r   r   rx   ½  r   )r   ZgcarP   Zget_major_ticksrQ   r   )ZxticksZyticksZxoffZyoff©Zmplr   r   Ú
is_grid_on¹  s
    z(_check_grid_settings.<locals>.is_grid_onrW   é   r   F)ÚgridÚkindT)r}   r|   )ÚpieZhexbinZscatter)r@   r   Zsubplotr   ÚrcZplotÚclf)ÚobjÚkindsÚkwsrz   Zspndxr}   r   ry   r   Ú_check_grid_settings´  s:    





r„   rF   c                   s   ‡ fdd„| d D ƒS )zL
    Auxiliary function for correctly unpacking cycler after MPL >= 1.5
    c                   s   g | ]}|ˆ  ‘qS r   r   r5   ©Úfieldr   r   r   å  r   z"_unpack_cycler.<locals>.<listcomp>zaxes.prop_cycler   )ZrcParamsr†   r   r…   r   Ú_unpack_cyclerá  s    r‡   c                 C  s
   | j d S )NÚx©Z_shared_axes©r   r   r   r   Ú
get_x_axisè  s    r‹   c                 C  s
   | j d S )NÚyr‰   rŠ   r   r   r   Ú
get_y_axisì  s    r�   Fc              	   K  sx   ddl m} |rt}nt}d}zH| d| ¡ ¡}| ¡  || |fi |¤ŽD ]}t |¡ qJW | 	|¡ n| 	|¡ 0 |S )a×  
    Create plot and ensure that plot return object is valid.

    Parameters
    ----------
    f : func
        Plotting function.
    default_axes : bool, optional
        If False (default):
            - If `ax` not in `kwargs`, then create subplot(211) and plot there
            - Create new subplot(212) and plot there as well
            - Mind special corner case for bootstrap_plot (see `_gen_two_subplots`)
        If True:
            - Simply run plotting function with kwargs provided
            - All required axes instances will be created automatically
            - It is recommended to use it when the plotting function
            creates multiple axes itself. It helps avoid warnings like
            'UserWarning: To output multiple subplots,
            the figure containing the passed axes is being cleared'
    **kwargs
        Keyword arguments passed to the plotting function.

    Returns
    -------
    Plot object returned by the last plotting.
    r   Nr\   )
r   r   Ú_gen_default_plotÚ_gen_two_subplotsÚgetZgcfr€   r!   Z"assert_is_valid_plot_return_objectr#   )ÚfZdefault_axesÚkwargsr%   Z	gen_plotsÚretÚfigr   r   r   Ú_check_plot_worksð  s    r•   c                 k  s   | f i |¤ŽV  dS )z'
    Create plot in a default way.
    Nr   ©r‘   r”   r’   r   r   r   rŽ      s    rŽ   c                 k  s^   d|vr|  d¡ | f i |¤ŽV  | tjju r<d|vsJJ ‚n|  d¡|d< | f i |¤ŽV  dS )z9
    Create plot on two subplots forcefully created.
    r   éÓ   éÔ   N)Zadd_subplotÚpdZplottingZbootstrap_plotr–   r   r   r   r�   '  s    
r�   )NT)NT)T)T)NNN)NNNN)rS   rS   )NNN)r   r   )NT)rF   )F)(Ú__doc__Ú
__future__r   Útypingr   ÚnumpyrC   Zpandas.core.dtypes.apir   Zpandasr™   r   Zpandas._testingZ_testingr!   Úcollections.abcr   rf   r   r   r   r'   r.   r4   r<   rI   r   rR   rT   r^   r
   rd   rs   r„   r‡   r‹   r�   r•   rŽ   r�   r   r   r   r   Ú<module>   s@   



@
/

,
 ÿ
=-

0