o
    5c<                     @   sd   d dl Z d dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
mZ G dd dZG dd dZdS )    N)Categorical	DataFrameSeries
date_rangec                   @   s   e Zd Zdd Zdd ZdS )TestCategoricalOpsWithFactorc                 C   s    t g ddd}t|| d S )N)abr   r   r   cr	   r	   Tordered)r   tmassert_categorical_equal)selffactor r   d/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/arrays/categorical/test_operators.py test_categories_none_comparisons   s   z=TestCategoricalOpsWithFactor.test_categories_none_comparisonsc                 C   s  ||dk }|t |dk }t|| ||dk }|t |dk }t|| ||dk  }|t |dk  }t|| ||dk }|t |dk }t|| ||dk }|t |dk }t|| ||dk }|t |dk }t|| t|}|t j| }||k}t |t |k}t|| |dk}t jt|t	d}t|| t
g dg ddd	}t
g d
g ddd	}t
g ddd}t
g d
|jdd	}	||k}
t g d}t|
| ||k }
t g d}t|
| ||	k}t g d}t|| d}tjt|d ||k W d    n	1 s%w   Y  t
g d
g dd}tjt|d ||k W d    n	1 sKw   Y  |d}||k r^J tjt|d ||k W d    n	1 suw   Y  tg d
}d}tjt|d ||k W d    n	1 sw   Y  tjt|d ||k W d    n	1 sw   Y  tjt|d ||k  W d    n	1 sw   Y  tjt|d ||k  W d    n	1 sw   Y  t g d
}tjt|d ||k W d    n	1 sw   Y  tjt|d ||k W d    n	1 s,w   Y  t
tdtddd	}t g d}|dk}t|| |t dk}t|| d S )Nr   r	   r   ddtype)r   r   r	   )r	   r   r   T
categoriesr   )r   r   r   r
   TFFFFT>Categoricals can only be compared if 'categories' are the samematch)r	   r   r   r   r   FMCannot compare a Categorical for op __gt__ with type <class 'numpy\.ndarray'>abccba)npasarrayr   r   lenrandompermutationassert_numpy_array_equalzerosboolr   r   arraypytestraises	TypeErrorset_orderedanyr   list)r   r   resultexpectednothercat_revcat_rev_basecatcat_baseres_revexp_revresexpmsgcat_rev_base2cat_unorderdsr   r   r   r   test_comparisons   s   









z-TestCategoricalOpsWithFactor.test_comparisonsN)__name__
__module____qualname__r   r@   r   r   r   r   r      s    r   c                   @   s   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
ejdedededfg dg dg dfgdd Zejddd dd gdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zejd*g d+d,d- Zd.d/ Zd0S )1TestCategoricalOpsc                 C   sn   g d}t |}t|}||jk}tg dg}t|| |d d d |jk}tg dg}t|| d S )Nr   r      r   )TTTT)FTTF)r   r   Tr   assert_frame_equal)r   datar6   dfr0   r1   r   r   r   test_compare_frame   s   
z%TestCategoricalOps.test_compare_framec                 C   sZ   |}t g d}t|}d}tjt|d ||| W d    d S 1 s&w   Y  d S )NrE   z5Unable to coerce to Series, length must be 1: given 4r   )r   r   r*   r+   
ValueError)r   comparison_opopr6   rK   r<   r   r   r   test_compare_frame_raises   s   "z,TestCategoricalOps.test_compare_frame_raisesc                 C   sT   t tddddd}t||d ktg d t|d |k tg d d S )Nz
2014-01-01   )periodsTr
   r   FTT)r   r   r   r&   r!   r)   )r   dt_catr   r   r   $test_datetime_categorical_comparison   s   "z7TestCategoricalOps.test_datetime_categorical_comparisonc                 C   sP   t g ddd}t||d ktg d t|d |k tg d d S )N   rF   rQ   Tr
   r   rS   )r   r   r&   r!   r)   )r   r6   r   r   r   &test_reflected_comparison_with_scalars   s   "z9TestCategoricalOps.test_reflected_comparison_with_scalarsc                 C   s$  t g ddd}d}tjt|d |dk  W d    n1 s w   Y  tjt|d |dk W d    n1 s;w   Y  tjt|d d|k  W d    n1 sVw   Y  tjt|d d|k W d    n1 sqw   Y  t|dktg d t|dktg d d S )	NrV   Tr
   z1Invalid comparison between dtype=category and intr      )FFF)TTT)r   r*   r+   r,   r   r&   r!   r)   )r   r6   r<   r   r   r   $test_comparison_with_unknown_scalars   s    



z7TestCategoricalOps.test_comparison_with_unknown_scalarsc                 C   s|   t tjg dtd}|dk}tjg dtd}t|| |dk}tjg dtd}t|| |dk}t||  d S )N)foor   rW   rQ   r\   r   r[   )TFFFr\   )FTFT)r   r!   r)   objectr(   r   r&   )r   r6   r0   r1   r   r   r   test_comparison_with_tuple   s   z-TestCategoricalOps.test_comparison_with_tuplec                 C   s   t g dg ddd}d}t  tdt tt|||}W d    n1 s,w   Y  t|||}t	|| d S )NrW   rF   rQ   NrV   Tr   rF   ignore
r   warningscatch_warningssimplefilterRuntimeWarninggetattrr!   r)   r   r&   )r   compare_operators_no_eq_ner6   scalarr1   actualr   r   r   9test_comparison_of_ordered_categorical_with_nan_to_scalar   s   
zLTestCategoricalOps.test_comparison_of_ordered_categorical_with_nan_to_scalarc                 C   s   t g dg ddd}t g dg ddd}t  tdt tt||d}W d    n1 s5w   Y  t|||}t	|| d S )Nr_   rV   Tr   )rF   rF   rF   rF   r`   rF   ra   )r   rg   r6   r3   r1   ri   r   r   r   ;test_comparison_of_ordered_categorical_with_nan_to_listlike   s   
zNTestCategoricalOps.test_comparison_of_ordered_categorical_with_nan_to_listlikezdata,reverse,baser   r    bbbrV   )rQ   rF   rW   )rF   rF   rF   c                 C   s4  t t||dd}t t||dd}t t|dd}t t||jjdd}t |}t|}	||k}
t g d}t|
| ||k }
t g d}t|
| ||k}t g d}t|| |d }||k}t g d}|j|k}t|| t	|j| ||k}
t g d}|j|k}t|
| t	|
j| d}t
jt|d ||k W d    n1 sw   Y  d	}t
jt|d ||k W d    n1 sw   Y  t
jt|d ||k W d    n1 sw   Y  t
jt|d ||	k W d    n	1 sw   Y  t
jt|d ||	k W d    n	1 s"w   Y  t
jt|d ||k  W d    n	1 s>w   Y  t
jt|d ||k  W d    n	1 sZw   Y  t
jt|d |	|k  W d    n	1 svw   Y  t
jt|d |	|k  W d    d S 1 sw   Y  d S )
NTr   r
   r   r   rW   r   r   r   )r   r   r6   r   r!   r)   r   assert_series_equalvaluesr&   r*   r+   r,   )r   rJ   reversebaser4   r5   r6   r7   r?   r   r8   r9   r:   r;   rh   exp2exp_rev2r<   r   r   r   r@      st   











$z#TestCategoricalOps.test_comparisonsctorc                  O   s   t | i |S N)r   argskwargsr   r   r   <lambda>.  s    zTestCategoricalOps.<lambda>c                  O   s   t t| i |S rt   )r   r   ru   r   r   r   rx   /  s    c                 C   s  |ddgddgdd}|ddgddgdd}||k  sJ |ddgddgdd}|ddgddgdd}||k  s<J |ddgddgdd}|ddgddgdd}||k  sZJ |ddgddgdd}|ddgddgdd}||k}tt|tddg d S )Nr   r   Fr   T)allr   r&   r!   r)   )r   rs   c1c2r0   r   r   r   $test_unordered_different_order_equal+  s   	 z7TestCategoricalOps.test_unordered_different_order_equalc                 C   sh   t ddgddgdd}t ddgddgdd}tjtdd ||k W d    d S 1 s-w   Y  d S )Nr   r   Fr   r	   z!Categoricals can only be comparedr   r   r*   r+   r,   )r   rz   r{   r   r   r   *test_unordered_different_categories_raisesE  s
   
"z=TestCategoricalOps.test_unordered_different_categories_raisesc                 C   s^   t g ddgd}t g dgd}d}tjt|d ||k W d    d S 1 s(w   Y  d S )Nr   r   r   z?Categoricals can only be compared if 'categories' are the same.r   r}   )r   rz   r{   r<   r   r   r   test_compare_different_lengthsL  s   
"z1TestCategoricalOps.test_compare_different_lengthsc                 C   s6   t dgddgd}t dgddgd}||rJ d S )Nr   r   r   )r   equals)r   r   r   r   r   r   &test_compare_unordered_different_orderT  s   z9TestCategoricalOps.test_compare_unordered_different_orderc              	   C   s  t dtjdddi}dd tdddD }t||}|jdgdd	}tj|j	tdd
dd|d|d< dD ](\}}d| d}t
jt|d t||| W d    n1 sYw   Y  q6|d }dD ]'}d| d}t
jt|d t||dd W d    n1 sw   Y  qed S )Nvaluer   i'  d   c                 S   s   g | ]}| d |d  qS )z - i  r   ).0ir   r   r   
<listcomp>^  s    z<TestCategoricalOps.test_numeric_like_ops.<locals>.<listcomp>i  T)by	ascendingi)  F)rightlabelsvalue_group)__add__z\+)__sub__-)__mul__z\*)__truediv__/$Series cannot perform the operation |unsupported operandr   )kurtskewvarstdmeansummedianzdoes not support reduction '')numeric_only)r   r!   r$   randintranger   sort_valuespdcutr   r*   r+   r,   rf   )r   rK   r   
cat_labelsrO   str_repr<   r?   r   r   r   test_numeric_like_ops[  s*   

z(TestCategoricalOps.test_numeric_like_opsc                 C   sN   t tg d}tjtdd t| W d    d S 1 s w   Y  d S )NrW   rF   rQ   rY   z does not support reduction 'sum'r   )r   r   r*   r+   r,   r!   r   )r   r?   r   r   r   test_numeric_like_ops_series{  s   "z/TestCategoricalOps.test_numeric_like_ops_serieszop, str_repr   c                 C   s^   t tg d}d| d}tjt|d t||d W d    d S 1 s(w   Y  d S )Nr   r   r   r   rF   )r   r   r*   r+   r,   rf   )r   rO   r   r?   r<   r   r   r   "test_numeric_like_ops_series_arith  s
   "z5TestCategoricalOps.test_numeric_like_ops_series_arithc                 C   sR   t tg d}d}tjt|d t| W d    d S 1 s"w   Y  d S )Nr   z:Object with dtype category cannot perform the numpy op logr   )r   r   r*   r+   r,   r!   log)r   r?   r<   r   r   r   $test_numeric_like_ops_series_invalid  s
   "z7TestCategoricalOps.test_numeric_like_ops_series_invalidN)rA   rB   rC   rL   rP   rU   rX   rZ   r^   rj   rk   r*   markparametrizer/   r@   r|   r~   r   r   r   r   r   r   r   r   r   r   rD      s@    	*
A
 
	rD   )rb   numpyr!   r*   pandasr   r   r   r   r   pandas._testing_testingr   r   rD   r   r   r   r   <module>   s    r