U
    +if'                     @   s  d Z ddlmZ ddlZddlZddlmZmZm	Z	 ddl
mZ ejdZejdddgd	d
 Zdd Zdd Zedd Zeejddddddgifdddddgifdddgeg dddfdddgeg dddfdddgeg dddfdddgeg dddfddgdge	jg gd ddgddfddgdge	jg gd ddgddfddgdge	jg gd ddgddfddgdge	jg gd ddgddfg
dd Zedd Zeejdd d gd!d gd d"gd!d"gd#d$ggd%d& Zed'd( Zed)d* Zed+d, Zejjd-d. Zed/d0 Zed1d2 Zed3d4 Z ed5d6 Z!ed7d8 Z"eejd9e#d:fd;gd<d= Z$ed>d? Z%dS )@z
Tests that the specified index column (a.k.a "index_col")
is properly handled or inferred during parsing for all of
the parsers defined in parsers.py
    )StringION)	DataFrameIndex
MultiIndexZpyarrow_skipwith_headerTFc           	   	   C   s   | }d}d}|rP|| }|j t|dd}|j t|ddd}t|| n4|}d}tjt|d |j t|dd W 5 Q R X d S )	Na  KORD1,19990127, 19:00:00, 18:56:00, 0.8100, 2.8100, 7.2000, 0.0000, 280.0000
KORD2,19990127, 20:00:00, 19:56:00, 0.0100, 2.2100, 7.2000, 0.0000, 260.0000
KORD3,19990127, 21:00:00, 20:56:00, -0.5900, 2.2100, 5.7000, 0.0000, 280.0000
KORD4,19990127, 21:00:00, 21:18:00, -0.9900, 2.0100, 3.6000, 0.0000, 270.0000
KORD5,19990127, 22:00:00, 21:56:00, -0.5900, 1.7100, 5.1000, 0.0000, 290.0000
KORD6,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000zBID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir
ZID	index_colr   headerzIndex ID invalidmatch)read_csvr   	set_indextmassert_frame_equalpytestraises
ValueError)	all_parsersr   parserZ	no_headerr
   dataresultexpectedmsg r   X/home/mars/bis/venv/lib/python3.8/site-packages/pandas/tests/io/parser/test_index_col.pytest_index_col_named   s    r   c                 C   sx   | }d}t dddgdddgdd	d
gdddgdtdddgddd}dddddg}|jt||dgd}t|| d S )Nz+1,2,3,4,hello
5,6,7,8,world
9,10,11,12,foo
      	         
                     )abcdZhelloZworldfoomessagenameindexr)   r*   r+   r,   )namesr   )r   r   r   r   r   r   )r   r   r   r   r3   r   r   r   r   test_index_col_named20   s    $r4   c              	   C   s<   d}| }d}t jt|d |jt|dd W 5 Q R X d S )Nza,b
1,2z)The value of index_col couldn't be 'True'r   Tr   )r   r   r   r   r   )r   r   r   r   r   r   r   test_index_col_is_trueB   s
    r5   c                 C   sX   d}| }| t|}tdddgdddgdd	d
ggdddgdddgd}t|| d S )Nz$A,B,C
foo,1,2,3
bar,4,5,6
baz,7,8,9
r   r    r#   r&   r   r!   r$   r'   r   r-   barZbazABCr2   columnsr   r   r   r   r   r   r   r   r   r   r   r   r   test_infer_index_colL   s    r>   zindex_col,kwargsr;   xyzr/   r;   r2   r   r    r3   c                 C   s4   d}| }|j t||d}tf |}t|| d S )Nzx,y,zr   r<   )r   r   kwargsr   r   r   r   r   r   r   test_index_col_empty_data^   s
    )
rE   c                 C   s8   d}| }|j t|dd}tddgd}t|| d S )Nzx,yFr   r?   r@   r;   r<   r=   r   r   r   test_empty_with_index_col_false   s
    rG   index_names r-   r6   ZNotReallyUnnamedz
Unnamed: 0c                 C   sv   | }d |dg }|jt|ddgd}tddddd	gitd
dgddggd}dd |D |j_t	|| d S )N,zcol
a,c,1
a,d,2
b,c,3
b,d,4r   r   r   colr    r#   r&   r)   r*   r+   r,   r1   c                 S   s   g | ]}|r|nd qS )Nr   ).0r0   r   r   r   
<listcomp>   s     z+test_multi_index_naming.<locals>.<listcomp>)
joinr   r   r   r   Zfrom_productr2   r3   r   r   )r   rH   r   r   r   r   r   r   r   test_multi_index_naming   s     rO   c              	   C   sr   | }d}|j t|ddgd}tdddddgitdd	gd
dddggddd
d
gdd
ddggdd}t|| d S )Nz$,Unnamed: 2,
a,c,1
a,d,2
b,c,3
b,d,4r   r    r   z
Unnamed: 2r+   r,   r)   r*   r   r#   r&   )Zlevelscodesr1   )r   r   r   r   r   r   )r   r   r   r   r   r   r   r   ,test_multi_index_naming_not_all_at_beginning   s     rQ   c              	   C   st   | }t dddg}ttjdd|dddgd}t $}|| |j	|dd	d
gd}W 5 Q R X t
|| d S )N)r7   r   r    )r8   r   r    r#   r?   r@   rA   r:   r   r   r    r   )r   from_tuplesr   nprandomrandnr   ensure_cleanto_csvr   r   )r   r   midxr   pathr   r   r   r   %test_no_multi_index_level_names_empty   s    

rZ   c                 C   s   | }d}t jddgddgd}tdg}tdd	gg||d
}|jt|dddgd}t|| tddg}tddgdd}tddgddgg||d
}|jt|ddd}t|| d S )Nz
I11,A,A
I12,B,B
I2,1,3
)r7   r8   )r7   zB.1ZI11ZI12rC   ZI2r   r#   r:   r   )r   r
   r7   zA.1r/   r8   13)r   rR   r   r   r   r   r   r   )r   r   r   rX   idxr   r   Zcol_idxr   r   r   test_header_with_index_col   s    
r^   c              	   C   sj   | }d}t t|tj|d}t $}|j|dd |j|dgd}W 5 Q R X t	||
d d S )NiAB r)   r*   Fr1   r   r   r)   )r   rangerS   rT   rU   r   rV   rW   r   r   r   )r   r   NZdfrY   r   r   r   r   test_index_col_large_csv   s    
rb   c                 C   sR   | }|j tdddgdd}tg tjddgddggd	d
gdd}t|| d S )Na0,a1,a2
b0,b1,b2
r   r   r
   r   a1a2b1b2a0b0rC   rF   r   r   r   r   from_arraysr   r   r   r   r   r   r   r   r   )test_index_col_multiindex_columns_no_data   s       rn   c                 C   sD   | }|j tddgdd}tg ddgtg ddd}t|| d S )	Nz	a0,a1,a2
r   rd   re   rf   ri   r/   rB   r   r   r   r   r   r   rm   r   r   r   test_index_col_header_no_data  s    
rp   c                 C   sL   | }|j tdddgd}tg tdddgdd	d
ggd}t|| d S )Nrc   r   r   r	   ri   re   rf   rj   rg   rh   rF   rk   rm   r   r   r   test_multiindex_columns_no_data  s     rq   c                 C   s`   | }|j tdddgdd}tddggtjddgdd	ggd
dgdtdgd}t|| d S )Nz a0,a1,a2
b0,b1,b2
data,data,datar   r   rd   r   re   rf   rg   rh   ri   rj   rC   rB   )r   r   r   r   rl   r   r   r   rm   r   r   r   +test_multiindex_columns_index_col_with_data  s       rr   c                 C   sR   | }|j tdddgdgddid}tdgdgdd	d}tj||d
d d S )Nz0,1r)   r*   ZUInt8)r3   r   dtyper   r   r_   )r   F)Zcheck_index_type)r   r   r   r   r   r   rm   r   r   r   test_infer_types_boolean_sum.  s     rt   z
dtype, valZ01)Zint64r   c                 C   sL   d}| }|j t|dd|id}tddgit|gddd}t|| d S )Nza,b
01,2r)   )r   rs   r*   r    r/   r1   ro   )r   rs   valr   r   r   r   r   r   r    test_specify_dtype_for_index_colF  s
    rv   c                 C   s`   | }d}|j t|ddgdd}tjdddgdd	gd
}tdddgg|dgd}t|| d S )Nza,b,c,d
e,f,g,h
x,y,1,2
r   r   rd   )r)   e)r+   g)r,   hr*   frC   r?   r    r@   rB   )r   r   r   rR   r   r   r   )r   r   r   r   colsr   r   r   r   -test_multiindex_columns_not_leading_index_colQ  s     r|   )&__doc__ior   numpyrS   r   Zpandasr   r   r   Zpandas._testingZ_testingr   markZusefixturesZskip_pyarrowZparametrizer   r4   r5   r>   rl   rE   rG   rO   rQ   rZ   r^   Zslowrb   rn   rp   rq   rr   rt   objectrv   r|   r   r   r   r   <module>   s   


'	












	