a
    dC6                     @   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   l/var/www/html/stable-diffusion-webui/venv/lib/python3.9/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s0J t|jtksBJ 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rR|  sVJ ttj|td}|jdkr~|  sJ ttj|tdd d d }|jdkr|  sJ 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!   Z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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              ?       @r/   r	   r1   r2   )r   r   r4   r3   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s8J 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   cir3   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s0J d S )Nz2012-1-1Mr:   )freqperiods)r   r	   r1   r2   rJ   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rO   rN   )r   listr	   rJ   r   )r   rngrO   r3   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"tdt|j d |ttg}|j|ks<J |g}||| d }	|t	u rt
t	tg}tjjdd}
|j|
 t}	t
|}t|	 t|| W d    n1 s0    Y  t
tj|td}t|	 t|| W d    n1 s0    Y  d S )NzWe don't cast z to datetime64/timedelta64z%Broken with np.NaT ctor; see GH 31884)reasonr   )rJ   r   pytestskiprC   __name__r   r   insertr   r	   markZxfailnodeZ
add_markerDeprecationWarningr1   Zassert_produces_warningr2   r   r   r   )r   rX   klassr   ZctorZnulls_fixturerequestr4   datawarnr_   r3   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 )NrY   r(   r   )r   
datetime64timedelta64r	   r   r1   r2   r   r   rg   rd   r4   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   rh   r   r1   r2   r	   r   r   rj   r   r   r   (test_constructor_datetime_and_datetime64   s    zFTestIndexConstructorInference.test_constructor_datetime_and_datetime64) r]   
__module____qualname__r    r$   r[   r_   parametrizer   r   r&   floatr,   rU   tupleiterr5   intr>   r   rB   rF   rL   rQ   rW   r   rh   r   ri   rf   rk   rq   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   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   float64r9   categoryc                 C   sH   t td}t ||d}|j|ks&J t td|d}|j|ksDJ d S rG   )r	   rI   r   )r   r   rV   r3   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   catr3   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:   rO   z
Asia/TokyorH   r   )
r   r   r	   r   r1   r2   Ztz_localizer
   from_breaksrI   )r   dtir   r3   dti2Z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   r:   r   r|   r   z
US/Pacific)rO   tz)r   r	   r   r1   r2   )r   r   r3   r4   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:   rS   rT   r|   r   )r   r	   r   r1   r2   )r   pir3   r4   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 DaysrH   r   r|   r   )r   r	   r   r1   r2   )r   Ztdir3   r4   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   r1   r2   )r   r   r   r3   r4   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   rS   )r   r	   Z	to_periodr1   r2   )r   r   r3   r4   r   r   r   :test_constructor_datetime64_values_mismatched_period_dtype  s    
zLTestDtypeEnforced.test_constructor_datetime64_values_mismatched_period_dtyper6   c                 C   sJ   t jg}d}tjt|d t||d W d    n1 s<0    Y  d S )Nzcannot convertmatchr   )r   r&   r[   raises
ValueErrorr	   )r   r   rd   msgr   r   r   %test_constructor_int_dtype_nan_raises  s    z7TestDtypeEnforced.test_constructor_int_dtype_nan_raisesr@   r~   r   )r;   r<   r/   c                 C   s"   |}t ||d}|j|ksJ d S rA   r	   r   )r   r@   Zany_int_numpy_dtyper   rE   r   r   r   test_constructor_dtypes_to_int  s    z0TestDtypeEnforced.test_constructor_dtypes_to_intc                 C   s"   |}t ||d}|j|ksJ d S rA   r   )r   r@   Zfloat_numpy_dtyper   rE   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	   rJ   r   )r   r@   rE   r   r   r   &test_constructor_dtypes_to_categorical2  s    
z8TestDtypeEnforced.test_constructor_dtypes_to_categoricalr?   TFc                 C   sH   |r.t |td}t|t sJ |jtksDJ nt |}t|tsDJ d S rA   )r	   r   rJ   r   r   rD   r   r   r   #test_constructor_dtypes_to_datetime?  s    	z5TestDtypeEnforced.test_constructor_dtypes_to_datetimerS   c                 C   sH   |r.t |td}t|t sJ |jtksDJ nt |}t|tsDJ d S rA   )r	   r   rJ   r   r   rD   r   r   r   $test_constructor_dtypes_to_timedeltaP  s    	z6TestDtypeEnforced.test_constructor_dtypes_to_timedeltaN)r]   rr   rs   rz   r[   r_   rt   r   r}   r   r   r   r   r   r   r   r   r   r   rx   ru   r   r   r   r   r	   rh   r   ri   r   r   r   r   r   r   ry      st   
	




	
	ry   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 )TestIndexConstructorUnwrappingrb   c                 C   s>   t dt dt dg}t|}t|}||}t|| d S )NZ20110101Z20120101Z20130101)r   r   r   r1   r2   )r   rb   Zstampsr4   serr3   r   r   r   !test_constructor_from_series_dt64e  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   r1   r2   )r   r   r3   r4   r   r   r    test_constructor_no_pandas_arraym  s    
z?TestIndexConstructorUnwrapping.test_constructor_no_pandas_arrayr   rH   )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dZdejdddZdS )zOTestIndexConstructorUnwrapping.test_constructor_ndarray_like.<locals>.ArrayLikeN)returnc                 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__)N)r]   rr   rs   r   r   Zndarrayr   r   r   r   r   	ArrayLike  s   r   r=   )r   r   r   r4   r3   r   r   r   test_constructor_ndarray_likes  s    z<TestIndexConstructorUnwrapping.test_constructor_ndarray_likeN)r]   rr   rs   r[   r_   rt   r	   r   r   r   r   Zaranger   r   r*   r   r   r   r   r   r   b  s   
r   c                   @   s   e Zd Zdd ZdS )TestIndexConstructionErrorsc                 C   sR   d}t jt|d, tttjjd gdd W d    n1 sD0    Y  d S )NzIThe elements provided in the data cannot all be casted to the dtype int64r   r!   r6   r   )r[   r   OverflowErrorr	   r   Ziinfor9   max)r   r   r   r   r   test_constructor_overflow_int64  s    z;TestIndexConstructionErrors.test_constructor_overflow_int64N)r]   rr   rs   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_testingr1   r   ry   r   r   r   r   r   r   <module>   s   H  ()