a
    Pf                     @   s   d Z ddl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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dS )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)using_pyarrow_string_dtypeCategoricalCategoricalDtype)basec                  C   s4   t jdjttjdd} | d | d kr q0q | S )N   d   )sizer      )nprandomZdefault_rngchoiceliststringascii_letters)values r   `/var/www/ai-form-bot/venv/lib/python3.9/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_missing8   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>   s    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_sortingC   s    r"   c                   C   s   t g dS )N)ar#   NNbr$   r#   cr   r   r   r   r   data_for_groupingH   s    r&   c                       s  e Zd Zejjdd fddZdd Zdd Zejj	d	d fd
dZ
ejjdd fddZdd Zejdddgdd Z fddZ fddZejd fddZejjddejddd g fd!d"Zejjd#dejd$d%d&g fd'd(Z  ZS ))TestCategoricalzMemory usage doesn't matchreasonc                    s   t  | d S r   )supertest_memory_usageselfr   	__class__r   r   r+   N   s    z!TestCategorical.test_memory_usagec                 C   s   |j j}||   }|d |v s&J |d |v s6J ||v sBJ ||vsNJ tjD ],}||u rbqT||vsnJ t sT||v sTJ qTd S )Nr   )r   na_valueZisnatmZNULL_OBJECTSr   )r-   r   r   r0   Zna_value_objr   r   r   test_containsS   s    
zTestCategorical.test_containsc                 C   s:   |  }|jd|d}t||s$J |jtg ks6J d S )N)   )r   )Zconstruct_array_type_empty
isinstancer   r   )r-   r   clsresultr   r   r   
test_emptym   s    zTestCategorical.test_emptyzBackwards compatibilityc                    s   t  | d S r   )r*   test_getitem_scalarr,   r.   r   r   r9   v   s    z#TestCategorical.test_getitem_scalarzUnobserved categories includedc                    s   t  ||S r   )r*   test_value_counts)r-   Zall_dataZdropnar.   r   r   r:   }   s    z!TestCategorical.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   | | S r   r   x1Zx2r   r   r   <lambda>       z2TestCategorical.test_combine_add.<locals>.<lambda>c                 S   s   g | ]\}}|| qS r   r   ).0r#   r$   r   r   r   
<listcomp>   r>   z4TestCategorical.test_combine_add.<locals>.<listcomp>r   c                 S   s   | | S r   r   r;   r   r   r   r=      r>   c                    s   g | ]}|  qS r   r   )r?   r#   valr   r   r@      r>   )pdSeriescombinezipr   r1   Zassert_series_equalZiloc)r-   Zdata_repeatedZ
orig_data1Z
orig_data2s1s2r7   expectedr   rA   r   test_combine_add   s    


z TestCategorical.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=      r>   z*TestCategorical.test_map.<locals>.<lambda>)rK   )mapr1   Zassert_extension_array_equal)r-   r   rK   r7   r   r   r   test_map   s    zTestCategorical.test_mapc                    s2   |}|dkr | tjjdd t || d S N__rmod__z/rmod never called when string is first argumentr(   )applymarkerpytestmarkxfailr*   test_arith_frame_with_scalarr-   r   Zall_arithmetic_operatorsrequestop_namer.   r   r   rV      s    z,TestCategorical.test_arith_frame_with_scalarc                    s2   |}|dkr | tjjdd t || d S rP   )rR   rS   rT   rU   r*   test_arith_series_with_scalarrW   r.   r   r   rZ      s    z-TestCategorical.test_arith_series_with_scalar)serc                    sj   d|j  d}|dvrTd}tjt|d ||| W d    qf1 sH0    Y  nt ||||S d S )N__)__eq____ne__z7Unordered Categoricals can only compare equality or not)match)__name__rS   Zraises	TypeErrorr*   _compare_other)r-   r[   r   opotherrY   msgr.   r   r   rb      s    *zTestCategorical._compare_otherzCategorical overrides __repr__r
   bigZsmallc                    s   t  || d S r   )r*   test_array_repr)r-   r   r
   r.   r   r   rg      s    zTestCategorical.test_array_reprZTBDas_indexTFc                    s   t  || d S r   )r*   test_groupby_extension_agg)r-   rh   r&   r.   r   r   ri      s    z*TestCategorical.test_groupby_extension_agg)r`   
__module____qualname__rS   rT   rU   r+   r2   r8   skipr9   r:   rJ   ZparametrizerO   rV   rZ   rC   rD   rb   rg   ri   __classcell__r   r   r.   r   r'   M   s(   	

	r'   c                   @   s   e Zd Zdd ZdS )Test2DCompatc                 C   sH   t |dd}|ddks"J t |dd}|ddksDJ d S )Nr   z
Categories)reprZreshapecount)r-   r   resr   r   r   test_repr_2d   s    zTest2DCompat.test_repr_2dN)r`   rj   rk   rs   r   r   r   r   rn      s   rn   )__doc__r   numpyr   rS   Zpandas._configr   ZpandasrC   r   Zpandas._testingZ_testingr1   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r!   r"   r&   ZExtensionTestsr'   ZNDArrayBacked2DTestsrn   r   r   r   r   <module>   s0   

	



s