U
    f/e                      @   s   d 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mZ ddlm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.
    )DecimalN)is_unsigned_integer_dtype)NACategoricalCategoricalIndexDatetimeIndexIndex
Int64IndexIntervalIndex
MultiIndexNaTPeriodIndexSeriesTimedeltaIndex	TimestampUInt64Index
date_rangeperiod_rangetimedelta_rangec                   @   s6  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dddgejdddg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)   Ztwo      @)r   r   from_tuplestmassert_index_equal)selfr   r   valuesresultexpected r!   G/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/indexes/test_index_new.py!test_construction_list_tuples_nan"   s    
z?TestIndexConstructorInference.test_construction_list_tuples_nandtypeZint64Zint32Zint16Zint8uint64Zuint32Zuint16Zuint8c                 C   sF   t |rt}nt}|ddddg}tddddg|d	}t|| d S )
Nr   r         g        g      ?g       @r   r$   )r   r   r	   r   r   r   )r   r$   Z
index_typer    r   r!   r!   r"    test_constructor_int_dtype_float+   s    z>TestIndexConstructorInference.test_constructor_int_dtype_float
cast_indexTFvalsr(   c                 C   s<   |rt |td}nt |}t|t ks*t|jtks8td S )Nr(   )r   booltypeAssertionErrorr$   object)r   r*   r+   indexr!   r!   r"   !test_constructor_dtypes_to_object:   s
    z?TestIndexConstructorInference.test_constructor_dtypes_to_objectc                 C   s*   t td}t|td}t|t r&td S N   r(   )r   ranger   r/   
isinstancer.   )r   cir   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s0td S )Nz2012-1-1Mr'   )freqperiods)r   r   r   r   r5   r   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,td S )Nz1/1/2000   Dr:   r9   )r   listr   r5   r   r.   )r   rngr:   r   r!   r!   r"   test_from_list_of_periodsS   s    z7TestIndexConstructorInference.test_from_list_of_periodsposr   r   zklass,dtype,ctorzdatetime64[ns]natztimedelta64[ns]c              	   C   s   t |trd S |ttg}|j|ks(t|g}||| d }	|tkrptttg}tj	j
dd}
|j|
 t}	t|}t|	 t|| W 5 Q R X ttj|td}t|	 t|| W 5 Q R X d S )Nz%Broken with np.NaT ctor; see GH 31884)reasonr(   )r5   r   r   r$   r.   insertr   r   pytestmarkZxfailnodeZ
add_markerDeprecationWarningr   Zassert_produces_warningr   nparrayr/   )r   rC   klassr$   ZctorZnulls_fixturerequestr    datawarnrH   r   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 )NrD   r(   )rK   
datetime64timedelta64r   r/   r   r   rL   r   rR   rO   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        	   *   nowrS   r(   )	r   rK   rT   r   r   r   r   rL   r/   rV   r!   r!   r"   (test_constructor_datetime_and_datetime64   s    zFTestIndexConstructorInference.test_constructor_datetime_and_datetime64)__name__
__module____qualname__rG   rH   parametrizerK   nanr@   tupleiterr#   intr)   rL   r,   r1   r7   r<   rB   r   rT   r   rU   rQ   rW   r]   r!   r!   r!   r"   r   !   s:   
 	 

r   c                   @   sx   e Z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dS )TestDtypeEnforcedr$   Zfloat64r%   categoryc                 C   sH   t td}t ||d}|j|ks&tt td|d}|j|ksDtd S r2   )r   r4   r$   r.   )r   r$   rA   r   r!   r!   r"   .test_constructor_range_values_mismatched_dtype   s
    z@TestDtypeEnforced.test_constructor_range_values_mismatched_dtypec                 C   s,   t dddg}t||d}|j|ks(td S )Nr   r&   r'   r(   )r   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-01r'   r:   z
Asia/Tokyor3   r(   )
r   r   r   r$   r   r   Ztz_localizer
   from_breaksr4   )r   dtiri   r   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 )Nrk   r'   rl   rg   r(   z
US/Pacific)r:   tz)r   r   r   r   r   )r   rn   r   r    ro   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 )Nrk   r'   r>   r?   rg   r(   )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 Daysr3   rl   rg   r(   )r   r   r   r   r   )r   Z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 )Nrk   r'   rl   rg   r(   )r   r
   rm   r   r   r   r   )r   rn   rp   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 )Nrk   r'   rl   z	Period[D]r(   r>   )r   r   Z	to_periodr   r   )r   rn   r   r    r!   r!   r"   :test_constructor_datetime64_values_mismatched_period_dtype   s    
zLTestDtypeEnforced.test_constructor_datetime64_values_mismatched_period_dtypeN)r^   r_   r`   rG   rH   ra   r/   rh   rj   rq   rs   ru   rv   rw   rx   r!   r!   r!   r"   rf      s   
	
rf   c                   @   s&   e Zd Zejdeegdd ZdS )TestIndexConstructorUnwrappingrM   c                 C   s>   t dt dt dg}t|}t|}||}t|| d S )NZ20110101Z20120101Z20130101)r   r   r   r   r   )r   rM   Zstampsr    Zserr   r!   r!   r"   !test_constructor_from_series_dt64   s
    z@TestIndexConstructorUnwrapping.test_constructor_from_series_dt64N)	r^   r_   r`   rG   rH   ra   r   r   rz   r!   r!   r!   r"   ry      s   ry   ) __doc__decimalr   ZnumpyrK   rG   Zpandas.core.dtypes.commonr   Zpandasr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingr   r   rf   ry   r!   r!   r!   r"   <module>   s   LwJ