
    Owg2                     d   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	m
Z
mZmZmZmZmZ d dlmZ d dlmc mZ  G d d      Z G d d      Z G d d      Zej4                  j7                  d	d
dg      d        Zej4                  j7                  d	d
dg      d        Zej<                  d        Zd Z y)    N)NACategoricalCategoricalIndexIndexIntervalIntervalIndexNaTPeriodIndexSeries	Timedelta	Timestampc            
          e Zd Zd Zd Zej                  j                  d eddg       eddgddg      g      d        Z	ej                  j                  d eddgg d       eddgg d	       eddgdg       eddgdg      g      d
        Z
ej                  j                  d eddg       eddgddgd       eddgg d	d      g      d        Zd Zd Zy)!TestCategoricalIndexingWithFactorc                    t        g dd      }|d   dk(  sJ |d   dk(  sJ |g d   }t        j                  |j                  t	        j
                  g d	t        j                  
             |t	        j                  |      dk(     }t        j                  |j                  t	        j
                  g dt        j                  
             y )Nabr   r   r   cr   r   Torderedr   r   r   )r         )r   r   r   dtype)r   r   r   )r   tmassert_numpy_array_equal_codesnparrayint8asarray)selffactorsubfs      d/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/arrays/categorical/test_indexing.pytest_getitemz.TestCategoricalIndexingWithFactor.test_getitem   s    EtTayCbzS   i 
##DKK)2771STbjj(C/0
##DKK)2771ST    c                 F   t        g dd      }|j                         }d|d<   |d   dk(  sJ d|d<   |d   dk(  sJ |j                         }t        j                  t	        |      d	      }d|d<   d|d<   d
||<   t        g dd      }t        j                  ||       y )Nr   Tr   r   r   r   r   boolr   r   )r   r   r   r   r   r   r   r   )r   copyr   zeroslenr   assert_categorical_equal)r#   r$   r   indexerexpecteds        r&   test_setitemz.TestCategoricalIndexingWithFactor.test_setitem#   s    EtTKKM!ts{{"u|| KKM((3q60
'
GQUV
##Ax0r(   otherr   r   
categoriesc                     t        ddgddg      }t        j                  ddg      }||   ||<   t        ddgddg      }t        j                  ||       y )Nr   r   r3   TF)r   r   r    r   r.   )r#   r2   targetmaskr0   s        r&   test_setitem_same_but_unorderedzATestCategoricalIndexingWithFactor.test_setitem_same_but_unordered6   s[     c3ZS#J?xxu&T{tSzsCjA
##FH5r(   )r   r   r   r   r   r   c                     t        ddgddg      }t        j                  ddg      }d}t        j                  t
        |      5  ||   ||<   d d d        y # 1 sw Y   y xY w)Nr   r   r3   TFCCannot set a Categorical with another, without identical categoriesmatchr   r   r    pytestraises	TypeErrorr#   r2   r6   r7   msgs        r&   'test_setitem_different_unordered_raiseszITestCategoricalIndexingWithFactor.test_setitem_different_unordered_raisesB   s_     c3ZS#J?xxu&S]]9C0 	' ;F4L	' 	' 	's   	AA!Tr4   r   c                     t        ddgddgd      }t        j                  ddg      }d}t        j                  t
        |      5  ||   ||<   d d d        y # 1 sw Y   y xY w)Nr   r   TrE   Fr;   r<   r>   rB   s        r&    test_setitem_same_ordered_raiseszBTestCategoricalIndexingWithFactor.test_setitem_same_ordered_raisesS   sa     c3ZS#JMxxu&S]]9C0 	' ;F4L	' 	' 	's   	AA"c                 B    t        g d      }|d   |d<   |d   dk(  sJ y )N)r   r   )r   r   rI   r   r   rI   )r   r#   cats     r&   test_setitem_tuplez4TestCategoricalIndexingWithFactor.test_setitem_tuplec   s.    23 QA1vr(   c                    t        t        j                  j                  d      j	                  ddd      j                  t        j                              j                  dg      }t        j                  dg      j                  t        j                        }d||<   |j                  t        j                  dg      j                  t        j                           }t        j                  |t        j                  dgd	             y )
Nr   r      I sizei順 r!   r   )r   r   randomdefault_rngintegersastyper!   add_categoriesr    int64codesr   r   )r#   rK   r/   results       r&   test_setitem_listlikez7TestCategoricalIndexingWithFactor.test_setitem_listlikek   s     II!!!$--a-@GGP

.%
! 	 ((F8$++BHH5G 288VH-44RXX>?
##FBHHaS,GHr(   N)__name__
__module____qualname__r'   r1   r?   markparametrizer   r8   rD   rG   rL   r[    r(   r&   r   r      s    	U1& [[	c3Z	 +sCjc3Z"PQ6	6 [[c
?c
?c
u5c
u5		
'' [[c
#c
Sz4Hc
M	
'' Ir(   r   c                   D   e Zd Zd Zd Zd Zej                  j                  dde	j                  eeej                  dddd	d
dg      d        Zej                  j                  dg dddgg      d        Zej                  j                  dg dg dg dg dg      ej                  j                  dddgddgddgddgg      ej                  j                  deeg      ej                  j                  dg d      d                             Zd Zd Zd Zd Zd  Zy)!TestCategoricalIndexingc                     t        g d      }|d   }|dk(  sJ |dd }t        ddgg d      }t        j                  ||       y )N)r   r   r   dr   r   r      re   rN   r   )r   r   r   re   r3   )r   r   r.   )r#   rK   slicedr0   s       r&   test_getitem_slicez*TestCategoricalIndexing.test_getitem_slice|   sN    =>Q}}QqSz6JK
##FH5r(   c                    t        t        j                  j                  d      j	                  ddd      j                  t        j                              }|j                  t        j                  dg      j                  t        j                           }|t        j                  dg      j                  t        j                           j                  }t        j                  ||       y )Nr   r   rN   rO   rP   rR   )r   r   rS   rT   rU   rV   r!   rY   r    rX   r   r   )r#   r   rZ   r0   s       r&   test_getitem_listlikez-TestCategoricalIndexing.test_getitem_listlike   s     II!!!$--a-@GGP
 6(+22288<=RXXvh'..rxx89??
##FH5r(   c                    t        g dd      }t        |      }t        |       t        j                  g dt        j
                        }t        g dd      }t        j                  |j                  |       t        j                  |j                  |       t        g dd      }t        |d	      }t        |       t        j                  g d
t        j
                        }t        g dd      }t        j                  |j                  |       t        j                  |j                  |       t        g dd      }t        |d	      }	t        j                  g dt        j
                        }t        g dd      }t        j                  |	j                  |       t        j                  |	j                  |       y )N)2014-01rl   2014-02rm   2014-03rn   Mfreq)r   r   r   r   r   r   r   )rl   rm   rn   )rn   rn   rm   rl   rn   rl   Tr   )r   r   r   r   r   r   )2013-122013-112013-102013-092013-082013-072013-05)   rN      rf   r   r   r   )rx   rw   rv   ru   rt   rs   rr   )r
   r   strr   r    r!   r   r   r   assert_index_equalr4   )
r#   idx1cat1exp_arrexp_idxidx2cat2exp_idx2idx3cat3s
             r&   test_periodindexz(TestCategoricalIndexing.test_periodindex   sS   N

 4 D	((-RWW=?cJ
##DKK9
doow7N
 4.D	((-RWW=@sK
##DKK9
doox8 
 4.((0@ 
 	##DKK9
doow7r(   null_valNr	   natNATnanNaNNANc                     t        dd|gd      }t        g dd      }|d   t        u sJ t        j                  ||       y )	N
2022-04-06
2022-04-07Drp   )r   r   r	   z	period[D]r   r   )r
   r	   r   r|   )r#   r   rZ   r0   s       r&   test_periodindex_on_null_typesz6TestCategoricalIndexing.test_periodindex_on_null_types   sF     lL(C#NB+VayC
fh/r(   new_categories)r   r   rf   rz   r   r   c                     t        g d      }d}t        j                  t        |      5  |j	                  |       d d d        y # 1 sw Y   y xY w)N)r   r   r   r   zKnew categories need to have the same number of items as the old categories!r<   )r   r?   r@   
ValueErrorrename_categories)r#   r   rK   rC   s       r&   /test_categories_assignments_wrong_length_raiseszGTestCategoricalIndexing.test_categories_assignments_wrong_length_raises   sJ    ./% 	 ]]:S1 	2!!.1	2 	2 	2s   AA
idx_values)r   rf   r   rz   )r   rf   rf   rz   )r   r   r   rz   
key_valuesrN   	key_classr   )Ncategorykeyc                     ||t        dd            }|dk(  r|j                  }t        ||      }|j                  |      \  }}|j                  |      \  }	}
t	        j
                  ||	       t	        j
                  ||
       |j                         j                  |      }|j                         j                  |      }t	        j
                  ||       y )Nr   rN   r3   r   r   )ranger   r   get_indexer_non_uniquer   r   uniqueget_indexer)r#   r   r   r   r   r   idxr0   exp_missrZ   res_miss
exp_unique
res_uniques                r&   test_get_indexer_non_uniquez3TestCategoricalIndexing.test_get_indexer_non_unique   s     
uQ{;E>IIE Je, 77
C(55c:
##Hf5
##Hh7ZZ\--j9
ZZ\--c2

##J
;r(   c                 h   t        t        ddg            }|j                  ddg      }t        t        dd gddg            }t        j                  ||       t        t        ddg            }|j                  ddg      }t        t        d d gddg            }t        j                  ||       y )Nr   r   TFr3   )r   r   wherer   assert_series_equalr#   serrZ   r0   s       r&   test_where_unobserved_nanz1TestCategoricalIndexing.test_where_unobserved_nan   s    [#s,-D%=)+sDksCjIJ
vx0 [#s,-E5>*+tTlSzJK
vx0r(   c                     t        t        g dg d            }|j                  g dd      }t        t        g d|j                  j                              }t        j                  ||       y )Nr9   re   r   r   r   r3   )TTFr   )r2   )r   r   r   )r   r   r   rK   r4   r   r   r   s       r&    test_where_unobserved_categoriesz8TestCategoricalIndexing.test_where_unobserved_categories  sR    [=QRS.c:+o#''BTBTUV
vx0r(   c                     t        t        g dg d            }t        g dg d      }|j                  g d|      }t        t        g d|j                              }t	        j
                  ||       y )	Nr9   r   r3   r   r   r   r   r   r   re   TFT)r   r   r   r   )r   r   r   r   r   r   )r#   r   r2   rZ   r0   s        r&   test_where_other_categoricalz4TestCategoricalIndexing.test_where_other_categorical  sW    [=QRSO8LM.6+oSYYGH
vx0r(   c                     t        t        g d            }d}t        j                  t        |      5  |j                  g dd       d d d        y # 1 sw Y   y xY w)Nr9   z3Cannot setitem on a Categorical with a new categoryr<   r   re   r   r   r?   r@   rA   r   )r#   r   rC   s      r&   test_where_new_category_raisesz6TestCategoricalIndexing.test_where_new_category_raises  sH    [12C]]9C0 	0II)3/	0 	0 	0s   AAc                     t        t        g dg dd            }t        g dg dd      }t        j                  t        d      5  |j                  g d	|       d d d        y # 1 sw Y   y xY w)
Nr9   r   TrE   r   r   zwithout identical categoriesr<   r   r   )r#   r   r2   s      r&   !test_where_ordered_differs_rasiesz9TestCategoricalIndexing.test_where_ordered_differs_rasies  sc    4HRVW
 (<d
 ]]9,JK 	2II)51	2 	2 	2s   	A''A0)r\   r]   r^   rh   rj   r   r?   r_   r`   r   r   r	   r   mathr   r   r   r   r   r   r   r   r   r   ra   r(   r&   rc   rc   {   sD   6	638j [[	rvvsB%ueUS0	0 [[-q!f/EF2 G2 [[|\<N [[\QFQFQFQF+KL[[[;8H*IJ[[W&?@< A K M	<&
11102r(   rc   c                       e Zd Zd Zej
                  j                  d edd      dfd edd      d	fd
 ed      d	f e	d      d	fge
      d        Zd Zy)TestContainsc                    t        t        d      t        d            }d|v sJ d|vsJ t        j                  |vsJ t	        j
                  t        d      5  dg|v sJ 	 d d d        d	|vsJ d|vsJ t        t        d      t        j                  gz   t        d            }t        j                  |v sJ y # 1 sw Y   [xY w)
Naabbcacabr3   r   zzunhashable type: 'list'r<   r   r   )r   listr   r   r?   r@   rA   rJ   s     r&   test_containszTestContains.test_contains   s    $x.T%[Aczz#~~vvS   ]]9,EF 	3#::	 ||||$x.BFF83ULvv}}	 	s   B>>Czitem, expectedr   r   T)      ?Tg      ?r   F)r   F)idsc                 f    t        t        j                  t        d                  }||v }||u sJ y )Nrf   )r   r   from_breaksr   )r#   itemr0   rK   rZ   s        r&   test_contains_intervalz#TestContains.test_contains_interval1  s4     -33E!H=>!!!r(   c                     t        g d      }d|vsJ t        j                  t        d      5  dg|v  d d d        t        j                  t        d      5  ddg|v  d d d        y # 1 sw Y   4xY w# 1 sw Y   y xY w)N)r   r   rf   r   zunhashable typer<   r   )r   r?   r@   rA   rJ   s     r&   test_contains_listzTestContains.test_contains_listC  s|    )$#~~]]9,=> 	ESL	 ]]9,=> 	#J#	 		 		 	s   A(A4(A14A=N)r\   r]   r^   r   r?   r_   r`   r   r   r   r{   r   r   ra   r(   r&   r   r     s|    " [[a^T"c3'q\5!q\5!	
   ""
r(   r   indexTFc                     t        t        d            }t        g d      }| rt        |      }t	        j
                  |      sJ ||   }||j                  d         }t        j                  ||       y )Nrf   r   object)	r   r   r   r   comis_bool_indexerrV   r   r   r   r   r   rZ   r0   s        r&   test_mask_with_booleanr   P  sh    
q
C
)
*Cs#s###XF3::h'(H68,r(   c                     t        t        d            }t        g d      }| rt        |      }||   }||j	                  d         }t        j                  ||       y )Nrf   )TFNF)r   r   r   r   fillnar   r   r   s        r&   *test_mask_with_boolean_na_treated_as_falser   ]  sV     q
C
)
*Cs#XF3::e$%H68,r(   c              #      K   dd}| j                         5 }|j                  t        d|       d ddd       y# 1 sw Y   yxY ww)z
    Monkeypatch Categorical.__array__ to ensure no implicit conversion.

    Raises
    ------
    ValueError
        When Categorical.__array__ is called.
    Nc                     t        d      )NzI cannot be converted.)r   )r#   r   s     r&   r    z(non_coercible_categorical.<locals>.arrayx  s    122r(   	__array__)N)contextsetattrr   )monkeypatchr    ms      r&   non_coercible_categoricalr   k  sB     3 
			 !			+{E2  s   A<	AAAc                  `    t        g d      } t        |       }|j                  d   }|dk(  sJ y )Nr9   r   r   )r   r   at)arrr   rZ   s      r&   test_series_atr     s.    
o
&C
+CVVAYFS==r(   )!r   numpyr   r?   pandasr   r   r   r   r   r   r	   r
   r   r   r   pandas._testing_testingr   pandas.core.commoncorecommonr   r   rc   r   r_   r`   r   r   fixturer   r   ra   r(   r&   <module>r      s              aI aIHa2 a2H. .b 4-0	- 1	- 4-0
- 1
-  (r(   