
     jw                         d dl mZm Z  d dlZd dlZd dlmZ d dlmZm	Z	 d dl
m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mZmZ d dlmZ  G d d          ZdS )	    )datedatetimeN)using_pyarrow_string_dtype)is_float_dtypeis_integer_dtype)CategoricalDtype)CategoricalCategoricalIndexDatetimeIndexIndexIntervalIntervalIndex
MultiIndexNaTSeries	Timestamp
date_rangeperiod_rangetimedelta_rangec                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zej                            d eddd           edddd           eddd          g          d             Zd Zd Zd Zd Zej                            d  ej         d!d"d#ej!        g           ej         g d$d%&          d'd(d)ej!        g e"j#        d*           e"j#        d+          e$g e%d,           e%d-          e$g e%d,d.           e%d-d.          e$gg          d/             Z&ej                            d0d1d2g          d3             Z'd4 Z(ej                            d5d6d'd(gd'd)gg          ej                            d0d1d2g          d7                         Z)d8 Z*ej        +                     e,            d9:          d;             Z-d< Z.d= Z/d> Z0d? Z1ej                            d@dA e2g          dB             Z3ej                            dCd1d2g          dD             Z4dE Z5ej                            dCd1d2g          dF             Z6dG Z7dH Z8dI Z9dJ Z:dK Z;dL Z<ej                            d@e=e>g          dM             Z?ej                            d@e=e>g          dN             Z@dO ZAej                            dPg dQg dRg          dS             ZBdT ZCdU ZDdV ZEdW ZFej                            dXd6dYg          dZ             ZGej                            dXd6dYg          d[             ZHd\ ZId] ZJej                            d0g d^          d_             ZKd` ZLda ZMdb ZNdc ZOdd ZPde ZQdf ZRd6S )gTestCategoricalConstructorsc                     t          j        g d          }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 )	N         abcdF
categoriesorderedz3The 'fastpath' keyword in Categorical is deprecatedmatchT)dtypefastpath)nparrayr   tmassert_produces_warningDeprecationWarningr	   selfcodesr'   msgs       C:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pandas/tests/arrays/categorical/test_constructors.pytest_fastpath_deprecatedz4TestCategoricalConstructors.test_fastpath_deprecated%   s    ## ,@,@,@%PPPC'(:#FFF 	; 	;UT::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   A''A+.A+c                 p    t          ddgg dd          }t          |d          }|j        j        sJ d S )Nr   r   r   r   r   Tr"   categoryr'   )r	   r'   r$   )r/   catress      r2   8test_categorical_from_cat_and_dtype_str_preserve_orderedzTTestCategoricalConstructors.test_categorical_from_cat_and_dtype_str_preserve_ordered,   sG    1a&YYYEEE#Z000y          c                     t          j        t          d          5  t          dddg           d d d            d S # 1 swxY w Y   d S )Nz#Categorical input must be list-liker%   ABr#   pytestraises	TypeErrorr	   r/   s    r2   !test_categorical_disallows_scalarz=TestCategoricalConstructors.test_categorical_disallows_scalar3   s    ]9,QRRR 	4 	4c
3333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4   =AAc                     d}t          j        t          |          5  t          t	          j        t          d          g                     d d d            d S # 1 swxY w Y   d S )Nz3> 1 ndim Categorical are not supported at this timer%   abcd)rA   rB   NotImplementedErrorr	   r)   r*   listr/   r1   s     r2   test_categorical_1d_onlyz4TestCategoricalConstructors.test_categorical_1d_only8   s    C].c::: 	2 	2$v,,00111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   0AA"Ac                 Z   d}t           }t          j        g d          }t          j        ||          5  t          g d|           d d d            n# 1 swxY w Y   t          j        ||          5  t          j        g dg d|           d d d            d S # 1 swxY w Y   d S )	Nz*'ordered' must either be 'True' or 'False'r   r   r   r%   r   r$   )r   r   r   r   r   r    r"   )rC   r)   r*   rA   rB   r	   
from_codes)r/   exp_msgexp_errr$   s       r2   test_validate_orderedz1TestCategoricalConstructors.test_validate_ordered>   sF   > (999%%]7'222 	4 	4			73333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 ]7'222 	 	"		ooow   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   AAA7B  B$'B$c                 
   t          g           }t          g           }t          j        |j        |           t          g g d          }t          g dt
          j                  }t          j        |j        |           d S )Nr   r?   r7   )r	   r   r+   assert_index_equalr#   r)   int64)r/   r    expecteds      r2   test_constructor_emptyz2TestCategoricalConstructors.test_constructor_emptyN   sv    OO99
alH555yyy111"(333
alH55555r;   c                     t          g ddg          }t          |j                                                  }|ddgk    sJ d S )NTFr?   )r	   sortedr#   tolist)r/   r8   r#   s      r2   test_constructor_empty_booleanz:TestCategoricalConstructors.test_constructor_empty_booleanX   sN    "$777CN113344
eT]******r;   c                     t          j        g dt                    }t          |          }t	          ddgd          }t          j        |j        |           |j        du sJ d S )N)r   r   r   r_   r`   r7   r_   r`   Ftupleize_cols)	r)   r*   objectr	   r   r+   rV   r#   r$   r/   valuesresultrX   s       r2   test_constructor_tuplesz3TestCategoricalConstructors.test_constructor_tuples^   so    666fEEEV$$$u===
f/:::~&&&&&&r;   c                 v   t          j        t          d          ft          d          ft          d          ft          d          fdgt                    d d         }t	          |          }t          t          d          ft          d          fgd          }t          j        |j        |           d S )Nz
2010-01-01z
2010-01-02r   r   r7   Fra   )	r)   r*   r   rc   r	   r   r+   rV   r#   rd   s       r2   !test_constructor_tuples_datetimesz=TestCategoricalConstructors.test_constructor_tuples_datetimese   s     <((*<((*<((*<((* 	
 	
 	
 2#	 V$$%%')L*A*A)CD
 
 
 	f/:::::r;   c                    t          j        dddt          j                    gd          }t	          |d          }|j        rJ d}t          j        t          |	          5  t	          |d
           d d d            d S # 1 swxY w Y   d S )Nr   r   r   Or7   FrO   zl'values' is not ordered, please explicitly specify the categories order by passing in a categories argument.r%   T)	r)   r*   r   nowr	   r$   rA   rB   rC   )r/   arrfactorr1   s       r2   test_constructor_unsortablez7TestCategoricalConstructors.test_constructor_unsortabley   s    h1a0<<<S%000>!!!D 	 ]9C000 	+ 	+T****	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   #BB	Bc                 z   t          t          dd          t          dd          t          dd          gd          }t          t          dd          t          dd          t          dd          g          }t          |d          }t          j        ||           t          j        |j        |           d S )Nr   r   r      TrO   )r	   r   r   r+   assert_categorical_equalrV   r#   )r/   rf   iiexps       r2   test_constructor_intervalz5TestCategoricalConstructors.test_constructor_interval   s    a^^Xa^^Xa^^<d
 
 
 HQNNHQNNHQNNKLL"d+++
#FC000
f/44444r;   c                 ,   t          j        g dt           j                  }t          |          }t	          j        |                                |           t          |g d          }t	          j        |                                |           t          |g d          }t	          j        |                                |           d}t          j        t          |          5  t          dd	gg d
           d d d            n# 1 swxY w Y   t          j        t          |          5  t          ddgg d           d d d            n# 1 swxY w Y   t          g d          }|j
        rJ t          g d          }t          |          }t	          j        ||           t          g dg d          }t          |          }t	          j        ||           t          g dg d          }t          |          }t	          j        ||           t          g dg d          }t          |g d          }t	          j        |                                |                                           t	          j        |j        t          g d                     t          g dg d          }t          t          |                    }t	          j        ||           t          g dg d          }t          t          |                    }t	          j        ||           t          g d          }t          t          g d                    }t	          j        ||           t          g dg d          }t          t          g d          g d          }t	          j        ||           t          dd	dt           j        gg d          }t#          |j                  sJ t          t           j        dd	dg          }t#          |j                  sJ t          t           j        dddg          }t%          |j                  sJ t          t           j        dddg          }t%          |j                  sJ t          dg          }t'          |j                  dk    sJ |j        d         dk    sJ t'          |j                  dk    sJ |j        d         dk    sJ t          dg          }t'          |j                  dk    sJ |j        d         dk    sJ t'          |j                  dk    sJ |j        d         dk    sJ t	          j        d           5  t          g dg d           d d d            n# 1 swxY w Y   t	          j        d           5  t          g dg d           d d d            n# 1 swxY w Y   t	          j        d           5  t          g dg d           t          dd	gg d          }d d d            n# 1 swxY w Y   t	          j        d           5  t          t          j        g d          g dd           d d d            d S # 1 swxY w Y   d S )N)r   r   r    r   r   r    r7   rP   r?   r    r   r   %Categorical categories must be uniquer%   r   r   )r   r   r   r   r   )r   r   r   r   r   r    r   r   )r   r    r   r   r          @      ?g      @r   )r   r   r   r   r   r   )r         rW   r5   Tr"   )r)   r*   object_r	   r+   assert_numpy_array_equal	__array__rA   rB   
ValueErrorr$   rt   rV   r#   r   r   nanr   r   lenr0   r,   )r/   exp_arrc1c2r1   r8   s         r2   test_constructorz,TestCategoricalConstructors.test_constructor   sU   (999LLL!!
#BLLNNG<<<___===
#BLLNNG<<<___===
#BLLNNG<<< 6]:S111 	+ 	+A			***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ ]:S111 	5 	5c
OOO444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 ---..: ---..__
#B+++---:N:N:NOOO__
#B+++---///JJJ__
#B+++---///JJJ888
#BLLNNBLLNNCCC
bmU???-C-CDDD ---:N:N:NOOO$$
#B+++---///JJJ$$
#B+++ ---.. 4 4 45566
#B+++---:N:N:NOOO 4 4 455BVBVBVWWW
#B+++ 1aBF+			BBB///// 261a+,,///// 261c1-..cn-----263S122cn----- 1#3>""a''''~a A%%%%39~~""""y|q    3%  3>""a''''~a C''''39~~""""y|q    
 '-- 	H 	H***GGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H '-- 	B 	B***yyyAAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B '-- 	< 	<***III666q!f;;;C	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<
 '-- 	Y 	Y7333			SWXXXX	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Ysl   *DDD1EEE<VV"%V"=WW#&W#>*X44X8;X8)Z		ZZc                    t          g d          }t          g dddg          }t          ||j                  }t          j        ||           t          t	          |          |j                  }t          j        ||           d S )Nr{   r   r    r?   )r	   r#   r+   rt   r   )r/   c0r   r   c3s        r2   )test_constructor_with_existing_categorieszETestCategoricalConstructors.test_constructor_with_existing_categories   s     ---..---3*EEE666
#B+++>>>
#B+++++r;   c                     d}t          j        t          |          5  t          ddgd           d d d            d S # 1 swxY w Y   d S )Nz.^Parameter 'categories' must be list-like, wasr%   r   r   r?   r@   rK   s     r2   test_constructor_not_sequencez9TestCategoricalConstructors.test_constructor_not_sequence
  s    ?]9C000 	4 	4c
s3333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   ?AAc                 *   d}t          j        t          |          5  t          t          j        dddgt          j        dddg           d d d            n# 1 swxY w Y   t          j        t          |          5  t          g dg d           d d d            n# 1 swxY w Y   t          j        t          |          5  t          t          dd	g          t          t          d	          g           d d d            d S # 1 swxY w Y   d S )
N%Categorical categories cannot be nullr%   r   r   r    r?   )Nr   r   r    nat20160101)	rA   rB   r   r	   r)   r   r   r   r   rK   s     r2   test_constructor_with_nullz6TestCategoricalConstructors.test_constructor_with_null  s   5]:S111 	U 	Uc3/RVS#s<STTTT	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U ]:S111 	Q 	Q---:O:O:OPPPP	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q ]:S111 	 	uj122:!6!67   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s5   .AAA>B  B$'B$5DDDc                    t          t          d          t          d                    }t          j        |j        t          |                     t          t          d          t          d                    }t          j        |j        t          |                    t                    |j                             d S )Naabbcacabr?   )	r
   rJ   r+   rt   re   r	   astyperc   r#   )r/   cis     r2   test_constructor_with_indexz7TestCategoricalConstructors.test_constructor_with_index  s    d8nneEEE
#BI{2???d8nneEEE
#I{299V#4#4OOO	
 	
 	
 	
 	
r;   c                    t          g d          }t          d dD                       }t          j        ||           t          t          d                    }t          j        ||           t	          j        t          d          g dg           t          g dd dD                       }t          j        ||           t          g dt          d                    }t          j        ||           d S )NrN   c              3      K   | ]}|V  d S N .0xs     r2   	<genexpr>zNTestCategoricalConstructors.test_constructor_with_generator.<locals>.<genexpr>-  s"      //!//////r;   r   r   rP   c              3      K   | ]}|V  d S r   r   r   s     r2   r   zNTestCategoricalConstructors.test_constructor_with_generator.<locals>.<genexpr>5  s"      0F0Fq0F0F0F0F0F0Fr;   r?   )r	   r+   rt   ranger   from_product)r/   rv   r8   s      r2   test_constructor_with_generatorz;TestCategoricalConstructors.test_constructor_with_generator(  s     )))$$//Y/////
#C---%((##
#C---q??? ;<<< )))0F0FI0F0F0FGGG
#C---)))a999
#C-----r;   c                     t          t          d                    }t          |          }t          j        |j        |d           t          g d|          }t          j        |j        |d           d S )Nr   T)exactr   r   r   r?   )r   r   r	   r+   rV   r#   )r/   rngr8   s      r2    test_constructor_with_rangeindexz<TestCategoricalConstructors.test_constructor_with_rangeindex:  sp    E!HHoo#
cnc>>>>)))444
cnc>>>>>>r;   dtlz1995-01-01 00:00:00r   s)periodsfreq
US/Eastern)r   r   tzz1 dayc                    t          |          }t          |          } t          |          |          }d |j        _        t          j        |j        |           t          j        |j	        t          j        dd                     |                                }t          |j        d<   t          |          } t          |          |                                          }d |j        _        t          j        |j        |           t          j        g dt          j                  }t          j        |j	        |           t%          |          }d|v sJ d S )Nr   int8r7   rj   )r   r   r   r   rj   r   )r   r	   type_datar   r+   rV   r#   r   r0   r)   arangecopyr   ilocdropnar*   r   repr)r/   r   r   r    rX   s2rv   rf   s           r2   "test_constructor_with_datetimelikez>TestCategoricalConstructors.test_constructor_with_datetimelikeD  s$    3KKNN499Q<<"
alH555
#AGRYq-G-G-GHHH VVXXOO499RYY[[))"
alH555h'''rw777
#AGS111ar;   c                    t          dddd          }|                    d           }t          |          }t          j        |j        |           t          t          |                    }t          j        |j        |           d S )Nz2015-01-01 10:00Dr   r   )r   r   r   )r   
_with_freqr	   r+   rV   r#   r   r/   idxrf   s      r2   -test_constructor_from_index_series_datetimetzzITestCategoricalConstructors.test_constructor_from_index_series_datetimetzi  s|    +#q\RRRnnT""S!!
f/555VC[[))
f/55555r;   c                     t          j                    }t          ||g          }|j        j        t
          k    sJ t          |j        d                   t           u sJ d S )Nr   )r   todayr	   r#   r'   rc   r   )r/   vr8   s      r2   test_constructor_date_objectsz9TestCategoricalConstructors.test_constructor_date_objectsr  sZ    JLL1a&!!~#v----CN1%&&$......r;   c                    t          ddd          }|                    d           }t          |          }t          j        |j        |           t          t          |                    }t          j        |j        |           d S )Nz1 daysr   r   r   r   )r   r   r	   r+   rV   r#   r   r   s      r2   ,test_constructor_from_index_series_timedeltazHTestCategoricalConstructors.test_constructor_from_index_series_timedeltaz  sy    hS!<<<nnT""S!!
f/555VC[[))
f/55555r;   c                     t          ddd          }t          |          }t          j        |j        |           t          t          |                    }t          j        |j        |           d S )Nz
2015-01-01r   r   r   )r   r	   r+   rV   r#   r   r   s      r2   )test_constructor_from_index_series_periodzETestCategoricalConstructors.test_constructor_from_index_series_period  sh    <c1===S!!
f/555VC[[))
f/55555r;   re   r}   g333333?g?r   rW   r7   r   r   r    z2014-01z2014-02z
2014-01-01z
2014-01-02)r   c                 l    t          |          }t          |          }t          j        ||           d S r   r	   r+   rt   )r/   re   r    r   s       r2   test_constructor_invariantz6TestCategoricalConstructors.test_constructor_invariant  s5    " ^^
#Ar*****r;   r$   TFc                     g d}t          ||          }t          g d|          }t          g d||          }t          j        ||           |j        |u sJ d S )N)r   r   r    rO   )r   r   r   r    r7   r"   )r   r	   r+   rt   r$   )r/   r$   r#   r'   rf   rX   s         r2   test_constructor_with_dtypez7TestCategoricalConstructors.test_constructor_with_dtype  s    $__
 W===111???   Z
 
 
 	#FH555~((((((r;   c                    t          ddgd          }d}t          j        t          |          5  t	          ddgddg|           d d d            n# 1 swxY w Y   t          j        t          |          5  t	          ddgd|           d d d            n# 1 swxY w Y   t          j        t          |          5  t	          ddgd	|           d d d            d S # 1 swxY w Y   d S )
Nr   r   TrO   z?Cannot specify `categories` or `ordered` together with `dtype`.r%   r#   r'   r$   r'   F)r   rA   rB   r   r	   r/   r'   r1   s      r2   (test_constructor_dtype_and_others_raiseszDTestCategoricalConstructors.test_constructor_dtype_and_others_raises  s    #sT:::O]:S111 	H 	Hc
SzGGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H ]:S111 	? 	?c
D>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? ]:S111 	@ 	@c
E????	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s5   AAA:BB"BC##C'*C'r#   Nc                     t          ddg||d          }t          ddg||          }t          j        ||           d S )Nr   r   r6   r#   r$   r'   r"   r   )r/   r#   r$   rf   rX   s        r2   test_constructor_str_categoryz9TestCategoricalConstructors.test_constructor_str_category  sX     #J:wj
 
 
 Szj'RRR
#FH55555r;   c                     t          j        t          d          5  t          ddgd           d d d            d S # 1 swxY w Y   d S )NzUnknown dtyper%   r   r   foor7   )rA   rB   r   r	   rD   s    r2   test_constructor_str_unknownz8TestCategoricalConstructors.test_constructor_str_unknown  s    ]:_=== 	- 	-Ae,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-rF   zCan't be NumPy strings)reasonc                     t          g dt          j        d          t          j        d          g          }t          d |j        D                       sJ d S )N)10r   r   r   c              3   J   K   | ]}t          |t          j                  V  d S r   )
isinstancer)   str_r   s     r2   r   zGTestCategoricalConstructors.test_constructor_np_strs.<locals>.<genexpr>  s.      BBa:a))BBBBBBr;   )r	   r)   r   allr#   )r/   r8   s     r2   test_constructor_np_strsz4TestCategoricalConstructors.test_constructor_np_strs  sW     ///BGCLL"'#,,+GHHBB3>BBBBBBBBBBr;   c                     t          g dd          }t          g d          }t          ||          }t          g dg dd          }t          j        ||           d S )NrP   TrO   r   r   r!   r7   r"   r   r	   r+   rt   r/   r'   re   rf   rX   s        r2   ,test_constructor_from_categorical_with_dtypezHTestCategoricalConstructors.test_constructor_from_categorical_with_dtype  sy     $???___--V5111OO
 
 
 	#FH55555r;   c                     t          d d          }t          g d          }t          ||          }t          g dg dd          }t          j        ||           d S )NTrO   r   r7   r"   r   r   s        r2   4test_constructor_from_categorical_with_unknown_dtypezPTestCategoricalConstructors.test_constructor_from_categorical_with_unknown_dtype  su     t444___--V5111OO
 
 
 	#FH55555r;   c                     t          g d          }t          |g ddd          }t          g dg dd          }t          j        ||           t          |g dd          }t          j        ||           d S )Nr   rP   Tr6   r   r"   r   rd   s       r2   (test_constructor_from_categorical_stringzDTestCategoricalConstructors.test_constructor_from_categorical_string  s    ___--J
 
 
 OO
 
 
 	#FH555 VNNN
#FH55555r;   c                    t          ddgg d          }t          ddgt          g d                    }t          j        ||           t          ddgt          g d                    }t          j        ||           d S )Nr   r   rP   r?   )r	   r+   rt   r
   )r/   rX   rf   s      r2   ,test_constructor_with_categorical_categorieszHTestCategoricalConstructors.test_constructor_with_categorical_categories  s    SzoooFFFc3ZK4P4PQQQ
#FH555c3Z4D___4U4UVVV
#FH55555r;   klassc                 8    t          j        | t                    S )Nr7   )r)   r*   rc   )r   s    r2   <lambda>z$TestCategoricalConstructors.<lambda>  s    !61J1J1J r;   c                      |d|dg          }t          |          }t          ddg          }g d}t          j        ||          }t          j        ||           d S )Nr   r   )r   rj   r   )r0   r'   )r	   r   rQ   r+   rt   )r/   r   nulls_fixturere   rf   r'   r0   rX   s           r2   test_construction_with_nullz7TestCategoricalConstructors.test_construction_with_null  so     ]C011V$$ #s,,

)UCCC
#FH55555r;   validatec                 |   t          j        t          d          |          }t          j                            d                              dd          }t          |          }t          j	        |||          }|j
        j        |j        k    sJ t          j        |j
        t          |                     d S )Nr   r7   r   r   )sizer'   r   )pdr*   r   r)   randomdefault_rngintegersr   r	   rQ   r#   r'   r+   rV   r   )r/   any_numeric_ea_dtyper   catsr0   r'   ro   s          r2   'test_from_codes_nullable_int_categorieszCTestCategoricalConstructors.test_from_codes_nullable_int_categories  s     xa(<===	%%a((11!!1<< &&$U%(KKK~#tz1111
cneDkk:::::r;   c                     g d}t          j        g |          }t          g |          }t          j        ||           d S )NrP   r?   r	   rQ   r+   rt   )r/   r8   rf   rX   s       r2   test_from_codes_emptyz1TestCategoricalConstructors.test_from_codes_empty  sK    oo's;;;rc222
#FH55555r;   c                     t          ddg          }|rOt          j        t          d          5  t	          j        ddg||           d d d            d S # 1 swxY w Y   d S t	          j        ddg||           d S )Nr   r   codes need to be between r%   r~   r   r   )r   rA   rB   r   r	   rQ   )r/   r   r'   s      r2   test_from_codes_validatez4TestCategoricalConstructors.test_from_codes_validate  s     !#s,, 	Kz1LMMM O O&1vUXNNNNO O O O O O O O O O O O O O O O O O "Aq6JJJJJJs   AAAc                 f   t          ddg          }d}t          j        t          |          5  t	          j        ddg|j                   d d d            n# 1 swxY w Y   t          j        t          |          5  t	          j        ddg|           d d d            d S # 1 swxY w Y   d S )Nr   r   r?   r  r%   r7   r   rA   rB   r   r	   rQ   r#   r   s      r2   "test_from_codes_too_few_categoriesz>TestCategoricalConstructors.test_from_codes_too_few_categories  sF    QF333)]:S111 	H 	H"Aq6e6FGGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H]:S111 	8 	8"Aq67777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8#   AA!A B&&B*-B*c                 b   t          ddg          }d}t          j        t          |          5  t	          j        dg|j                   d d d            n# 1 swxY w Y   t          j        t          |          5  t	          j        dg|           d d d            d S # 1 swxY w Y   d S )Nr   r   r?   $codes need to be array-like integersr%   r   r7   r  r   s      r2   test_from_codes_non_int_codesz9TestCategoricalConstructors.test_from_codes_non_int_codes'  sB    QF3334]:S111 	G 	G"C5U5EFFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G]:S111 	7 	7"C56666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s#   AA A?B$$B(+B(c                     t          j        t          d          5  t          j        g dg d           d d d            d S # 1 swxY w Y   d S )Nrz   r%   rN   )r   r   r   r?   rA   rB   r   r	   rQ   rD   s    r2   %test_from_codes_non_unique_categorieszATestCategoricalConstructors.test_from_codes_non_unique_categories/  s    ]:-TUUU 	J 	J"999IIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   AAAc                     t          j        t          d          5  t          j        g dddt
          j        g           d d d            d S # 1 swxY w Y   d S )Nr   r%   rN   r   r   r?   )rA   rB   r   r	   rQ   r)   r   rD   s    r2    test_from_codes_nan_cat_includedz<TestCategoricalConstructors.test_from_codes_nan_cat_included3  s    ]:-TUUU 	M 	M"999#sBF9KLLLL	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	Ms   &AAAc                 f   t          g d          }d}t          j        t          |          5  t	          j        g d|j                   d d d            n# 1 swxY w Y   t          j        t          |          5  t	          j        g d|           d d d            d S # 1 swxY w Y   d S )NrP   r?   z3codes need to be between -1 and len\(categories\)-1r%   )r   r   r7   r  r   s      r2   test_from_codes_too_negativez8TestCategoricalConstructors.test_from_codes_too_negative7  sF    OOO<<<D]:S111 	L 	L":::%:JKKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L]:S111 	< 	<":::U;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<r
  c                    t          g d          }t          g dd          }t          j        g d|j                  }t	          j        ||           t          j        g d|          }t	          j        ||           d S )NrP   r?   FrO   rN   r7   )r   r	   rQ   r#   r+   rt   )r/   r'   rv   r9   s       r2   test_from_codesz+TestCategoricalConstructors.test_from_codes?  s     OOO<<<///5999$YYY5;KLLL
#C---$YYYe<<<
#C-----r;   c                     t          ddgg d          }t          j        ddg |g d                    }t          j        ||           d S )Nr   r   rP   r?   r   r   r  )r/   r   rX   rf   s       r2   +test_from_codes_with_categorical_categorieszGTestCategoricalConstructors.test_from_codes_with_categorical_categoriesH  s^     SzoooFFF'A55;Q;QRRR
#FH55555r;   c                     t          j        t          d          5  t          j        ddg |g d                     d d d            d S # 1 swxY w Y   d S )Nrz   r%   r   r   )r   r   r   r  )r/   r   s     r2   6test_from_codes_with_non_unique_categorical_categorieszRTestCategoricalConstructors.test_from_codes_with_non_unique_categorical_categoriesP  s    ]:-TUUU 	C 	C"Aq655+A+ABBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   #AAAc                 x   ddt           j        g}t          g d          }t          j        t
          d          5  t          j        ||j                   d d d            n# 1 swxY w Y   t          j        t
          d          5  t          j        ||           d d d            d S # 1 swxY w Y   d S )Nr   r   rP   r?   r  r%   r7   )	r)   r   r   rA   rB   r   r	   rQ   r#   )r/   r0   r'   s      r2   test_from_codes_with_nan_codez9TestCategoricalConstructors.test_from_codes_with_nan_codeU  sH   Arv OOO<<<]:-STTT 	G 	G"5U5EFFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G]:-STTT 	7 	7"56666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s#   A%%A),A)B//B36B3r0   )r}   r|   r   )g?r|   r   c                 \   t          g d          }d}t          j        t          |          5  t	          j        ||j                   d d d            n# 1 swxY w Y   t          j        t          |          5  t	          j        ||           d d d            d S # 1 swxY w Y   d S )NrP   r?   r  r%   r7   r  r.   s       r2   test_from_codes_with_floatz6TestCategoricalConstructors.test_from_codes_with_float^  s,    !OOO<<<4]:S111 	< 	<"5%*:;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<]:S111 	7 	7"56666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s#   AAA=B!!B%(B%c           	      |   d}t          j        t          |          5  t          j        ddgddgt          ddg                     d d d            n# 1 swxY w Y   t          j        t          |          5  t          j        ddgdt          ddg          	           d d d            d S # 1 swxY w Y   d S )
NzCannot specifyr%   r   r   r   r   r   Tr   )rA   rB   r   r	   rQ   r   rK   s     r2   !test_from_codes_with_dtype_raisesz=TestCategoricalConstructors.test_from_codes_with_dtype_raisesj  sT   ]:S111 	 	"AC:5EsCj5Q5Q   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 ]:S111 	 	"A,<c3Z,H,H   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   +AAA;)B11B58B5c                     d}t          j        t          |          5  t          j        ddg           d d d            d S # 1 swxY w Y   d S )NzBoth were Noner%   r   r   r  rK   s     r2   test_from_codes_neitherz3TestCategoricalConstructors.test_from_codes_neitherv  s    ]:S111 	+ 	+"Aq6***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   AA	Ac                     t          j        ddgd          }ddg}t          j        ||          }t          j        |                    t
                    |          }t          j        ||           d S )Nr   r   Int64r7   r   r   r?   )r   r*   r	   rQ   to_numpyintr+   rt   )r/   r0   r#   rf   rX   s        r2   !test_from_codes_with_nullable_intz=TestCategoricalConstructors.test_from_codes_with_nullable_int{  sr    !Qw///3Z
'*EEE)%..*=*=*UUU
#FH55555r;   c                     t          j        dd gd          }ddg}d}t          j        t          |          5  t          j        ||           d d d            d S # 1 swxY w Y   d S )	Nr   r%  r7   r   r   zcodes cannot contain NA valuesr%   r?   )r   r*   rA   rB   r   r	   rQ   )r/   r0   r#   r1   s       r2   +test_from_codes_with_nullable_int_na_raiseszGTestCategoricalConstructors.test_from_codes_with_nullable_int_na_raises  s    !T'2223Z
.]:S111 	A 	A"5Z@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As   AA"%A"r'   r6   c                     ddg}t          j        g dd          }t          j        |||          }t          j        ||          }t          j        ||           d S )Nr   r   )r   r   r   r   i8r7   r)   r*   r	   _from_inferred_categoriesrQ   r+   rt   r/   r'   r   r0   rf   rX   s         r2   test_from_inferred_categoriesz9TestCategoricalConstructors.test_from_inferred_categories  sb    SzT2226tUEJJ)%66
#FH55555r;   c                     ddg}t          j        g dd          }t          j        |||          }t          j        g dddg          }t          j        ||           d S )Nr   r   )r   r   r   r   r,  r7   )r   r   r   r   r-  r/  s         r2   #test_from_inferred_categories_sortsz?TestCategoricalConstructors.test_from_inferred_categories_sorts  sj    SzT2226tUEJJ),,,c
CC
#FH55555r;   c                     g d}t          j        g dd          }t          g dd          }t          j        |||          }t          g dg dd	          }t          j        ||           d S )
Nr   )r   r   r   r   r,  r7   ry   TrO   )r   r   r   r!   r"   )r)   r*   r   r	   r.  r+   rt   r/   r   r0   r'   rf   rX   s         r2   #test_from_inferred_categories_dtypez?TestCategoricalConstructors.test_from_inferred_categories_dtype  s    T222 $???6tUEJJ   ___d
 
 
 	#FH55555r;   c                     g d}t          j        g dd          }t          ddg          }t          j        |||          }t          dddt           j        g          }t          j        ||           d S )N)r   2bad)r   r   r   r   r,  r7   r   r   )r)   r*   r   r	   r.  r   r+   rt   r4  s         r2   %test_from_inferred_categories_coerceszATestCategoricalConstructors.test_from_inferred_categories_coerces  s{       T222 !Q((6tUEJJ1a011
#FH55555r;   )NTFc                 `    t          g d|          }|j        t          |          k    sJ d S )NrN   rO   )r	   r$   bool)r/   r$   r8   s      r2   test_construction_with_orderedz:TestCategoricalConstructors.test_construction_with_ordered  s9     )))W555{d7mm++++++r;   c                     g d}t          |          }t          j        |j        t	          |                     t          j        t          j        |          t          j        |                     d S )N)r   r   y      @      ?)r	   r+   rV   r#   r   r   r)   r*   )r/   re   r   s      r2   test_constructor_imaginaryz6TestCategoricalConstructors.test_constructor_imaginary  s^      
bmU6]];;;
#BHRLL"(62B2BCCCCCr;   c                     t          t          j        g dt                              }t	          g d          }|j                            |          sJ d S )N)r    ri   r   r   r    r7   )ri   r@  r    )r	   r)   r*   rc   r   r#   equals)r/   r    expected_indexs      r2   "test_constructor_string_and_tuplesz>TestCategoricalConstructors.test_constructor_string_and_tuples  s[    !C!C!C6RRRSS<<<==|"">2222222r;   c                    t          j        ddd          }t          ||          }t          j        dd          }t          j        |j        |           t          j        |j	        |           t          |          }t          j        |j        |           t          j        |j	        |           t          t          |                    }t          j        |j        |           t          j        |j	        |           t          t          |          t          |                    }t          j        |j        |           t          j        |j	        |           |                    g d          }t          ||          }t          j        |j        t          j        g dd                     t          j        |j	        |           t          j        dd	d
          }t          ||          }t          j        g dd          }t          j        |j        |           t          j        |j	        |           t          t          dd          t          dd          g          }t          ||          }t          j        ddgd          }t          j        |j        |           t          j        |j	        |           d S )Nr   
   r   r?   r   r7   r         r   )rG  	   rj   r   r   )r   interval_ranger	   r)   r   r+   r   r0   rV   r#   rJ   taker*   r   r   )r/   r   r8   expected_codesre   s        r2   test_intervalz)TestCategoricalConstructors.test_interval  s|   2r222##...2V444
#CI~>>>
cnc222 #
#CI~>>>
cnc222 $s))$$
#CI~>>>
cnc222 $s))S		:::
#CI~>>>
cnc222 )))$$&S111
#CIrx			/P/P/PQQQ
cnc222 "1b!444&S111***F;;;
#CI~>>>
cnc222 Xa^^Xa^^<==##...1a&777
#CI~>>>
cnc22222r;   c                 d   t           j        j                            |gdz  t          j                              }t          |          }|j        |j        j        k    sJ t          t          t           j	        t           j	        g|j                            }t          j        ||           d S )Nr   r7   )r   arraysStringArray_from_sequenceStringDtyper	   r'   r#   r   NAr+   rt   )r/   r   ro   rf   rX   s        r2   )test_categorical_extension_array_nullablezETestCategoricalConstructors.test_categorical_extension_array_nullable  s    i#22Oar~'7'7 3 
 
 S!!yF-33333vrubenCIFFFGG
#FH55555r;   c                 ,   t          t          j        d                              d                    }t          j        ||j        d          }|j        |j        u sJ t          j        ||j        d          }t          j        ||          rJ d S )Nr   r   F)r'   r   T)	r	   r)   r   repeatrQ  r'   _codesr+   shares_memory)r/   r8   rf   s      r2   test_from_sequence_copyz3TestCategoricalConstructors.test_from_sequence_copy  s    ")A,,--a0011+CsyuMMM }
****+CsytLLL#FC0000000r;   c                     t          j        d                              d          }|d d d                                         }t	          ||          }||k                                    sJ d S )NrE  zM8[D]r   r?   )r)   r   viewr   r	   r   )r/   r#   re   r8   s       r2   $test_constructor_datetime64_non_nanoz@TestCategoricalConstructors.test_constructor_datetime64_non_nano  sl    Yr]]''00
CCaC%%''&Z888v""$$$$$$$r;   c                 |    t          dd          }|j        }t          |          }|j        j        }||k    sJ d S )Nz
2016-01-01r   rF  )r   r   r	   r#   )r/   dtirX   r8   rf   s        r2   test_constructor_preserves_freqz;TestCategoricalConstructors.test_constructor_preserves_freq  sI    q1118#$6!!!!!!r;   )S__name__
__module____qualname__r3   r:   rE   rL   rT   rY   r]   rg   rk   rq   rw   r   r   r   r   r   r   r   rA   markparametrizer   r   r   r   r   r   r   r)   r*   r   r   Periodr   r   r   r   r   r   r   xfailr   r   r   r   r   r   rJ   r   r   r  r  r	  r  r  r  r  r  r	   r
   r  r  r  r  r!  r#  r(  r*  r0  r2  r5  r9  r<  r>  rC  rM  rT  rY  r\  r_  r   r;   r2   r   r   $   s       ; ; ;! ! !4 4 4
2 2 2   6 6 6+ + +' ' '; ; ;(+ + +5 5 5lY lY lY\
, 
, 
,4 4 4  
 
 
. . .$? ? ? [J,acBBBJ,aclSSSOGQS999	
   :6 6 6/ / /6 6 66 6 6 [BHc3RV,--BHYYYg...#sBF#RYy!!929Y#7#7=Y|$$ii&=&=sC	,<888	,<888	
 + + + [Yu66) ) 76)
@ 
@ 
@ [\D3*sCj+IJJ[Yu666 6 76 KJ6- - - [1133<TUUC C VUC
6 6 66 6 66 6 66 6 6 [W'J'JD&QRR	6 	6 SR	6 [Z$77; ; 87;6 6 6 [Z$77K K 87K8 8 87 7 7J J JM M M< < <. . . [W{4D&EFF6 6 GF6 [W{4D&EFFC C GFC7 7 7 [W}}}mmm&DEE	7 	7 FE	7
 
 
+ + +
6 6 6A A A [WtZ&8996 6 :96 [WtZ&8996 6 :966 6 66 6 6 [Y(;(;(;<<, , =<,
D D D3 3 3(3 (3 (3T6 6 6	1 	1 	1% % %	" 	" 	" 	" 	"r;   r   )r   r   numpyr)   rA   pandas._configr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.dtypesr   pandasr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   pandas._testing_testingr+   r   r   r;   r2   <module>rn     s         
      5 5 5 5 5 5        7 6 6 6 6 6                                       k" k" k" k" k" k" k" k" k" k"r;   