HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/tests/plotting/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/tests/plotting/__pycache__/common.cpython-36.pyc
3

���hCI�@s�ddlZddlZddlZddlmZddlmZddljj	Z
ddlmZddl
Zddl
mZmZddljZe
jGdd�d��Zd
d	d
�Zdd�ZdS)�N)�random)�cache_readonly)�is_list_like)�	DataFrame�Seriesc@s�eZdZdd�Zdd�Zedd��Zedd��Zd.dd�Zd/d
d�Z	dd�Z
d0dd�Zdd�Zd1dd�Z
dd�Zd2dd�Zd3dd�Zd4dd�Zd d!�Zd"d#�Zd5d%d&�Zd6d'd(�Zifd)d*�Zd7d,d-�Zd	S)8�TestPlotBasecCs ddl}ddlm}|j�|j�|_|j�|_|j�|_	|j
�|_d|_d|_
d|_d|_d}tjd	��htjjd
dg|d�}tjjd
ddg|d�}t||tjdd|d�tjdd|d�tjd|d�d��|_WdQRXtj�|_ttjjdd�tjjdd�tjd�tjjdd�d��|_dS)Nr)�compat��皙����@�333333@�left�d�*ZMaleZFemale)�size�A�B�C�B��� )�gender�	classroom�heightZweight�category�)rrr)rr)�
matplotlibZpandas.plotting._matplotlibrZ
rcdefaultsZ
_mpl_ge_2_2_3Zmpl_ge_2_2_3Z
_mpl_ge_3_0_0Zmpl_ge_3_0_0Z
_mpl_ge_3_1_0�mpl_ge_3_1_0Z
_mpl_ge_3_2_0Zmpl_ge_3_2_0Zbp_n_objectsZpolycollection_factor�default_figsizeZdefault_tick_position�tmZ
RNGContext�npr�choicerZnormal�randintZhist_dfZmakeTimeDataFrameZtdf�uniformZarangeZ	hexbin_df)�self�method�mplr�nrr�r)�>/tmp/pip-build-5_djhm0z/pandas/pandas/tests/plotting/common.py�setup_methods4



 
zTestPlotBase.setup_methodcCstj�dS)N)r �close)r%r&r)r)r*�teardown_methodAszTestPlotBase.teardown_methodcCsddlj}|S)Nr)�matplotlib.pyplot�pyplot)r%�pltr)r)r*r0Ds
zTestPlotBase.pltcCsddlj}|jS)Nr)Zmatplotlib.colors�colorsZcolorConverter)r%r1r)r)r*�colorconverterJs
zTestPlotBase.colorconverterNTcCsj|r|dkrtd��|j|�}xF|D]>}|rR|j�dk	s<t�|j|j�j�|�q$|j�dks$t�q$WdS)aQ
        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�AssertionError�_check_text_labelsZ	get_texts)r%�axes�labels�visible�axr)r)r*�_check_legend_labelsPs


z!TestPlotBase._check_legend_labelscCsT|r|dkrtd��|r@|j�\}}dd�|D�}||ksPt�n|j�dksPt�dS)aB
        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 TruecSsg|]}|j��qSr))Z
get_marker)�.0�handler)r)r*�
<listcomp>xsz5TestPlotBase._check_legend_marker.<locals>.<listcomp>)r3Zget_legend_handles_labelsr6r5)r%r;Zexpected_markersr:Zhandles�_�markersr)r)r*�_check_legend_markergs
z!TestPlotBase._check_legend_markercsP|j�}|j�}dd��t|�t|�ks,t��fdd�t||�D�tj�dS)z�
        Check each axes has identical lines

        Parameters
        ----------
        xp : matplotlib Axes object
        rs : matplotlib Axes object
        cSs |j�}|j�}tj||�dS)N)Z
get_xydatar �assert_almost_equal)�xpl�rslZxpdataZrsdatar)r)r*�
check_line�sz,TestPlotBase._check_data.<locals>.check_linecsg|]\}}�||��qSr)r))r=rDrE)rFr)r*r?�sz,TestPlotBase._check_data.<locals>.<listcomp>N)�	get_lines�lenr6�zipr r,)r%Zxp�rsZxp_linesZrs_linesr))rFr*�_check_data}s	zTestPlotBase._check_datacCsJddlm}t||�r(t|�r(|g}x|D]}|j�|ks.t�q.WdS)a
        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.collectionsrL�
isinstancer�get_visibler6)r%�collectionsr:rL�patchr)r)r*�_check_visible�s

zTestPlotBase._check_visiblecs*|j�}tt||����fdd�|jD�S)Ncsg|]}�|�qSr)r))r=�v)�mappedr)r*r?�sz3TestPlotBase._get_colors_mapped.<locals>.<listcomp>)�unique�dictrI�values)r%Zseriesr1rUr))rTr*�_get_colors_mapped�szTestPlotBase._get_colors_mappedcCs�ddlm}m}m}ddlm}|j}	|dk	r�|dk	rR|j||�}|dt|��}t|�t|�ksft	�xrt
||�D]d\}
}t|
|�r�|
j�}|	j
|�}n(t|
||f�r�t|
j�d�}n|
j�}|	j
|�}
||
ksrt	�qrW|dk	�r�|dk	�r
|j||�}|dt|��}t|�t|�k�s t	�xht
||�D]Z\}
}t|
|��rN|
j�d}n|
j�}t|tj��rlt|�}|	j
|�}
||
k�s,t	��q,WdS)a3
        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)rL�LineCollection�PolyCollection)�Line2DN)rMrLrYrZZmatplotlib.linesr[r2rXrHr6rIrNZ	get_colorZto_rgba�tupleZ
get_edgecolorZ
get_facecolorr!Zndarray)r%rPZ
linecolorsZ
facecolors�mappingrLrYrZr[�convrQ�color�result�expectedr)r)r*�
_check_colors�s<




zTestPlotBase._check_colorscCsdt|�s|j�|ks`t�nFdd�|D�}t|�t|�ks<t�x"t||�D]\}}||ksHt�qHWdS)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
        cSsg|]}|j��qSr))�get_text)r=�tr)r)r*r?�sz3TestPlotBase._check_text_labels.<locals>.<listcomp>N)rrcr6rHrI)r%Ztextsrar9�label�er)r)r*r7�szTestPlotBase._check_text_labelsc
Cs&ddlm}|j|�}�x|D�]�}|dk	s4|dk	r�t|jj�|�rN|j�}n|j�|jdd�}x<|D]4}	|dk	r�tj|	j	�|�|dk	rhtj|	j
�|�qhW|dk	s�|dk	rt|jj�|�r�|j�}n|j�|jdd�}x>|D]6}	|dk	�rtj|	j	�|�|dk	r�tj|	j
�|�q�WqWdS)a�
        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)
Zmatplotlib.tickerrgr4rN�xaxisZget_minor_formatterZget_xticklabelsr rCZget_fontsizeZget_rotation�yaxisZget_yticklabels)
r%r8Z
xlabelsizeZxrotZ
ylabelsizeZyrotrgr;r9rer)r)r*�_check_ticks_props�s*





zTestPlotBase._check_ticks_props�linearcCs@|j|�}x0|D](}|jj�|ks&t�|jj�|kst�qWdS)a
        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)r4riZ	get_scaler6rj)r%r8rirjr;r)r)r*�_check_ax_scales-s

zTestPlotBase._check_ax_scalesc	Cs�ddlm}|dkr|j}|j|�}|dk	r^t|�|ks<t�x |D]}t|j��dksBt�qBW|dk	r�|j||��}||ks�t�tj	|dj
j�tj
|tjd��dS)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)�_flattenN)Zdtype)�!pandas.plotting._matplotlib.toolsrnrr4rHr6Zget_children�_get_axes_layoutr Zassert_numpy_array_equal�figureZget_size_inchesr!�arrayZfloat64)	r%r8Zaxes_numZlayoutZfigsizernZvisible_axesr;r`r)r)r*�_check_axes_shape>s

zTestPlotBase._check_axes_shapecCsZt�}t�}x<|D]4}|j�j�}|j|dd�|j|dd�qWt|�t|�fS)Nr�)�set�get_positionZ
get_points�addrH)r%r8Zx_setZy_setr;Zpointsr)r)r*rpbs
zTestPlotBase._get_axes_layoutcCs&ddlm}||�}dd�|D�}|S)z�
        Flatten axes, and filter only visible

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

        r)rncSsg|]}|j�r|�qSr))rO)r=r;r)r)r*r?xsz1TestPlotBase._flatten_visible.<locals>.<listcomp>)rorn)r%r8rnr)r)r*r4ls	zTestPlotBase._flatten_visiblercCs�|j|�}xp|D]h}|j}d}d}x<|D]4}t|dd�}	t|dd�}
|	rP|d7}|
r(|d7}q(W||kslt�||kst�qWdS)a
        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_yerrrtN)r4�
containers�getattrr6)r%r8ZxerrZyerrr;rzZ
xerr_countZ
yerr_count�crxryr)r)r*�_check_has_errorbars{s


z!TestPlotBase._check_has_errorbarscCs�ddlm}t|td�}|dkrj|dkr,d}t|||�s>t�|dkrft|j|�sVt�t|jt�sft��n$|dkr�x |j|�D]}t||�s~t�q~WdSt|t	�s�t�t
|j��t
|�ks�t�x�|j�D]�\}}	t|	||�s�t�|dk�r|�r�|	j
�|k�s�t�q�|dk�rP|�r*|	jj
�|k�s*t�t|	j|��s<t�t|	jt��s�t�q�|dk�r�|	dd}
|
j}|�r�|j
�|k�s�t�q�t�q�WdS)	at
        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)�Axes)rVr8�bothNrVrr8Zmedians)Zmatplotlib.axesr~rVr\rNr6r;�linesr4r�sorted�keys�itemsZ	get_titler8)r%Zreturned�return_typeZ
expected_keysZcheck_ax_titler~�types�r�key�value�liner8r)r)r*�_check_box_return_type�s>


z#TestPlotBase._check_box_return_typecspddl}�fdd�}d}�xP|D�]F}�jjddt|�|�|d7}|jddd�|jfd	|i|��|�stt��jjddt|�|�|d7}|jdd
d�|jf|dd�|��|�s�t�|dkr �jjddt|�|�|d7}|jdd
d�|jfd	|i|��|��st��jjddt|�|�|d7}|jddd�|jf|d
d�|��|�s t�q WdS)
Nrcsz�jj�jj�}�jj�jj�}�jrLtdd�|D��}tdd�|D��}n$tdd�|D��}tdd�|D��}|ov|S)Ncss|]}|jj�VqdS)N)�gridlinerO)r=�gr)r)r*�	<genexpr>�szHTestPlotBase._check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>css|]}|jj�VqdS)N)r�rO)r=r�r)r)r*r��scss|]}|jVqdS)N)�gridOn)r=r�r)r)r*r��scss|]}|jVqdS)N)r�)r=r�r)r)r*r��s)r0ZgcariZget_major_ticksrjr�all)ZxticksZyticksZxoffZyoff)r%r)r*�
is_grid_on�sz5TestPlotBase._check_grid_settings.<locals>.is_grid_onrtrr8F)�grid�kindT)r�r�Zpie)rr0ZsubplotrH�rcZplotr6)r%�objZkinds�kwsr'r�Zspndxr�r))r%r*�_check_grid_settings�s2z!TestPlotBase._check_grid_settingsr_cs�fdd�|dD�S)zT
        Auxiliary function for correctly unpacking cycler after MPL >= 1.5
        csg|]}|��qSr)r))r=rS)�fieldr)r*r?sz/TestPlotBase._unpack_cycler.<locals>.<listcomp>zaxes.prop_cycler))r%ZrcParamsr�r))r�r*�_unpack_cyclerszTestPlotBase._unpack_cycler)NT)NT)T)NNN)NNNN)rlrl)NNN)rr)NT)r_)�__name__�
__module__�__qualname__r+r-rr0r2r<rBrKrRrXrbr7rkrmrsrpr4r}r�r�r�r)r)r)r*rs(*



=
/

$


;0r�alwayscKs�ddlj}d}tj���tj|�z�y|d}Wntk
rL|j�}YnX|j�|jd|j	d��|f|�}t
j|�|tj
jkr�d|ks�t�n|j	d�|d<|f|�}t
j|�t
jdd��}|j|�WdQRXWdt
j|�X|SQRXdS)Nrrqr;����T)Zreturn_filelike)r.r/�warnings�catch_warnings�simplefilter�KeyErrorZgcfZclf�getZadd_subplotr Z"assert_is_valid_plot_return_object�pdZplottingZbootstrap_plotr6Zensure_cleanZsavefigr,)�f�filterwarnings�kwargsr0�retZfig�pathr)r)r*�_check_plot_works	s,






r�cCstjjtjjt��\}}|S)N)�osr��split�abspath�__file__)�pthr@r)r)r*�curpath,sr�)r�)r�r�Znumpyr!rZpandas.util._decoratorsrZpandas.util._test_decorators�utilZ_test_decorators�tdZpandas.core.dtypes.apirZpandasr�rrZpandas._testingZ_testingr Zskip_if_no_mplrr�r�r)r)r)r*�<module>s
w
#