a
    `>                     @   s   d dl Zd dlmZmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZmZ d dlmZ ddlmZ G d	d
 d
eZG dd deZG dd deZG dd deZdS )    N)SkipTestexpectedFailure)parameterized)	NdOverlayStore)CurveAreaScatterPointsPathHeatMap)ComparisonTestCase   )is_daskc                   @   s   e Zd Zdd Zedefdefgdd Zedefdefgdd Z	edefdefgd	d
 Z
edefdefgdd Zedefdefgdd Zedefdefgdd Zedefdefgdd Zdd Zdd ZdS )TestChart2Dc              
   C   s   zdd l }W n   tdY n0 dd l}|jddgddgddggd	d
gd| _|jg dg dg dgg dd| _||jdddddtt	ddtj
 d d| _d S )Nr   Pandas not available   r               xycolumnsr   r   Ar   r   Br   r   Cr   r   category1/1/2000x   Z1HUTC)periodsZfreqtz
   )timetemp)pandasr   hvplot.pandas	DataFramedfcat_df
date_rangenpZsinZlinspaceZpiZcumsumtime_dfselfpdhvplot r7   6lib/python3.9/site-packages/hvplot/tests/testcharts.pysetUp   s    &zTestChart2D.setUpZpointspathsc                 C   s*   | j j|d}| ||| j ddg d S )Nkindr   r   r.   r6   assertEqualr4   r<   elementplotr7   r7   r8   test_2d_defaults   s    zTestChart2D.test_2d_defaultsc                 C   s.   | j jdd|d}| ||| j ddg d S Nr   r   r   r   r<   r=   r?   r7   r7   r8   test_2d_chart!   s    zTestChart2D.test_2d_chartc                 C   s4   | j jddd|d}| ||| j ddgdg d S )Nindexr   r   )r   r   cr<   r=   r?   r7   r7   r8   test_2d_index_and_c&   s    zTestChart2D.test_2d_index_and_cc                 C   s6   | j jdddg|d}| ||| j ddgdg d S )Nr   r   r"   r   r   
hover_colsr<   r/   r6   r>   r?   r7   r7   r8   test_2d_set_hover_cols_to_list+   s    z*TestChart2D.test_2d_set_hover_cols_to_listc                 C   s`   | j jdddg|d}|dkr(|jd n|j}d|jv s<J | ||| j  ddgdg d S )Nr   r   rF   rI   r:   r   r/   r6   datar   r>   reset_indexr4   r<   r@   rA   rN   r7   r7   r8   &test_2d_set_hover_cols_including_index0   s    z2TestChart2D.test_2d_set_hover_cols_including_indexc                 C   s`   | j jddd|d}|dkr&|jd n|j}d|jv s:J | ||| j  ddgddg d S )	Nr   r   allrI   r:   r   rF   r"   rM   rP   r7   r7   r8   test_2d_set_hover_cols_to_all7   s    z)TestChart2D.test_2d_set_hover_cols_to_allc                 C   s6   | j jdddd|d}| ||| j ddgdg d S )Nr   r   rR   F)r   r   rJ   	use_indexr<   r"   rK   r?   r7   r7   r8   5test_2d_set_hover_cols_to_all_with_use_index_as_false>   s    zATestChart2D.test_2d_set_hover_cols_to_all_with_use_index_as_falsec                 C   s:   | j j }| |tddgg d| j jfddgd d S )Nr   r   )r   r   r   r   rF   value)r.   r6   heatmapr>   r   valuesr4   rA   r7   r7   r8   test_heatmap_2d_index_columnsC   s    z)TestChart2D.test_heatmap_2d_index_columnsc                 C   s:   | j jjdddd}|jddgks&J |jdgks6J d S )Nz	time.hourtime.dayr*   )r   r   r    )r2   r6   rW   kdimsvdimsrY   r7   r7   r8   test_heatmap_2d_derived_x_and_yH   s    z+TestChart2D.test_heatmap_2d_derived_x_and_yN)__name__
__module____qualname__r9   r   expandr
   r   rB   rE   rH   rL   rQ   rS   rU   rZ   r^   r7   r7   r7   r8   r      s"   






r   c                       s(   e Zd Z fddZedd Z  ZS )TestChart2DDaskc                    sd   t t|   zdd lm} W n   tdY n0 dd l}|j| jdd| _|j| j	dd| _	d S )Nr   Dask not availabler   Znpartitionsr   )
superrc   r9   dask.dataframe	dataframer   hvplot.daskfrom_pandasr.   r/   r4   ddr6   	__class__r7   r8   r9   P   s    zTestChart2DDask.setUpc                 C   s   | j j  d S )N)r.   r6   rW   r4   r7   r7   r8   rZ   Z   s    z-TestChart2DDask.test_heatmap_2d_index_columns)r_   r`   ra   r9   r   rZ   __classcell__r7   r7   rm   r8   rc   N   s   
rc   c                   @   s  e Zd Zdd Zedefdefdefgdd Z	dd	 Z
edefdefdefgd
d Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgdd Zedefdefdefgd d! Zedefdefdefgd"d# Zedefdefdefgd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zedefdefdefgd0d1 Zedefdefdefgd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"d:d; Z#d<d= Z$d>d? Z%d@dA Z&dBdC Z'dDdE Z(dFdG Z)dHS )ITestChart1Dc                 C   s   zdd l }W n   tdY n0 dd l}|jddgddgddggd	d
gd| _|jtjd|ddd| _	|jg dg dg dgg dd| _
|jddgddgddggddgd| _||jddddg d td!d"| _d S )#Nr   r   r   r   r   r   r   r   r   r   r   Z   z
2019-01-01z
2019-03-31)rF   r   r   r   r!   r   ar   br    rG   upperlowerr#   r(   r%   )r&   r'   )
r   r   r   r   r   r         	   r(   Z
abcdefghij)r)   r   r   )r+   r   r,   r-   r.   r1   ZrandomZrandr0   dt_dfr/   cat_only_dflistr2   r3   r7   r7   r8   r9   a   s$    & zTestChart1D.setUplineareascatterc                 C   sR   | j j|d}t|| j ddjdd|| j ddjdddd	}| || d S 
Nr;   rF   r   rV   r   r   r   r   r   Variabler.   r6   r   redimr>   r4   r<   r@   rA   objr7   r7   r8   test_wide_chartr   s    zTestChart1D.test_wide_chartc                 C   sF   | j jjdddd}tdd | j | j jjD d}| || d S )Nindex.dt.day0zindex.dt.monthbyc                 S   s*   i | ]"\}}|t |jj|d  fddqS )r   r   r   )r   rF   Zday).0mgr7   r7   r8   
<dictcomp>{   s   z9TestChart1D.test_by_datetime_accessor.<locals>.<dictcomp>)rz   r6   r}   r   groupbyrF   Zmonthr>   r4   rA   r   r7   r7   r8   test_by_datetime_accessory   s    z%TestChart1D.test_by_datetime_accessorc                 C   sV   | j j|ddd}t|| j ddjdd|| j ddjddd	d}| || d S )
NTestCategory)r<   value_labelgroup_labelrF   r   r   r   r   r   r   r   r7   r7   r8   test_wide_chart_labels   s    z"TestChart1D.test_wide_chart_labelsc                 C   s8   | j j|dddd}td|d}| |jd d d S )Nr   r   left)r<   r   r   legendbokehrA   legend_positionr.   r6   r   lookup_optionsr>   kwargsr4   r<   r@   rA   optsr7   r7   r8   test_wide_chart_legend_position   s    z+TestChart1D.test_wide_chart_legend_positionc                 C   s$   d| j j_| | j  jdg d S )NzMy Name)r.   r   namer>   r6   r\   )r4   r<   r@   r7   r7   r8    test_wide_chart_auto_group_label   s    
z,TestChart1D.test_wide_chart_auto_group_labelc                 C   s,   | j jdd|d}| ||| j dd d S rC   r=   r?   r7   r7   r8   test_tidy_chart   s    zTestChart1D.test_tidy_chartc                 C   s,   | j jdd|d}| ||| j dd d S )NrF   r   rD   r=   r?   r7   r7   r8   test_tidy_chart_index   s    z!TestChart1D.test_tidy_chart_indexc                 C   sx   | j jddd|d}t|| j | j jdk dd|| j | j jdk dd|| j | j jdk dddd}| || d S )	NrF   r   r   )r   r   r   r<   r   r   r   )r   r   r   )r.   r6   r   r   r>   r   r7   r7   r8   test_tidy_chart_index_by   s    z$TestChart1D.test_tidy_chart_index_byc                 C   s:   | j jddd|dd}td|d}| |jd d d S )	NrF   r   r   r   )r   r   r   r<   r   r   rA   r   r   r   r7   r7   r8   (test_tidy_chart_index_by_legend_position   s    z4TestChart1D.test_tidy_chart_index_by_legend_positionc                 C   s4   | j jd|d}| |jdg | |jdg d S )NF)rT   r<   r   r   )r.   r6   r>   r\   r]   r?   r7   r7   r8   'test_use_index_disabled_uses_first_cols   s    z3TestChart1D.test_use_index_disabled_uses_first_colsc                 C   sJ   | j jdd|ddd}td|dj}| |d d | |d	 d d S )
Nr   r   r   r   r   r(   )r   r   r<   xlimylimr   rA   r   r   )r.   r6   r   r   optionsr>   r   r7   r7   r8   test_tidy_chart_ranges   s    z"TestChart1D.test_tidy_chart_rangesc                 C   sH   | j j|ddd}td|jdj}| |d d | |d d d S )Nr   r   )r<   r   r   r   rA   r   r   )r.   r6   r   r   Zlastr   r>   r   r7   r7   r8   test_wide_chart_ranges   s    z"TestChart1D.test_wide_chart_rangesc                 C   s4   | j jdd|dgd}| ||| j dddg d S )Nr   r   r"   r   r   r<   rJ   rK   r?   r7   r7   r8   test_tidy_chart_with_hover_cols   s    z+TestChart1D.test_tidy_chart_with_hover_colsc                 C   s<   | j jdd|dgd}| j  }| |||dddg d S )Nr   r   rF   r   )r.   r6   rO   r>   r4   r<   r@   rA   
altered_dfr7   r7   r8   (test_tidy_chart_with_index_in_hover_cols   s    
z4TestChart1D.test_tidy_chart_with_index_in_hover_colsc                 C   s:   | j jdd|dd}| j  }| |||dg d d S )Nr   r   rR   r   )r   rF   r"   )r/   r6   rO   r>   r   r7   r7   r8   &test_tidy_chart_with_hover_cols_as_all   s    
z2TestChart1D.test_tidy_chart_with_hover_cols_as_allc                 C   s4   | j jdd|ddd}| ||| j dddg d S )Nr   r   rR   F)r   r   r<   rJ   rT   r"   rK   r?   r7   r7   r8   >test_tidy_chart_with_hover_cols_as_all_with_use_index_as_false   s    zJTestChart1D.test_tidy_chart_with_hover_cols_as_all_with_use_index_as_falsec                 C   sZ   | j jjdd}tt| j ddjddt| j ddjddd	d
}| |t| d S )NT)ZstackedrF   r   rV   r   r   r   r   r   )r.   r6   r~   r   r   r   r>   stackr   r7   r7   r8   test_area_stacked   s    zTestChart1D.test_area_stackedc                 C   sl   t | jd r| jd  }n
| jd }| jjjdd|d}| jj|d}|jjdddd}| || d S )Nr   r   )rG   )_colorr   )r   r.   computer6   r   Zassignr>   )r4   r   actualr   Zexpectedr7   r7   r8    test_scatter_color_set_to_series   s    
z,TestChart1D.test_scatter_color_set_to_seriesc                 C   sp   t | jd r| jd  }n
| jd }| jjjdd|d}td|d}d|jjv sZJ | 	|j
d d d S )Nr   r   )sr   Zstyle_sizesize)r   r.   r   r6   r   r   r   rN   r   r>   r   )r4   r   rA   r   r7   r7   r8   test_scatter_size_set_to_series   s    
z+TestChart1D.test_scatter_size_set_to_seriesc                 C   s:   | j jjddddd}td|d}| |jd d d S )	Nr   r   r"   r   )rG   r   r   rA   r   )r/   r6   r   r   r   r>   r   r4   rA   r   r7   r7   r8   %test_scatter_color_by_legend_position   s    z1TestChart1D.test_scatter_color_by_legend_positionc                 C   s8   | j jjdddd}td|d}| |jd d d S )Nr   r"   r   )r   r   r   rA   r   )r/   r6   Zhistr   r   r>   r   r   r7   r7   r8   *test_histogram_by_category_legend_position   s    z6TestChart1D.test_histogram_by_category_legend_positionc                 C   sR   | j j|d}t|| j ddjdd|| j ddjdddd	}| || d S r   )r/   r6   r   r   r>   r   r7   r7   r8   test_only_includes_num_chart   s    z(TestChart1D.test_only_includes_num_chartc                 C   sR   | j j|d}t|| j ddjdd|| j ddjdddd	}| || d S )
Nr;   rF   ru   rV   )ru   rv   )rv   )ru   rv   r   )r{   r6   r   r   r>   r   r7   r7   r8   !test_includes_str_if_no_num_chart   s    z-TestChart1D.test_includes_str_if_no_num_chartc                 C   sV   | j jdd}|jdd}|j| j k  s2J t|jj t|jjksRJ d S )Nr   Zfracr)   r   r2   sampler6   rN   rR   lenr)   uniquer4   	scrambledrA   r7   r7   r8   test_time_df_sorts_on_plot  s    z&TestChart1D.test_time_df_sorts_on_plotc                 C   sV   | j jdd}|jddd}|j|k  s2J t|jj t|jjksRJ d S )Nr   r   r)   F)r   	sort_dater   r   r7   r7   r8   3test_time_df_does_not_sort_on_plot_if_sort_date_off  s    z?TestChart1D.test_time_df_does_not_sort_on_plot_if_sort_date_offc                 C   s\   | j d}|jdd}| }|jd |jk s8J t|jj	 t|jjksXJ d S )Nr)   r   r   )
r2   	set_indexr   r6   rN   rF   rR   r   r)   r   r4   r.   r   rA   r7   r7   r8   +test_time_df_sorts_on_plot_using_index_as_x  s
    z7TestChart1D.test_time_df_sorts_on_plot_using_index_as_xc                 C   sb   | j d}|jdd}|jdd}|jj|jk  s>J t|jj	 t|jjks^J d S )Nr)   r   r   F)r   )
r2   r   r   r6   rN   r)   rF   rR   r   r   r   r7   r7   r8   Dtest_time_df_does_not_sort_on_plot_if_sort_date_off_using_index_as_x  s
    zPTestChart1D.test_time_df_does_not_sort_on_plot_if_sort_date_off_using_index_as_xc                 C   sD   | j jddd}t| g dks(J t| g dks@J d S )Ntime.dayofweekF)r   dynamic)r   r   r   r   r   r   r   )r   rF   r   r2   r6   r|   keys
dimensionsrY   r7   r7   r8   -test_time_df_with_groupby_as_derived_datetime!  s    z9TestChart1D.test_time_df_with_groupby_as_derived_datetimec                 C   sB   | j jddd}t| dgks&J t| g dks>J d S )N
time.monthF)r   r   r   )r   rF   r   r   rY   r7   r7   r8   (test_time_df_with_by_as_derived_datetime&  s    z4TestChart1D.test_time_df_with_by_as_derived_datetimec                 C   s.   | j jjddd}t| ddgks*J d S )Nr[   Fr   r   r   )r2   r6   r   r|   r   rY   r7   r7   r8   'test_time_df_with_x_as_derived_datetime+  s    z3TestChart1D.test_time_df_with_x_as_derived_datetimec                 C   s8   | j d}|jjddd}t| ddgks4J d S )Nr)   r[   Fr   r   r2   r   r6   r   r|   r   r4   ZindexedrA   r7   r7   r8   ;test_time_df_as_index_with_x_as_derived_datetime_using_name/  s    zGTestChart1D.test_time_df_as_index_with_x_as_derived_datetime_using_namec                 C   s8   | j d}|jjddd}t| ddgks4J d S )Nr)   z	index.dayFr   r   r   r   r7   r7   r8   <test_time_df_as_index_with_x_as_derived_datetime_using_index4  s    zHTestChart1D.test_time_df_as_index_with_x_as_derived_datetime_using_indexc                 C   sL   | j jjdd}|jdgks J |d jdgks4J |d jdgksHJ d S )Nr   r   r   rF   r   )r/   r6   r   r\   r]   rY   r7   r7   r8   test_default_y_not_in_by9  s    z$TestChart1D.test_default_y_not_in_byN)*r_   r`   ra   r9   r   rb   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   r7   r7   r7   r8   rq   _   sf   


















rq   c                       s$   e Zd Z fddZdd Z  ZS )TestChart1DDaskc                    s   t t|   zdd lm} W n   tdY n0 dd l}|j| jdd| _|j| j	dd| _	|j| j
dd| _
|j| jdd| _d S )Nr   rd   r   re   r   r   )rf   r   r9   rg   rh   r   ri   rj   r.   rz   r/   r{   rk   rm   r7   r8   r9   B  s    zTestChart1DDask.setUpc                 C   s   t dd S )Nz0Can't expand dt accessor columns when using dask)r   ro   r7   r7   r8   r   N  s    z)TestChart1DDask.test_by_datetime_accessor)r_   r`   ra   r9   r   rp   r7   r7   rm   r8   r   @  s   r   )Znumpyr1   Zunittestr   r   r   Z	holoviewsr   r   Zholoviews.elementr   r   r	   r
   r   r   Zholoviews.element.comparisonr   utilr   r   rc   rq   r   r7   r7   r7   r8   <module>   s    A b