U
    sVc=Z                     @   s  d dl Zd dlZd dlmZ d dlZd dlmZmZ d dl	m
Z d dlmZmZmZ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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d Zdd Z dS )     N)	Timestamp)IndexSeries)Float64Index
Int64IndexNumericIndexUInt64Index)NumericBasec                	   @   s  e Zd ZeZejejej	gddd Z
ej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dId%d&Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zejd5ed6dged7d8ged9ed6dged9fd:d; Zejd<e j!d=dd>e j"d?dd>gd@dA Z#dBdC Z$dDdE Z%dFdG Z&dHS )JTestFloatNumericIndexparamsc                 C   s   |j S Nparamselfrequest r   M/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/indexes/numeric/test_numeric.pydtype   s    zTestFloatNumericIndex.dtypecategory
datetime64objectc                 C   s   |j S r   r   r   r   r   r   invalid_dtype   s    z#TestFloatNumericIndex.invalid_dtypec                 C   s   t jd|d}| |S N   r   )nparange
_index_cls)r   r   valuesr   r   r   simple_index    s    z"TestFloatNumericIndex.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TestFloatNumericIndex.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_index1   s    z!TestFloatNumericIndex.mixed_indexc                 C   s   | j dddddg|dS )Nr&   r'   r(   r)   r*   r   r3   r4   r   r   r   float_index5   s    z!TestFloatNumericIndex.float_indexc                 C   s   t jtt||dd d S )NTexact)tmassert_index_equalevalrepr)r   r2   r   r   r   test_repr_roundtrip9   s    z)TestFloatNumericIndex.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$TestFloatNumericIndex.check_is_indexTc                 C   sB   | |sttj||dd |r4t|| js>tn
| | d S )NFr7   )equalsr?   r9   r:   r>   r   rB   )r   abis_float_indexr   r   r   check_coerce@   s
    z"TestFloatNumericIndex.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|dddddg|d}t||s(t|j|ks8t|tdddddg|d}t||sdt|j|kstt|tj	tj	g|d}t
|j st|ttj	g|d}t
|j std S )N   r#   r$   r%   r   r         ?)r   r>   r?   r   r   arrayr9   assert_numpy_array_equalr    nanpdisnaall)r   r   	index_clsr2   expectedresultr   r   r   test_constructorH   s2    z&TestFloatNumericIndex.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	|j }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'rD   rE   zdata is not compatible with Z20130101)r   __name__pytestraises	TypeErrorjoin
ValueErrorr   )r   rP   Zcls_namemsgr   r   r   test_constructor_invalido   s     z.TestFloatNumericIndex.test_constructor_invalidc              	   C   s   |  |tdddddg |  |ttdd  tjtdd" ttjtdd td	}W 5 Q R X |  ||	d
 d S )Nr"   r#   r$   r%   r   r'   will not inferrT   r   float64)
rG   r   r   r   r9   assert_produces_warningFutureWarningrJ   r   astype)r   r5   r6   rR   r   r   r   test_constructor_coerce   s
    &z-TestFloatNumericIndex.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)rF   r"   r#   r$   r%   )rG   r   r   r   r   )r   r5   r6   r   r   r   test_constructor_explicit   s        z/TestFloatNumericIndex.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 integersrT   rH   r#         @r   )rX   rY   r\   r   )r   Zany_int_numpy_dtyper]   r   r   r   test_type_coercion_fail   s    z-TestFloatNumericIndex.test_type_coercion_failc                 C   s0   t dddg|d}tj|t dddgdd d S )NrH   r#   rf   r   Tr7   )r   r9   r:   )r   Zfloat_numpy_dtyperA   r   r   r   test_type_coercion_valid   s    z.TestFloatNumericIndex.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 NrI          @)r   rC   r?   	identicalr   rL   )r   rP   rA   Zidx2r   r   r   test_equals_numeric   s    z)TestFloatNumericIndex.test_equals_numericotherrH   rI   rj   r   c                 C   s.   |  ddg}||st||s*td S ri   )r   rC   r?   )r   rm   rA   r   r   r   $test_equals_numeric_other_index_type   s    	z:TestFloatNumericIndex.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$      r2   rH   g      @r%   )r   ranger2   rc   r9   ra   rb   	get_valuer>   typer?   locatilocZiat)r   ro   r   ZserrQ   rR   r   r   r    test_lookups_datetimelike_values   s2    





z6TestFloatNumericIndex.test_lookups_datetimelike_valuesc                 C   sP   |  tjg}|dg r"t|dg r6t|tjg sLtd S )Nr   rH   )r   r   rL   isinitemr?   r@   r   r   r   "test_doesnt_contain_all_the_things   s    z8TestFloatNumericIndex.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 )NrI   TFrj   )r   r   rL   r9   rK   ry   rJ   pi)r   rP   rA   r   r   r   test_nan_multiple_containment   s    " "z3TestFloatNumericIndex.test_nan_multiple_containmentc                 C   s   | j }tdtjdgtdd}tdddgdd}tj|d|dd |tkrPdnd	}|dd
dgdd}tj|d||d tdddgdd}tj|d|dd d S )NrI   g      @xr   nameg?r   Tr7   equivrj   r#   obj)	r   r   r   rL   r,   r9   r:   Zfillnar   )r   rP   rA   expr8   r   r   r   test_fillna_float64  s    z)TestFloatNumericIndex.test_fillna_float64N)T)'rW   
__module____qualname__r   r   rX   fixturer   r`   float32r   r   r!   r2   r5   r6   r=   rB   rG   rS   r^   rd   re   rg   rh   rl   markparametrizer   r   r   rn   rM   Z
date_rangeZtimedelta_rangerx   r{   r}   r   r   r   r   r   r
      s`   



	



'	



&r
   c                   @   sL   e Zd ZeZejdd Zejdddddgdd	d
 Zdd Z	dd Z
dS )TestFloat64Indexc                 C   s   t jS r   )r   r`   r   r   r   r   r     s    zTestFloat64Index.dtypeint64uint64r   r   r   r   c                 C   s   |j S r   r   r   r   r   r   r     s    zTestFloat64Index.invalid_dtypec                 C   sP   | j }ttjtjg|d}t||s*t|j|ks8tt	|j
 sLtd S r/   )r   r   r   rJ   rL   r>   r?   r   rM   rN   r    rO   )r   r   rP   rR   r   r   r    test_constructor_from_base_index#  s
    z1TestFloat64Index.test_constructor_from_base_indexc                 C   s   | j }|tdddddgtjd}t||s2t|jtjksBt|tdddddgtjd}t||snt|jtjks~td S )NrI   r#   r$   r%   r   r   rH   )r   r   rJ   r   r>   r?   r   r`   r   r   rP   r2   r   r   r   test_constructor_32bit+  s    z'TestFloat64Index.test_constructor_32bitN)rW   r   r   r   r   rX   r   r   r   r   r   r   r   r   r   r     s   

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   sr   | j }|g |dd}| }|jdks*t||}tj|||dddd ||}tj|||dddd d S )NZFoor   r   Tr7   )r   viewr   r?   r9   r:   )r   r   rP   rA   Zidx_viewr   r   r   	test_view8  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 )NrH   r#   r$   r%   TFr   Zis_monotonic_increasingr?   Z!_is_strictly_monotonic_increasingZis_monotonic_decreasingZ!_is_strictly_monotonic_decreasingr   rP   r2   r   r   r   test_is_monotonicE  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 )NrH   r#   r$   TFr   r   r   r   r   test_is_strictly_monotonic[  s    


z%NumericInt.test_is_strictly_monotonicc                 C   s4   |}|  |j  kst| |j ks0td S r   )rO   r    r?   any)r   r!   rA   r   r   r   test_logical_compatl  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   copyrk   r?   r   rc   rename)r   r!   r   r2   rA   Zsame_values_different_typeZsame_valuesr   r   r   test_identicalq  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bazrT   012)rX   rY   rZ   r   )r   r]   datar   r   r   test_cant_or_shouldnt_cast  s    

z%NumericInt.test_cant_or_shouldnt_castc                 C   s   |}| t d S r   )r   r   )r   r!   r2   r   r   r   test_view_index  s    zNumericInt.test_view_indexc                 C   s"   |}| d}|jtjkstd S )NO)rc   r   r   Zobject_r?   )r   r!   r2   rR   r   r   r   test_prevent_casting  s    
zNumericInt.test_prevent_castingN)rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   7  s   r   c                   @   s   e Zd ZeZejejej	ej
ejgddd Zej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d Zdd  Zd!S )"TestIntNumericIndexr   c                 C   s   |j S r   r   r   r   r   r   r     s    zTestIntNumericIndex.dtyper   r   r   c                 C   s   |j S r   r   r   r   r   r   r     s    z!TestIntNumericIndex.invalid_dtypec                 C   s   | j tddd|dS )Nr      r#   r   )r   rr   r4   r   r   r   r!     s    z TestIntNumericIndex.simple_indexr   r   r#      	index_inc	index_decr-   c                 C   s   | j |j|dS r/   r0   r1   r   r   r   r2     s    zTestIntNumericIndex.indexc              	   C   s  | j }|j d}tjt|d |d W 5 Q R X |ddddg|d}|j}||d	d
}tj||d	d |d d }||d< |d |kst|t	j
kr|tkrdnd	}|ddddg|d}tddddg|d}	tj||	|d |tddddg|d}|ddddg|d}	tj||	|d |ddg|d}	t|fD ]V}
|
ddg|d|
t	ddg|d|
tddg|dfD ]}tj||	|d qrq6d S )NzF\(\.\.\.\) must be called with a collection of some kind, 5 was passedrT   r   r   rH   r#   r   T)r   r7     r   )r   rW   rX   rY   rZ   r    r9   r:   r?   r   r   r   r   iterrJ   r   )r   r   rP   r]   r2   arrZ	new_indexvalr8   rQ   clsrA   r   r   r   rS     s6    
z$TestIntNumericIndex.test_constructorc              	   C   s   | j }tjddddgtd}|||d}|jj|jks:t|tjkrd}tj	t
|d t|}W 5 Q R X |tkrvdnd	}tj|||d
 tjddddgtd}tjtdd |||d W 5 Q R X d S )NrH   r#   r$   r%   r   r_   rT   Tr   r7   r   4Zcasting)r   r   rJ   r   r    r   r?   r   r9   ra   rb   r   r   r:   rX   rY   rZ   )r   r   rP   r   r2   r]   Zwithout_dtyper8   r   r   r   test_constructor_corner  s    
z+TestIntNumericIndex.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 integersrT   r   r   )rX   rY   OverflowErrorr   )r   any_unsigned_int_numpy_dtyper]   r   r   r   ,test_constructor_coercion_signed_to_unsigned  s    z@TestIntNumericIndex.test_constructor_coercion_signed_to_unsignedc                 C   s4   t |d}t|g}tdg}t|| d S NrH   )r   r   rt   r   r   r9   r:   )r   Zany_signed_int_numpy_dtypescalarrR   rQ   r   r   r   test_constructor_np_signed   s    

z.TestIntNumericIndex.test_constructor_np_signedc                 C   s4   t |d}t|g}tdg}t|| d S r   )r   r   rt   r   r   r9   r:   )r   r   r   rR   rQ   r   r   r   test_constructor_np_unsigned  s    

z0TestIntNumericIndex.test_constructor_np_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 )NrH   r#   r$   r%   r   )r   r>   r   r?   r   rt   )r   r   r   r   r   test_coerce_list  s    z$TestIntNumericIndex.test_coerce_listN)rW   r   r   r   r   rX   r   r   r   int32Zint16int8r   r   r!   rr   r2   rS   r   r   r   r   r   r   r   r   r   r     s$   


 
.r   c                   @   sD   e Zd ZeZejdd Zejdddddgdd	d
 Zdd Z	dS )TestInt64Indexc                 C   s   t jS r   )r   r   r   r   r   r   r     s    zTestInt64Index.dtyper`   r   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dgtjd}t||s2t|jtjksBt|tdddddgtjd}t||snt|jtjks~td S NrH   r#   r$   r%   r   r   )r   r   rJ   r   r>   r?   r   r   r   r   r   r   r   %  s    z%TestInt64Index.test_constructor_32bitN)
rW   r   r   r   r   rX   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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S )TestUIntNumericIndexr   c                 C   s   |j S r   r   r   r   r   r   r   5  s    zTestUIntNumericIndex.dtyper   r   r   c                 C   s   |j S r   r   r   r   r   r   r   9  s    z"TestUIntNumericIndex.invalid_dtypec                 C   s   |  tjd|dS r   )r   r   r   r4   r   r   r   r!   =  s    z!TestUIntNumericIndex.simple_index            l   
        l           l           l           r   r   r-   c                 C   s   | j |jtjdS r/   )r   r   r   r   r   r   r   r   r2   B  s    zTestUIntNumericIndex.indexN)rW   r   r   r   r   rX   r   r   r   r   r   r!   r2   r   r   r   r   r   1  s   


r   c                   @   sT   e Zd ZeZejdd Zejdddddgdd	d
 Zdd Z	dd Z
dd ZdS )TestUInt64Indexc                 C   s   t jS r   )r   r   r   r   r   r   r   Q  s    zTestUInt64Index.dtyper   r`   r   r   r   r   c                 C   s   |j S r   r   r   r   r   r   r   U  s    zTestUInt64Index.invalid_dtypec                 C   s  | j }|tkrdnd}|dddg}tdddg|d}tj|||d |ddg}tddg|d}tj|||d |ddg}tddg}tj|||d td	dgtd}ttjd	dgtd}tj|||d |dd
g|d}tdd
g|d}tj|||d d S )NTr   rH   r#   r$   r   r7   r   r   l           )r   r   r   r9   r:   r   r   rJ   )r   r   rP   r8   rA   resr   r   r   rS   [  s"    z TestUInt64Index.test_constructorc                 C   s.   dt t jjg}t|}t||ks*td S )Nr   )r   Ziinfor   maxr   listr?   )r   r    rR   r   r   r   'test_constructor_does_not_cast_to_floatt  s    z7TestUInt64Index.test_constructor_does_not_cast_to_floatc                 C   s   | j }|tdddddgtjd}t||s2t|jtjksBt|tdddddgtjd}t||snt|jtjks~td S r   )r   r   rJ   Zuint32r>   r?   r   r   r   r   r   r   r   {  s    z&TestUInt64Index.test_constructor_32bitN)rW   r   r   r   r   rX   r   r   r   rS   r   r   r   r   r   r   r   M  s   

r   boxc                 C   s   t j| tdS r/   )r   rJ   r   r~   r   r   r   <lambda>      r   c                 C   s   t | tdS r/   )r   r   r   r   r   r   r     r   c                 C   sp   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||jd d  d S )Nr   rH   r#   r$   r%   r   l   @>"NL l   '2w@ l   :e/ l   Ol_)#;f l   Pl_)#;f rq   r   r   )r   ru   r   r9   r:   r2   Zassert_equalrw   )r   ZseriesrR   rQ   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 )NrI   r#   r$   r   r   3F)r   rC   r?   )r6   Zstring_indexrR   r   r   r   test_float64_index_equals  s    

r   c                  C   s:   t dddg} | dd }tdddg}t|| d S )	NrH   r#   r$   c                 S   s   |  S r   r   r   r   r   r   r     r   z=test_map_dtype_inference_unsigned_to_signed.<locals>.<lambda>r   )r   mapr   r9   r:   rA   rR   rQ   r   r   r   +test_map_dtype_inference_unsigned_to_signed  s    r   c                  C   sL   t tjdddgtjd} | dd }t ddd	gtjd}t|| d S )
NrH   r#   r$   r   c                 S   s   | d S )N  r   r   r   r   r   r     r   z4test_map_dtype_inference_overflows.<locals>.<lambda>r   i  r   )r   r   rJ   r   r   r   r9   r:   r   r   r   r   "test_map_dtype_inference_overflows  s    r   )!Znumpyr   rX   Zpandas._libs.tslibsr   ZpandasrM   r   r   Zpandas._testingZ_testingr9   Zpandas.core.indexes.apir   r   r   r   Zpandas.tests.indexes.commonr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s0     !f{:
