o
    5c%                     @   s  d Z ddlZddlZddlZddlZddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZ dd Zejdd	 Zejd
d Zejdd Zejdd Zejdd Zejdd Zejdd ZG dd dejZG dd dejZG dd dejZG dd dej Z!G dd dej"Z#G d d! d!ej$Z%G d"d# d#ej&Z'G d$d% d%ej(Z)G d&d' d'ej*Z+G d(d) d)ej,Z-G d*d+ d+ej.Z/G d,d- d-ej0Z1G d.d/ d/ej2Z3G d0d1 d1ej4Z5G d2d3 d3ej6Z7dS )4aj  
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)CategoricalCategoricalIndex	TimestampCategoricalDtype)basec                  C   s0   	 t jjttjdd} | d | d kr	 | S q)NTd   )sizer      )nprandomchoiceliststringascii_letters)values r   ]/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/extension/test_categorical.py	make_data    s   r   c                   C   s   t  S Nr   r   r   r   r   dtype+      r   c                   C   s
   t t S )zLength-100 array for this type.

    * data[0] and data[1] should both be non missing
    * data[0] and data[1] should not be equal
    )r   r   r   r   r   r   data0   s   
r   c                   C   s   t tjdgS )zLength 2 array with [NA, Valid]A)r   r   nanr   r   r   r   data_missing:   s   r   c                   C   s   t g dg dddS )N)r   BC)r   r   r   T
categoriesorderedr   r   r   r   r   data_for_sorting@      r"   c                   C   s   t g dddgddS )N)r   Nr   r   r   Tr   r!   r   r   r   r   data_missing_for_sortingE   r#   r$   c                   C   s   t jS r   )r   r   r   r   r   r   na_valueJ   r   r%   c                   C   s   t g dS )N)ar&   NNbr'   r&   cr!   r   r   r   r   data_for_groupingO   s   r)   c                   @      e Zd ZdS )	TestDtypeN__name__
__module____qualname__r   r   r   r   r+   T       r+   c                       2   e Zd Zejjdd fddZdd Z  ZS )TestInterfacezMemory usage doesn't matchreasonc                       t  | d S r   )supertest_memory_usageselfr   	__class__r   r   r7   Y   s   zTestInterface.test_memory_usagec                 C   s   |j j}||   }|d |v sJ |d |v sJ ||v s!J ||vs'J tjD ]}||u r1q*||vs7J ||v s=J q*d S )Nr   )r   r%   isnatmNULL_OBJECTS)r9   r   r   r%   na_value_objr   r   r   test_contains^   s   
zTestInterface.test_contains)	r-   r.   r/   pytestmarkxfailr7   r@   __classcell__r   r   r:   r   r2   X   s    r2   c                   @      e Zd Zdd ZdS )TestConstructorsc                 C   s:   |  }|jd|d}t||sJ |jtg ksJ d S )N)   r   )construct_array_type_empty
isinstancer   r   )r9   r   clsresultr   r   r   
test_emptyx   s   zTestConstructors.test_emptyN)r-   r.   r/   rN   r   r   r   r   rF   w       rF   c                   @   r*   )TestReshapingNr,   r   r   r   r   rP      r0   rP   c                       s*   e Zd Zejjdd fddZ  ZS )TestGetitemzBackwards compatibilityr3   c                    r5   r   )r6   test_getitem_scalarr8   r:   r   r   rR      s   zTestGetitem.test_getitem_scalar)r-   r.   r/   rA   rB   skiprR   rD   r   r   r:   r   rQ      s    rQ   c                   @   r*   )TestSetitemNr,   r   r   r   r   rT      r0   rT   c                   @   r*   )	TestIndexNr,   r   r   r   r   rU      r0   rU   c                   @   r*   )TestMissingNr,   r   r   r   r   rV      r0   rV   c                   @   r*   )
TestReduceNr,   r   r   r   r   rW      r0   rW   c                       r1   )TestMethodszUnobserved categories includedr3   c                    s   t  ||S r   )r6   test_value_counts)r9   all_datadropnar:   r   r   rY      s   zTestMethods.test_value_countsc                    s   |d\}}t |}t |}||dd }t dd tt|t|D }| || |jd  | dd }t  fddt|D }| || d S )	N   c                 S      | | S r   r   x1x2r   r   r   <lambda>       z.TestMethods.test_combine_add.<locals>.<lambda>c                 S   s   g | ]\}}|| qS r   r   ).0r&   r'   r   r   r   
<listcomp>   s    z0TestMethods.test_combine_add.<locals>.<listcomp>r   c                 S   r]   r   r   r^   r   r   r   ra      rb   c                    s   g | ]}|  qS r   r   )rc   r&   valr   r   rd      s    )pdSeriescombinezipr   assert_series_equaliloc)r9   data_repeated
orig_data1
orig_data2s1s2rM   expectedr   re   r   test_combine_add   s   


zTestMethods.test_combine_add)	r-   r.   r/   rA   rB   rC   rY   rs   rD   r   r   r:   r   rX      s    rX   c                   @   s  e Zd Zejdeegejddej	ge
dejggdd Zejdejdd	gd
dejddgddejeded	gddejeddeddgddejdej	gddgdd Zejddejdgddfdee
dddgjfgdd ZdS )TestCastingrL   r   r
   2000c                 C   sN   ||}d}t jttf|d |t W d    d S 1 s w   Y  d S )NzCannot (cast|convert)match)rA   raises
ValueError	TypeErrorastypeint)r9   rL   r   smsgr   r   r   test_cast_nan_to_int   s
   "z TestCasting.test_cast_nan_to_intrr   20192020zdatetime64[ns, UTC]rH   r   ztimedelta64[ns]zperiod[A-DEC]r\   intervalInt64c                 C   s"   | d |j}t|| d S )Ncategory)r{   r   r=   rk   )r9   rr   rM   r   r   r   %test_cast_category_to_extension_dtype   s   z1TestCasting.test_cast_category_to_extension_dtypezdtype, expectedzdatetime64[ns]z2015-01-01T00:00:00.000000000zdatetime64[ns, MET]z2015-01-01 00:00:00+0100MET)tzc                 C   s    t dg|}||ksJ d S )Nz
2015-01-01)r   r{   )r9   r   rr   rM   r   r   r   test_consistent_casting   s   z#TestCasting.test_consistent_castingN)r-   r.   r/   rA   rB   parametrizer   r   r   r   r   rg   NaTr   rh   PeriodIntervalr   arrayDatetimeIndexr   r   r   r   r   rt      s8      

rt   c                       sH   e Zd Z fddZ fddZdd Zdd Zef fd	d
	Z  Z	S )TestArithmeticOpsc                    4   |}|dkr|j tjjdd t || d S N__rmod__z/rmod never called when string is first argumentr3   )node
add_markerrA   rB   rC   r6   test_arith_frame_with_scalarr9   r   all_arithmetic_operatorsrequestop_namer:   r   r   r      s   z.TestArithmeticOps.test_arith_frame_with_scalarc                    r   r   )r   r   rA   rB   rC   r6   test_arith_series_with_scalarr   r:   r   r   r      s   z/TestArithmeticOps.test_arith_series_with_scalarc                 C   sF   t |}tjtdd ||  W d    d S 1 sw   Y  d S )Nz"cannot perform|unsupported operandrv   )rg   rh   rA   rx   rz   )r9   r   serr   r   r   $test_add_series_with_extension_array   s   

"z6TestArithmeticOps.test_add_series_with_extension_arrayc                 C   s   d S r   r   )r9   r   r   r   test_divmod_series_array  s   z*TestArithmeticOps.test_divmod_series_arrayc                    s   t  j|||tdS )N)exc)r6   _check_divmod_oprz   )r9   r}   opotherr   r:   r   r   r     s   z"TestArithmeticOps._check_divmod_op)
r-   r.   r/   r   r   r   r   NotImplementedErrorr   rD   r   r   r:   r   r      s    
r   c                   @   sD   e Zd Zdd Zejdddgddgeded	ggd
d ZdS )TestComparisonOpsc           	      C   s   d|j  d}|dkr"|||}||dd }||k s J d S |dkr=|||}||dd }||k s;J d S d}tjt|d ||| W d    d S 1 sWw   Y  d S )	N____eq__c                 S   s   | |kS r   r   xyr   r   r   ra     rb   z2TestComparisonOps._compare_other.<locals>.<lambda>__ne__c                 S   s   | |kS r   r   r   r   r   r   ra     rb   z7Unordered Categoricals can only compare equality or notrv   )r-   ri   allrA   rx   rz   )	r9   r}   r   r   r   r   rM   rr   r~   r   r   r   _compare_other  s   

"z TestComparisonOps._compare_otherr   r&   r'   r   r
   r   r   c                 C   s<   t jddg|d}t jddg|d}||k}| sJ d S )Nr   )r   r
   )r   
from_codesr   )r9   r   c1c2rM   r   r   r   test_not_equal_with_na  s   z(TestComparisonOps.test_not_equal_with_naN)	r-   r.   r/   r   rA   rB   r   r   r   r   r   r   r   r   
  s    r   c                   @   r*   )TestParsingNr,   r   r   r   r   r   *  r0   r   c                   @   rE   )Test2DCompatc                 C   sH   t |dd}|ddksJ t |dd}|ddks"J d S )Nr
   r   z
Categories)reprreshapecount)r9   r   resr   r   r   test_repr_2d/  s   zTest2DCompat.test_repr_2dN)r-   r.   r/   r   r   r   r   r   r   .  rO   r   )8__doc__r   numpyr   rA   pandasrg   r   r   r   pandas._testing_testingr=   pandas.api.typesr   pandas.tests.extensionr   r   fixturer   r   r   r"   r$   r%   r)   BaseDtypeTestsr+   BaseInterfaceTestsr2   BaseConstructorsTestsrF   BaseReshapingTestsrP   BaseGetitemTestsrQ   BaseSetitemTestsrT   BaseIndexTestsrU   BaseMissingTestsrV   BaseNoReduceTestsrW   BaseMethodsTestsrX   BaseCastingTestsrt   BaseArithmeticOpsTestsr   BaseComparisonOpsTestsr   BaseParsingTestsr   NDArrayBacked2DTestsr   r   r   r   r   <module>   sN    

	




	0$ 