U
    f/eI                     @   s   d dl Zd dlZd dlmZ d dlmZmZ d dlZ	d dlm
Z
mZmZmZmZ d dlmZ d dlmZ G dd deZG dd	 d	eZG d
d deZG dd deZejdedd dd gdd Zdd ZdS )    N)	Timestamp)is_platform_armis_platform_mac)Float64IndexIndex
Int64IndexSeriesUInt64Index)NumericBasec                	   @   s  e Zd ZeZejejgddd Z	ejdddddgdd	d
 Z
ejdd Zejdddddgdddddgdddddgdddddggddddgddd Zejdd Zejd d! Zd"d# Zd$d% ZdKd'd(Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zejd7ed8dged9d:ged;ed8dged;fd<d= Zejd>ej d?dd@ej!dAdd@gdBdC Z"dDdE Z#dFdG Z$dHdI Z%dJS )LTestFloat64Indexparamsc                 C   s   |j S Nparamselfrequest r   M/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/indexes/numeric/test_numeric.pydtype   s    zTestFloat64Index.dtypeint64uint64category
datetime64objectc                 C   s   |j S r   r   r   r   r   r   invalid_dtype   s    zTestFloat64Index.invalid_dtypec                 C   s   t jd|d}| |S N   r   )nparange
_index_cls)r   r   valuesr   r   r   simple_index#   s    zTestFloat64Index.simple_index      ?         r                 @      @      @      $@mixedfloatZ	mixed_decZ	float_decr   idsc                 C   s   | j |j|dS Nr   r"   r   r   r   r   r   r   r   index(   s    
zTestFloat64Index.indexc                 C   s   | j dddddg|dS )Nr%   r&   r'   r(   r   r   r"   r   r   r   r   r   mixed_index4   s    zTestFloat64Index.mixed_indexc                 C   s   | j dddddg|dS )Nr)   r*   r+   r,   r-   r   r6   r7   r   r   r   float_index8   s    zTestFloat64Index.float_indexc                 C   s   t tt|| d S r   )tmassert_index_equalevalrepr)r   r5   r   r   r   test_repr_roundtrip<   s    z$TestFloat64Index.test_repr_roundtripc                 C   s"   t |tstt || jrtd S r   )
isinstancer   AssertionErrorr"   r   idxr   r   r   check_is_index?   s    zTestFloat64Index.check_is_indexTc                 C   sB   | |sttj||dd |r4t|| js>tn
| | d S )NF)exact)equalsr@   r:   r;   r?   r"   rC   )r   abis_float_indexr   r   r   check_coerceC   s
    zTestFloat64Index.check_coercec                 C   s$  | j }|dddddg|d}t||s*t|j|ks8ttjdddddg|d}t|j| |tdddddg|d}t||st|j|kst|dddddg|d}t||st|j|kst|tdddddg|d}t||st|j|kst|tdddddgtj	d}t||s0t|j|ks@t|tdddddgtj	d}t||snt|j|ks~t|tj
tj
g|d}t|j st|ttj
g|d}t|j stttjtj
g|d}t||st|j|ks
tt|j s td S )N   r&   r'   r(   r   r         ?)r"   r?   r@   r   r    arrayr:   assert_numpy_array_equalr#   Zfloat32nanpdZisnaallr   )r   r   	index_clsr5   expectedresultr   r   r   test_constructorK   s:    z!TestFloat64Index.test_constructorc              	   C   s   | j }|j}| d}tjt|d |d W 5 Q R X dddg}tjttf|d |dddg W 5 Q R X d	}tjt|d |td
g W 5 Q R X d S )NzI\(\.\.\.\) must be called with a collection of some kind, 0\.0 was passedmatchr)   |z<String dtype not supported, you may need to explicitly cast z&could not convert string to float: 'a'rF   rG   zHfloat\(\) argument must be a string or a( real)? number, not 'Timestamp'Z20130101)r"   __name__pytestraises	TypeErrorjoin
ValueErrorr   )r   rQ   Zcls_namemsgr   r   r   test_constructor_invalidw   s"    z)TestFloat64Index.test_constructor_invalidc              	   C   s\   |  |tdddddg |  |ttdd  |  |ttjtdd td d S )Nr%   r&   r'   r(   r   r*   r   )rI   r   r    r!   rL   r   r   r8   r9   r   r   r   test_constructor_coerce   s     z(TestFloat64Index.test_constructor_coercec                 C   sH   | j |ttdd tddd | j |tdddd	dgtddd d S )
Nr   r*   r   F)rH   r%   r&   r'   r(   )rI   r   r    r!   r   r`   r   r   r   test_constructor_explicit   s        z*TestFloat64Index.test_constructor_explicitc              	   C   s4   d}t jt|d tdddg|d W 5 Q R X d S )Nz)Trying to coerce float values to integersrU   rJ   r&         @r   )rY   rZ   r]   r   )r   Zany_int_dtyper^   r   r   r   test_type_coercion_fail   s    z(TestFloat64Index.test_type_coercion_failc                 C   s,   t dddg|d}t|t dddg d S )NrJ   r&   rc   r   )r   r:   r;   )r   Zfloat_dtyperB   r   r   r   test_type_coercion_valid   s    z)TestFloat64Index.test_type_coercion_validc                 C   s   | j }|ddg}||s t||s.t|ddg}||sHt|dtjg}||sdt||srt|dtjg}||std S NrK          @)r"   rE   r@   	identicalr    rN   )r   rQ   rB   Zidx2r   r   r   test_equals_numeric   s    z$TestFloat64Index.test_equals_numericotherrJ   rK   rg   r   c                 C   s.   |  ddg}||st||s*td S rf   )r"   rE   r@   )r   rj   rB   r   r   r   $test_equals_numeric_other_index_type   s    	z5TestFloat64Index.test_equals_numeric_other_index_typevalsz
2016-01-01)Zperiodsz1 Dayc              	   C   s  t |tddd}|j||_|d }tt |j|d}W 5 Q R X t|t	|rb||ksft
tt |j|d}W 5 Q R X t|t	|r||kst
|d }t|t	|r||kst
|d }t|t	|r||kst
|jd }t|t	|r||kst
|jd }t|t	|r4||ks8t
|jd }t|t	|r\||ks`t
|jd }t|t	|r||kst
|jd }t|t	|r||kst
|jd }t|t	|r||kst
d S )Nr'      r5   rJ   g      @r(   )r   ranger5   astyper:   Zassert_produces_warningFutureWarning	get_valuer?   typer@   locatZilocZiat)r   rl   r   ZserrR   rS   r   r   r    test_lookups_datetimelike_values   s2    





z1TestFloat64Index.test_lookups_datetimelike_valuesc                 C   sP   |  tjg}|dg r"t|dg r6t|tjg sLtd S )Nr   rJ   )r"   r    rN   isinitemr@   rA   r   r   r   "test_doesnt_contain_all_the_things   s    z3TestFloat64Index.test_doesnt_contain_all_the_thingsc                 C   s   | j }|dtjg}t|dgtddg t|dtjgtddg t|tjgtddg t|dtjgtddg |ddg}t|tjgtddg d S )NrK   TFrg   )r"   r    rN   r:   rM   rw   rL   pi)r   rQ   rB   r   r   r   test_nan_multiple_containment  s    " "z.TestFloat64Index.test_nan_multiple_containmentc                 C   s   t dtjdgtdd}t dddgdd}t|d| | jdddgdd}t|d| t dd	dgdd}t|d	| d S )
NrK   g      @xr   nameg?r~   rg   r&   obj)r   r    rN   r/   r:   r;   Zfillnar"   )r   rB   expr   r   r   test_fillna_float64  s    z$TestFloat64Index.test_fillna_float64N)T)&rX   
__module____qualname__r   r"   rY   fixturer    float64r   r   r$   r5   r8   r9   r>   rC   rI   rT   r_   ra   rb   rd   re   ri   markparametrizer   r   r   rk   rO   Z
date_rangeZtimedelta_rangerv   ry   r{   r   r   r   r   r   r      sd   



	



,



&r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )
NumericIntc                 C   sj   | j }|g |dd}| }|jdks*t||}t|||dd ||}t|||dd d S )NZFoor}   r   )r"   viewr~   r@   r:   r;   )r   r   rQ   rB   Zidx_viewr   r   r   	test_view  s    

zNumericInt.test_viewc                 C   s   | j }|ddddg}|jdks$t|jdks2t|jdks@t|jdksNt|jdks\t|ddddg}|jdkszt|jdkst|jdkst|dg}|jdkst|jdkst|jdkst|jdkst|jdkstd S )NrJ   r&   r'   r(   TF)r"   Zis_monotonicr@   is_monotonic_increasing!_is_strictly_monotonic_increasingis_monotonic_decreasing!_is_strictly_monotonic_decreasingr   rQ   r5   r   r   r   test_is_monotonic+  s"    
zNumericInt.test_is_monotonicc                 C   s   | j }|ddddg}|jdks$t|jdks2t|ddddg}|jdksPt|jdks^t|ddg}|jstt|js~t|jrt|jrtd S )NrJ   r&   r'   TF)r"   r   r@   r   r   r   r   r   r   r   test_is_strictly_monotonicA  s    


z%NumericInt.test_is_strictly_monotonicc                 C   s4   |}|  |j  kst| |j ks0td S r   )rP   r#   r@   any)r   r$   rB   r   r   r   test_logical_compatR  s    zNumericInt.test_logical_compatc                 C   s   |}t | }||stt |td}||r8t|jtd}|d}t |td}||sht||rvtt |dtd|st|jtd|j|drtd S )Nr   foo)r~   r   )r   copyrh   r@   r   rp   rename)r   r$   r   r5   rB   Zsame_values_different_typeZsame_valuesr   r   r   test_identicalW  s    
zNumericInt.test_identicalc              	   C   sd   d}dddg}t jt|d | | W 5 Q R X dddg}t jt|d | | W 5 Q R X d S )	NzMString dtype not supported, you may need to explicitly cast to a numeric typer   barZbazrU   012)rY   rZ   r[   r"   )r   r^   datar   r   r   test_cant_or_shouldnt_castj  s    

z%NumericInt.test_cant_or_shouldnt_castc                 C   s   |}| t d S r   )r   r   )r   r$   r5   r   r   r   test_view_indexy  s    zNumericInt.test_view_indexc                 C   s"   |}| d}|jtjkstd S )NO)rp   r   r    Zobject_r@   )r   r$   r5   rS   r   r   r   test_prevent_casting}  s    
zNumericInt.test_prevent_castingN)rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   r   c                   @   s   e Zd ZeZejejgddd Z	ejdddddgdd	d
 Z
ejdd Zejedddedddgddgddd Zdd Zdd Zdd Zdd ZdS ) TestInt64Indexr   c                 C   s   |j S r   r   r   r   r   r   r     s    zTestInt64Index.dtyper   r   r   r   r   c                 C   s   |j S r   r   r   r   r   r   r     s    zTestInt64Index.invalid_dtypec                 C   s   | j tddd|dS )Nr      r&   r   )r"   ro   r7   r   r   r   r$     s    zTestInt64Index.simple_indexr   r   r&      	index_inc	index_decr0   c                 C   s   | j |j|dS r2   r3   r4   r   r   r   r5     s    zTestInt64Index.indexc              	   C   s4  | j }|ddddg|d}tddddg|d}t|| |tddddg}t|| |j d}tjt|d |d W 5 Q R X |j	}||d	d
}t|| |d d }||d< |d |kst
|ddg}t|fD ]P}	|	ddg|d|	tddg|d|	tddg|dfD ]}
t|
| qqd S )Nr   rJ   r&   r   zF\(\.\.\.\) must be called with a collection of some kind, 5 was passedrU   r   T)r   i  )r"   r   r:   r;   iterrX   rY   rZ   r[   r#   r@   r    rL   r   )r   r   rQ   r5   rR   r^   arrZ	new_indexvalclsrB   r   r   r   rT     s.    
zTestInt64Index.test_constructorc              	   C   s   | j }tjddddgtd}||}|jj|ks4tt|t	| tjddddgtd}t
jtdd	 || W 5 Q R X d
dddddddg}t
jtdd	 || W 5 Q R X d S )NrJ   r&   r'   r(   r   r   4ZcastingrU   r   r   g      ?r   )r"   r    rL   r   r#   r   r@   r:   r;   r   rY   rZ   r[   )r   r   rQ   r   r5   Zarr_with_floatsr   r   r   test_constructor_corner  s    z&TestInt64Index.test_constructor_cornerc              	   C   s0   d}t jt|d tdg|d W 5 Q R X d S )Nz5Trying to coerce negative values to unsigned integersrU   r   r   )rY   rZ   OverflowErrorr   )r   Z
uint_dtyper^   r   r   r   ,test_constructor_coercion_signed_to_unsigned  s    z;TestInt64Index.test_constructor_coercion_signed_to_unsignedc                 C   sH   t ddddg}t|| js tt ddddgtd}t|t ksDtd S )NrJ   r&   r'   r(   r   )r   r?   r"   r@   r   rs   )r   r   r   r   r   test_coerce_list  s    zTestInt64Index.test_coerce_listN)rX   r   r   r   r"   rY   r   r    r   r   r   r$   ro   r5   rT   r   r   r   r   r   r   r   r     s$   


 
(r   c                   @   s   e Zd ZeZejdd Zejdddddgdd	d
 Zejdd Z	ejdddddgdddddggddgddd Z
dd Zejje oe  dddd ZdS )TestUInt64Indexc                 C   s   t jS r   )r    r   )r   r   r   r   r     s    zTestUInt64Index.dtyper   r   r   r   r   r   c                 C   s   |j S r   r   r   r   r   r   r     s    zTestUInt64Index.invalid_dtypec                 C   s   |  tjd|dS r   )r"   r    r!   r7   r   r   r   r$     s    zTestUInt64Index.simple_index            l   
        l           l           l           r   r   r0   c                 C   s   |  |jS r   r3   r   r   r   r   r5     s    zTestUInt64Index.indexc                 C   s   | j }|dddg}tdddg|d}t|| |ddg}tddg|d}t|| |ddg}tddg}t|| tddgtd}ttjddgtd}t|| |ddg|d}tddg|d}t|| d S )NrJ   r&   r'   r   r   r   l           )r"   r   r:   r;   r   r    rL   )r   r   rQ   rB   resr   r   r   rT     s     z TestUInt64Index.test_constructorz+https://github.com/numpy/numpy/issues/19146)reasonc                 C   s.   dt t jjg}t|}t||ks*td S )Nr   )r    Ziinfor   maxr	   listr@   )r   r#   rS   r   r   r   'test_constructor_does_not_cast_to_float  s    z7TestUInt64Index.test_constructor_does_not_cast_to_floatN)rX   r   r   r	   r"   rY   r   r   r   r$   r5   rT   r   Zxfailr   r   r   r   r   r   r   r     s,   



r   boxc                 C   s   t j| tdS r2   )r    rL   r   r|   r   r   r   <lambda>(      r   c                 C   s   t | tdS r2   )r   r   r   r   r   r   r   (  r   c                 C   sn   t ddddddgdddd	d
dgd}|j| ddg }tdddgdd}t|j| t||d d  d S )Nr   rJ   r&   r'   r(   r   l   @>"NL l   '2w@ l   :e/ l   Ol_)#;f l   Pl_)#;f rn   r   r   )r   rt   r	   r:   r;   r5   Zassert_equal)r   ZseriesrS   rR   r   r   r   +test_uint_index_does_not_convert_to_float64&  s"    r   c                  C   sL   t dddg} t dddg}| |}|dks2t|| }|dksHtd S )NrK   r&   r'   r   r   3F)r   rE   r@   )r9   Zstring_indexrS   r   r   r   test_float64_index_equalsD  s    

r   )Znumpyr    rY   Zpandas._libs.tslibsr   Zpandas.compatr   r   ZpandasrO   r   r   r   r   r	   Zpandas._testingZ_testingr:   Zpandas.tests.indexes.commonr
   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s&     	fbA
