o
    ҷhG                     @   s  d Z ddlZddlZddl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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j-Z.G d,d- d-ej/Z0G d.d/ d/ej1Z2G d0d1 d1ej3Z4G d2d3 d3ej5Z6d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CategoricalDtype)basec                  C   s6   	 t jdjttjdd} | d | d kr	 | S q)NT   d   )sizer      )nprandomdefault_rngchoiceliststringascii_letters)values r   Z/var/www/html/venv/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'   s   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   data,   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_missing6   s   r   c                   C   s   t g dg dddS )N)r   BC)r   r   r   T
categoriesorderedr   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_sortingA   r"   r#   c                   C   s   t g dS )N)ar$   NNbr%   r$   cr   r   r   r   r   data_for_groupingF   s   r'   c                   @      e Zd ZdS )	TestDtypeN__name__
__module____qualname__r   r   r   r   r)   K       r)   c                       s2   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   r4   P   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   na_valueisnatmNULL_OBJECTS)r6   r   r   r9   na_value_objr   r   r   test_containsU   s   
zTestInterface.test_contains)	r+   r,   r-   pytestmarkxfailr4   r>   __classcell__r   r   r7   r   r/   O   s    r/   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   )r6   r   clsresultr   r   r   
test_emptyo   s   zTestConstructors.test_emptyN)r+   r,   r-   rK   r   r   r   r   rD   n       rD   c                   @   r(   )TestReshapingNr*   r   r   r   r   rM   y   r.   rM   c                       s*   e Zd Zejjdd fddZ  ZS )TestGetitemzBackwards compatibilityr0   c                    r2   r   )r3   test_getitem_scalarr5   r7   r   r   rO   ~   s   zTestGetitem.test_getitem_scalar)r+   r,   r-   r?   r@   skiprO   rB   r   r   r7   r   rN   }   s    rN   c                   @   r(   )TestSetitemNr*   r   r   r   r   rQ      r.   rQ   c                   @   r(   )	TestIndexNr*   r   r   r   r   rR      r.   rR   c                   @   r(   )TestMissingNr*   r   r   r   r   rS      r.   rS   c                   @   r(   )
TestReduceNr*   r   r   r   r   rT      r.   rT   c                   @   r(   )TestAccumulateNr*   r   r   r   r   rU      r.   rU   c                       sL   e Zd Zejjdd fddZdd Zejddd	gd
d Z	  Z
S )TestMethodszUnobserved categories includedr0   c                    s   t  ||S r   )r3   test_value_counts)r6   all_datadropnar7   r   r   rW      s   zTestMethods.test_value_countsc                    s   |d\}}t |}t |}||dd }t dd tt|t|D }t|| |jd  | dd }t  fddt|D }t|| d S )	Nr   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   rZ   r   r   r[   r   r   r   r^      r_   c                    s   g | ]}|  qS r   r   )r`   r$   valr   r   ra      s    )pdSeriescombinezipr   r;   assert_series_equaliloc)r6   data_repeated
orig_data1
orig_data2s1s2rJ   expectedr   rb   r   test_combine_add   s   


zTestMethods.test_combine_add	na_actionNignorec                 C   s"   |j dd |d}t|| d S )Nc                 S   s   | S r   r   )xr   r   r   r^      s    z&TestMethods.test_map.<locals>.<lambda>)rq   )mapr;   assert_extension_array_equal)r6   r   rq   rJ   r   r   r   test_map   s   zTestMethods.test_map)r+   r,   r-   r?   r@   rA   rW   rp   parametrizerv   rB   r   r   r7   r   rV      s    rV   c                   @   r(   )TestCastingNr*   r   r   r   r   rx      r.   rx   c                       s(   e Zd Z fddZ 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 argumentr0   )node
add_markerr?   r@   rA   r3   test_arith_frame_with_scalarr6   r   all_arithmetic_operatorsrequestop_namer7   r   r   r      s   z.TestArithmeticOps.test_arith_frame_with_scalarc                    rz   r{   )r}   r~   r?   r@   rA   r3   test_arith_series_with_scalarr   r7   r   r   r      s   z/TestArithmeticOps.test_arith_series_with_scalar)r+   r,   r-   r   r   rB   r   r   r7   r   ry      s    ry   c                       s   e Zd Z fddZ  ZS )TestComparisonOpsc                    sj   d|j  d}|dvr,d}tjt|d ||| W d    d S 1 s%w   Y  d S t ||||S )N__)__eq____ne__z7Unordered Categoricals can only compare equality or not)match)r+   r?   raises	TypeErrorr3   _compare_other)r6   sr   opotherr   msgr7   r   r   r      s   "z TestComparisonOps._compare_other)r+   r,   r-   r   rB   r   r   r7   r   r      s    r   c                   @   r(   )TestParsingNr*   r   r   r   r   r      r.   r   c                   @   rC   )Test2DCompatc                 C   sH   t |dd}|ddksJ t |dd}|ddks"J d S )Nr
   z
Categories)reprreshapecount)r6   r   resr   r   r   test_repr_2d   s   zTest2DCompat.test_repr_2dN)r+   r,   r-   r   r   r   r   r   r      rL   r   )7__doc__r   numpyr   r?   pandasrd   r   pandas._testing_testingr;   pandas.api.typesr   pandas.tests.extensionr   r   fixturer   r   r   r!   r#   r'   BaseDtypeTestsr)   BaseInterfaceTestsr/   BaseConstructorsTestsrD   BaseReshapingTestsrM   BaseGetitemTestsrN   BaseSetitemTestsrQ   BaseIndexTestsrR   BaseMissingTestsrS   BaseReduceTestsrT   BaseAccumulateTestsrU   BaseMethodsTestsrV   BaseCastingTestsrx   BaseArithmeticOpsTestsry   BaseComparisonOpsTestsr   BaseParsingTestsr   NDArrayBacked2DTestsr   r   r   r   r   <module>   sL    

	



	