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   W/app/.heroku/python/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   Z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   int64Zint32Zint16Zint8uint64Zuint32Zuint16Zuint8c                 C   s0   t g d|d}t g d|d}t|| d S )N)r   r!   r"      r   )g              ?       @r0   r	   r2   r3   )r   r   r5   r4   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   r>   r?   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   cir4   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Mr9   )freqperiods)r   r	   r2   r3   rI   r   )r   Z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rN   rM   )r   listr	   rI   r   )r   rngrN   r4   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   )rI   r   r   r   insertr   r	   pytestmarkZxfailnodeZ
add_markerDeprecationWarningr2   Zassert_produces_warningr3   r   r   r   )r   rW   klassr   ZctorZnulls_fixturerequestr5   datawarnr\   r4   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 )NrX   r(   r   )r   
datetime64timedelta64r	   r   r2   r3   r   r   rd   ra   r5   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   re   r   r2   r3   r	   r   r   rg   r   r   r   (test_constructor_datetime_and_datetime64   s   zFTestIndexConstructorInference.test_constructor_datetime_and_datetime64) __name__
__module____qualname__r    r$   r[   r\   parametrizer   r   r&   floatr,   rT   tupleiterr6   intr=   r   rA   rE   rK   rP   rV   r   re   r   rf   rc   rh   rn   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   Z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   Zfloat64r8   categoryc                 C   sH   t td}t ||d}|j|ksJ t td|d}|j|ks"J d S rF   )r	   rH   r   )r   r   rU   r4   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"   r9   r   )r   r	   r   )r   r   catr4   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-01r9   rN   z
Asia/TokyorG   r   )
r   r   r	   r   r2   r3   Ztz_localizer
   from_breaksrH   )r   dtir|   r4   dti2cat2iiZ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~   r9   r   ry   r   z
US/Pacific)rN   tz)r   r	   r   r2   r3   )r   r   r4   r5   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~   r9   rR   rS   ry   r   )r   r	   r   r2   r3   )r   pir4   r5   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 DaysrG   r   ry   r   )r   r	   r   r2   r3   )r   Ztdir4   r5   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~   r9   r   ry   r   )r   r
   r   r	   r   r2   r3   )r   r   r   r4   r5   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~   r9   r   z	Period[D]r   rR   )r   r	   Z	to_periodr2   r3   )r   r   r4   r5   r   r   r   :test_constructor_datetime64_values_mismatched_period_dtype  s   
zLTestDtypeEnforced.test_constructor_datetime64_values_mismatched_period_dtyper7   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&   r[   raises
ValueErrorr	   )r   r   ra   msgr   r   r   %test_constructor_int_dtype_nan_raises  s
   "z7TestDtypeEnforced.test_constructor_int_dtype_nan_raisesr?   r{   r   )r:   r;   r0   c                 C   "   |}t ||d}|j|ksJ d S r@   r	   r   )r   r?   Zany_int_numpy_dtyper   rD   r   r   r   test_constructor_dtypes_to_int  s   z0TestDtypeEnforced.test_constructor_dtypes_to_intc                 C   r   r@   r   )r   r?   Zfloat_numpy_dtyper   rD   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 )Nry   r   )r	   rI   r   )r   r?   rD   r   r   r   &test_constructor_dtypes_to_categorical/  s   
z8TestDtypeEnforced.test_constructor_dtypes_to_categoricalr>   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	   r   rI   r   r   rC   r   r   r   #test_constructor_dtypes_to_datetime<     	z5TestDtypeEnforced.test_constructor_dtypes_to_datetimerR   c                 C   r   r@   )r	   r   rI   r   r   rC   r   r   r   $test_constructor_dtypes_to_timedeltaM  r   z6TestDtypeEnforced.test_constructor_dtypes_to_timedeltaN)ro   rp   rq   rx   r[   r\   rr   r   rz   r}   r   r   r   r   r   r   r   r   r   rv   rs   r   r   r   r   r	   re   r   rf   r   r   r   r   r   r   rw      sv    
	





		rw   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 )TestIndexConstructorUnwrappingr_   c                 C   s>   t dt dt dg}t|}t|}||}t|| d S )NZ20110101Z20120101Z20130101)r   r   r   r2   r3   )r   r_   Zstampsr5   serr4   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   r2   r3   )r   r   r4   r5   r   r   r    test_constructor_no_pandas_arrayj  s   
z?TestIndexConstructorUnwrapping.test_constructor_no_pandas_arrayr   rG   )abcz
2000-01-01r9   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   )ro   rp   rq   r   r   Zndarrayr   r   r   r   r   	ArrayLike|  s    
r   r<   )r   r   r   r5   r4   r   r   r   test_constructor_ndarray_likep  s   z<TestIndexConstructorUnwrapping.test_constructor_ndarray_likeN)ro   rp   rq   r[   r\   rr   r	   r   r   r   r   Z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!   r7   r   )r[   r   OverflowErrorr	   r   Ziinfor8   max)r   r   r   r   r   test_constructor_overflow_int64  s
   "z;TestIndexConstructionErrors.test_constructor_overflow_int64N)ro   rp   rq   r   r   r   r   r   r     s    r   ) __doc__r   r   decimalr   numpyr   r[   Zpandasr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingr2   r   rw   r   r   r   r   r   r   <module>   s    H  ()