U
    >vf%                     @   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   s.   t jjttjdd} | d | d kr q*q | S )Nd   )sizer      )nprandomchoiceliststringascii_letters)values r   K/tmp/pip-unpacked-wheel-vdrwu74i/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   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 dddgdddgddS )Nr   BCT
categoriesZorderedr   r   r   r   r   data_for_sorting@   s    r    c                   C   s   t dd dgddgddS )Nr   r   Tr   r   r   r   r   r   data_missing_for_sortingE   s    r!   c                   C   s   t jS r   )r   r   r   r   r   r   na_valueJ   s    r"   c                	   C   s   t ddd d ddddgS )Nabcr   r   r   r   r   data_for_groupingO   s    r&   c                   @   s   e Zd ZdS )	TestDtypeN__name__
__module____qualname__r   r   r   r   r'   T   s   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                    s   t  | d S r   )supertest_memory_usageselfr   	__class__r   r   r0   Y   s    zTestInterface.test_memory_usagec                 C   s   |j j}||   }|d |ks&t|d |ks6t||ksBt||ksNttjD ]&}||krbqT||ksnt||ksTtqTd S )Nr   )r   r"   ZisnaAssertionErrortmZNULL_OBJECTS)r2   r   r   r"   Zna_value_objr   r   r   test_contains^   s    
zTestInterface.test_contains)	r)   r*   r+   pytestmarkxfailr0   r7   __classcell__r   r   r3   r   r,   X   s   r,   c                   @   s   e Zd Zdd ZdS )TestConstructorsc                 C   s:   |  }|jd|d}t||s$t|jtg ks6td S )N)   r   )Zconstruct_array_type_empty
isinstancer5   r   r   )r2   r   clsresultr   r   r   
test_emptyx   s    zTestConstructors.test_emptyN)r)   r*   r+   rC   r   r   r   r   r<   w   s   r<   c                   @   s   e Zd ZdS )TestReshapingNr(   r   r   r   r   rD      s   rD   c                       s*   e Zd Zejjdd fddZ  ZS )TestGetitemzBackwards compatibilityr-   c                    s   t  | d S r   )r/   test_getitem_scalarr1   r3   r   r   rF      s    zTestGetitem.test_getitem_scalar)r)   r*   r+   r8   r9   skiprF   r;   r   r   r3   r   rE      s   rE   c                   @   s   e Zd ZdS )TestSetitemNr(   r   r   r   r   rH      s   rH   c                   @   s   e Zd ZdS )	TestIndexNr(   r   r   r   r   rI      s   rI   c                   @   s   e Zd ZdS )TestMissingNr(   r   r   r   r   rJ      s   rJ   c                   @   s   e Zd ZdS )
TestReduceNr(   r   r   r   r   rK      s   rK   c                   @   s&   e Zd Zejdddgdd ZdS )TestAccumulateskipnaTFc                 C   s   d S r   r   )r2   r   Zall_numeric_accumulationsrM   r   r   r   test_accumulate_series   s    z%TestAccumulate.test_accumulate_seriesN)r)   r*   r+   r8   r9   parametrizerN   r   r   r   r   rL      s   rL   c                       s2   e Zd Zejjdd fddZdd Z  ZS )TestMethodszUnobserved categories includedr-   c                    s   t  ||S r   )r/   test_value_counts)r2   Zall_dataZdropnar3   r   r   rQ      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   | | 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   s   | | S r   r   rS   r   r   r   rU      rV   c                    s   g | ]}|  qS r   r   )rW   r#   valr   r   rX      s     )pdSeriescombinezipr   assert_series_equalZiloc)r2   Zdata_repeatedZ
orig_data1Z
orig_data2s1s2rB   expectedr   rY   r   test_combine_add   s    


zTestMethods.test_combine_add)	r)   r*   r+   r8   r9   r:   rQ   rc   r;   r   r   r3   r   rP      s   rP   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 )TestCastingrA   r   r
   2000c              	   C   s8   ||}d}t jttf|d |t W 5 Q R X d S )NzCannot (cast|convert)match)r8   raises
ValueError	TypeErrorastypeint)r2   rA   r   smsgr   r   r   test_cast_nan_to_int   s    z TestCasting.test_cast_nan_to_intrb   20192020zdatetime64[ns, UTC]r>   r   ztimedelta64[ns]zperiod[A-DEC]rR   intervalZInt64c                 C   s"   | d |j}t|| d S )Ncategory)rk   r   r6   r_   )r2   rb   rB   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td S )Nz
2015-01-01)r   rk   r5   )r2   r   rb   rB   r   r   r   test_consistent_casting   s    z#TestCasting.test_consistent_castingN)r)   r*   r+   r8   r9   rO   r   r   r   r   r   r[   ZNaTro   r\   ZPeriodZIntervalrt   arrayZDatetimeIndexrv   r   r   r   r   rd      s4     

rd   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                    s4   |}|dkr"|j tjjdd t || d S N__rmod__z/rmod never called when string is first argumentr-   )node
add_markerr8   r9   r:   r/   test_arith_frame_with_scalarr2   r   Zall_arithmetic_operatorsrequestop_namer3   r   r   r}      s    z.TestArithmeticOps.test_arith_frame_with_scalarc                    s4   |}|dkr"|j tjjdd t || d S ry   )r{   r|   r8   r9   r:   r/   test_arith_series_with_scalarr~   r3   r   r   r      s    z/TestArithmeticOps.test_arith_series_with_scalarc              	   C   s0   t |}tjtdd ||  W 5 Q R X d S )Nz"cannot perform|unsupported operandrf   )r[   r\   r8   rh   rj   )r2   r   Zserr   r   r   $test_add_series_with_extension_array  s    
z6TestArithmeticOps.test_add_series_with_extension_arrayc                 C   s   d S r   r   )r2   r   r   r   test_divmod_series_array  s    z*TestArithmeticOps.test_divmod_series_arrayc                    s   t  j|||tdS )N)exc)r/   _check_divmod_oprj   )r2   rm   opotherr   r3   r   r   r     s    z"TestArithmeticOps._check_divmod_op)
r)   r*   r+   r}   r   r   r   NotImplementedErrorr   r;   r   r   r3   r   rx      s
   
rx   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rB|||}||dd }||k stn\|dkrv|||}||dd }||k stn(d}tjt|d ||| W 5 Q R X d S )	N____eq__c                 S   s   | |kS r   r   xyr   r   r   rU     rV   z2TestComparisonOps._compare_other.<locals>.<lambda>__ne__c                 S   s   | |kS r   r   r   r   r   r   rU     rV   z7Unordered Categoricals can only compare equality or notrf   )r)   r]   allr5   r8   rh   rj   )	r2   rm   r   r   r   r   rB   rb   rn   r   r   r   _compare_other  s    

z TestComparisonOps._compare_otherr   r#   r$   r   r
   rp   rq   c                 C   s<   t jddg|d}t jddg|d}||k}| s8td S )Nr   )r   r
   )r   Z
from_codesr   r5   )r2   r   Zc1c2rB   r   r   r   test_not_equal_with_na"  s    z(TestComparisonOps.test_not_equal_with_naN)	r)   r*   r+   r   r8   r9   rO   r   r   r   r   r   r   r     s   r   c                   @   s   e Zd ZdS )TestParsingNr(   r   r   r   r   r   0  s   r   c                   @   s   e Zd Zdd ZdS )Test2DCompatc                 C   sH   t |dd}|ddks"tt |dd}|ddksDtd S )Nr
   r   z
Categories)reprZreshapecountr5   )r2   r   resr   r   r   test_repr_2d5  s    zTest2DCompat.test_repr_2dN)r)   r*   r+   r   r   r   r   r   r   4  s   r   ):__doc__r   Znumpyr   r8   Zpandasr[   r   r   r   Zpandas._testingZ_testingr6   Zpandas.api.typesr   Zpandas.tests.extensionr   r   Zfixturer   r   r   r    r!   r"   r&   ZBaseDtypeTestsr'   ZBaseInterfaceTestsr,   ZBaseConstructorsTestsr<   ZBaseReshapingTestsrD   ZBaseGetitemTestsrE   ZBaseSetitemTestsrH   ZBaseIndexTestsrI   ZBaseMissingTestsrJ   ZBaseNoReduceTestsrK   ZBaseAccumulateTestsrL   ZBaseMethodsTestsrP   ZBaseCastingTestsrd   ZBaseArithmeticOpsTestsrx   ZBaseComparisonOpsTestsr   ZBaseParsingTestsr   ZNDArrayBacked2DTestsr   r   r   r   r   <module>   sN   

	




	0$ 