o
    i1                     @   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	 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 ddlmZm Z 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)is_unsigned_integer_dtype)NACategoricalCategoricalIndexDatetimeIndexIndexIntervalIndex
MultiIndexNaTPeriodIndexSeriesTimedeltaIndex	Timestamparray
date_rangeperiod_rangetimedelta_range)Float64Index
Int64IndexUInt64Indexc                   @   s2  e Z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d(ddgd)d* Zejd(ddgd+d, ZdS )-TestIndexConstructorInferencena_valueNvtypec                 C   s2   dd|fg}t ||}t|}t|| d S )N)   two      @)r
   r   from_tuplestmassert_index_equal)selfr   r   valuesresultexpected r&   ^/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pandas/tests/indexes/test_index_new.py!test_construction_list_tuples_nan*   s   
z?TestIndexConstructorInference.test_construction_list_tuples_nandtypeint64int32int16int8uint64uint32uint16uint8c                 C   s>   t |rt}nt}|g d}tg d|d}t|| d S )N)r   r         )g              ?       @r   r)   )r   r   r   r
   r    r!   )r"   r)   
index_typer%   r$   r&   r&   r'    test_constructor_int_dtype_float3   s   z>TestIndexConstructorInference.test_constructor_int_dtype_float
cast_indexTFvals)TFTr6   c                 C   s<   |r	t |td}nt |}t|t u sJ |jtksJ d S Nr6   )r
   booltyper)   r"   r9   r:   indexr&   r&   r'   !test_constructor_dtypes_to_objectB   s
   z?TestIndexConstructorInference.test_constructor_dtypes_to_objectc                 C   s*   t td}t|td}t|t rJ d S N   r6   )r   ranger
   object
isinstance)r"   cir$   r&   r&   r'   &test_constructor_categorical_to_objectO   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Mr3   )freqperiods)r   r
   r    r!   rE   r   )r"   xprsr&   r&   r'   "test_constructor_infer_periodindexU   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rJ   rI   )r   listr
   rE   r   )r"   rngrJ   r$   r&   r&   r'   test_from_list_of_periods[   s   z7TestIndexConstructorInference.test_from_list_of_periodsposr   r   zklass,dtype,ctordatetime64[ns]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)reasonr6   )rE   r   r   r)   insertr   r
   pytestmarkxfailnode
add_markerDeprecationWarningr    assert_produces_warningr!   npr   rD   )r"   rT   klassr)   ctornulls_fixturerequestr%   datawarnrZ   r$   r&   r&   r'   "test_constructor_infer_nat_dt_likeb   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 )NrV   r6   )r`   
datetime64timedelta64r
   rD   r    r!   r   r"   rh   re   r%   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        	   *   nowri   r6   )	r   r`   rj   r	   r    r!   r
   r   rD   rl   r&   r&   r'   (test_constructor_datetime_and_datetime64   s   zFTestIndexConstructorInference.test_constructor_datetime_and_datetime64)__name__
__module____qualname__rY   rZ   parametrizer`   nanrQ   tupleiterr(   intr8   r   r<   r@   rG   rM   rS   r	   rj   r   rk   rg   rm   rs   r&   r&   r&   r'   r   )   s:    
	 

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   r6   )r   r
   rD   r)   )r"   any_numeric_ea_dtypearridxr&   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 rA   )r
   rC   r)   )r"   r)   rR   r$   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   r2   r3   r6   )r   r
   r)   )r"   r)   catr$   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-01r3   rJ   z
Asia/TokyorB   r6   )
r   r   r
   r)   r    r!   tz_localizer   from_breaksrC   )r"   dtir   r$   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   r3   r   r   r6   z
US/Pacific)rJ   tz)r   r
   r   r    r!   )r"   r   r$   r%   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   r3   rO   rP   r   r6   )r   r
   r   r    r!   )r"   pir$   r%   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 DaysrB   r   r   r6   )r   r
   r   r    r!   )r"   tdir$   r%   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   r3   r   r   r6   )r   r   r   r
   r   r    r!   )r"   r   r   r$   r%   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   r3   r   z	Period[D]r6   rO   )r   r
   	to_periodr    r!   )r"   r   r$   r%   r&   r&   r'   :test_constructor_datetime64_values_mismatched_period_dtype   s   
zLTestDtypeEnforced.test_constructor_datetime64_values_mismatched_period_dtyper*   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matchr6   )r`   rx   rY   raises
ValueErrorr
   )r"   r)   re   msgr&   r&   r'   %test_constructor_int_dtype_nan_raises   s
   "z7TestDtypeEnforced.test_constructor_int_dtype_nan_raisesr:   r   r6   )r4   r5   r   c                 C      t |td}t|tsJ d S r;   )r
   r{   rE   r   r"   r:   r?   r&   r&   r'    test_constructor_dtypes_to_int64   s   z2TestDtypeEnforced.test_constructor_dtypes_to_int64c                 C   r   r;   )r
   floatrE   r   r   r&   r&   r'   "test_constructor_dtypes_to_float64  s   z4TestDtypeEnforced.test_constructor_dtypes_to_float64z
2011-01-01z
2011-01-02rU   i  r   r2   c                 C   s   t |dd}t|tsJ d S )Nr   r6   )r
   rE   r   r   r&   r&   r'   &test_constructor_dtypes_to_categorical  s   
z8TestDtypeEnforced.test_constructor_dtypes_to_categoricalr9   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 r;   )r
   rD   rE   r)   r	   r>   r&   r&   r'   #test_constructor_dtypes_to_datetime"     	z5TestDtypeEnforced.test_constructor_dtypes_to_datetimerO   c                 C   r   r;   )r
   rD   rE   r)   r   r>   r&   r&   r'   $test_constructor_dtypes_to_timedelta3  r   z6TestDtypeEnforced.test_constructor_dtypes_to_timedeltaN)rt   ru   rv   r   rY   rZ   rw   rD   r   r   r   r   r   r   r   r   r   r`   r   r{   r   r   r   r   r   r
   rj   r   rk   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 )TestIndexConstructorUnwrappingra   c                 C   s>   t dt dt dg}t|}t|}||}t|| d S )N201101012012010120130101)r   r	   r   r    r!   )r"   ra   stampsr%   serr$   r&   r&   r'   !test_constructor_from_series_dt64H  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   r    r!   )r"   r   r$   r%   r&   r&   r'    test_constructor_no_pandas_arrayP  s   
z?TestIndexConstructorUnwrapping.test_constructor_no_pandas_arrayr   rB   )abcz
2000-01-01r3   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__c  s   
zXTestIndexConstructorUnwrapping.test_constructor_ndarray_like.<locals>.ArrayLike.__init__c                 S   s   | j S r   r   )r"   r)   r&   r&   r'   	__array__f  s   zYTestIndexConstructorUnwrapping.test_constructor_ndarray_like.<locals>.ArrayLike.__array__)r   Nr   )rt   ru   rv   r   r`   ndarrayr   r&   r&   r&   r'   	ArrayLikeb  s    
r   )r
   r    r!   )r"   r   r   r%   r$   r&   r&   r'   test_constructor_ndarray_likeV  s   z<TestIndexConstructorUnwrapping.test_constructor_ndarray_likeN)rt   ru   rv   rY   rZ   rw   r
   r	   r   r   r`   aranger   r   r#   r   r&   r&   r&   r'   r   E  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   r*   r6   )rY   r   OverflowErrorr
   r`   iinfor.   max)r"   r   r&   r&   r'   test_constructor_overflow_int64o  s
   "z;TestIndexConstructionErrors.test_constructor_overflow_int64N)rt   ru   rv   r   r&   r&   r&   r'   r   n  s    r   )&__doc__r   r   decimalr   numpyr`   rY   pandas.core.dtypes.commonr   pandasr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   pandas._testing_testingr    pandas.core.apir   r   r   r   r|   r   r   r&   r&   r&   r'   <module>   s    Hw &)