o
    d5                     @   s   d Z ddlmZmZ ddlmZ ddlZddlZddlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ G dd dZG dd	 d	ZG d
d dZG dd dZdS )z7
Tests for the Index constructor conducting inference.
    )datetime	timedelta)DecimalN)NACategoricalCategoricalIndexDatetimeIndexIndexIntervalIndex
MultiIndexNaTPeriodIndexSeriesTimedeltaIndex	Timestamparray
date_rangeperiod_rangetimedelta_rangec                   @   sf  e Zd Zdd Zdd Zejdede	j
edgdd	 Zejd
de	j
gejdeeegdd Zejdeddddddddg	dd Zejdddgejdg de	jg dedgdd  Zd!d" Zd#d$ Zd%d& Zejd'd(d)gejd*ed+e	d,fed-e	d,fgd.d/ Zejd0ddgd1d2 Zejd0ddgd3d4 ZdS )5TestIndexConstructorInferencec                 C   s>   t jddgtd}t|}|jtksJ t|jtksJ d S )NTFdtype)npr   objectr	   r   r   selfarrres r   h/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/indexes/test_index_new.pytest_object_all_bools#   s   z3TestIndexConstructorInference.test_object_all_boolsc                 C   sF   t jtdtdgtd}t|}|jtksJ t|jtks!J d S )N      r   )r   r   complexr   r	   r   r   r   r   r   r   test_object_all_complex,   s   z5TestIndexConstructorInference.test_object_all_complexvalNnanc                 C   s   t |g}t|}|jdkr|  sJ t|d d d }|jdkr)|  s+J ttj|td}|jdkr?|  sAJ ttj|tdd d d }|jdkrZ|  s\J d S )Ndatetime64[ns]r   )r   r	   r   isnaallr   r   r   )r   r%   valuesidxr   r   r   test_infer_nat5   s   z,TestIndexConstructorInference.test_infer_natna_valuevtypec                 C   s2   dd|fg}t ||}t|}t|| d S )N)r!   two      @)r	   r   from_tuplestmassert_index_equal)r   r.   r/   r+   resultexpectedr   r   r   !test_construction_list_tuples_nanG   s   
z?TestIndexConstructorInference.test_construction_list_tuples_nanr   int64int32int16int8uint64uint32uint16uint8c                 C   s0   t g d|d}t g d|d}t|| d S )N)r   r!   r"      r   )g              ?       @r1   r	   r3   r4   )r   r   r6   r5   r   r   r    test_constructor_int_dtype_floatP   s   z>TestIndexConstructorInference.test_constructor_int_dtype_float
cast_indexTFvals)TFTr   c                 C   s<   |r	t |td}nt |}t|t u sJ |jtksJ d S Nr   )r	   booltyper   r   rE   rF   indexr   r   r   !test_constructor_dtypes_to_objectZ   s
   z?TestIndexConstructorInference.test_constructor_dtypes_to_objectc                 C   s*   t td}t|td}t|t rJ d S N   r   )r   ranger	   r   
isinstance)r   cir5   r   r   r   &test_constructor_categorical_to_objectg   s   zDTestIndexConstructorInference.test_constructor_categorical_to_objectc                 C   s4   t dddd}t|}t|| t|tsJ d S )Nz2012-1-1Mr@   )freqperiods)r   r	   r3   r4   rP   r   )r   xprsr   r   r   "test_constructor_infer_periodindexm   s   z@TestIndexConstructorInference.test_constructor_infer_periodindexc                 C   s0   t dddd}t|}t|}t|tsJ d S )Nz1/1/2000   DrU   rT   )r   listr	   rP   r   )r   rngrU   r5   r   r   r   test_from_list_of_periodss   s   z7TestIndexConstructorInference.test_from_list_of_periodsposr   r!   zklass,dtype,ctorr'   natztimedelta64[ns]c                 C   s   t |trd S |ttg}|j|ksJ |g}||| d }	|tu r8tttg}tjj	dd}
|j
|
 t}	t|}t|	 t|| W d    n1 sRw   Y  ttj|td}t|	 t|| W d    d S 1 sww   Y  d S )Nz%Broken with np.NaT ctor; see GH 31884)reasonr   )rP   r   r   r   insertr   r	   pytestmarkxfailnode
add_markerDeprecationWarningr3   assert_produces_warningr4   r   r   r   )r   r_   klassr   ctornulls_fixturerequestr6   datawarnrd   r5   r   r   r   "test_constructor_infer_nat_dt_likez   s(   
"z@TestIndexConstructorInference.test_constructor_infer_nat_dt_like	swap_objsc                 C   s`   t dt dg}|r|d d d }t|td}tt|| ttt j|td| d S )Nr`   r(   r   )r   
datetime64timedelta64r	   r   r3   r4   r   r   rq   rn   r6   r   r   r   -test_constructor_mixed_nat_objs_infers_object   s   zKTestIndexConstructorInference.test_constructor_mixed_nat_objs_infers_objectc                 C   sb   t dddddtdg}|r|d d d }t|}tt|| tttj|td| d S )	Ni        	   *   nowr(   r   )	r   r   rr   r   r3   r4   r	   r   r   rt   r   r   r   (test_constructor_datetime_and_datetime64   s   zFTestIndexConstructorInference.test_constructor_datetime_and_datetime64) __name__
__module____qualname__r    r$   rc   rd   parametrizer   r   r&   floatr-   r\   tupleiterr7   intrD   r   rH   rL   rR   rX   r^   r   rr   r   rs   rp   ru   r{   r   r   r   r   r   "   sB    		

	 

r   c                   @   s8  e Zd Zdd Zejdedddgdd Zejdedddgd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zejdddgdd Zejdg deg dejg dedg dejg dedgdd Zejdg dg deg dejg dedejg dedgd d! Zejdg dejg dedejd"d#gd$ded%d&d&ed%d&d'ggd(d) Zejd*d+d,gejdeeed"ed#geed%d&d&ed%d&d'ggd-d. Zejd*d+d,gejdeed&d/ed&d/ged&ed&ggd0d1 Zd2S )3TestDtypeEnforcedc                 C   s,   t dg|d}t|td}|jtksJ d S )Nr   r   )r   r	   r   r   )r   any_numeric_ea_dtyper   r,   r   r   r   *test_constructor_object_dtype_with_ea_data   s   z<TestDtypeEnforced.test_constructor_object_dtype_with_ea_datar   float64r<   categoryc                 C   sH   t td}t ||d}|j|ksJ t td|d}|j|ks"J d S rM   )r	   rO   r   )r   r   r]   r5   r   r   r   .test_constructor_range_values_mismatched_dtype   s
   z@TestDtypeEnforced.test_constructor_range_values_mismatched_dtypec                 C   s*   t g d}t||d}|j|ksJ d S )Nr!   r"   r@   r   )r   r	   r   )r   r   catr5   r   r   r   ;test_constructor_categorical_values_mismatched_non_ea_dtype   s   zMTestDtypeEnforced.test_constructor_categorical_values_mismatched_non_ea_dtypec                 C   s   t ddd}t|}t||j}t|| |d}t|}t||j}t|| tt	d}t|}t||jd}t|| d S )N
2016-01-01r@   rU   z
Asia/TokyorN   r   )
r   r   r	   r   r3   r4   tz_localizer
   from_breaksrO   )r   dtir   r5   dti2cat2iicat3r   r   r   4test_constructor_categorical_values_mismatched_dtype   s   
zFTestDtypeEnforced.test_constructor_categorical_values_mismatched_dtypec                 C   s^   t ddd}t|dd}t|}t|| t dddd}t|dd}t|}t|| d S )Nr   r@   r   r   r   z
US/Pacific)rU   tz)r   r	   r   r3   r4   )r   r   r5   r6   r   r   r   r   7test_constructor_ea_values_mismatched_categorical_dtype   s   zITestDtypeEnforced.test_constructor_ea_values_mismatched_categorical_dtypec                 C   s2   t dddd}t|dd}t|}t|| d S )Nr   r@   rZ   r[   r   r   )r   r	   r   r3   r4   )r   pir5   r6   r   r   r   /test_constructor_period_values_mismatched_dtype   s   zATestDtypeEnforced.test_constructor_period_values_mismatched_dtypec                 C   s0   t ddd}t|dd}t|}t|| d S )Nz4 DaysrN   r   r   r   )r   r	   r   r3   r4   )r   tdir5   r6   r   r   r   4test_constructor_timedelta64_values_mismatched_dtype   s   zFTestDtypeEnforced.test_constructor_timedelta64_values_mismatched_dtypec                 C   s:   t ddd}t|}t|dd}t|}t|| d S )Nr   r@   r   r   r   )r   r
   r   r	   r   r3   r4   )r   r   r   r5   r6   r   r   r   1test_constructor_interval_values_mismatched_dtype   s
   
zCTestDtypeEnforced.test_constructor_interval_values_mismatched_dtypec                 C   s2   t ddd}t|dd}|d}t|| d S )Nr   r@   r   z	Period[D]r   rZ   )r   r	   	to_periodr3   r4   )r   r   r5   r6   r   r   r   :test_constructor_datetime64_values_mismatched_period_dtype  s   
zLTestDtypeEnforced.test_constructor_datetime64_values_mismatched_period_dtyper8   c                 C   sL   t jg}d}tjt|d t||d W d    d S 1 sw   Y  d S )Nzcannot convertmatchr   )r   r&   rc   raises
ValueErrorr	   )r   r   rn   msgr   r   r   %test_constructor_int_dtype_nan_raises  s
   "z7TestDtypeEnforced.test_constructor_int_dtype_nan_raisesrF   r   r   )rA   rB   r1   c                 C   "   |}t ||d}|j|ksJ d S rG   r	   r   )r   rF   any_int_numpy_dtyper   rK   r   r   r   test_constructor_dtypes_to_int  s   z0TestDtypeEnforced.test_constructor_dtypes_to_intc                 C   r   rG   r   )r   rF   float_numpy_dtyper   rK   r   r   r    test_constructor_dtypes_to_float   s   z2TestDtypeEnforced.test_constructor_dtypes_to_floatz
2011-01-01z
2011-01-02r'   i  r!   r"   c                 C   s   t |dd}t|tsJ d S )Nr   r   )r	   rP   r   )r   rF   rK   r   r   r   &test_constructor_dtypes_to_categorical/  s   
z8TestDtypeEnforced.test_constructor_dtypes_to_categoricalrE   TFc                 C   J   |rt |td}t|t sJ |jtksJ d S t |}t|ts#J d S rG   )r	   r   rP   r   r   rJ   r   r   r   #test_constructor_dtypes_to_datetime<     	z5TestDtypeEnforced.test_constructor_dtypes_to_datetimerZ   c                 C   r   rG   )r	   r   rP   r   r   rJ   r   r   r   $test_constructor_dtypes_to_timedeltaM  r   z6TestDtypeEnforced.test_constructor_dtypes_to_timedeltaN)r|   r}   r~   r   rc   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   rr   r   rs   r   r   r   r   r   r   r      sv    
	





		r   c                	   @   sd   e Zd Zejdeegdd Zdd Z	ejde
de
g ded	d
djgdd ZdS )TestIndexConstructorUnwrappingrj   c                 C   s>   t dt dt dg}t|}t|}||}t|| d S )N201101012012010120130101)r   r   r   r3   r4   )r   rj   stampsr6   serr5   r   r   r   !test_constructor_from_series_dt64b  s
   z@TestIndexConstructorUnwrapping.test_constructor_from_series_dt64c                 C   s2   t g d}t|j}tg d}t|| d S )Nr   )r   r	   r   r3   r4   )r   r   r5   r6   r   r   r    test_constructor_no_pandas_arrayj  s   
z?TestIndexConstructorUnwrapping.test_constructor_no_pandas_arrayr   rN   )abcz
2000-01-01r@   r   c                 C   s2   G dd d}t |}t ||}t|| d S )Nc                   @   s(   e Zd ZdddZddejfddZdS )	zOTestIndexConstructorUnwrapping.test_constructor_ndarray_like.<locals>.ArrayLikereturnNc                 S   s
   || _ d S Nr   )r   r   r   r   r   __init__}  s   
zXTestIndexConstructorUnwrapping.test_constructor_ndarray_like.<locals>.ArrayLike.__init__c                 S   s   | j S r   r   )r   r   r   r   r   	__array__  s   zYTestIndexConstructorUnwrapping.test_constructor_ndarray_like.<locals>.ArrayLike.__array__)r   Nr   )r|   r}   r~   r   r   ndarrayr   r   r   r   r   	ArrayLike|  s    
r   rC   )r   r   r   r6   r5   r   r   r   test_constructor_ndarray_likep  s   z<TestIndexConstructorUnwrapping.test_constructor_ndarray_likeN)r|   r}   r~   rc   rd   r   r	   r   r   r   r   aranger   r   r+   r   r   r   r   r   r   _  s    
r   c                   @   s   e Zd Zdd ZdS )TestIndexConstructionErrorsc                 C   sT   d}t jt|d tttjjd gdd W d    d S 1 s#w   Y  d S )NzIThe elements provided in the data cannot all be casted to the dtype int64r   r!   r8   r   )rc   r   OverflowErrorr	   r   iinfor<   max)r   r   r   r   r   test_constructor_overflow_int64  s
   "z;TestIndexConstructionErrors.test_constructor_overflow_int64N)r|   r}   r~   r   r   r   r   r   r     s    r   ) __doc__r   r   decimalr   numpyr   rc   pandasr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   pandas._testing_testingr3   r   r   r   r   r   r   r   r   <module>   s    H  ()