a
    Pf:q                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddl	Z
ddl	mZmZmZ ddlmZ ddlmZmZmZmZmZmZ ddlmZ edZed	ZG d
d dZdS )z Test cases for DataFrame.plot     N)is_platform_linux)np_version_gte1p24)	DataFrameSeries
date_range)_check_axes_shape_check_box_return_type_check_legend_labels_check_ticks_props_check_visible_flatten_visible)pprint_thingZ
matplotlibzmatplotlib.pyplotc                   @   s  e Zd Zejjejdg ddd Zejjejdg ddd Zejjejdg ddd Z	ejdd	d
gdd Z
ejdd	d
gdd Zejdg ddd Zdd Zejjdddd Zejdddgddgddgddgddgdd ggd!d" Zd#d$ Zejd%i d&d'd(fd)d*id&d*d*fgd+d, Zejjejd-ed.ed/d.d0gd1d2 Zd3d4 Zd5d6 Zejdd7dgddgddggd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE Zejjeoe  dFdGdHdIdJ Z!ejjeoe  dFdGdHdKdL Z"dMdN Z#ejdOg dPdQdR Z$dSdT Z%dUdV Z&dWdX Z'dYdZ Z(d[d\ Z)ejd]d^d_d`dadbdcd&ddgfgejdg dedfdg Z*ejdhdidjdkdidjdldmdndjdkdndjdldmdidGdkdidGdldmdndGdkdndGdldmdidjdodidjdldpdndjdodndjdldpdidjdqdrdidjdldqdsdndjdqdrdndjdldqdsdidGdqdrdidGdldqdsdndGdqdrdndGdldqdsdidjdqdtdidjdldqdudndjdqdtdndjdldqdugdvdw Z+ejdhdidGdkdidjdkdndGdkdndjdkdidjdodndjdogdxdy Z,ejdhdidGdkdidjdkdndGdkdndjdkdidjdodndjdogdzd{ Z-ejd|d&d}gd~d Z.ejddiddjigdnddGigdnddjigdiddjigdnddjiggdd Z/dddZ0dbS )TestDataFramePlotsSubplotskind)barbarhlineareac                 C   s<  t tjddttjd d d}|j|dddd}t|ddd	 |j	d
ksVJ t
||jD ]\}}t|t|gd qb|d d D ]X}t|j t| dd |dkrt|jdddd t|j dd t|  qt|d j t|d   t|d jdd t|d j  t|d   d S )N   
      r   indexT)r   subplotssharexlegendr   r      Zaxes_numlayoutr   labelsFvisibler   minor)r   nprandomdefault_rngliststringascii_lettersplotr   shapezipcolumnsr	   r   r   xaxisget_xticklabels	get_labelget_yticklabels)selfr   dfaxesaxcolumn r=   h/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/plotting/frame/test_frame_subplots.pytest_subplots"   s*    
z(TestDataFramePlotsSubplots.test_subplotsc                 C   s   t tjddttjd d d}|j|ddd}|D ]D}t|j	 t|
  t|j
dd t|j	  t|  q<d S )	Nr   r   r   r   TFr   r   r   r'   )r   r*   r+   r,   r-   r.   r/   r0   r   r4   r5   r6   r7   r8   r   r9   r:   r;   r=   r=   r>   test_subplots_no_share_x@   s    
z3TestDataFramePlotsSubplots.test_subplots_no_share_xc                 C   sV   t tjddttjd d d}|j|ddd}|D ]}| d u s<J q<d S )Nr   r   r   r   TF)r   r   r   )	r   r*   r+   r,   r-   r.   r/   r0   Z
get_legendrA   r=   r=   r>   test_subplots_no_legendO   s    z2TestDataFramePlotsSubplots.test_subplots_no_legendr   r   c                 C   s  t dddd}ttjdd|d}|j|ddd	}t|d
dd |d d D ]P}t|j t|	 dd t|j	dddd t|j
 dd t|  qRt|d j t|d 	  t|d j	dd t|d j
  t|d   t|dd d S )N
2014-07-01MEr   startfreqperiodsr   r   r   Tr@   r   r   r   r$   Fr%   r'   r)   r   )xrot)r   r   r*   r+   r,   r0   r   r   r4   r5   r6   r7   r
   r8   r   idxr9   r:   r;   r=   r=   r>   test_subplots_timeseriesZ   s     
z3TestDataFramePlotsSubplots.test_subplots_timeseriesc                 C   s   t dddd}ttjdd|d}|j|dd	d
dd}|D ]T}t|j t|  t|jdd t|j	  t|
  t|dd
dd q@d S )NrD   rE   r   rF   r   r   r   TF-      )r   r   r   Zrotfontsizer'   )Z
xlabelsizerJ   Z
ylabelsize)r   r   r*   r+   r,   r0   r   r4   r5   r6   r7   r
   rK   r=   r=   r>   test_subplots_timeseries_rotq   s    
z7TestDataFramePlotsSubplots.test_subplots_timeseries_rotcol)numeric	timedeltadatetime_no_tzdatetime_all_tzc              	   C   s   t g dtjdddtjdddtjdddgtdtd	td
gtjdddtjd	ddtjd
ddgg dd}t|}|j|d}| d  d }|| j	}||k
 sJ d S )Nr   r      is)unitr   mh2017-08-01 00:00:002017-08-01 02:00:002017-08-02 00:00:00TutcZThisZshouldZfail)rS   rT   rU   rV   textyr   r   )r*   arraypdZ	Timedeltato_datetimer   r0   	get_linesget_datavaluesall)r8   rR   datatestdatar;   resultexpectedr=   r=   r>   test_subplots_timeseries_y_axis~   s(    
z:TestDataFramePlotsSubplots.test_subplots_timeseries_y_axisc                 C   sb   t g dg dd}t|}d}tjt|d |jdd W d    n1 sT0    Y  d S )NrW   rb   )rS   rc   zno numeric data to plotmatchrc   rd   )r*   rf   r   pytestraises	TypeErrorr0   )r8   rm   rn   msgr=   r=   r>   %test_subplots_timeseries_y_text_error   s    z@TestDataFramePlotsSubplots.test_subplots_timeseries_y_text_errorz6not support for period, categorical, datetime_mixed_tz)reasonc                 C   s  t g dtjdddtjdddtjdddgtjg dg dd	d
tjdddtdtdgd}t|}|jddd}| d 	 d |d j
k sJ |jddd}| d 	 d |d j
k sJ |jddd}| d 	 d |d j
k sJ dS )a  
        This test will fail for:
            period:
                since period isn't yet implemented in ``select_dtypes``
                and because it will need a custom value converter +
                tick formatter (as was done for x-axis plots)

            categorical:
                 because it will need a custom value converter +
                 tick formatter (also doesn't work for x-axis, as of now)

            datetime_mixed_tz:
                because of the way how pandas handles ``Series`` of
                ``datetime`` objects with different timezone,
                generally converting ``datetime`` objects in a tz-aware
                form could help with this problem
        rW   r]   H)rH   z2017-08-01 02:00r_   )cba)r}   r|   r{   F)
categoriesorderedTr`   r^   )rS   periodcategoricaldatetime_mixed_tzrS   r   )xre   r   r   r   r   N)r*   rf   rg   ZPeriodZCategoricalrh   r   r0   ri   rj   rk   rl   )r8   rm   rn   Z	ax_periodZax_categoricalZax_datetime_mixed_tzr=   r=   r>   -test_subplots_timeseries_y_axis_not_supported   s6    

zHTestDataFramePlotsSubplots.test_subplots_timeseries_y_axis_not_supportedzlayout, exp_layout)r   r   )r)   r   )r   r)   )r      )r)   r   )r   r)   )r   r   c                 C   sV   t tjddttjd d d}|jd|d}t|d|d |j	|ksRJ d S )	Nr   r   r   r   Tr   r    r   r   
r   r*   r+   r,   r-   r.   r/   r0   r   r1   )r8   r    
exp_layoutr9   r:   r=   r=   r>   !test_subplots_layout_multi_column   s    z<TestDataFramePlotsSubplots.test_subplots_layout_multi_columnc                 C   s   t tjddttjd d d}d}tjt	|d |j
ddd	 W d    n1 s^0    Y  d
}tjt	|d |j
ddd	 W d    n1 s0    Y  d S )Nr   r   r   r   z1Layout of 1x1 must be larger than required size 3rr   Tr   r   r   z1At least one dimension of layout must be positive)r)   r)   )r   r*   r+   r,   r-   r.   r/   rt   ru   
ValueErrorr0   )r8   r9   rw   r=   r=   r>   'test_subplots_layout_multi_column_error   s    ,zBTestDataFramePlotsSubplots.test_subplots_layout_multi_column_errorz:kwargs, expected_axes_num, expected_layout, expected_shaper   r   r   r    )r   r   c                 C   s\   t tjddttjd d d}|jf ddi|}t|||d |j	|ksXJ d S )Nr   r   r   r   r   r   Tr   r   )r8   kwargsZexpected_axes_numZexpected_layoutZexpected_shaper9   r:   r=   r=   r>   "test_subplots_layout_single_column   s    z=TestDataFramePlotsSubplots.test_subplots_layout_single_columnrL   rX   1/1/2000rI   c                 C   sV   t d 8 ttjdd|d}|jddd W d    n1 sH0    Y  d S )Nr   )rX   r   r   T)r   r   r   )tmassert_produces_warningr   r*   r+   r,   standard_normalr0   )r8   rL   r9   r=   r=   r>   test_subplots_warnings  s    z1TestDataFramePlotsSubplots.test_subplots_warningsc                 C   s   t jdd\}}ttjddttj	d d d}|j
d|d ddd	}t|dd
d |jdkslJ |d j|u s~J |j
d|d ddd	}t|dd
d |jdksJ |d j|u sJ t|ddd d S )Nr   r   r   r   r   Tr   Fr   r;   r   sharey)r   r   r   r!   r      )r   r   )mplpyplotr   r   r*   r+   r,   r-   r.   r/   r0   r   r1   Zfigure)r8   Zfigr:   r9   returnedr=   r=   r>   test_subplots_multiple_axes  s    z6TestDataFramePlotsSubplots.test_subplots_multiple_axesc                 C   s~   t tjddttjd d d}d}tj	dd\}}t
jt|d |jd|d	 W d    n1 sp0    Y  d S )
Nr   r   r   r   z@The number of passed axes must be 3, the same as the output plotr   rr   Tr   r;   )r   r*   r+   r,   r-   r.   r/   r   r   r   rt   ru   r   r0   )r8   r9   rw   _r:   r=   r=   r>   !test_subplots_multiple_axes_error2  s    z<TestDataFramePlotsSubplots.test_subplots_multiple_axes_error)r   r   c                 C   s   t jdd\}}ttjddttj	d d d}t
t@ |jd||ddd}t|d|d	 |jd
ksvJ W d    n1 s0    Y  d S )Nr   )r   r   r   r   TF)r   r;   r    r   r   r   r   )r   )r   r   r   r   r*   r+   r,   r-   r.   r/   r   r   UserWarningr0   r   r1   )r8   r    r   r   r:   r9   r   r=   r=   r>   !test_subplots_multiple_axes_2_dim?  s    
z<TestDataFramePlotsSubplots.test_subplots_multiple_axes_2_dimc                 C   sn   t jdd\}}ttjddttj	d d d}|j
d|gddd}t|dd	d
 |jdksjJ d S )Nr   r   r   r   r   TFr   r   r   r   )r   r   r   r   r*   r+   r,   r-   r.   r/   r0   r   r1   )r8   r   r:   r9   r=   r=   r>   &test_subplots_multiple_axes_single_colY  s    zATestDataFramePlotsSubplots.test_subplots_multiple_axes_single_colc                 C   sL  t jjddddd\}}t jjddddd ttjdd	t	d
dddd}t
| D ]\}}|| j|dd q\|dd  D ]}t| dd q|d  D ]}t| dd q|g ddgf  D ]}t| dd q|g ddgf  D ]}t| dd q|g ddgf  D ]}t| dd q0d S )Nr   T)r   r   g?gffffff?g333333?)leftrightZhspaceZwspacer   )r   	   rD   rE   r   rF   r   rX   )r;   rP   r   r)   Fr%   )r   r   r   r   )r   r   r   Zsubplots_adjustr   r*   r+   r,   r   r   	enumerateravelr0   r   r5   r7   )r8   r   r:   r9   ir;   r=   r=   r>   test_subplots_ts_share_axesf  s$    z6TestDataFramePlotsSubplots.test_subplots_ts_share_axesc                 C   s   g dg dg dd}t |tddd}|dd	g jd
d}|d j|d d
d t|d  dd t|d  d
d | D ]}t| d
d qd S )N)      ?       @      @      @)r   r   r   r   )rX   r   r   r   )ABCz
2014 10 11z
2014 10 14r   r   r   Tr   r   r   )r;   secondary_yFr%   r   )r   r   r0   r   r5   r   r7   )r8   dr9   r:   r;   r=   r=   r>   'test_subplots_sharex_axes_existing_axes  s    zBTestDataFramePlotsSubplots.test_subplots_sharex_axes_existing_axesc                 C   sX   t tjddtdd}|jdd}|D ]$}t|dgd t|jd	ks.J q.d S )
Nr   rX   rX   aaaaar3   Tr   r}   r"   r   	r   r*   r+   r,   r-   r0   r	   lenlinesr8   r9   r:   r;   r=   r=   r>   test_subplots_dup_columns  s
    z4TestDataFramePlotsSubplots.test_subplots_dup_columnsc                 C   sZ   t tjddtdd}|jddd}|D ]$}t|dgd t|jd	ks0J q0d S )
Nr   r   r   r   Tr}   )r   r   r"   r   r   r   r=   r=   r>   %test_subplots_dup_columns_secondary_y  s
    z@TestDataFramePlotsSubplots.test_subplots_dup_columns_secondary_yc                 C   sf   t tjddtdd}|jdd}t|dgd d	 t|jd
ksNJ t|j	jdksbJ d S )Nr   r   r   r   r}   )r   z	a (right)rX   r"   r   )
r   r*   r+   r,   r-   r0   r	   r   r   Zright_ax)r8   r9   r;   r=   r=   r>   0test_subplots_dup_columns_secondary_y_no_subplot  s
    zKTestDataFramePlotsSubplots.test_subplots_dup_columns_secondary_y_no_subplotzWeird rounding problemsF)ry   strictc                 C   sZ   t g d}tdgd ttdddtdd}|jjddd	}t|j	
 | d S )
N)皙?r         $@d   r   rX   r   r   r   r   r   T)gridlog)r*   rf   r   r-   ranger0   r   r   assert_numpy_array_equalyaxisget_ticklocs)r8   rp   r9   r;   r=   r=   r>   test_bar_log_no_subplots  s    &z3TestDataFramePlotsSubplots.test_bar_log_no_subplotsc                 C   sf   t g d}ttddgtddggjjddd}t|d j	 | t|d j	 | d S )	N)r   r   r   g      Y@g     @@g     @   i,  i  T)r   r   r   r   )
r*   rf   r   r   r0   r   r   r   r   r   )r8   rp   r;   r=   r=   r>   test_bar_log_subplots  s    z0TestDataFramePlotsSubplots.test_bar_log_subplotsc                 C   s6   |}|j jdd}t|ts J t|d g dd d S )NTr   heightweightcategory)expected_keys)r0   box
isinstancer   r   )r8   hist_dfr9   ro   r=   r=   r>   )test_boxplot_subplots_return_type_default  s    
zDTestDataFramePlotsSubplots.test_boxplot_subplots_return_type_defaultrt)dictr:   Zbothc                 C   s,   |}|j j|dd}t||g ddd d S )NT)return_typer   r   F)r   Zcheck_ax_title)r0   r   r   )r8   r   r   r9   r   r=   r=   r>   !test_boxplot_subplots_return_type  s    z<TestDataFramePlotsSubplots.test_boxplot_subplots_return_typec                 C   s   t tjddtdddtdd}tjddd	d
\}}|j	d	|d}|D ]&}t
|jdksdJ t| d	d qNt|d  dd t|d jd	ddd t|d  d	d t|d jd	dd	d d S )Nr   r   r   r   r   r   ABr   r3   r   T)r   r   r%   r   Fr'   r   r*   r+   r,   r   r   r-   pltr   r0   r   r   r   r7   r5   r8   r9   r   r:   r;   r=   r=   r>   $test_df_subplots_patterns_minorticks  s    
z?TestDataFramePlotsSubplots.test_df_subplots_patterns_minorticksc                 C   s   t tjddtdddtdd}tdd\}}t	
t  |jd	|d	d
}W d    n1 sh0    Y  |D ]&}t|jdksJ t| d	d qvt|d  dd t|d jd	ddd t|d  d	d t|d jd	dd	d d S )Nr   r   r   r   r   r   r   r   T)r   r;   r   r%   r   Fr'   )r   r*   r+   r,   r   r   r-   r   r   r   r   r   r0   r   r   r   r7   r5   r   r=   r=   r>   2test_df_subplots_patterns_minorticks_1st_ax_hidden  s    
.zMTestDataFramePlotsSubplots.test_df_subplots_patterns_minorticks_1st_ax_hiddenc                 C   s   t tjddtdddtdd}tdd\}}|j	d	|d
}|D ]J}t
|jdks`J t| d	d t| d	d t|jd	dd	d qJd S )Nr   r   r   r   r   r   r   r   Tr   r%   r'   r   r   r=   r=   r>   /test_df_subplots_patterns_minorticks_not_shared  s    
zJTestDataFramePlotsSubplots.test_df_subplots_patterns_minorticks_not_sharedc                 C   s   t tjdd}tj|jdd df< tj|jd ddf< tjdd\}}|j	j
|ddd td	d
d}tddd}t|d  | t|d  | d S )Nr   r   rX   r   r   TF)r;   r   r   g      @r         ?      )r   r*   r+   r,   nanZilocr   r   r   r0   r   aranger   r   Z
get_xticks)r8   r9   r   ZaxsZexpected_ax1Zexpected_ax2r=   r=   r>   test_subplots_sharex_false  s    z5TestDataFramePlotsSubplots.test_subplots_sharex_falsec              	   C   s   t ddd}ttjdd|d}i }ttjjdr@d|d	< tjj	di |\}}t
d X |j|d
 d t
jdd}tj| W d    n1 s0    Y  W d    n1 s0    Y  d S )Nnowr   )rG   rI   r   r   r   Zget_constrained_layoutTZconstrained_layoutr   )r;   )Zreturn_filelike)r   )r   r   r*   r+   r,   hasattrr   r   ZFigurer   r   r   r0   Zensure_cleanZsavefig)r8   rL   r9   r   r   r:   pathr=   r=   r>    test_subplots_constrained_layout#  s    z;TestDataFramePlotsSubplots.test_subplots_constrained_layoutz index_name, old_label, new_label)N new)oldr   r   )Nr   r   )Nr   r   Nr   r   )r   r   r   c                    s   t ddgddggddgd}||j_|j|dd}td	d
 |D sHJ tfdd
|D sbJ |j|  dd}t fdd
|D sJ t fdd
|D sJ d S )Nr   r   rX   zType AzType Br   Tr   r   c                 s   s   | ]}|  d kV  qdS )r   N)
get_ylabel.0r;   r=   r=   r>   	<genexpr>D      zSTestDataFramePlotsSubplots.test_xlabel_ylabel_dataframe_subplots.<locals>.<genexpr>c                 3   s   | ]}|   kV  qd S N)
get_xlabelr   )	old_labelr=   r>   r   E  r   )r   ZylabelZxlabelr   c                 3   s   | ]}|  t kV  qd S r   )r   strr   	new_labelr=   r>   r   I  r   c                 3   s   | ]}|  t kV  qd S r   )r   r   r   r   r=   r>   r   J  r   )r   r   namer0   rl   )r8   r   Z
index_namer   r   r9   r:   r=   )r   r   r>   %test_xlabel_ylabel_dataframe_subplots0  s    z@TestDataFramePlotsSubplots.test_xlabel_ylabel_dataframe_subplotsr   r   T)r   stacked?)r   r   widthr   r   )r   r   r   edge)r   r   align)r   r   r   r  )r   r   r  )r   r   r   r  c                 C   s:   t dgd ttddtdd}| j|fi | d S )Nr   rX   r   r   )r   r-   r   _check_bar_alignmentr8   r   r9   r=   r=   r>   test_bar_align_multiple_columnsL  s    #$z:TestDataFramePlotsSubplots.test_bar_align_multiple_columnsc                 C   s,   t tjdd}| j|fi | d S )Nr   rX   r   r*   r+   r,   r   r  r  r=   r=   r>   test_bar_align_single_columnr  s    z7TestDataFramePlotsSubplots.test_bar_align_single_columnc                 C   s2   t tjdd}| j|fddd| d S )Nr   r   r   g?)r   positionr  r  r=   r=   r>   test_bar_barwidth_position  s    z5TestDataFramePlotsSubplots.test_bar_barwidth_positionwr   c                 C   s   t tjdd}|jjd|d}|j }t	
|tg d | dksVJ |jd  dkslJ |jd	  d
ksJ d S )Nr   r   T)r   r   )r   r   r   r   r   )g      g      @r   r   r)   g      @)r   r*   r+   r,   r   r0   r   r4   r   r   r   rf   get_xlimpatchesget_x)r8   r
  r9   r;   Zticksr=   r=   r>   test_bar_barwidth_position_int  s    
z9TestDataFramePlotsSubplots.test_bar_barwidth_position_intzkind, kwargsr   r   c                 C   s2   t tjdd}| j|f|dd| d S )Nr   r   r   )r   r   r  )r8   r   r   r9   r=   r=   r>   &test_bar_barwidth_position_int_width_1  s    zATestDataFramePlotsSubplots.test_bar_barwidth_position_int_width_1centerr   c              	   C   s8  |j ||||||dd}t|}|D ]}	|dkrn|	j}
|	 \}}tdd |	jD }tdd |	jD }nH|dkr|	j}
|	 \}}tdd |	jD }td	d |	jD }nt	t
||d
  t
||d
  |	jd }|dkr|du s|du r| }|| |  }n|dkrR|du rR| | t|j |  }| }n||dkr|du sp|du r| | |  }| }n@|dkr|du r| | t|j |  }| }nt	|
 tt|k sJ |dkrt
|
 d | q$|dkr.t
|
 d | q$t	q$|S )NT)r   r   r   r  r   r  r   r   c                 s   s   | ]}|  V  qd S r   )r  r   pr=   r=   r>   r     r   zBTestDataFramePlotsSubplots._check_bar_alignment.<locals>.<genexpr>c                 s   s   | ]}|  |  V  qd S r   )r  	get_widthr  r=   r=   r>   r     r   r   c                 s   s   | ]}|  V  qd S r   )get_yr  r=   r=   r>   r     r   c                 s   s   | ]}|  |  V  qd S r   )r  
get_heightr  r=   r=   r>   r     r   g      ?r   Fr  r  )r0   r   r4   r  minr  maxr   Zget_ylimr   r   Zassert_almost_equalr  r  r   r3   r  r  r   r*   r   rl   )r8   r9   r   r   r   r  r   r  r:   r;   ZaxisZax_minZax_maxZmin_edgeZmax_edger  r  r  r=   r=   r>   r    sZ    






 

z/TestDataFramePlotsSubplots._check_bar_alignment)r   FFr  r   r   )1__name__
__module____qualname__rt   markZslowZparametrizer?   rB   rC   rM   rQ   rq   rx   Zxfailr   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  r  r	  r  r  r  r=   r=   r=   r>   r   !   s>  	



2



	





















!










      r   )__doc__r.   numpyr*   rt   Zpandas.compatr   Zpandas.compat.numpyr   Zpandasrg   r   r   r   Zpandas._testingZ_testingr   Zpandas.tests.plotting.commonr   r   r	   r
   r   r   Zpandas.io.formats.printingr   Zimportorskipr   r   r   r=   r=   r=   r>   <module>   s    	

