U
    f/eH4                     @   sv   d dl Z d dlZd dlZd dl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 d dlmZ G dd dZdS )    N)PYPY)CategoricalCategoricalDtypeIndexNaTSeries
date_range)	is_scalarc                   @   s  e Zd Zejdddgdd Zdd Zejded	e	j
fd
ddge	j
fejeedddddeejjdddgejdddgdd Zejdddde	jgedfd
dde	jgddd
gfg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ejd#ddgd$d% Zejd#ddgd&d' Zejd(d)d*d+gejd#ddgd,d- Zejd.d/d0gd1d2 Zejd3d
d
dd4d5d5d5gd5d4ddd
gd5gfd
d
d
d4d5d5d5gd5d4ddd
gd5d
gfd
ddd4d5gd5d4ddd
gd5d4ddd
gfe	je	je	jd4d5gd5d4ddd
gd5d4gfe	je	je	jd4d5d4gd5d4ddd
gd4gfe	je	jd4d5d4gd5d4ddd
gd4gfgd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZejdFd
dGd
ddgdHgdIdJ Z dKS )LTestCategoricalAnalyticsaggregationminmaxc              	   C   sL   t ddddgdd}d| }t||}tjt|d |  W 5 Q R X d S )	NabcdFordered)Categorical is not ordered for operation match)r   getattrpytestraises	TypeError)selfr   catmsgagg_func r   R/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/arrays/categorical/test_analytics.pytest_min_max_not_ordered_raises   s
    

z8TestCategoricalAnalytics.test_min_max_not_ordered_raisesc                 C   s   t ddddgdd}| }| }|dks0t|dks<tt ddddgddddgdd}| }| }|dksvt|dkstd S )Nr   r   r   r   Tr   
categoriesr   )r   r   r   AssertionError)r   r   Z_minZ_maxr   r   r    test_min_max_ordered    s    
 
 z-TestCategoricalAnalytics.test_min_max_orderedzcategories,expectedABC         z
2020-01-01)Zperiodscategorydtypez1https://github.com/pandas-dev/pandas/issues/29962)reason)Zmarksc                 C   s.   t g |dd}t||}| }||ks*td S NTr"   )r   r   r$   )r   r#   expectedr   r   r   resultr   r   r    test_min_max_ordered_empty/   s    
z3TestCategoricalAnalytics.test_min_max_ordered_emptyzvalues, categoriesr   r   r   cbaskipnaTFfunctionc                 C   s^   t ||dd}t|||d}|dkr6|tjksZtn$|dkrF|d n|d }||ksZtd S )NTr"   r3   Fr   r   r(   )r   r   npnanr$   )r   valuesr#   r4   r3   r   r0   r/   r   r   r    test_min_max_with_nanF   s    z.TestCategoricalAnalytics.test_min_max_with_nanc                 C   s8   t tjgddgdd}t|||d}|tjks4td S )Nr'   r(   Tr"   r5   )r   r6   r7   r   r$   )r   r4   r3   r   r0   r   r   r    test_min_max_only_nanW   s    z.TestCategoricalAnalytics.test_min_max_only_nanmethodc              	   C   sP   t tjddtjgdddddgdd}tjtd t||dd	 W 5 Q R X d S )
Nr'   r(         r)   Tr"   )Zexpected_warning)Znumeric_only)r   r6   r7   tmassert_produces_warningFutureWarningr   )r   r;   r   r   r   r    #test_deprecate_numeric_only_min_max_   s      z<TestCategoricalAnalytics.test_deprecate_numeric_only_min_maxc              	   C   sV   t ddddgdd}d| d}tt|}tjtt|d || W 5 Q R X d S )	Nr   r   r   Fr   r   zF
you can use .as_ordered() to change the Categorical to an ordered oner   )r   r   r6   r   r   r   reescape)r   r;   r   r   r   r   r    test_numpy_min_max_raisesh   s    

z2TestCategoricalAnalytics.test_numpy_min_max_raiseskwargaxisoutZkeepdimsc              	   C   sl   t ddddgdd}d| d| }|dkr0d	}|d
i}tt|}tjt|d ||f| W 5 Q R X d S )Nr   r   r   Tr   zthe 'z=' parameter is not supported in the pandas implementation of rF   z8`axis` must be fewer than the number of dimensions \(1\)*   r   )r   r   r6   r   r   
ValueError)r   r;   rE   r   r   kwargsr   r   r    ,test_numpy_min_max_unsupported_kwargs_raisess   s    
zETestCategoricalAnalytics.test_numpy_min_max_unsupported_kwargs_raiseszmethod, expected)r   r   )r   r   c                 C   s:   t ddddgdd}tt|}||d d}||ks6td S )Nr   r   r   Tr   )rF   )r   r   r6   r$   )r   r;   r/   r   r0   r   r   r    #test_numpy_min_max_axis_equals_none   s    
z<TestCategoricalAnalytics.test_numpy_min_max_axis_equals_nonezvalues,categories,exp_moder=   r<   c                 C   s4   t ||dd}| }t ||dd}t|| d S r.   )r   moder>   assert_categorical_equal)r   r8   r#   Zexp_modesresexpr   r   r    	test_mode   s    z"TestCategoricalAnalytics.test_modec              	   C   s  t dddddgddddg|d}t|}|d}|dks>tt|sJt|d}|dks`tt|slt|dg}|dg}tjdgtjd}t	|| t	|| |jddgd	d
}|jddgd	d
}tjddgtjd}t	|| t	|| t
jtdd |d W 5 Q R X t
jtdd |d W 5 Q R X t
jtdd |ddg W 5 Q R X t
jtdd |ddg W 5 Q R X d S )NZcheeseZmilkZappleZbreadr"   r(   r)   r+   right)Zsider<   Zcucumberr   )r   r   Zsearchsortedr$   r	   r6   arrayZintpr>   Zassert_numpy_array_equalr   r   KeyError)r   r   r   ZserZres_catZres_serrQ   r   r   r    test_searchsorted   s<    


z*TestCategoricalAnalytics.test_searchsortedc                 C   s   t dddg|d}tdddg|d}| }t|| tddddg|d}| }t|tddg|d tdddddg|d}| }tdddg|d}t|| tdtjdtjdg|d}| }tdtjdg|d}t|| d S )Nr   r   r   r   r+   )r   r   uniquer>   rN   r6   r7   )r   r   r,   r   rP   Zexp_catr   r   r    test_unique   s    z$TestCategoricalAnalytics.test_uniquec                 C   s   t dddg|d}tdddddg|d}tdddg|d}t| | tt| t| tt| | tddddg|d}tddg|d}t| | tt| t| tt| | d S )Nr)   r(   r'   r   r+   )r   r   r>   rN   rW   assert_index_equalr   r   )r   r   r,   r   rQ   r   r   r    test_unique_index_series   s    z1TestCategoricalAnalytics.test_unique_index_seriesc                 C   s   t dddddg}|d}t tjddddg}t|| t|d d |dd   |d}t dddtjtjgddddgd}t|| t|d	d  |d d  t||d
 d S )Nr   r   r   r   r'   )r#   r(   r   )r   shiftr6   r7   r>   rN   )r   r   Zsp1Zxp1Zsn2Zxp2r   r   r    
test_shift   s    

 
z#TestCategoricalAnalytics.test_shiftc                 C   s$   t dddg}d}|j|ks td S )Nr'   r(   r)      )r   nbytesr$   )r   r   rQ   r   r   r    test_nbytes  s    z$TestCategoricalAnalytics.test_nbytesc                 C   s   t dddg}d|j  k r(| ks.n td|j  k rL|jddksRn tt dddg}|jdd|jksvtts|jddt| }t|d	k std S )
Nr'   r(   r)   r   T)deepZfoobard   )r   r`   Zmemory_usager$   r   sys	getsizeofabs)r   r   Zdiffr   r   r    test_memory_usage  s     $z*TestCategoricalAnalytics.test_memory_usagec                 C   s   t tdtddd}|dd }t tdtddd}t|| t tdtd	d
d}|dd }t tdtdd
d}t|| |dd }t|ttjdgd tj	d d S )NZABABCZCBATr"   c                 S   s   |   S Nlowerxr   r   r    <lambda>      z3TestCategoricalAnalytics.test_map.<locals>.<lambda>Zababcr2   r&   Fc                 S   s   |   S ri   rj   rl   r   r   r    rn   $  ro   abcc                 S   s   dS )Nr'   r   rl   r   r   r    rn   (  ro   r'   r<   r+   )
r   listmapr>   rN   rY   r   r6   rT   Zint64)r   r   r0   rQ   r   r   r    test_map  s    z!TestCategoricalAnalytics.test_mapvalueTrueg      @c              
   C   sT  t dddddg}dt|j }tjt|d |jd|d W 5 Q R X tjt|d |j|d W 5 Q R X tjt|d |j|d W 5 Q R X tjt|d2 t	
t |jd	d
dgd|d W 5 Q R X W 5 Q R X tjt|d0 t	
t |jd	d
dg|d W 5 Q R X W 5 Q R X tjt|d2 t	
t |jd	d
dgd|d W 5 Q R X W 5 Q R X tjt|d0 t	
t |jdddg|d W 5 Q R X W 5 Q R X tjt|d0 t	
t |jdddg|d W 5 Q R X W 5 Q R X tjt|d( t	
t |j|d W 5 Q R X W 5 Q R X tjt|d |j|d W 5 Q R X d S )NABCz9For argument "inplace" expected type bool, received type r   T)rt   inplace)ry   XYZ)renamery   )r   ry   DEF)Znew_categoriesry   )Zremovalsry   )r   type__name__r   r   rI   Zset_orderedZ
as_orderedZas_unorderedr>   r?   r@   Zset_categoriesZrename_categoriesZreorder_categoriesZadd_categoriesZremove_categoriesZremove_unused_categoriesZsort_values)r   rt   r   r   r   r   r    test_validate_inplace_raises,  s:    *(*(( z5TestCategoricalAnalytics.test_validate_inplace_raisesN)!r   
__module____qualname__r   markZparametrizer!   r%   rq   r6   NaNparamr   r   r   Zxfailr1   r7   r9   r:   rA   rD   rK   rL   rR   rV   rX   rZ   r^   ra   rh   rs   r   r   r   r   r    r
      sr   
	,



"$&&&"
.r
   )rB   re   Znumpyr6   r   Zpandas.compatr   Zpandasr   r   r   r   r   r   Zpandas._testingZ_testingr>   Zpandas.api.typesr	   r
   r   r   r   r    <module>   s    