o
    5c=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                	   @   st  e Zd ZeZejejej	gddd Z
ejg dddd Zejdd Zejg d	g d
g dg dgg dddd Zejdd Zejdd Zdd Zdd Zd@ddZdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zejd*ed+d,ged-d.ged/ed+d,ged/fd0d1 Zejd2e j!d3d4d5e j"d6d4d5gd7d8 Z#d9d: Z$d;d< Z%d=d> Z&d?S )ATestFloatNumericIndexparamsc                 C      |j S Nparamselfrequest r   _/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/indexes/numeric/test_numeric.pydtype      zTestFloatNumericIndex.dtypecategory
datetime64objectc                 C   r   r   r   r   r   r   r   invalid_dtype   r   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                 @      @      @      $@)r   r)   r(   r'   r&   )r/   r.   r-   r,   r+   )mixedfloat	mixed_dec	float_decr   idsc                 C      | j |j|dS Nr   r"   r   r   r   r   r   r   r   index%   s   
zTestFloatNumericIndex.indexc                 C      | j g d|dS )Nr%   r   r"   r   r   r   r   r   mixed_index1      z!TestFloatNumericIndex.mixed_indexc                 C   r;   )Nr*   r   r<   r=   r   r   r   float_index5   r?   z!TestFloatNumericIndex.float_indexc                 C   s   t jtt||dd d S )NTexact)tmassert_index_equalevalrepr)r   r:   r   r   r   test_repr_roundtrip9   s   z)TestFloatNumericIndex.test_repr_roundtripc                 C   s"   t |tsJ t || jrJ d S r   )
isinstancer   r"   r   idxr   r   r   check_is_index<   s   z$TestFloatNumericIndex.check_is_indexTc                 C   sD   | |sJ tj||dd |rt|| jsJ d S | | d S )NFrA   )equalsrC   rD   rH   r"   rK   )r   abis_float_indexr   r   r   check_coerce@   s
   z"TestFloatNumericIndex.check_coercec                 C   s  | j }|g d|d}t||sJ |j|ksJ tjg d|d}t|j| |tg d|d}t||s;J |j|ksBJ |g d|d}t||sQJ |j|ksXJ |tg d|d}t||sjJ |j|ksqJ |g d|d}t||sJ |j|ksJ |tg d|d}t||sJ |j|ksJ |tjtjg|d}t	
|j sJ |ttjg|d}t	
|j sJ d S )N   r'   r(   r)   r   r         ?r'   r(   r)   r   )r"   rH   r   r    arrayrC   assert_numpy_array_equalr#   nanpdisnaall)r   r   	index_clsr:   expectedresultr   r   r   test_constructorH   s2   z&TestFloatNumericIndex.test_constructorc                 C   s   | j }|j}| d}tjt|d |d W d    n1 s!w   Y  dddg}tjttf|d |g d W d    n1 sGw   Y  d|j }tjt|d |td	g W d    d S 1 slw   Y  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')rM   rN   r+   zdata is not compatible with 20130101)r"   __name__pytestraises	TypeErrorjoin
ValueErrorr   )r   r[   cls_namemsgr   r   r   test_constructor_invalido   s&   
"z.TestFloatNumericIndex.test_constructor_invalidc                 C   s   |  |tg d |  |ttdd  tjtdd ttjtdd td}W d    n1 s7w   Y  |  ||	d d S )Nr%   r   r,   will not inferr_   r   float64)
rP   r   r    r!   rC   assert_produces_warningFutureWarningrU   r   astype)r   r>   r@   r]   r   r   r   test_constructor_coerce   s   z-TestFloatNumericIndex.test_constructor_coercec                 C   sB   | j |ttdd tddd | j |tg dtddd d S )Nr   r,   r   F)rO   r%   )rP   r   r    r!   r   )r   r>   r@   r   r   r   test_constructor_explicit   s   
z/TestFloatNumericIndex.test_constructor_explicitc                 C   sH   d}t jt|d tg d|d W d    d S 1 sw   Y  d S )Nz)Trying to coerce float values to integersr_   rR   r'   g      @r   )rd   re   rh   r   )r   any_int_numpy_dtyperj   r   r   r   test_type_coercion_fail   s   "z-TestFloatNumericIndex.test_type_coercion_failc                 C   s,   t g d|d}tj|t g ddd d S )Nrs   r   TrA   )r   rC   rD   )r   float_numpy_dtyperJ   r   r   r   test_type_coercion_valid   s   z.TestFloatNumericIndex.test_type_coercion_validc                 C   s   | j }|ddg}||sJ ||sJ |ddg}||s$J |dtjg}||s2J ||s9J |dtjg}||sGJ d S NrT          @)r"   rL   	identicalr    rW   )r   r[   rJ   idx2r   r   r   test_equals_numeric   s   z)TestFloatNumericIndex.test_equals_numericotherrR   r'   rT   ry   r   c                 C   s.   |  ddg}||sJ ||sJ d S rx   )r"   rL   )r   r}   rJ   r   r   r   $test_equals_numeric_other_index_type   s   	z:TestFloatNumericIndex.test_equals_numeric_other_index_typevalsz
2016-01-01r(   )periodsz1 Dayc                 C   s  t |tddd}|j||_|d }tt |j|d}W d    n1 s+w   Y  t|t	|r;||ks=J tt |j|d}W d    n1 sTw   Y  t|t	|rd||ksfJ |d }t|t	|ru||kswJ |d }t|t	|r||ksJ |j
d }t|t	|r||ksJ |j
d }t|t	|r||ksJ |jd }t|t	|r||ksJ |jd }t|t	|r||ksJ |jd }t|t	|r||ksJ |jd }t|t	|r||ksJ d S )Nr(      r:   rR   g      @r)   )r   ranger:   rp   rC   rn   ro   	get_valuerH   typelocatilociat)r   r   r   serr\   r]   r   r   r    test_lookups_datetimelike_values   s6   





z6TestFloatNumericIndex.test_lookups_datetimelike_valuesc                 C   sP   |  tjg}|dg rJ |dg rJ |tjg s&J d S )Nr   rR   )r"   r    rW   isinitemrI   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 )NrT   TFry   )r"   r    rW   rC   rV   r   rU   pi)r   r[   rJ   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g ddd}tj|d|dd	 |tu r'dnd
}|g ddd}tj|d||d	 tg ddd}tj|d|dd	 d S )NrT         @xr   name)rT   皙?r   r   r   TrA   equiv)rT   ry   r   r'   )rT   objr   r   )	r"   r   r    rW   r1   rC   rD   fillnar   )r   r[   rJ   exprB   r   r   r   test_fillna_float64  s   z)TestFloatNumericIndex.test_fillna_float64N)T)'rc   
__module____qualname__r   r"   rd   fixturer    rm   float32r   r   r$   r:   r>   r@   rG   rK   rP   r^   rk   rq   rr   ru   rw   r|   markparametrizer   r   r   r~   rX   
date_rangetimedelta_ranger   r   r   r   r   r   r   r   r
      sb    



	


'	



&r
   c                   @   sF   e Zd ZeZejdd Zejg dddd Zdd Z	d	d
 Z
dS )TestFloat64Indexc                 C      t jS r   )r    rm   r   r   r   r   r     r   zTestFloat64Index.dtype)int64uint64r   r   r   r   c                 C   r   r   r   r   r   r   r   r        zTestFloat64Index.invalid_dtypec                 C   sP   | j }ttjtjg|d}t||sJ |j|ksJ t|j	
 s&J d S r7   )r"   r   r    rU   rW   rH   r   rX   rY   r#   rZ   )r   r   r[   r]   r   r   r    test_constructor_from_base_index#  s
   z1TestFloat64Index.test_constructor_from_base_indexc                 C   sv   | j }|tg dtjd}t||sJ |jtjksJ |tg dtjd}t||s1J |jtjks9J d S )NrS   r   rQ   )r"   r    rU   r   rH   r   rm   r   r   r[   r:   r   r   r   test_constructor_32bit+     z'TestFloat64Index.test_constructor_32bitN)rc   r   r   r   r"   rd   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J ||}tj|||dddd ||}tj|||dddd d S )NFoor   r   TrA   )r"   viewr   rC   rD   )r   r   r[   rJ   idx_viewr   r   r   	test_view8  s   

zNumericInt.test_viewc                 C   s   | j }|g d}|jdu sJ |jdu sJ |jdu sJ |jdu s%J |jdu s,J |g d}|jdu s9J |jdu s@J |jdu sGJ |dg}|jdu sSJ |jdu sZJ |jdu saJ |jdu shJ |jdu soJ d S )NrR   r'   r(   r)   TF)r)   r(   r'   rR   rR   r"   is_monotonic_increasing!_is_strictly_monotonic_increasingis_monotonic_decreasing!_is_strictly_monotonic_decreasingr   r[   r:   r   r   r   test_is_monotonicE  s"   
zNumericInt.test_is_monotonicc                 C   s   | j }|g d}|jdu sJ |jdu sJ |g d}|jdu s$J |jdu s+J |ddg}|js6J |js;J |jr@J |jrEJ d S )N)rR   rR   r'   r(   TF)r(   r'   rR   rR   rR   r   r   r   r   r   test_is_strictly_monotonic[  s   


z%NumericInt.test_is_strictly_monotonicc                 C   s4   |}|  |j  ksJ | |j ksJ d S r   )rZ   r#   any)r   r$   rJ   r   r   r   test_logical_compatl  s   zNumericInt.test_logical_compatc                 C   s   |}t | }||sJ t |td}||rJ |jtd}|d}t |td}||s4J ||r;J t |dtd|sGJ |jtd|j|drVJ d S )Nr   foo)r   r   )r   copyrz   r   rp   rename)r   r$   r   r:   rJ   same_values_different_typesame_valuesr   r   r   test_identicalq  s   
"zNumericInt.test_identicalc                 C   s   d}g d}t jt|d | | W d    n1 sw   Y  g d}t jt|d | | W d    d S 1 s>w   Y  d S )NzMString dtype not supported, you may need to explicitly cast to a numeric type)r   barbazr_   )012)rd   re   rf   r"   )r   rj   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$   r:   r   r   r   test_view_index  s   zNumericInt.test_view_indexc                 C   s"   |}| d}|jtjksJ d S )NO)rp   r   r    object_)r   r$   r:   r]   r   r   r   test_prevent_casting  s   
zNumericInt.test_prevent_castingN)rc   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g d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   r   r   r   r   r   r   r   r     r   zTestIntNumericIndex.dtyper   c                 C   r   r   r   r   r   r   r   r     r   z!TestIntNumericIndex.invalid_dtypec                 C   s   | j tddd|dS )Nr      r'   r   )r"   r   r=   r   r   r   r$     s   z TestIntNumericIndex.simple_indexr   r   r'      	index_inc	index_decr4   c                 C   r6   r7   r8   r9   r   r   r   r:     s   zTestIntNumericIndex.indexc                 C   s  | j }|j d}tjt|d |d W d    n1 sw   Y  |g d|d}|j}||dd}tj||dd |d	 d
 }||d	< |d	 |ksOJ |tj	kr|t
krZdnd}|g d|d}tg d|d}	tj||	|d |tg d|d}|g d|d}	tj||	|d |dd	g|d}	t|fD ]+}
|
dd	g|d|
tdd	g|d|
tdd	g|dfD ]
}tj||	|d qqd S d S )NzF\(\.\.\.\) must be called with a collection of some kind, 5 was passedr_   r   )r   rR   r'   r   T)r   rA   r     r   )r"   rc   rd   re   rf   r#   rC   rD   r    r   r   r   iterrU   r   )r   r   r[   rj   r:   arr	new_indexvalrB   r\   clsrJ   r   r   r   r^     s>   


z$TestIntNumericIndex.test_constructorc                 C   s   | j }tjg dtd}|||d}|jj|jksJ |tjkrMd}tjt	|d t
|}W d    n1 s8w   Y  |tu rCdnd}tj|||d tjg dtd}tjtd	d |||d W d    d S 1 sow   Y  d S )
Nr   r   rl   r_   Tr   rA   )rR   r   r(   4casting)r"   r    rU   r   r#   r   r   rC   rn   ro   r   r   rD   rd   re   rf   )r   r   r[   r   r:   rj   without_dtyperB   r   r   r   test_constructor_corner  s   

"z+TestIntNumericIndex.test_constructor_cornerc                 C   sF   d}t jt|d tdg|d W d    d S 1 sw   Y  d S )Nz5Trying to coerce negative values to unsigned integersr_   r   r   )rd   re   OverflowErrorr   )r   any_unsigned_int_numpy_dtyperj   r   r   r   ,test_constructor_coercion_signed_to_unsigned  s   "z@TestIntNumericIndex.test_constructor_coercion_signed_to_unsignedc                 C   4   t |d}t|g}tdg}t|| d S NrR   )r    r   r   r   r   rC   rD   )r   any_signed_int_numpy_dtypescalarr]   r\   r   r   r   test_constructor_np_signed      

z.TestIntNumericIndex.test_constructor_np_signedc                 C   r   r   )r    r   r   r   r   rC   rD   )r   r   r   r]   r\   r   r   r   test_constructor_np_unsigned  r   z0TestIntNumericIndex.test_constructor_np_unsignedc                 C   s@   t g d}t|| jsJ t g dtd}t|t u sJ d S )Nr   r   )r   rH   r"   r   r   )r   r   r   r   r   test_coerce_list  s   z$TestIntNumericIndex.test_coerce_listN)rc   r   r   r   r"   rd   r   r    r   int32int16int8r   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dd Zejg dddd Zdd Z	d	S )
TestInt64Indexc                 C   r   r   )r    r   r   r   r   r   r     r   zTestInt64Index.dtype)rm   r   r   r   r   r   c                 C   r   r   r   r   r   r   r   r     r   zTestInt64Index.invalid_dtypec                 C   v   | j }|tg dtjd}t||sJ |jtjksJ |tg dtjd}t||s1J |jtjks9J d S NrQ   r   )r"   r    rU   r   rH   r   r   r   r   r   r   r   %  r   z%TestInt64Index.test_constructor_32bitN)
rc   r   r   r   r"   rd   r   r   r   r   r   r   r   r   r     s    

r   c                   @   st   e Zd ZeZejejgddd Z	ejg dddd Z
ejdd Zejg d	g d
gddgddd ZdS )TestUIntNumericIndexr   c                 C   r   r   r   r   r   r   r   r   5  r   zTestUIntNumericIndex.dtyper   c                 C   r   r   r   r   r   r   r   r   9  r   z"TestUIntNumericIndex.invalid_dtypec                 C   s   |  tjd|dS r   )r"   r    r!   r=   r   r   r   r$   =  s   z!TestUIntNumericIndex.simple_index)               
                                         )r   r   r   r   r   r   r   r4   c                 C   s   | j |jtjdS r7   )r"   r   r    r   r   r   r   r   r:   B  s   zTestUIntNumericIndex.indexN)rc   r   r   r   r"   rd   r   r    r   r   r   r$   r:   r   r   r   r   r   1  s    


r   c                   @   sN   e Zd ZeZejdd Zejg dddd Zdd Z	d	d
 Z
dd ZdS )TestUInt64Indexc                 C   r   r   )r    r   r   r   r   r   r   Q  r   zTestUInt64Index.dtype)r   rm   r   r   r   r   c                 C   r   r   r   r   r   r   r   r   U  r   zTestUInt64Index.invalid_dtypec                 C   s   | j }|tu r	dnd}|g d}tg d|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   rR   r'   r(   r   rA   rR   r   r   l           )r"   r   r   rC   rD   r   r    rU   )r   r   r[   rB   rJ   resr   r   r   r^   [  s"   z TestUInt64Index.test_constructorc                 C   s.   dt t jjg}t|}t||ksJ d S )Nr   )r    iinfor   maxr   list)r   r#   r]   r   r   r   'test_constructor_does_not_cast_to_floatt  s   z7TestUInt64Index.test_constructor_does_not_cast_to_floatc                 C   r   r   )r"   r    rU   uint32rH   r   r   r   r   r   r   r   {  r   z&TestUInt64Index.test_constructor_32bitN)rc   r   r   r   r"   rd   r   r   r   r^   r   r   r   r   r   r   r   M  s    

r   boxc                 C   s   t j| tdS r7   )r    rU   r   r   r   r   r   <lambda>  s    r  c                 C   s   t | tdS r7   )r   r   r   r   r   r   r    s    c                 C   s^   t g dg dd}|j| ddg }tg ddd}t|j| t||jd d	  d S )
N)r   rR   r'   r(   r)   r   )   @>"NL    '2w@ r  l   :e/ l   Ol_)#;f l   Pl_)#;f r   r  r  )r  r  r  r   r   r(   )r   r   r   rC   rD   r:   assert_equalr   )r   seriesr]   r\   r   r   r   +test_uint_index_does_not_convert_to_float64  s   r  c                  C   sH   t g d} t g d}| |}|du sJ || }|du s"J d S )N)rT   r'   r(   )r   r   3F)r   rL   )r@   string_indexr]   r   r   r   test_float64_index_equals  s   

r	  c                  C   s6   t g d} | dd }tg d}t|| d S )Nr   c                 S   s   |  S r   r   r   r   r   r   r    s    z=test_map_dtype_inference_unsigned_to_signed.<locals>.<lambda>)r   )r   mapr   rC   rD   rJ   r]   r\   r   r   r   +test_map_dtype_inference_unsigned_to_signed  s   r  c                  C   sH   t tjg dtjd} | dd }t g dtjd}t|| d S )Nr   r   c                 S   s   | d S )N  r   r   r   r   r   r    s    z4test_map_dtype_inference_overflows.<locals>.<lambda>)r  i  r   )r   r    rU   r   r  r   rC   rD   r  r   r   r   "test_map_dtype_inference_overflows  s   r  )!numpyr    rd   pandas._libs.tslibsr   pandasrX   r   r   pandas._testing_testingrC   pandas.core.indexes.apir   r   r   r   pandas.tests.indexes.commonr	   r
   r   r   r   r   r   r   r   r   r   r  r	  r  r  r   r   r   r   <module>   s2      !f{:
