a
    `                     @   sd   d Z ddlZddlZddlmZ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dS )z2
Tests  utilities to convert data and projections
    N)TestCaseSkipTest)process_xarrayc                   @   sl   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )TestProcessXarrayc                 C   sX   zdd l }dd l}W n   tdY n0 dd dddd d d d g d
| _|jd| _d S )Nr   zxarray or pandas not availablevalueF)
Zvalue_labelZlabelgriddedZpersistZuse_daskgroupbyyxbyZ
other_dimsZair_temperature)xarraypandasr   default_kwargsZtutorialZopen_datasetds)selfxrpd r   4lib/python3.9/site-packages/hvplot/tests/testutil.pysetUp   s"    zTestProcessXarray.setUpc           	      C   s|   dd l }dd l}|jg dd}tf d|i| j\}}}}}t||jsNJ |dksZJ |dgkshJ |rpJ |rxJ d S )Nr            )datar   indexr   r   r   	DataArrayr   r   
isinstance	DataFrame	r   r   r   dar   r
   r	   r   r   r   r   r   /test_process_1d_xarray_dataarray_with_no_coords#   s    zATestProcessXarray.test_process_1d_xarray_dataarray_with_no_coordsc           	      C   s   dd l }dd l}|jg ddg didgd}tf d|i| j\}}}}}t||js\J |dkshJ |dgksvJ |r~J |rJ d S )Nr   r   day         r   coordsdimsr   r   r   r    r   r   r   ,test_process_1d_xarray_dataarray_with_coords1   s    
z>TestProcessXarray.test_process_1d_xarray_dataarray_with_coordsc           	      C   s   dd l }dd l}|jg ddg didgdd}tf d|i| j\}}}}}t||js^J |dksjJ |dgksxJ |rJ |rJ d S )Nr   r   r#   r$   Ztemp)r   r)   r*   namer   r   r    r   r   r   5test_process_1d_xarray_dataarray_with_coords_and_nameA   s    
zGTestProcessXarray.test_process_1d_xarray_dataarray_with_coords_and_namec           	      C   s   dd l }dd l}|tjdd}tf d|i| j\}}}}}t||j	sRJ |dks^J |dgkslJ |rtJ |r|J d S )Nr      r%   r   r   r   )
r   r   r   nprandomrandnr   r   r   r   r    r   r   r   /test_process_2d_xarray_dataarray_with_no_coordsR   s    zATestProcessXarray.test_process_2d_xarray_dataarray_with_no_coordsc           	      C   s   dd l }|tjdd}| j}|jdd tf d|i|\}}}}}t||j	sZJ t
|j dgksrJ |dks~J |d	ksJ |rJ |rJ d S )
Nr   r.   r%   Tr   r   r   Zdim_1Zdim_0r   r   r/   r0   r1   r   updater   r   Datasetlist	data_varskeys	r   r   r!   kwargsr   r
   r	   r   r   r   r   r   :test_process_2d_xarray_dataarray_with_no_coords_as_gridded_   s    zLTestProcessXarray.test_process_2d_xarray_dataarray_with_no_coords_as_griddedc           	      C   s   dd l }|jtjdddg diddgd}| j}|jdd	 tf d
|i|\}}}}}t||j	slJ t
|j dgksJ |dksJ |dksJ |rJ |rJ d S )Nr   r.   r%   r	   )r   r.   r%   r&   r'   r
   r(   Tr3   r   r   r4   r:   r   r   r   7test_process_2d_xarray_dataarray_with_coords_as_griddedo   s    
zITestProcessXarray.test_process_2d_xarray_dataarray_with_coords_as_griddedc                 C   sn   dd l }tf d| ji| j\}}}}}t||js8J |dksDJ |dgksRJ |rZJ |ddgksjJ d S )Nr   r   timeairlonlat)r   r   r   r   r   r   )r   r   r   r
   r	   r   r   r   r   r   *test_process_3d_xarray_dataset_with_coords   s     z<TestProcessXarray.test_process_3d_xarray_dataset_with_coordsc                 C   s   dd l }| j}|jdddd tf d| ji|\}}}}}t||jsLJ t|j	 dgksdJ |dkspJ |dks|J |d u sJ |dgksJ d S )	Nr   Tr@   rA   )r   r
   r	   r   r?   r>   
r   r   r5   r   r   r   r6   r7   r8   r9   r   r   r;   r   r
   r	   r   r   r   r   r   5test_process_3d_xarray_dataset_with_coords_as_gridded   s    zGTestProcessXarray.test_process_3d_xarray_dataset_with_coords_as_griddedc                 C   s   dd l }| j}|jdd tf d| ji|\}}}}}t||jsHJ t|j	 dgks`J |dkslJ |dksxJ |rJ |dgksJ d S )	Nr   Tr3   r   r?   r@   rA   r>   rC   rD   r   r   r   Otest_process_3d_xarray_dataset_with_coords_as_gridded_uses_axis_to_get_defaults   s    zaTestProcessXarray.test_process_3d_xarray_dataset_with_coords_as_gridded_uses_axis_to_get_defaultsc                 C   s   dd l }| jjddgd}| j}|jdddgd tf d	|i|\}}}}}t||js^J |d
ksjJ |dksvJ |dgksJ |rJ d S )Nr   rA   r@   ZdimFr?   z	time.hour)r   r	   r   r   r>   r   r   Zmeanr   r5   r   r   r   r   r   r   r;   r
   r	   r   r   r   r   r   7test_process_xarray_dataset_with_by_as_derived_datetime   s    zITestProcessXarray.test_process_xarray_dataset_with_by_as_derived_datetimec                 C   s   dd l }| jjddgd}| j}|jdddd tf d	|i|\}}}}}t||js\J |dkshJ |dkstJ |r|J |rJ d S )
Nr   rA   r@   rG   Fr?   ztime.dayofyear)r   r	   r
   r   rH   rI   r   r   r   6test_process_xarray_dataset_with_x_as_derived_datetime   s    zHTestProcessXarray.test_process_xarray_dataset_with_x_as_derived_datetimeN)__name__
__module____qualname__r   r"   r+   r-   r2   r<   r=   rB   rE   rF   rJ   rK   r   r   r   r   r      s   
r   c                   @   s   e Zd Zdd Zdd ZdS )TestGeoUtilc                 C   sJ   t jdkrtdzdd l}dd lm} W n   tdY n0 || _d S )Nwin32z!Skip geo tests on windows for nowr   z!geoviews or cartopy not available)sysplatformr   geoviewsZcartopy.crscrsccrs)r   rS   rU   r   r   r   r      s    
zTestGeoUtil.setUpc                 C   s*   ddl m} |d}t|| jjs&J d S )Nr   )proj_to_cartopyz+init=epsg:26911)utilrV   r   rU   ZCRS)r   rV   rT   r   r   r   test_proj_to_cartopy   s    z TestGeoUtil.test_proj_to_cartopyN)rL   rM   rN   r   rX   r   r   r   r   rO      s   
rO   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestDynamicArgsc                 C   s&   zdd l }W n   tdY n0 d S )Nr   zpanel not available)panelr   )r   pnr   r   r   r      s    zTestDynamicArgs.setUpc           	      C   s~   dd l }ddlm} d}|jjddddgd}|jjd	d
dd
gd}||||\}}}d|vsbJ d|v snJ |g kszJ d S )Nr   r   process_dynamic_argssepal_widthr	   sepal_lengthZpetal_length)r,   r   optionskindscatterZ	bivariater
   )rZ   rW   r]   widgetsZSelect)	r   r[   r]   r
   r	   ra   dynamicarg_deps	arg_namesr   r   r   test_dynamic_and_static   s    z'TestDynamicArgs.test_dynamic_and_staticc           
      C   sl   dd l }ddlm} d}d}d}|jjdd}|||||d	\}}}	d
|vsPJ d|v s\J |g kshJ d S )Nr   r   r\   r_   r^   rb   #ff0000r   cr
   rk   )rZ   rW   r]   rc   ColorPicker)
r   r[   r]   r
   r	   ra   colorrd   re   rf   r   r   r   test_dynamic_kwds   s    z!TestDynamicArgs.test_dynamic_kwdsc                 C   s   dd l }ddlm} d}d}d}|jjdd}|jjd	d
}||jj|jjdd }|||||d\}	}
}|	i kszJ |ddgksJ t	|
dksJ d S )Nr   r   r\   r_   r^   rb   z
By species)r,   rh   ri   c                 S   s   | rdS |S )NZspeciesr   )
by_speciesrm   r   r   r   by_species_fn  s    z3TestDynamicArgs.test_fn_kwds.<locals>.by_species_fnrj   rk   )
rZ   rW   r]   rc   ZCheckboxrl   ZdependsZparamr   len)r   r[   r]   r
   r	   ra   ro   rm   rp   rd   re   rf   r   r   r   test_fn_kwds   s    
zTestDynamicArgs.test_fn_kwdsN)rL   rM   rN   r   rg   rn   rr   r   r   r   r   rY      s   rY   )__doc__rQ   Znumpyr/   Zunittestr   r   Zhvplot.utilr   r   rO   rY   r   r   r   r   <module>   s    9