o
    d%                     @   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Z7G d4d5 d5ej8Z9dS )6aj  
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   [/app/.heroku/python/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
categoriesZ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   r6   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$   ZisnatmZNULL_OBJECTS)r8   r   r   r$   Zna_value_objr   r   r   test_contains^   s   
zTestInterface.test_contains)	r,   r-   r.   pytestmarkxfailr6   r<   __classcell__r   r   r9   r   r1   X   s    r1   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   )Zconstruct_array_type_empty
isinstancer   r   )r8   r   clsresultr   r   r   
test_emptyx   s   zTestConstructors.test_emptyN)r,   r-   r.   rI   r   r   r   r   rB   w       rB   c                   @   r)   )TestReshapingNr+   r   r   r   r   rK      r/   rK   c                       s*   e Zd Zejjdd fddZ  ZS )TestGetitemzBackwards compatibilityr2   c                    r4   r   )r5   test_getitem_scalarr7   r9   r   r   rM      s   zTestGetitem.test_getitem_scalar)r,   r-   r.   r=   r>   skiprM   r@   r   r   r9   r   rL      s    rL   c                   @   r)   )TestSetitemNr+   r   r   r   r   rO      r/   rO   c                   @   r)   )	TestIndexNr+   r   r   r   r   rP      r/   rP   c                   @   r)   )TestMissingNr+   r   r   r   r   rQ      r/   rQ   c                   @   r)   )
TestReduceNr+   r   r   r   r   rR      r/   rR   c                   @   s&   e Zd Zejdddgdd ZdS )TestAccumulateskipnaTFc                 C      d S r   r   )r8   r   Zall_numeric_accumulationsrT   r   r   r   test_accumulate_series   s   z%TestAccumulate.test_accumulate_seriesN)r,   r-   r.   r=   r>   parametrizerV   r   r   r   r   rS      s    rS   c                       r0   )TestMethodszUnobserved categories includedr2   c                    s   t  ||S r   )r5   test_value_counts)r8   Zall_dataZdropnar9   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   x1Z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   r^      r_   c                    s   g | ]}|  qS r   r   )r`   r%   valr   r   ra      s    )pdSeriescombinezipr   assert_series_equalZiloc)r8   Zdata_repeatedZ
orig_data1Z
orig_data2s1s2rH   expectedr   rb   r   test_combine_add   s   


zTestMethods.test_combine_add)	r,   r-   r.   r=   r>   r?   rY   rl   r@   r   r   r9   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 )TestCastingrG   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)r=   raises
ValueError	TypeErrorastypeint)r8   rG   r   smsgr   r   r   test_cast_nan_to_int   s
   "z TestCasting.test_cast_nan_to_intrk   20192020zdatetime64[ns, UTC]rD   r   ztimedelta64[ns]zperiod[A-DEC]rZ   intervalZInt64c                 C   s"   | d |j}t|| d S )Ncategory)rt   r   r;   rh   )r8   rk   rH   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+0100ZMET)tzc                 C   s    t dg|}||ksJ d S )Nz
2015-01-01)r   rt   )r8   r   rk   rH   r   r   r   test_consistent_casting   s   z#TestCasting.test_consistent_castingN)r,   r-   r.   r=   r>   rW   r   r   r   r   r   rd   ZNaTrx   re   ZPeriodZIntervalr}   arrayZDatetimeIndexr   r   r   r   r   rm      s8      

rm   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 argumentr2   )node
add_markerr=   r>   r?   r5   test_arith_frame_with_scalarr8   r   Zall_arithmetic_operatorsrequestop_namer9   r   r   r      s   z.TestArithmeticOps.test_arith_frame_with_scalarc                    r   r   )r   r   r=   r>   r?   r5   test_arith_series_with_scalarr   r9   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 operandro   )rd   re   r=   rq   rs   )r8   r   Zserr   r   r   $test_add_series_with_extension_array  s   

"z6TestArithmeticOps.test_add_series_with_extension_arrayc                 C   rU   r   r   )r8   r   r   r   test_divmod_series_array  s   z*TestArithmeticOps.test_divmod_series_arrayc                    s   t  j|||tdS )N)exc)r5   _check_divmod_oprs   )r8   rv   opotherr   r9   r   r   r     s   z"TestArithmeticOps._check_divmod_op)
r,   r-   r.   r   r   r   r   NotImplementedErrorr   r@   r   r   r9   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   r^     r_   z2TestComparisonOps._compare_other.<locals>.<lambda>__ne__c                 S   s   | |kS r   r   r   r   r   r   r^     r_   z7Unordered Categoricals can only compare equality or notro   )r,   rf   allr=   rq   rs   )	r8   rv   r   r   r   r   rH   rk   rw   r   r   r   _compare_other  s   

"z TestComparisonOps._compare_otherr   r%   r&   r   r
   ry   rz   c                 C   s<   t jddg|d}t jddg|d}||k}| sJ d S )Nr   )r   r
   )r   Z
from_codesr   )r8   r   c1c2rH   r   r   r   test_not_equal_with_na"  s   z(TestComparisonOps.test_not_equal_with_naN)	r,   r-   r.   r   r=   r>   rW   r   r   r   r   r   r   r     s    r   c                   @   r)   )TestParsingNr+   r   r   r   r   r   0  r/   r   c                   @   rA   )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)reprZreshapecount)r8   r   resr   r   r   test_repr_2d5  s   zTest2DCompat.test_repr_2dN)r,   r-   r.   r   r   r   r   r   r   4  rJ   r   ):__doc__r   numpyr   r=   Zpandasrd   r   r   r   Zpandas._testingZ_testingr;   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r!   r#   r$   r(   ZBaseDtypeTestsr*   ZBaseInterfaceTestsr1   ZBaseConstructorsTestsrB   ZBaseReshapingTestsrK   ZBaseGetitemTestsrL   ZBaseSetitemTestsrO   ZBaseIndexTestsrP   ZBaseMissingTestsrQ   ZBaseNoReduceTestsrR   ZBaseAccumulateTestsrS   ZBaseMethodsTestsrX   ZBaseCastingTestsrm   ZBaseArithmeticOpsTestsr   ZBaseComparisonOpsTestsr   ZBaseParsingTestsr   ZNDArrayBacked2DTestsr   r   r   r   r   <module>   sP    

	




	0$ 