
     j`>                     z    d dl Zd dlZd dlZd dlmZmZmZmZm	Z	 d dl
mZ  G d d          Z G d d          ZdS )    N)Categorical	DataFrameSeries	Timestamp
date_rangec                       e Zd Zd Zd ZdS )TestCategoricalOpsWithFactorc                 V    t          g dd          }t          j        ||           d S )Nabr   r   r   cr   r   Tordered)r   tmassert_categorical_equal)selffactors     C:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pandas/tests/arrays/categorical/test_operators.py test_categories_none_comparisonsz=TestCategoricalOpsWithFactor.test_categories_none_comparisons   s4    EEEtTTT
#FF33333    c                    t          g dd          }||dk             }|t          j        |          dk             }t          j        ||           ||dk             }|t          j        |          dk             }t          j        ||           ||dk              }|t          j        |          dk              }t          j        ||           ||dk             }|t          j        |          dk             }t          j        ||           ||dk             }|t          j        |          dk             }t          j        ||           ||dk             }|t          j        |          dk             }t          j        ||           t          |          }|t          j                            d                              |                   }||k    }t          j        |          t          j        |          k    }t          j	        ||           |dk    }t          j
        t          |          t          	          }t          j	        ||           t          g d
g dd          }t          g dg dd          }t          g d
d          }t          g d|j        d          }	||k    }
t          j        g d          }t          j	        |
|           ||k     }
t          j        g d          }t          j	        |
|           ||	k    }t          j        g d          }t          j	        ||           d}t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   t          g dg d          }t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   |                    d          }||k                                    rJ t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   t'          g dt(          	          }d}t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   t          j        t           |          5  ||k      d d d            n# 1 swxY w Y   t          j        t           |          5  ||k      d d d            n# 1 swxY w Y   t          j        g dt(          	          }t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   t          j        t           |          5  ||k     d d d            n# 1 swxY w Y   t          t+          d          t+          d          d          }t          j        g d          }|dk    }t          j	        ||           |t          j        d          k    }t          j	        ||           d S )Nr   Tr   r   r   r      ddtype)r   r   r   )r   r   r   
categoriesr   )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)r   npasarrayr   r   lenrandomdefault_rngpermutationassert_numpy_array_equalzerosboolr   arraypytestraises	TypeErrorset_orderedanyr   object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_unorderedsr   s                      r   test_comparisonsz-TestCategoricalOpsWithFactor.test_comparisons   sK   EEEtTTT#&"*V,,34
#FH555#&"*V,,34
#FH555%"*V,,s23
#FH555%"*V,,s23
#FH555#&"*V,,34
#FH555#&"*V,,34
#FH555KKry,,Q//;;A>>?5:f%%E):)::
#FH55538CKKt444
#FH555 ooo///SWXXX"OO
 
 
 ///48883>SWXXX L((///00
#GW555L((///00
#GW555Hnh+++,,
#C--- O]9C000 	 	'MM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 $OOO@T@T@TUUU]9C000 	$ 	$m##	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ ..#I??$$$$$]9C000 	  	 -	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  ???&111( 	 ]9C000 	 	!GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	aKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 H___F333]9C000 	 	!GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	aKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 d5kkd5kk4PPPh+++,,m
#C--- %
#C-----s   %M88M<?M<3OO
O
P..P25P2.RRR'R::R>R> S33S7:S7T,,T03T0/VV	V(V;;V?V?N)__name__
__module____qualname__r   rI    r   r   r	   r	      s7        4 4 4k. k. k. k. k.r   r	   c            	          e Zd Zej                            dddgddg ed           ed          gg          d             Zd	 Zd
 Z	d Z
d Zd Zd Zej                            d          d             Zej                            d          d             Zej                            d ed           ed           ed          fg dg dg dfg          d             Zej                            dd d g          d             Zd Zd Zd  Zd! Zd" Zej                            d#g d$          d%             Zd& Zd'S )(TestCategoricalOpsr   r   r   r      20192020c                     t          j        ddg|          }t          j        ddg|          }||k    }|                                sJ d S )Nr   r$   rP   )r   
from_codesall)r   r   c1c2r9   s        r   test_not_equal_with_naz)TestCategoricalOps.test_not_equal_with_na   sY     #RG
CCC#QFzBBBrzz||r   c                 $   g d}t          |          }t          |          }||j        k    }t          g dg          }t          j        ||           |d d d         |j        k    }t          g dg          }t          j        ||           d S )Nr   r   r   r   )TTTTrT   )FTTF)r   r   Tr   assert_frame_equal)r   datar?   dfr9   r:   s         r   test_compare_framez%TestCategoricalOps.test_compare_frame   s    !!!$s^^666788
fh///TTrTbd"8889::
fh/////r   c                     |}t          g d          }t          |          }d}t          j        t          |          5   |||           d d d            d S # 1 swxY w Y   d S )Nr[   z5Unable to coerce to Series, length must be 1: given 4r"   )r   r   r2   r3   
ValueError)r   comparison_opopr?   r_   rE   s         r   test_compare_frame_raisesz,TestCategoricalOps.test_compare_frame_raises   s    ,,,--s^^E]:S111 	 	BsBKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    AA!Ac                    t          t          dd          d          }t          j        ||d         k    t	          j        g d                     t          j        |d         |k     t	          j        g d                     d S )Nz
2014-01-01   )periodsTr   r   FTT)r   r   r   r.   r(   r1   )r   dt_cats     r   $test_datetime_categorical_comparisonz7TestCategoricalOps.test_datetime_categorical_comparison   s    Za@@@$OOO
#FVAY$6ATATAT8U8UVVV
#F1I$6ATATAT8U8UVVVVVr   c                     t          g dd          }t          j        ||d         k    t          j        g d                     t          j        |d         |k     t          j        g d                     d S )NrP   r   rg   Tr   r   ri   )r   r   r.   r(   r1   )r   r?   s     r   &test_reflected_comparison_with_scalarsz9TestCategoricalOps.test_reflected_comparison_with_scalars   sv    )))T222
#C#a&L"(;N;N;N2O2OPPP
#CFSL"(;N;N;N2O2OPPPPPr   c                    t          g dd          }d}t          j        t          |          5  |dk      d d d            n# 1 swxY w Y   t          j        t          |          5  |dk     d d d            n# 1 swxY w Y   t          j        t          |          5  d|k      d d d            n# 1 swxY w Y   t          j        t          |          5  d|k     d d d            n# 1 swxY w Y   t	          j        |dk    t          j        g d                     t	          j        |dk    t          j        g d                     d S )	Nrm   Tr   z1Invalid comparison between dtype=category and intr"      )FFF)TTT)r   r2   r3   r4   r   r.   r(   r1   )r   r?   rE   s      r   $test_comparison_with_unknown_scalarsz7TestCategoricalOps.test_comparison_with_unknown_scalars   sC    )))T222A]9C000 	 	!GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	!GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#C1Hbh7L7L7L.M.MNNN
#C1Hbh7I7I7I.J.JKKKKKsG   AAA*A==BB#B66B:=B:C//C36C3c                 r   t          t          j        g dt                              }|dk    }t          j        g dt                    }t          j        ||           |dk    }t          j        g dt                    }t          j        ||           |dk    }t          j        ||            d S )N)foor   rP   rg   rt   r   rs   )TFFFrt   )FTFT)r   r(   r1   r7   r0   r   r.   )r   r?   r9   r:   s       r   test_comparison_with_tuplez-TestCategoricalOps.test_comparison_with_tuple   s    "(#=#=#=VLLLMM8777tDDD
#FH5558666dCCC
#FH555
#FXI66666r   zignore::RuntimeWarningc                     t          g dg dd          }d} t          t          j        |          |          |          } t          ||          |          }t	          j        ||           d S )NrP   r   rg   Nrm   Tr   r   r   getattrr(   r1   r   r.   )r   compare_operators_no_eq_ner?   scalarr:   actuals         r   9test_comparison_of_ordered_categorical_with_nan_to_scalarzLTestCategoricalOps.test_comparison_of_ordered_categorical_with_nan_to_scalar   sz     ///iiiNNNE728C==*DEEfMM9899&AA
#FH55555r   c                    t          g dg dd          }t          g dg dd          } t          t          j        |          |          d          } t          ||          |          }t	          j        ||           d S )Nrw   rm   Tr   )r   r   r   r   r   rx   )r   rz   r?   r<   r:   r|   s         r   ;test_comparison_of_ordered_categorical_with_nan_to_listlikezNTestCategoricalOps.test_comparison_of_ordered_categorical_with_nan_to_listlike   s     ///iiiNNNLLLYYYMMME728C==*DEEaHH9899%@@
#FH55555r   zdata,reverse,baser&   r'   bbbrm   )rg   r   rP   )r   r   r   c                    t          t          ||d                    }t          t          ||d                    }t          t          |d                    }t          t          ||j        j        d                    }t          ||t	          d          k    rt
          nd           }t          j        |          }	||k    }
t          g d          }t          j	        |
|           ||k     }
t          g d          }t          j	        |
|           ||k    }t          g d          }t          j	        ||           |d         }||k    }t          g d          }|j
        |k    }t          j	        ||           t          j        |j
        |           ||k    }
t          g d          }|j
        |k    }t          j	        |
|           t          j        |
j
        |           d	}t          j        t          |
          5  ||k     d d d            n# 1 swxY w Y   d}t          j        t          |
          5  ||k     d d d            n# 1 swxY w Y   t          j        t          |
          5  ||k     d d d            n# 1 swxY w Y   t          j        t          |
          5  ||	k     d d d            n# 1 swxY w Y   t          j        t          |
          5  ||	k     d d d            n# 1 swxY w Y   t          j        t          |
          5  ||k      d d d            n# 1 swxY w Y   t          j        t          |
          5  ||k      d d d            n# 1 swxY w Y   t          j        t          |
          5  |	|k      d d d            n# 1 swxY w Y   t          j        t          |
          5  |	|k      d d d            d S # 1 swxY w Y   d S )NTr   r   r   r   r   r    rP   r!   r"   r%   )r   r   r?   r   r8   r7   r(   r1   r   assert_series_equalvaluesr.   r2   r3   r4   )r   r^   reversebaser=   r>   r?   r@   rH   r   rA   rB   rC   rD   r{   exp2exp_rev2rE   s                     r   rI   z#TestCategoricalOps.test_comparisons   s#   
 TgtLLLMMk$7DQQQRR[t44455);TJJJ
 
 4e)<Fvv$GGGHTNN L(---..
w000L(---..
w000Hn)))**
sC(((aFl)))**zF"
sC(((
#CJ555F"---..>F*
w000
#GNH=== O]9C000 	 	'MM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	( 	 ]9C000 	 	!GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	aKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	!GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	aKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]9C000 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]9C000 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]9C000 	 	KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   H##H'*H'II"%I"JJJ=KKK6L		LL/MM	M(M;;M?M?!N44N8;N8O..O25O2ctorc                      t          | i |S N)r   argskwargss     r   <lambda>zTestCategoricalOps.<lambda>9  s    K$@$@$@ r   c                  4    t          t          | i |          S r   )r   r   r   s     r   r   zTestCategoricalOps.<lambda>:  s    F;+G+G+G$H$H r   c                 D    |ddgddgd          } |ddgddgd          }||k                                     sJ  |ddgddgd          } |ddgddgd          }||k                                     sJ  |ddgddgd          } |ddgddgd          }||k                                     sJ  |ddgddgd          } |ddgddgd          }||k    }t          j        t          j        |          t          j        ddg                     d S )Nr   r   Fr   T)rV   r   r.   r(   r1   )r   r   rW   rX   r9   s        r   $test_unordered_different_order_equalz7TestCategoricalOps.test_unordered_different_order_equal6  s|    T3*#sUCCCT3*#sUCCCb~~T3*#sUCCCT3*#sUCCCb~~T3*#sUCCCT3*#sUCCCb~~T3*#sUCCCT3*#sUCCCr
#BHV$4$4bhe}6M6MNNNNNr   c                     t          ddgddgd          }t          ddgddgd          }t          j        t          d          5  ||k     d d d            d S # 1 swxY w Y   d S )Nr   r   Fr   r   z!Categoricals can only be comparedr"   r   r2   r3   r4   )r   rW   rX   s      r   *test_unordered_different_categories_raisesz=TestCategoricalOps.test_unordered_different_categories_raisesP  s    #sc
EJJJ#sc
EJJJ]9-PRRR 	 	"HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA #A c                     t          g ddg          }t          g dg          }d}t          j        t          |          5  ||k     d d d            d S # 1 swxY w Y   d S )Nr   r   r$   z?Categoricals can only be compared if 'categories' are the same.r"   r   )r   rW   rX   rE   s       r   test_compare_different_lengthsz1TestCategoricalOps.test_compare_different_lengthsW  s    c
333...O]9C000 	 	"HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     t          dgddg          }t          dgddg          }|                    |          rJ d S )Nr   r   r$   )r   equals)r   r   r   s      r   &test_compare_unordered_different_orderz9TestCategoricalOps.test_compare_unordered_different_order_  sP     3*5553*55588A;;r   c                    t          dt          j                            d                              ddd          i          }d t          ddd          D             }t          ||          }|                    dgd	          }t          j	        |j
        t          dd
d          d|          |d<   dD ]W\  }}d| d}t          j        t          |          5   t          ||          |           d d d            n# 1 swxY w Y   X|d         }dD ]U}d| d}t          j        t          |          5   t          ||          d           d d d            n# 1 swxY w Y   Vd S )Nvaluer   r   i'  d   c                 "    g | ]}| d |dz    S )z - i  rM   ).0is     r   
<listcomp>z<TestCategoricalOps.test_numeric_like_ops.<locals>.<listcomp>h  s*    CCCQ$$1s7$$CCCr   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+   r,   integersranger   sort_valuespdcutr   r2   r3   r4   ry   )r   r_   r   
cat_labelsrd   str_reprE   rH   s           r   test_numeric_like_opsz(TestCategoricalOps.test_numeric_like_opsf  s   !6!6q!9!9!B!B1eS!Q!QRSSCCeAuc.B.BCCC 00
^^yD^99FHeAuc**%

 
 
=

 	$ 	$KB WVVVCy444 $ $B###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $
 }I 	3 	3B6666Cy444 3 32E22223 3 3 3 3 3 3 3 3 3 3 3 3 3 3	3 	3s$   DD	D	=E$$E(	+E(	c                     t          t          g d                    }t          j        t          d          5  t          j        |           d d d            d S # 1 swxY w Y   d S )NrP   r   rg   rp   z does not support reduction 'sum'r"   )r   r   r2   r3   r4   r(   r   )r   rH   s     r   test_numeric_like_ops_seriesz/TestCategoricalOps.test_numeric_like_ops_series  s    ;|||,,--]9,NOOO 	 	F1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA #A zop, str_repr   c                     t          t          g d                    }d| d}t          j        t          |          5   t          ||          d           d d d            d S # 1 swxY w Y   d S )Nr   r   r   r"   r   )r   r   r2   r3   r4   ry   )r   rd   r   rH   rE   s        r   "test_numeric_like_ops_series_arithz5TestCategoricalOps.test_numeric_like_ops_series_arith  s     ;|||,,--RWRRR]9C000 	 	GArNN1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    A''A+.A+c                     t          t          g d                    }d}t          j        t          |          5  t          j        |           d d d            d S # 1 swxY w Y   d S )Nr   z:Object with dtype category cannot perform the numpy op logr"   )r   r   r2   r3   r4   r(   log)r   rH   rE   s      r   $test_numeric_like_ops_series_invalidz7TestCategoricalOps.test_numeric_like_ops_series_invalid  s    ;|||,,--J]9C000 	 	F1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA"%A"N)rJ   rK   rL   r2   markparametrizer   rY   r`   re   rk   rn   rq   ru   filterwarningsr}   r   r8   rI   r   r   r   r   r   r   r   r   rM   r   r   rO   rO      s~       [
saVii//61B1BCD  	 0 0 0  W W W
Q Q QL L L&7 7 7 [ 8996 6 :96 [ 8996 6 :96 [
$u++ttE{{DDKK	0999iii2ST ? ?	 ?B [@@HH	
 O O O&      3 3 3:   [	
 	
 	
       r   rO   )numpyr(   r2   pandasr   r   r   r   r   r   pandas._testing_testingr   r	   rO   rM   r   r   <module>r      s                               p. p. p. p. p. p. p. p.f\ \ \ \ \ \ \ \ \ \r   