
    Owg[F                        d Z ddlZddlZddlmZ ddlZddlmZ ddl	m
Z ddlmZ ddlmZ d Zej"                  d        Z ej"                  dej&                  g	      d
        Zej"                  d        Z ej"                  dej&                  g	      d        Z ej"                  dej&                  g	      d        Z ej"                  dej&                  g	      d        Z ej"                  dej&                  g	      d        Zej"                  d        Z ej"                  dej&                  g	      d        Z ej"                  dej&                  g	      d        Z G d dej:                        Zd Zy)aj  
This file contains a minimal set of tests for compliance with the extension
array interface test suite, and should contain no other tests.
The test suite for the full functionality of the array is located in
`pandas/tests/arrays/`.

The tests in this file are inherited from the BaseExtensionTests, and only
minimal tweaks should be applied to get the tests passing (by overwriting a
parent method).

Additional tests should either be added to one of the BaseExtensionTests
classes (if they are relevant for the extension interface for all dtypes), or
be added to the array-specific tests in `pandas/tests/arrays/`.

    N)PerformanceWarningSparseDtype)SparseArray)basec                    t         j                  j                  d      }t        j                  |       r|j	                  d      }n1|j                  dddt              }|d   |d   k(  r|dxx   dz  cc<   | |dd d<   |S )N   d   )size   )r   dtyper      )nprandomdefault_rngisnanuniformintegersint)
fill_valuerngdatas      Y/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/extension/test_sparse.py	make_datar      sy    
))


"C	xx
{{{$||AsC|87d1gGqLGDAJK    c                      t               S Nr    r   r   r   r   *   s
    =r   )paramsc                 Z    t        t        | j                        | j                        }|S )z*Length-100 PeriodArray for semantics test.r   )r   r   param)requestress     r   r   r   /   s"     i.7==
ICJr   c                  D    t        t        j                  d      dz        S )Nr
   r	   )r   r   onesr   r   r   data_for_twosr'   6   s    rwws|a'((r   c                 P    t        t        j                  dg| j                        S )zLength 2 array with [NA, Valid]r   r!   r   r   nanr"   r#   s    r   data_missingr,   ;   s     {w}}==r   c              #        K    fd}| yw)z1Return different versions of data for count timesc              3      K   t        |       D ].  }t        t        j                        j                         0 y w)Nr!   )ranger   r   r"   )count_r#   s     r   genzdata_repeated.<locals>.genE   s6     u 	RAi67==QQ	Rs   >ANr   )r#   r2   s   ` r   data_repeatedr3   A   s     R Is   c                 4    t        g d| j                        S )N)r	   r   r   r!   )r   r"   r+   s    r   data_for_sortingr5   L   s    yW]];;r   c                 R    t        dt        j                  dg| j                        S )Nr	   r   r!   r)   r+   s    r   data_missing_for_sortingr7   Q   s    2661~'--@@r   c                      d S )Nc                 Z    t        j                  |       xr t        j                  |      S r   )pdisna)leftrights     r   <lambda>zna_cmp.<locals>.<lambda>X   s    rwwt}? r   r   r   r   r   na_cmpr?   V   s    ??r   c           
      x    t        ddt        j                  t        j                  ddddg| j                        S )Nr   r	   r   r!   r)   r+   s    r   data_for_groupingrA   [   s,    1bffbffaAq9gmmTTr   c                 `    t        ddt        j                  dddddddg
| j                        S )Nr      r	   r   r!   r)   r+   s    r   data_for_comparerF   `   s,    1bffb"aAq!<WWr   c                       e Zd ZdedefdZej                  j                  dddg       fd       Z	ej                  j                  dddg       fd       Z
d	 Zd
 Zej                  j                  d      ej                  j                  dddgej                  j!                  ddgddg      g      ej                  j                  dddg       fd                     Z fdZ fdZ fdZ fdZ fdZ fdZd Z fdZd Z fdZ fd Zej                  j;                  d!"       fd#       Zd$ Zd%Z d& Z!d' Z"ej                  j;                  d("       fd)       Z#d* Z$ fd+Z%d, Z&ej                  j                  d-d.d/g       fd0       Z'ej                  jP                  ej                  j                  d1ejR                  ejT                  ejV                  g       fd2              Z,ej                  jP                   fd3       Z-ej                  j                  d4d5 d6 e.d7e/j`                  g      fd8 d9 e.d7e/j`                  g      fed6 e.d:d;gd;<      fed9 e.d:e/j`                  g      fg      d=        Z1ej                  j                  d>d6d9g      d?        Z2ej                  j;                  e3d@A       fdB       Z4d6Z5d6Z6d6Z7d6Z8dC Z9 fdDZ: fdEZ; fdFZ<dGejT                  dHe.fdIZ=dHe.fdJZ>dHe.fdKZ?dHe.fdLZ@ej                  j;                  dM"       fdN       ZAej                  j;                  dO"      ej                  j                  dPddg       fdQ              ZB xZCS )RTestSparseArrayop_namereturnc                      y)NTr   )selfobjrI   s      r   _supports_reductionz#TestSparseArray._supports_reductionf   s    r   skipnaTFc                 \   |dv r<t         j                  j                  d      }|j                  j	                  |       nZ|dv rV|j
                  j                  dk(  r=|s;t         j                  j                  d      }|j                  j	                  |       t        | !  |||       y )Nprodmedianvarstdsemskewkurt,This should be viable but is not implementedreasonsummaxminmeanfzgetting a non-nan float)	pytestmarkxfailnode
add_markerr   kindsupertest_reduce_series_numericrL   r   all_numeric_reductionsrO   r#   rc   	__class__s         r   ri   z*TestSparseArray.test_reduce_series_numerici   s    ! &
 
 ;;$$E % D LL##D)"&CC

3&;;$$,E$FDLL##D)*41GPr   c                 \   |dv r<t         j                  j                  d      }|j                  j	                  |       nZ|dv rV|j
                  j                  dk(  r=|s;t         j                  j                  d      }|j                  j	                  |       t        | !  |||       y )NrQ   rY   rZ   r\   ra   z$ExtensionArray NA mask are different)	rb   rc   rd   re   rf   r   rg   rh   test_reduce_framerj   s         r   rn   z!TestSparseArray.test_reduce_frame   s    ! &
 
 ;;$$E % D LL##D)"&CC

3&;;$$,R$SDLL##D)!$(>Gr   c                 j    |j                   t        t        d      k(  rt        j                  d       y y )Nr   zCan't store nan in int array.)r   r   r   rb   skiprL   r   s     r   _check_unsupportedz"TestSparseArray._check_unsupported   s'    ::S!,,KK78 -r   c                    t        j                  d|d d i      }t        j                  dg di      }t        j                  dg di      j                  d      }|||g}t        j                  |      }t        j                  |D cg c]  }|j	                  d        c}      }t        j                  ||       y c c}w )NAr   )r   r	   r   )abccategoryc                 R    t        j                  |       j                  t              S r   )r   asarrayastypeobject)ss    r   r>   z:TestSparseArray.test_concat_mixed_dtypes.<locals>.<lambda>   s    rzz!}33F; r   )r:   	DataFramer{   concatapplytmassert_frame_equal)	rL   r   df1df2df3dfsresultxexpecteds	            r   test_concat_mixed_dtypesz(TestSparseArray.test_concat_mixed_dtypes   s     llCbq?+llC+,llC1299*ECo 399FIJQWW;<J
 	fh/ Ks   	C z9ignore:The previous implementation of stack is deprecatedcolumnsrt   B)rt   ru   )rt   rv   outerinner)namesfuture_stackc                 (    t         |   |||       y r   )rh   
test_stack)rL   r   r   r   rl   s       r   r   zTestSparseArray.test_stack   s     	4,7r   c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   test_concat_columnsrL   r   na_valuerl   s      r   r   z#TestSparseArray.test_concat_columns   s     %#D(3r   c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   'test_concat_extension_arrays_copy_falser   s      r   r   z7TestSparseArray.test_concat_extension_arrays_copy_false   s     %7hGr   c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   
test_alignr   s      r   r   zTestSparseArray.test_align        %4*r   c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   test_align_framer   s      r   r   z TestSparseArray.test_align_frame   s     % x0r   c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   test_align_series_framer   s      r   r   z'TestSparseArray.test_align_series_frame   s     %'h7r   c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   
test_merger   s      r   r   zTestSparseArray.test_merge   r   r   c                    t        j                  |t        t        |            D cg c]  }d|z  	 c}      }t	        j
                  |j                  j                        rHt	        j
                  |j                  d            r"t	        j
                  |j                  d         s%J |j                  d      |j                  d   k(  sJ |j                  d      |j                  d   k(  sJ y c c}w )Nr	   )indexrE   r   )
r:   Seriesr/   lenr   r   valuesr   getiloc)rL   r   isers       r   test_getzTestSparseArray.test_get   s    iiE#d)4D$EqQU$EF88CJJ))*88CGGAJ'BHHSXXa[,AAA771:!,,,wwqzSXXa[((( %Fs   C3
c                 H    | j                  |       t        | 	  ||       y r   )rr   rh   test_reindexr   s      r   r   zTestSparseArray.test_reindex   s     %T8,r   c                    t        |      }t        t        t        j                  |j
                  j                              }t        ddg|      }|j	                         }t        j                  ||       |j                  d      }t        t        t        j                  |j
                  j                              }t        ddgd|      }t        j                  |j	                         |       y )NTFr   r   r   r   )r   r   boolr:   r;   r   r   r   assert_sp_array_equalfillnaassert_equal)rL   r,   sarrexpected_dtyper   r   s         r   	test_isnazTestSparseArray.test_isna   s    <($T277<3E3E3P3P+QRe}NC
  2 {{1~$T277<3E3E3P3P+QRu~%~V
		X.r   c                     t         t        f}t        j                  |d      5  t        |   |       d d d        y # 1 sw Y   y xY wNF)check_stacklevel)r   FutureWarningr   assert_produces_warningrh   test_fillna_limit_backfill)rL   r,   warnsrl   s      r   r   z*TestSparseArray.test_fillna_limit_backfill   s?    #]3''F 	=G.|<	= 	= 	=s	   >Ac                     t        j                  |j                        r/|j                  t        j
                  j                  d             t        | !  |       y )Nz'returns array with different fill valuerZ   )	r   r   r   applymarkerrb   rc   rd   rh   test_fillna_no_op_returns_copy)rL   r   r#   rl   s      r   r   z.TestSparseArray.test_fillna_no_op_returns_copy   sF    88DOO$!!)R!S 	.t4r   UnsupportedrZ   c                 "    t         |           y r   )rh   test_fillna_seriesrL   r,   rl   s     r   r   z"TestSparseArray.test_fillna_series   s    
 	"$r   c                 j   |d   }t        j                  |ddgd      j                  |      }t        j                  |j                        rt        |j                  |      }n|j                  }t        j                  |j                  ||g|      ddgd      }t        j                  ||       y )Nr   r	   )rt   r   r   )
r:   r~   r   r;   r   r   r   _from_sequencer   r   )rL   r,   r   r   r   r   s         r   test_fillna_framez!TestSparseArray.test_fillna_frame  s    !!_
L1v>?FFzR77<**+ 2 2J?E &&E<<!00*j1IQV0WV
 	fh/r   zSparse[bool]c                    |j                  ddg      }t        j                  d|id      }|j                  d   }|j	                  |      }t        |j                  d      r^|r.|j                  j                  |j                  j                  u s0J |j                  j                  |j                  j                  usJ |j                  j                  j                         |j                         u sJ y )Nr   rt   Fcopy)r   r   blocks)taker:   r~   r   r   hasattr_mgrr   r   rt   _valuesto_dense)rL   r,   using_copy_on_writearrdf
filled_valr   s          r   test_fillna_copy_framez&TestSparseArray.test_fillna_copy_frame  s    A'\\3*51WWT]
:&277H%"yy~~););;;;yy~~V]]-?-????tt||$$&#,,.888r   c                 H   |j                  ddg      }t        j                  |d      }|d   }|j                  |      }|r|j                  |j                  u sJ |j                  |j                  usJ |j                  j                         |j                         u sJ y )Nr   Fr   r   )r   r:   r   r   r   r   )rL   r,   r   r   r   r   r   s          r   test_fillna_copy_seriesz'TestSparseArray.test_fillna_copy_series&  s    A'ii%(V
J';;&..000 ;;fnn444{{##%777r   zNot Applicablec                 $    t         |   |       y r   )rh   test_fillna_length_mismatchr   s     r   r   z+TestSparseArray.test_fillna_length_mismatch4  s    +L9r   c                    |d   |d   k7  sJ t        |      }|d d \  }}t        j                  |j                  ||||g|j                              }t        j                  g d      }|j                  |      }t        dd      }	t        j                  |j                  ||||g|	            }
t        j                  ||
       |j                  ||||g|j                        }t        j                  g d      }|j                  ||      }t        j                  |j                  ||||g|j                              }
t        j                  ||
       y )	Nr   r   r	   r   )TTFFfloatg        )TFTT)typer:   r   r   r   r   arraywherer   r   assert_series_equal)rL   r   r   clsru   rv   r   condr   	new_dtyper   others               r   test_where_seriesz!TestSparseArray.test_where_series8  s8   Aw$q'!!!4jBQx1ii**Aq!Q<tzz*JKxx234-	991h9K
 	vx0""Aq!Q<tzz"Bxx124'99S//Aq!DJJ/OP
vx0r   c                     t        j                  t        d      5  t        |   ||       d d d        y # 1 sw Y   y xY wr   )r   r   r   rh   test_searchsorted)rL   r5   	as_seriesrl   s      r   r   z!TestSparseArray.test_searchsortedN  s=    ''(:US 	CG%&6	B	C 	C 	Cs	   7A c                     |j                  d      }|j                  d   |j                  d<   |j                  d   |j                  d   k7  sJ y )Nr   r   )shift_sparse_values)rL   r   r   s      r   test_shift_0_periodsz$TestSparseArray.test_shift_0_periodsR  sN    A!%!4!4Q!7A$$Q'6+@+@+CCCCr   methodargmaxargminc                 J    | j                  |       t        | 	  |||       y r   )rr   rh   test_argmin_argmax_all_na)rL   r   r   r   rl   s       r   r   z)TestSparseArray.test_argmin_argmax_all_naY  s$     	%)&$Ar   boxc                 L    | j                  |       t        | 	  ||||       y r   )rr   rh   test_equals)rL   r   r   r   r   rl   s        r   r   zTestSparseArray.test_equals_  s&     	%D(Is;r   c                 $    t         |   |       y r   )rh   &test_equals_same_data_different_object)rL   r   rl   s     r   r   z6TestSparseArray.test_equals_same_data_different_objecte  s    6t<r   zfunc, na_action, expectedc                     | S r   r   r   s    r   r>   zTestSparseArray.<lambda>l      q r   Ng      ?c                     | S r   r   r   s    r   r>   zTestSparseArray.<lambda>m  r   r   ignorez1.0r*   r!   c                     t        dt        j                  g      }|j                  ||      }t	        j
                  ||       y )Nr   	na_action)r   r   r*   mapr   assert_extension_array_equal)rL   funcr   r   r   r   s         r   test_mapzTestSparseArray.test_mapi  s8     Arvv;'$)4
''9r   r   c                     d}t        j                  t        |      5  |j                  d |       d d d        y # 1 sw Y   y xY w)Nz-fill value in the sparse values not supported)matchc                 "    t         j                  S r   )r   r*   r   s    r   r>   z1TestSparseArray.test_map_raises.<locals>.<lambda>}  s
    rvv r   r   )rb   raises
ValueErrorr   )rL   r   r   msgs       r   test_map_raiseszTestSparseArray.test_map_raisesx  s=     >]]:S1 	<HH%H;	< 	< 	<s	   <Azno sparse StringDtype)r  r[   c                 $    t         |   |       y r   )rh   test_astype_string)rL   r   nullable_string_dtyperl   s      r   r  z"TestSparseArray.test_astype_string  s     	"4(r   c                 N    |j                   dk(  rt        j                  d       y y )Nr   z=Incorrected expected from Series.combine and tested elsewhere)r   rb   rp   rq   s     r   _skip_if_different_combinez*TestSparseArray._skip_if_different_combine  s"    ??a KKWX	  r   c                 H    | j                  |       t        | 	  ||       y r   )r  rh   test_arith_series_with_scalarrL   r   all_arithmetic_operatorsrl   s      r   r  z-TestSparseArray.test_arith_series_with_scalar  s!    ''--d4LMr   c                 H    | j                  |       t        | 	  ||       y r   )r  rh   test_arith_series_with_arrayr  s      r   r  z,TestSparseArray.test_arith_series_with_array  s!    ''-,T3KLr   c                     |j                   j                  dk7  rnD|j                  d      dvr1t        j                  j                  d      }|j                  |       t        | !  ||       y )Nr   r1   )mulrmulfloordiv	rfloordivpowmodrmodz result dtype.fill_value mismatchrZ   )	r   r   striprb   rc   rd   r   rh   test_arith_frame_with_scalar)rL   r   r  r#   rc   rl   s        r   r  z,TestSparseArray.test_arith_frame_with_scalar  sh    ::  A%%++C0 9
 
 ;;$$,N$OD%,T3KLr   r   rF   c                    |} |||      }t        |t        j                        r8t        |t        j                        sJ t        |j                  t              sJ t        |t
              sJ |j                  j                  t        j                  k(  sJ t        |t        j                        rl ||j                  |j                  j                        }t         ||j                         t        j                  |            |t        j                        }nt        j                   |t        j                  |j                        t        j                  |                  }t         ||j                         t        j                  |            |t        j                        }t        |t        j                        rt        j                  |      }t        j                  ||       y )Nr   )
isinstancer:   r   r   r   r   subtyper   bool_r   r   r   rz   allr   r   )	rL   r   rF   comparison_opr   opr   r   r   s	            r   _compare_otherzTestSparseArray._compare_other  sf    $e,eRYY'fbii000fllK888fk222||##rxx///eRYY',779Q9QRJ"#,,.

50AB%hhH 2::.99:BJJu<MNJ ##,,.

50AB%hhH
 eRYY'yy*H
)r   c                     t        j                  |      }| j                  |||d       | j                  |||d       | j                  |||d       | j                  |||t        j                         y )Nr   r   rD   )r:   r   r&  r   r*   )rL   rF   r$  r   s       r   test_scalarzTestSparseArray.test_scalar  si    ii()C!1=!DC!1=!DC!1="EC!1="&&Ir   c                 4   |j                   j                  dk(  r?|j                  dv r1t        j                  j                  d      }|j                  |       t        j                  ddd      }t        j                  |      }| j                  ||||       y )Nr   )eqgeleWrong fill_valuerZ      
   )r   r   __name__rb   rc   rd   r   r   linspacer:   r   r&  )rL   rF   r$  r#   rc   r   r   s          r   
test_arrayzTestSparseArray.test_array  s    !!,,1m6L6L Q
 7

 ;;$$,>$?D%kk"a$ii()C!1=#Fr   c                 D   |j                   j                  dk(  r@|j                  dk7  r1t        j                  j                  d      }|j                  |       t        j                  |      }|dz   }| j                  ||||       |dz  }| j                  ||||       y )Nr   gtr-  rZ   r   r	   )
r   r   r1  rb   rc   rd   r   r:   r   r&  )rL   rF   r$  r#   rc   r   r   s          r   test_sparse_arrayz!TestSparseArray.test_sparse_array  s    !!,,1m6L6LPT6T;;$$,>$?D%ii()"C!1=#F"C!1=#Fr   zDifferent reprc                 &    t         |   ||       y r   )rh   test_array_repr)rL   r   r   rl   s      r   r8  zTestSparseArray.test_array_repr  s    d+r   zresult does not match expectedas_indexc                 &    t         |   ||       y r   )rh   test_groupby_extension_agg)rL   r9  rA   rl   s      r   r;  z*TestSparseArray.test_groupby_extension_agg  s     	*85FGr   )Dr1  
__module____qualname__strr   rN   rb   rc   parametrizeri   rn   rr   r   filterwarningsr:   
MultiIndexfrom_tuplesr   r   r   r   r   r   r   r   r   r   r   r   rd   r   r   _combine_le_expected_dtyper   r   r   r   r   r   r   fails_arm_wheelsr   r   r~   r   r   r   r   r*   r  r	  	TypeErrorr  series_scalar_excframe_scalar_exc
divmod_excseries_array_excr  r  r  r  r&  r(  r3  r6  r8  r;  __classcell__)rl   s   @r   rH   rH   e   s      [[Xe}5Q 6Q0 [[Xe}5H 6H090 [[C [[#JMM%%Z('0B & 	
 [[^dE];8 <84H+18+)-/=
5 [[m,% -%0( "098 [[./: 0:1,CD [[X(';<B =B
 [[!![[URXXryy",,$GH< I "< [[!!= "= [[#$S"&&M :;(Kbff$>?$UENuEF(K89		
:: [[[4*:;< << [[i0GH) I)
 JYNMM "*99"*0;"*HJK JG; G	G+ 	G [[./, 0, [[>?[[Z$7H 8 @Hr   rH   c                 4    | j                         t        u sJ y r   )construct_array_typer   r   s    r   test_array_type_with_argrM    s    %%';666r   ) __doc__numpyr   rb   pandas.errorsr   pandasr:   r   pandas._testing_testingr   pandas.arraysr   pandas.tests.extensionr   r   fixturer   r*   r   r'   r,   r3   r5   r7   r?   rA   rF   ExtensionTestsrH   rM  r   r   r   <module>rX     s      ,    % '
   266{# $ ) ) 266{#> $>
 266{# $ 266{#< $< 266{#A $A @ @ 266{#U $U 266{#X $XNHd)) NHb7r   