a
    Pf3                     @   sz   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mZ d dlmZ d dlmZ G dd dZdS )    N)PYPY)CategoricalCategoricalDtype	DataFrameIndexNaTSeries
date_range)	is_scalarc                   @   s  e Zd Zejdddgdd Zdd Zdd	 Zejd
e	de
jfg d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g d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,g d-ejd'ddgd.d/ Zejd0d1d2gd3d4 Zejd5g d6g d7d8gfg d9g d7d8dgfg d:g d7g d7fe
je
je
jd;d8gg d7d8d;gfe
je
je
jd;d8d;gg d7d;gfe
je
jd;d8d;gg d7d;gfgd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZejdLddMg ddNgdOdP Z dQdR Z!dSS )TTestCategoricalAnalyticsaggregationminmaxc                 C   s   t g ddd}d| }t||}tjt|d |  W d    n1 sN0    Y  |dkrftjntj}tjt|d || W d    n1 s0    Y  d S )NabcdFordered)Categorical is not ordered for operation matchr   )	r   getattrpytestraises	TypeErrornpminimummaximumreduce)selfr   catmsgagg_funcZufunc r%   g/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/arrays/categorical/test_analytics.pytest_min_max_not_ordered_raises   s    

$z8TestCategoricalAnalytics.test_min_max_not_ordered_raisesc                 C   s   t g ddd}||}| }| }|dks4J |dks@J tj|dksTJ tj|dkshJ t g dg ddd}||}| }| }|dksJ |dksJ tj|dksJ tj|dksJ d S )Nr   Tr   r   r   )r   r   r   r   
categoriesr   )r   r   r   r   r   r    r   )r!   Zindex_or_series_or_arrayr"   obj_min_maxr%   r%   r&   test_min_max_ordered%   s$    z-TestCategoricalAnalytics.test_min_max_orderedc                 C   sp   t g ddd}t|}|d}tt dg|jd}t|| |d}tt dg|jd}t|| d S )	Nr   Tr   r   r   dtyper   r   )r   r   Zaggr   r/   tmZassert_series_equal)r!   r"   ZdfZ
result_maxZexpected_maxZ
result_minZexpected_minr%   r%   r&   test_min_max_reduce<   s    

z,TestCategoricalAnalytics.test_min_max_reducezcategories,expectedABC         z
2020-01-01r6   )Zperiodscategoryr.   z1https://github.com/pandas-dev/pandas/issues/29962)reason)Zmarksc                 C   s.   t g |dd}t||}| }||u s*J d S NTr(   )r   r   )r!   r)   expectedr   r"   r$   resultr%   r%   r&   test_min_max_ordered_emptyI   s    
z3TestCategoricalAnalytics.test_min_max_ordered_emptyzvalues, categoriesr   r   r   cbar4   r5   r6   r5   r4   skipnaTFfunctionc                 C   s^   t ||dd}t|||d}|du r6|tju sZJ n$|dkrF|d n|d }||ksZJ d S )NTr(   r?   Fr   r   r5   )r   r   r   nan)r!   valuesr)   r@   r?   r"   r;   r:   r%   r%   r&   test_min_max_with_nan`   s    z.TestCategoricalAnalytics.test_min_max_with_nanc                 C   s8   t tjgddgdd}t|||d}|tju s4J d S )Nr4   r5   Tr(   rA   )r   r   rB   r   )r!   r@   r?   r"   r;   r%   r%   r&   test_min_max_only_nanq   s    z.TestCategoricalAnalytics.test_min_max_only_nanmethodc                 C   s`   t tjddtjgg ddd}tjtdd  t||dd W d    n1 sR0    Y  d S )	Nr4   r5         r6   r5   r4   Tr(   z.* got an unexpected keywordr   )Znumeric_only)r   r   rB   r   r   r   r   )r!   rF   r"   r%   r%   r&    test_numeric_only_min_max_raisesy   s
    z9TestCategoricalAnalytics.test_numeric_only_min_max_raisesc                 C   sf   t g ddd}d| d}tt|}tjtt|d || W d    n1 sX0    Y  d S )Nr   r   r   r   Fr   r   zF
you can use .as_ordered() to change the Categorical to an ordered oner   )r   r   r   r   r   r   reescape)r!   rF   r"   r#   r%   r%   r&   test_numpy_min_max_raises   s    

z2TestCategoricalAnalytics.test_numpy_min_max_raiseskwarg)axisoutZkeepdimsc                 C   s   t g ddd}d| d| }|dkr,d}|di}tt|}tjt|d	  ||fi | W d    n1 sr0    Y  d S )
NrK   Tr   zthe 'z=' parameter is not supported in the pandas implementation of rP   z8`axis` must be fewer than the number of dimensions \(1\)*   r   )r   r   r   r   r   
ValueError)r!   rF   rO   r"   r#   kwargsr%   r%   r&   ,test_numpy_min_max_unsupported_kwargs_raises   s    
zETestCategoricalAnalytics.test_numpy_min_max_unsupported_kwargs_raiseszmethod, expected)r   r   )r   r   c                 C   s6   t g ddd}tt|}||d d}||ks2J d S )NrK   Tr   )rP   )r   r   r   )r!   rF   r:   r"   r;   r%   r%   r&   #test_numpy_min_max_axis_equals_none   s    
z<TestCategoricalAnalytics.test_numpy_min_max_axis_equals_nonezvalues,categories,exp_mode)r4   r4   r5   rI   rH   rH   rH   rG   rH   )r4   r4   r4   rI   rH   rH   rH   )r4   r5   r6   rI   rH   rI   c                 C   s:   t ||dd}t| j}t ||dd}t|| d S r9   )r   r   modeZ_valuesr0   assert_categorical_equal)r!   rC   r)   Zexp_moder"   resexpr%   r%   r&   	test_mode   s    z"TestCategoricalAnalytics.test_modec                 C   s  t g dg d|d}t|}|d}|dks4J t|s@J |d}|dksVJ t|sbJ |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 d    n1 s$0    Y  t	j
tdd |d W d    n1 s^0    Y  d}t	j
t|d |ddg W d    n1 s0    Y  t	j
t|d |ddg W d    n1 s0    Y  d S )N)cheesemilkapplebreadr_   )r\   r]   r^   r_   r(   r^   r5   r_   r6   r.   right)ZsiderH   cucumberr   zMCannot setitem on a Categorical with a new category, set the categories first)r   r   Zsearchsortedr
   r   arrayZintpr0   Zassert_numpy_array_equalr   r   r   )r!   r   r"   ZserZres_catZres_serrZ   r#   r%   r%   r&   test_searchsorted   s@    

**.z*TestCategoricalAnalytics.test_searchsortedc                 C   s   t g d|d}tg d|d}| }t|| tg d|d}| }t|tddg|d tg d|d}| }tg d|d}t|| tdtjdtjdg|d}| }tdtjdg|d}t|| d S )	N)r   r   r   r   r.   )r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   )r   r   uniquer0   rX   r   rB   )r!   r   r/   r"   rY   Zexp_catr%   r%   r&   test_unique   s    z$TestCategoricalAnalytics.test_uniquec                 C   s   t g d|d}tg d|d}tg d|d}t| | tt| t| tt| | tg d|d}tddg|d}t| | tt| t| tt| | d S )	Nr>   r   )r6   r4   r5   r5   r4   r.   )r6   r4   r5   )r4   r4   r5   r5   r4   r5   )r   r   r0   rX   rd   assert_index_equalr   r   )r!   r   r/   r   rZ   r%   r%   r&   test_unique_index_series   s    z1TestCategoricalAnalytics.test_unique_index_seriesc                 C   s   t g d}|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g d	d
}t|| t|dd  |d d  t||d d S )N)r   r   r   r   r   r4   r   r   r   r   r   )r)   r5   r   )r   shiftr   rB   r0   rX   )r!   r"   Zsp1Zxp1Zsn2Zxp2r%   r%   r&   
test_shift  s    

z#TestCategoricalAnalytics.test_shiftc                 C   s"   t g d}d}|j|ksJ d S )Nr3      )r   nbytes)r!   r"   rZ   r%   r%   r&   test_nbytes&  s    z$TestCategoricalAnalytics.test_nbytesc                 C   s   t g d}d|j  k r&| ks,n J d|j  k rJ|jddksPn J t g d}|jdd|jksrJ ts|jddt| }t|dk sJ d S )Nr3   r   T)deep)foorp   bard   )r   rm   Zmemory_usager   sys	getsizeofabs)r!   r"   diffr%   r%   r&   test_memory_usage+  s     $z*TestCategoricalAnalytics.test_memory_usagec                 C   s   t tdtddd}|jdd d d}t tdtd	dd}t|| t tdtd
dd}|jdd d d}t tdtddd}t|| |jdd 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	na_actionZababcr=   r2   Fc                 S   s   |   S rx   ry   r{   r%   r%   r&   r}   B  r~   abcc                 S   s   dS )Nr4   r%   r{   r%   r%   r&   r}   F  r~   r4   rH   r.   )
r   listmapr0   rX   rf   r   r   rb   Zint64)r!   r   r;   rZ   r%   r%   r&   test_map;  s    z!TestCategoricalAnalytics.test_mapvalueTrueg      @c                 C   sZ   t g d}dt|j }tjt|d |j|d W d    n1 sL0    Y  d S )N)ABr   Cr   z9For argument "inplace" expected type bool, received type r   )Zinplace)r   type__name__r   r   rS   Zsort_values)r!   r   r"   r#   r%   r%   r&   test_validate_inplace_raisesJ  s    z5TestCategoricalAnalytics.test_validate_inplace_raisesc                 C   sb   t ddg}tddg}|d d j|dd}|jjtjks@J |jddgd	d
}t	|| d S )Nr   r   g        g      ?r   Zlinear)interpolationrh   T)Z
allow_fill)
r   r   Z	_quantile_codesr/   r   Zint8Ztaker0   Zassert_extension_array_equal)r!   r"   idxr;   r:   r%   r%   r&   test_quantile_emptyU  s    z,TestCategoricalAnalytics.test_quantile_emptyN)"r   
__module____qualname__r   markZparametrizer'   r-   r1   r   r   rB   paramr   r	   r   Zxfailr<   rD   rE   rJ   rN   rU   rV   r[   rc   re   rg   rk   rn   rw   r   r   r   r%   r%   r%   r&   r      sv   
*



  
2

r   )rL   rs   numpyr   r   Zpandas.compatr   Zpandasr   r   r   r   r   r   r	   Zpandas._testingZ_testingr0   Zpandas.api.typesr
   r   r%   r%   r%   r&   <module>   s   $	