o
    ds                     @   s   d Z ddlZddlZddlZddlm  mZ ddl	m
Z
mZmZmZ ddlmZ ddlmZmZ ejdd ZejG dd deZejG d	d
 d
eZejG dd deZdS )z Test cases for .hist method     N)	DataFrameIndexSeriesto_datetime)TestPlotBase_check_plot_worksc                   C   s   t jddS )Ntsname)tmmakeTimeSeries r   r   k/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/plotting/test_hist_method.pyr      s   r   c                   @   s   e Zd Zdd Zdd Zdd Zejjdd Z	d	d
 Z
dd Zdd Z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dd Zejjdd ejd!d" Zejd#d$ ZdS )%TestSeriesPlotsc                 C   sv  t |j t |jdd t |jdd tjtdd t |j|jjd W d    n1 s.w   Y  tjtdd t |j|jjdd W d    n1 sOw   Y  | jd	d	\}}t |j|d
d t |j||d
d t |j|d
d t	  | jd	d\}\}}t |j||d
d t |j||d
d d}t
jt|d |j|j|d W d    d S 1 sw   Y  d S )NFgrid   
   figsizecheck_stacklevelby   )r   bins   T)axdefault_axes)r   figurer   )r    r      )r    r   r   z`Cannot pass 'figure' when using the 'by' argument, since a new 'Figure' instance will be createdmatch)r   r    )r   histr   assert_produces_warningUserWarningindexmonthpltsubplotsclosepytestraises
ValueError)selfr   figr   ax1ax2msgr   r   r   test_hist_legacy   s,   
"z TestSeriesPlots.test_hist_legacyc                 C   s<   t tjdd}|jddd d }t|jdksJ d S )Nr   r!   r   r   )r   nprandomrandnr$   lenpatches)r/   dfr   r   r   r   test_hist_bins_legacy8   s   z%TestSeriesPlots.test_hist_bins_legacyc                 C   s   |}d}t jt|d |jjdd W d    n1 sw   Y  t jt|d |jjddgd W d    d S 1 s>w   Y  d S )Nz7The 'layout' keyword is not supported when 'by' is Noner"   r   r   layoutr   )r,   r-   r.   heightr$   )r/   hist_dfr;   r3   r   r   r   test_hist_layout=   s   "z TestSeriesPlots.test_hist_layoutc                 C   sn  |}t jtdd t|jj|jdd}W d    n1 sw   Y  | j|ddd t jtdd t|jj|jdd}W d    n1 sGw   Y  | j|ddd t jtdd t|jj|jd	d}W d    n1 spw   Y  | j|d
d	d t jtdd t|jj|jdd}W d    n1 sw   Y  | j|d
dd t jtdd t|jj|jdd}W d    n1 sw   Y  | j|d
dd t jtdd t|jj|jdd}W d    n1 sw   Y  | j|d
dd t jtdd t|jj|j	dd}W d    n	1 sw   Y  | j|ddd |jj|jddd}| j|d
ddd d S )NFr   r!   r   r   r?   r!   axes_numr?   )   )rG   r      r   rJ   r!   rH   r!   r!   )rG   r!   rH   rJ   r   rJ   rG   rJ   r!   )      )r   r?   r   rF   r?   r   )
r   r%   r&   r   r@   r$   gender_check_axes_shapecategory	classroomr/   rA   r;   axesr   r   r   test_hist_layout_with_byF   s>   z(TestSeriesPlots.test_hist_layout_with_byc                 C   sp   ddl m}m} ttjd}ttjd}|d |  |d |  | }|j}t	|dks6J d S )Nr   )gcfsubplotr!   y   z   )
matplotlib.pyplotrZ   r[   r   r6   r7   r8   r$   rX   r9   )r/   rZ   r[   xyr0   rX   r   r   r   test_hist_no_overlapl   s   z$TestSeriesPlots.test_hist_no_overlapc                 C   s.   |}|j j|jd}t| j dksJ d S )Nr   r   )r@   r$   rS   r9   r)   get_fignumsrW   r   r   r   test_hist_by_no_extra_plots|   s   z+TestSeriesPlots.test_hist_by_no_extra_plotsc                 C   sh   ddl m} | }| }|d}d}tjt|d |j||d W d    d S 1 s-w   Y  d S )Nr   )r    o   z&passed axis not bound to passed figurer"   )r   r    )pylabr    add_subplotr,   r-   AssertionErrorr$   )r/   r   r    fig1fig2r1   r3   r   r   r   +test_plot_fails_when_ax_differs_from_figure   s   
"z;TestSeriesPlots.test_plot_fails_when_ax_differs_from_figurehisttype, expected)barT)
barstackedT)stepF)
stepfilledTc                 C   s0   t tjdd}|j|d}| j||d d S )Nr   r   histtypefilled)r   r6   r7   randintr$   _check_patches_all_filled)r/   rr   expectedserr   r   r   r   test_histtype_argument   s   z&TestSeriesPlots.test_histtype_argumentz&by, expected_axes_num, expected_layout)Nr   r=   )br!   )r   r!   c                 C   sd   ddg ddg  }t tjd|dd}d|j_t|jdd|d	}| j|||d
 | 	|d d S )N   12   ar'   r
   rz   T)r   legendr   rE   )
r   r6   r7   r8   r'   r
   r   r$   rT   _check_legend_labels)r/   r   expected_axes_numexpected_layoutr'   srX   r   r   r   test_hist_with_legend   s   z%TestSeriesPlots.test_hist_with_legendr   Nrz   c                 C   sv   ddg ddg  }t tjd|dd}d|j_tjtdd	 |j	d
|dd W d    d S 1 s4w   Y  d S )Nr{   r|   r}   r~   r   r   rz    Cannot use both legend and labelr"   Tc)r   r   label)
r   r6   r7   r8   r'   r
   r,   r-   r.   r$   )r/   r   r'   r   r   r   r   test_hist_with_legend_raises   s   "z,TestSeriesPlots.test_hist_with_legend_raisesc                 C   s   | j  \}}|jjd|d}t|jdksJ | |j d t	
  | j  \}}|jjd|d}| |j d t	
  | j  \}}|jjdd|d}t	
  d S )	Nr   r   r   	Frequency
horizontal)orientationr   leftT)alignstackedr   )r)   r*   plotr$   r9   r:   _check_text_labelsyaxis	get_labelr   r+   xaxis)r/   r   _r   r   r   r   test_hist_kwargs   s   z TestSeriesPlots.test_hist_kwargszApi changed in 3.6.0)reasonc                 C   s   | j  \}}|jjd|d}| j|dd | }| |dgt|  | }| |dgt|  t	|jj
 t	|jj | j  \}}|jj
d|d}| j|dd | }| |dgt|  | }| |dgt|  d S )NT)logyr   logr    )r)   r*   r   r$   _check_ax_scalesget_xticklabelsr   r9   get_yticklabelsr   kdedensity)r/   r   r   r   xlabelsylabelsr   r   r   test_hist_kde   s    zTestSeriesPlots.test_hist_kdec                 C   s   | j  \}}|jjddd|d}| j|dd t|jdks!J | j|jdgd d | j  \}}|jjdd|d	}| j|dd |	 }t|d
ksOJ | |dg d S )NTr   rz   )r   r   colorr   r   r   )
facecolorsr)r   r   r   r   )
r)   r*   r   r$   r   r9   r:   _check_colorsr   	get_lines)r/   r   r   r   linesr   r   r   test_hist_kde_color   s   z#TestSeriesPlots.test_hist_kde_color)__name__
__module____qualname__r4   r<   rB   r,   markslowrY   ra   rc   rj   parametrizery   r   r   r   xfailtdskip_if_no_scipyr   r   r   r   r   r   r      s4    	
%

	

	r   c                   @   s  e Zd Zejjdd Zdd Zdd Zdd Z	d	d
 Z
ejddg dfg dg dfgdd Zejdg ddd Zejdddgejdddgdd Zejdddgejdddgdd Zdd Zdd  Zd!d" Zejd#d$ ZdS )%TestDataFramePlotsc                    sN  ddl m  tjtdd t|j W d    n1 sw   Y  ttj	
dd}ttj	jdddtjd	|d< tjtdd t|jdd
}W d    n1 sSw   Y  | j|ddd |d  rhJ t|dg j ttj	
dd}t|j ttj	
dd}ttj	jdddtjd	|d< tjtdd t|jdd}W d    n1 sw   Y  | j|ddd tjtdd t|jddd W d    n1 sw   Y  tjtdd t|jdd W d    n1 sw   Y  tjtdd t|jdd W d    n	1 sw   Y  |d }d\}}d\}}|j||||d}| j|||||d d\}}d\}}|j||||d}| j|||||d t  |jdddd}	 fdd|	 D }
t|
d   d! t  |jdd"}	| j|	d#d$ t  tt |jd%d& W d    d S 1 sw   Y  d S )'Nr   	RectangleFr   d   r!        j+2Z     ReZsizedtyper   rG   rL   rE   r=   r   r   rO   r>      T)sharexshareyr   r   r5         r~   (   
xlabelsizexrot
ylabelsizeyrotrJ   )
cumulativer   r   c                       g | ]	}t | r|qS r   
isinstance.0r_   r   r   r   
<listcomp>2      z:TestDataFramePlots.test_hist_df_legacy.<locals>.<listcomp>rH         ?)r   r   r   rm   )foo)matplotlib.patchesr   r   r%   r&   r   r$   r   r6   r7   r8   r   ru   int64rT   get_visible_check_ticks_propsr+   get_childrenassert_almost_equal
get_heightr   external_error_raisedAttributeError)r/   rA   r;   rX   rx   xfyfr   r   r   rectsr   r   r   test_hist_df_legacy   s   


$z&TestDataFramePlots.test_hist_df_legacyc                 C   s   t tjdtjdddttjjdddtjdttjjdddtjdddd}|t}d	}t	j
t|d
 |  W d    d S 1 sIw   Y  d S )Nr   r   l     p/ l    @spc/ )r   T)utc)r   rz   r   dzDhist method requires numerical or datetime columns, nothing to plot.r"   )r   r6   r7   randru   r   r   astypeobjectr,   r-   r.   r$   )r/   r;   df_or3   r   r   r   *test_hist_non_numerical_or_datetime_raises@  s*   




"z=TestDataFramePlots.test_hist_non_numerical_or_datetime_raisesc                 C   st  t tjdd}ttjjdddtjd|d< d ddddddddd	d	dd
d
ddd	ddddddddddf	}|D ]}|j|d d}|d }| j|d|d q@d}t	j
t|d |jdd W d    n1 sqw   Y  td}t	j
t|d |jdd W d    n1 sw   Y  d}t	j
t|d |jdd W d    d S 1 sw   Y  d S )Nr   r!   r   r   r   rL   )r?   expected_sizerI   rN   )rG   rG   rM   )rJ   rH   )rH   r!   rK   r?   r>   r   rG   rE   z1Layout of 1x1 must be larger than required size 3r"   r=   z)Layout must be a tuple of (rows, columns))r   1At least one dimension of layout must be positiverH   rH   )r   r6   r7   r8   r   ru   r   r$   rT   r,   r-   r.   reescape)r/   r;   layout_to_expected_sizelayout_testrX   rw   r3   r   r   r   rB   Y  sF   

"z#TestDataFramePlots.test_hist_layoutc                 C   sT   t tjdd}ttjjdddtjd|d< t|jdd | j	
  t  d S )Nr   r!   r   r   r   T)r   )r   r6   r7   r8   r   ru   r   r   r$   r)   tight_layoutr   r+   )r/   r;   r   r   r   test_tight_layout  s   	
z$TestDataFramePlots.test_tight_layoutc                 C   s>   t g dg dd}t|jdddddd	}| j|dd
 d S )Ng      ?      ?g333333??rG   )pigrabbitr   r   r   )lengthanimalTr   r   r   r   )r   columnr   r   r   r   )r   r   r$   r   )r/   r;   rX   r   r   r   test_hist_subplot_xrot  s   z)TestDataFramePlots.test_hist_subplot_xrotzcolumn, expectedNwidthr   r@   )r   r   r@   c                    s\   t g dg dg ddg dd}t|jd|dd	  fd
dtdD }||ks,J d S )N)ffffff?皙?g333333?r   g?r   )rG   r   g333333@r!   r   r   )r   r   duckchickenhorse)r'   Tr   rG   )r   r   r?   c                    s   g | ]
} d |f   qS )r   )	get_title)r   irX   r   r   r     s    zGTestDataFramePlots.test_hist_column_order_unchanged.<locals>.<listcomp>rG   )r   r   r$   range)r/   r   rw   r;   resultr   r  r    test_hist_column_order_unchanged  s   

z3TestDataFramePlots.test_hist_column_order_unchangedrk   rl   c                 C   s<   t tjjddddddgd}|j|d}| j||d	 d S )
Nr   r   r   r!   r   r   rz   columnsrq   rs   r   r6   r7   ru   r$   rv   r/   rr   rw   r;   r   r   r   r   ry     s   z)TestDataFramePlots.test_histtype_argumentr   r   r   rz   c                 C   s   |d u r
|d ur
dnd}d|f}|pddg}|d ur|gd }t ddg ddg  dd	}ttjd
d|ddgd}t|jdd||d}| j|||d |d u rY|d u rY|d }t||D ]
\}	}
| 	|
|	 q^d S )Nr   r!   r   rz   r{   r|   r}   r   r	   r~   r'   r  T)r   r   r   r   rE   r   )
r   r   r6   r7   r8   r   r$   rT   zipr   )r/   r   r   r   r   expected_labelsr'   r;   rX   expected_labelr   r   r   r   r     s(   
z(TestDataFramePlots.test_hist_with_legendc                 C   s~   t ddg ddg  dd}ttjdd|dd	gd
}tjtdd |jd||dd W d    d S 1 s8w   Y  d S )Nr{   r|   r}   r   r	   r~   r!   r   rz   r  r   r"   Tr   )r   r   r   r   )	r   r   r6   r7   r8   r,   r-   r.   r$   )r/   r   r   r'   r;   r   r   r   r     s
   "z/TestDataFramePlots.test_hist_with_legend_raisesc                 C   sF   t tjdd}| j \}}|jjd|d}t|j	dks!J d S )Nr   r!   r   r   )
r   r6   r7   r8   r)   r*   r   r$   r9   r:   r/   r;   r   r   r   r   r   test_hist_df_kwargs  s   z&TestDataFramePlots.test_hist_df_kwargsc                 C   s   t tjdddg dd}ddgd |d	< | j \}}|jjd|d
}t	|j
dks0J | j \}}|jj|d}t	|j
dksGJ d S )N*   r   rJ   )ABCDr  r_   r`   r   Er   r   )r   r   )r   r6   r7   RandomStater8   r)   r*   r   r$   r9   r:   r  r   r   r   test_hist_df_with_nonnumerics  s   z0TestDataFramePlots.test_hist_df_with_nonnumericsc                 C   s  t tjddtdd}| j \}}|d jjd|d}|d jj|ddd	 | j	|dd
gd |
  s:J |j
  sCJ t  | j \}}|d jjdd|d}|d jj|ddd	 | j	|jdd
gd |j
  rwJ |
  sJ t  | j \}}|d jjdd|d}|d jj|dd | j	|jddgd |j
  sJ |
  sJ t  d S )Nr~   rJ   abcdr  r   T)r   r   rz   )r   r   secondary_yz	b (right))labels)r   r   r   z	a (right))r   r   )r   r6   r7   r8   listr)   r*   r   r$   r   	get_yaxisr   right_axr   r+   left_axr  r   r   r   test_hist_secondary_legend  s,   z-TestDataFramePlots.test_hist_secondary_legendc                    s  t tjddgdtjtjgg dgtdd}tg d}t g dg dgtdd}tg d	g d
g}ddlm  | j \}}|j	j
||d  fdd| D }dd |D }| j \}}	|j	j
|	|d  fdd|	 D }
dd |
D }tdd t||D sJ tddgddgg}d}tjt|d | j \}}|j	j
||d W d    d S 1 sw   Y  d S )Nr   333333?皙?)r   g?r   abcr  )      ?r'  ?)r(  r   r'  )r'  r*  r*  )r+  r+  r+  r   r   )r   weightsc                    r   r   r   r   r   r   r   r   A  r   zFTestDataFramePlots.test_hist_with_nans_and_weights.<locals>.<listcomp>c                 S      g | ]}|  qS r   r   r   rectr   r   r   r   B      c                    r   r   r   r   r   r   r   r   E  r   c                 S   r-  r   r.  r/  r   r   r   r   F  r1  c                 s   s    | ]	\}}||kV  qd S )Nr   )r   h0h1r   r   r   	<genexpr>G  s    zETestDataFramePlots.test_hist_with_nans_and_weights.<locals>.<genexpr>r*  r+  z?weights must have the same shape as data, or be a single columnr"   )r   r6   nanr"  arrayr   r   r)   r*   r   r$   r   allr  r,   r-   r.   )r/   r;   r,  	no_nan_dfno_nan_weightsr   ax0r   heightsr1   no_nan_rectsno_nan_heightsidxerror_weightsr3   r2   r   r   r   test_hist_with_nans_and_weights2  s.   "z2TestDataFramePlots.test_hist_with_nans_and_weights)r   r   r   r,   r   r   r   r   rB   r   r   r   r
  ry   r   r   r  r  r&  r   skip_if_no_mplr?  r   r   r   r   r      s<    
U*


	&r   c                   @   sf   e Zd Zdd Zdd Zejjdd Zdd Z	d	d
 Z
dd Zdd Zejdg ddd ZdS )TestDataFrameGroupByPlotsc                    s$  ddl m  ddlm} ttjdddgd}ttjj	dd	dtj
d
|d< tj	ddd|d< dgd |d< ||j|jd}| j|ddd t  |j|jd}| j|ddd t  |jddd}| j|ddd | j|dd t  d\}}d\}}||j|jdd||||dd	}| D ]} fdd| D }	|	d  }
t|
d q| j|||||d t  ||j|jdd }| j|d!d" t  tt ||j|jd#d$ W d    n1 sw   Y  d%}tjt|d& |jdd'd( W d    d S 1 sw   Y  d S ))Nr   r   )_grouped_histi  r   r  r  r   r   r   r  rJ   r  Xr  r   rL   rE   r~   )r   rotr=   r   r   r   T)r   r   r   r   r   r   r   r   c                    r   r   r   r   r   r   r   r     r   zFTestDataFrameGroupByPlots.test_grouped_hist_legacy.<locals>.<listcomp>rH   r   r   )r   r   r   r   rm   )r   r   z$Specify figure size by tuple insteadr"   default)r   r   )r   r    pandas.plotting._matplotlib.histrB  r   r6   r7   r8   r   ru   r   r  r  rT   r   r+   r$   r   ravelr   r   r   r   r   r   r,   r-   r.   )r/   rB  r;   rX   r   r   r   r   r   r   r@   r3   r   r   r   test_grouped_hist_legacyS  sl   
$z2TestDataFrameGroupByPlots.test_grouped_hist_legacyc                 C   s   d}t tjjdd|d}t tjjdd|d}tjdjddg|d}t|||d	}|d
}| }t	|dks>J t	| j
 dksIJ t  d S )Nr      r   r  <   r  r   r   )r@   weightrS   rS   r!   )r   r6   r7   normalr  choicer   groupbyr$   r9   r)   rb   r   r+   )r/   nrK  r@   
gender_intdf_intgbrX   r   r   r   test_grouped_hist_legacy2  s   
z3TestDataFrameGroupByPlots.test_grouped_hist_legacy2c                 C   s  |}d}t jt|d |jd|jdd W d    n1 sw   Y  d}t jt|d |jd|jdd W d    n1 sAw   Y  d	}t jt|d |jd|jd
d W d    n1 scw   Y  tjtdd t	|jd|jdd}W d    n1 sw   Y  | j
|ddd tjtdd t	|jd|jdd}W d    n1 sw   Y  | j
|ddd |jd|jdd}| j
|ddd |jd|jdd}| j
|ddd |jd|jddd}| j
|dddd t  tjtdd t	|jdddd}W d    n	1 sw   Y  | j
|ddd tjtdd t	|jdd}W d    n	1 s6w   Y  | j
|ddd |jddd}| j
|ddd |jg dd }| j
|ddd d S )!Nz1Layout of 1x1 must be larger than required size 2r"   rK  r=   )r   r   r?   z1Layout of 1x3 must be larger than required size 4r@   r  r   r   Fr   rC   r!   rE   rK   rI   rJ   )rH   r   rO   )rP   r   )r   r   r?   r   rR   rV   rL   rG   r   rS   )rG   r   rD   r@   rK  rU   )r   )r,   r-   r.   r$   rS   rU   r   r%   r&   r   rT   r+   )r/   rA   r;   r3   rX   r   r   r   test_grouped_hist_layout  s\   
z2TestDataFrameGroupByPlots.test_grouped_hist_layoutc                 C   s   |}| j dd\}}|jg d|d d}| j|ddd t||d  |d j|u s/J |jd|d	 d
}| j|ddd t||d	  |d j|u sQJ | j dd\}}d}tjt	|d |jd|d}W d    d S 1 svw   Y  d S )Nr!   rG   rT  r   )r   r   r  rE   rV   r   )r   r   z@The number of passed axes must be 1, the same as the output plotr"   r@   )
r)   r*   r$   rT   r   assert_numpy_array_equalr    r,   r-   r.   )r/   rA   r;   r0   rX   returnedr3   r   r   r   test_grouped_hist_multiple_axes  s   "z9TestDataFrameGroupByPlots.test_grouped_hist_multiple_axesc                 C   v   |}|j d|jdd\}}| |||sJ | |||s#J | |||r.J | |||r9J d S )Nr@   T)r   r   r   r$   rS   
get_x_axisjoined
get_y_axisr/   rA   r;   r1   r2   r   r   r   test_axis_share_x  s   z+TestDataFrameGroupByPlots.test_axis_share_xc                 C   rY  )Nr@   T)r   r   r   )r$   rS   r]  r\  r[  r^  r   r   r   test_axis_share_y  s   z+TestDataFrameGroupByPlots.test_axis_share_yc                 C   sx   |}|j d|jddd\}}| |||sJ | |||s$J | |||s/J | |||s:J d S )Nr@   T)r   r   r   r   rZ  r^  r   r   r   test_axis_share_xy  s   z,TestDataFrameGroupByPlots.test_axis_share_xyrk   rl   c                 C   s>   t tjjddddddgd}|jd|d}| j||d	 d S )
Nr   r   r  r  r   rz   r  )r   rr   rs   r  r  r   r   r   ry     s   z0TestDataFrameGroupByPlots.test_histtype_argumentN)r   r   r   rH  rS  r,   r   r   rU  rX  r_  r`  ra  r   ry   r   r   r   r   rA  Q  s    E
6	rA  )__doc__r   numpyr6   r,   pandas.util._test_decoratorsutil_test_decoratorsr   pandasr   r   r   r   pandas._testing_testingr   pandas.tests.plotting.commonr   r   fixturer   r@  r   r   rA  r   r   r   r   <module>   s&    
 M  j