U
    >vfD                     @   s   d Z ddlmZ ddlZddlmZmZ ddlZddlZddl	m
Z
 ddlm  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 ddlm Z! ddl"m#Z# ddl$m%Z% e&d	Z'G d
d dZ(G dd dZ)G dd dZ*G dd dZ+G dd dZ,G dd dZ-dS )z* test positional based indexing with iloc     )datetimeN)catch_warningssimplefilter)IndexingError)NACategoricalCategoricalDtype	DataFrameIndexIntervalNaTSeries	Timestamparrayconcat
date_rangeinterval_rangeisnato_datetime)	is_scalar)"check_indexing_smoketest_or_raiseszuonly integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indicesc                
   @   sX   e Zd Zejddddddggejdddgejd	d
ddddgdd ZdS )TestiLockey   r      kindseriesframecollabelsmixedtsZfloatsemptyc                 C   s(   | | d| }t|d|td d S )N_iloc)Zfails)Zgetfixturevaluer   
IndexError)selfr   r   r   requestobj r*   C/tmp/pip-unpacked-wheel-vdrwu74i/pandas/tests/indexing/test_iloc.py"test_iloc_getitem_int_and_list_int-   s    z+TestiLoc.test_iloc_getitem_int_and_list_intN)__name__
__module____qualname__pytestmarkparametrizer,   r*   r*   r*   r+   r   ,   s   r   c                   @   s  e Zd ZdZejdedededdddge	ede
dddggejdejejgd	d
 Zejdeegdd Zdd Zdd Zejde
dedfgejdedddggddgedfedddgedf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+d*d+ggd,d- Zd.d/ Z d0d1 Z!d2d3 Z"d4d5 Z#d6d7 Z$d8d9 Z%d:d; Z&d<d= Z'd>d? Z(d@dA Z)dBdC Z*dDdE Z+dFdG Z,ejddgeddde
dggejdHdIge
dIggdJdK Z-dLdM Z.dNdO Z/dPdQ Z0dRdS Z1dTdU Z2dVdW Z3dXdY Z4dZd[ Z5d\d] Z6d^d_ Z7ejdHde8e
j9gd`da Z:ejdbe;dddcddgdedf Z<dgdh Z=ejdejejgdidj Z>dkdl Z?dmdn Z@ejdoee
jgdpdq ZAejddgeddgdrds ZBdtdu ZCdvdw ZDdxdy ZEdzd{ ZFd|d} ZGd~d ZHejdee
jgejdee
jgdd ZIdd ZJdd ZKeLjMdd ZNdd ZOdS )TestiLocBaseIndependentzTests Independent Of Base Classr   N   r   r   r   indexerc           	      C   s  t dtditd}tdddg}|s<|jjd |s<t| }|j	}||||df< t d|i
t}|st|d j	|stt|| d|jd< |d dkstt tjddd	gtdtdd
}| }|j	}||||df< t |
ttdd
}t|| d S )Nr   r4   dtypealphabetagammar   r   r   r   r   r   )r	   rangeobjectr   _mgrblocksZ_can_hold_elementAssertionErrorcopyvaluesastypenpshares_memorytmassert_frame_equalr%   r   )	r'   r5   r   using_array_managerr   catdfZ	orig_valsexpectedr*   r*   r+   %test_iloc_setitem_fullcol_categoricalC   s&    
"z=TestiLocBaseIndependent.test_iloc_setitem_fullcol_categoricalboxc                 C   s   t ddddg}||d}|tkr.|j}n|jjd }|tkr^||dd  |jd d< n||dd  |jd ddf< |tj ddddgdd}t	|| |tkr|r|j|k	st
t|j|st
q|j|kst
nt|d j|st
d S )Nr   r   r4      i8r   r6   )r   Zto_numpyr   rC   r?   Zarraysr%   rE   rG   Zassert_equalrA   rF   )r'   frame_or_seriesrN   using_copy_on_writearrr)   rC   rL   r*   r*   r+   test_iloc_setitem_ea_inplacep   s     z4TestiLocBaseIndependent.test_iloc_setitem_ea_inplacec                 C   sJ   t dddg}ttd|d}|jds.t| }|jdsFtd S )Nr   r   r4   index)r   r   r   )r
   r   r=   r%   Z_is_scalar_accessrA   to_frame)r'   rV   serrK   r*   r*   r+   test_is_scalar_access   s
    z-TestiLocBaseIndependent.test_is_scalar_accessc              	   C   s  t tjdtdd}d}tjt|d$ |jd d dddd	d
dgf  W 5 Q R X tjt|d |jddg  W 5 Q R X tjt|d |jddg  W 5 Q R X tjt|d |jdg  W 5 Q R X |d }tjt|d |jdg  W 5 Q R X tjt|d |jdg  W 5 Q R X d}tjt|d |jd  W 5 Q R X tjt|d |jd  W 5 Q R X tjt|d |jd  W 5 Q R X tjt|d |jd  W 5 Q R X |jd d d
df }|jd d d
d f }t	
|| |jd d ddf }|jd d d df }t	
|| |jd d dd
df }|jd d d d
df }t	
|| |jd d d
ddf }|jd d d
d df }t	
|| |jd d dd
f }|jd d d d
f }t	
|| |jd d dd
f }|jd d d df }t	
|| |jd d dddf }|jd d d df }t	
|| |jd d ddf }|jd d d df }t	
|| |jdd }|jdd  }t	|| |jdd  }|jd d }t	|| |jdd d }|jd d d }t	|| dd }t tjddtdd}||jd d dd	f t |jg d ||jd d dd	f |jd d dgf  ||jd
d |jd
g  d}tjt|d |jd
ddg  W 5 Q R X d}tjt|d |jd d d
f  W 5 Q R X d S )N)      ABCDEcolumnsz%positional indexers are out-of-boundsmatchr   r   r   r4   rO   r\      id   Aiz*single positional indexer is out-of-bounds
   ir   i      c                 S   s   t |  | j t| | d S N)strdtypesrG   rH   )resultrL   r*   r*   r+   check   s    z?TestiLocBaseIndependent.test_iloc_exceeds_bounds.<locals>.checkZABrV   r_      )r	   rE   randomZrandom_samplelistr0   raisesr&   r%   rG   rH   assert_series_equalrandnrV   )r'   rK   msgsrl   rL   rm   Zdflr*   r*   r+   test_iloc_exceeds_bounds   s    (&,z0TestiLocBaseIndependent.test_iloc_exceeds_boundszindex,columnsr[   r]   zindex_vals,column_valsrd   D12i  c              	   C   sP   t tjt|t|||d}d}tjt|d |j||f  W 5 Q R X d S )Nrn   z$.iloc requires numeric indexers, gotr`   )	r	   rE   rp   rt   lenr0   rr   r&   r%   )r'   rV   r_   Z
index_valsZcolumn_valsrK   ru   r*   r*   r+   test_iloc_non_integer_raises   s      z4TestiLocBaseIndependent.test_iloc_non_integer_raisesc              	   C   sJ   t tddd}t||}tjtdd |j	d  W 5 Q R X d S )Nrc   re   zCannot index by location indexr`   a)
r	   rE   arangereshaperG   get_objr0   rr   	TypeErrorr%   )r'   rQ   r)   r*   r*   r+    test_iloc_getitem_invalid_scalar  s    z8TestiLocBaseIndependent.test_iloc_getitem_invalid_scalarc                 C   s|   t dddg}| }tdddgddd	gd
ddgddddgd}|j|  t|| |jd d |f  t|| d S )Nr   r   r   rc   e   f   g   h   i   j   k   l   rd   BCr4   rU   )rE   r   rB   r	   r%   rG   Zassert_numpy_array_equal)r'   Zarray_with_neg_numbersZ
array_copyrK   r*   r*   r+   -test_iloc_array_not_mutating_negative_indices  s    
zETestiLocBaseIndependent.test_iloc_array_not_mutating_negative_indicesc                 C   s   t dddgdddgd}|d }|jd	 }|jd
 }t|| |jd	g }|jd
g }t|| |jd	 }|jd
 }||kst|jd	g }|jd
g }t|| tdgdgd}|jdg }t|| d S )Nr   r4   r\      rg      rd   r   rd   r   r}   rU   r   )r	   r%   rG   rs   rH   rA   r   )r'   rK   rv   rL   rl   r*   r*   r+   /test_iloc_getitem_neg_int_can_reach_first_index%  s"    



zGTestiLocBaseIndependent.test_iloc_getitem_neg_int_can_reach_first_indexc                 C   s   t d dddddg}t ddddddg}t||gdd}|jd }t|sVt|jdd d f }ttjdddgd	d
d	d
gdd}t	|| d S )Nr   r   r   r4   rO   Zaxisr;   r   rd   r   )rV   name)
r	   r   r%   r   rA   r   rE   nanrG   rs   )r'   df1df2rK   rl   rL   r*   r*   r+   test_iloc_getitem_dups@  s    
 z.TestiLocBaseIndependent.test_iloc_getitem_dupsc                 C   s   t dddddddddd	d
dg}t ddddg}t|jdg | t ddddddddg}t|jddg | t dddd	d
dgddgd}|jddgddgf }t|| d S )Nr   r   r4   r   rc      ,        r   )r   r   rU   )r	   rG   rH   r%   r'   rK   rL   rl   r*   r*   r+   test_iloc_getitem_arrayN  s    


 z/TestiLocBaseIndependent.test_iloc_getitem_arrayc                 C   s   t dddddddddd	d
dg}t ddddddddg}|jdddg }t|| t dddddd	d
dgddgd}|jdd  }t|| d S )Nr   r   r4   r   rc   r   r   r   r   r   TFr   rU   c                 S   s   | j d dkS )Nr   r   rU   xr*   r*   r+   <lambda>q      z@TestiLocBaseIndependent.test_iloc_getitem_bool.<locals>.<lambda>r	   r%   rG   rH   r   r*   r*   r+   test_iloc_getitem_boola  s    


 z.TestiLocBaseIndependent.test_iloc_getitem_boolrV   TFc              	   C   sN   t dddg}dt| dt| }tjt|d |j|  W 5 Q R X d S )Nr   r   r4   z Boolean index has wrong length: z instead of r`   )r   r{   r0   rr   r&   r%   )r'   rV   rv   ru   r*   r*   r+   test_iloc_getitem_bool_diff_lent  s    z7TestiLocBaseIndependent.test_iloc_getitem_bool_diff_lenc                 C   s   t dddddddddd	d
dg}t ddddddddg}|jd d }t|| t dddgdgd}|jddddf }t|| t dddddddd
dg}|jd d dd f }t|| d S )Nr   r   r4   r   rc   r   r   r   r   r   r   rU   r   )rd   r   c                 S   s   ddgS )Nr   r   r*   )rK   r*   r*   r+   r     r   zATestiLocBaseIndependent.test_iloc_getitem_slice.<locals>.<lambda>r   r   r*   r*   r+   test_iloc_getitem_slice|  s"    


z/TestiLocBaseIndependent.test_iloc_getitem_slicec                 C   s  t tjddddddgd}t tjjdddddd	dd
gd}t||gdd}t|j	d d d df | t|j	d d dd f | t||gdd}t|j	d d d d	f | t|j	d d d	d f | t||j	d d dgf gdd}t|j	d d ddf | t||gdd}t|j	ddd d	f | t|j	ddd	d f | t|j	dd d d	f | t|j	dd d	d f | d S )Nre   rO   rd   r   r^   r   r[   sizer   r   r   r   r4   )
r	   rE   rp   rt   randintr   r   rG   rH   r%   )r'   r   r   rK   expr*   r*   r+   test_iloc_getitem_slice_dups  s$      z4TestiLocBaseIndependent.test_iloc_getitem_slice_dupsc                 C   s   t tjddtdddtdddd}d|jd	< |jd	 }|dksLtd|jd d ddf< |jd d ddf }|jd d ddf }t|| t	ddd
dgd}|jdd  d7  < t	dddgdd
dgd}t
|| d S )NrO   r      r      r4   rn   r   r   r   r\   ro   rU   )r	   rE   rp   rt   r~   r%   rA   rG   rH   r   rs   r'   rK   rl   rL   rv   r*   r*   r+   test_iloc_setitem  s       

z)TestiLocBaseIndependent.test_iloc_setitemc                 C   s   t dddgdddgddd	gg}t dddgdddgd
d
d
gg}d
|jddd< t|| t dddgdddgddd	gg}t ddd
gddd
gddd
gg}d
|jddd< t|| d S )Nro   cre   r   drg   r   er   r\   r   r   r   r   r   r'   rK   rL   r*   r*   r+   test_iloc_setitem_axis_argument  s        z7TestiLocBaseIndependent.test_iloc_setitem_axis_argumentc                 C   s   t tdddddgdddgd}|jddgdd	gf  |jddgdd	gf  d
7  < t tdddddddddg	ddddgdddgd}t|| d S )N	   )r4   r4   rd   r   r   rn   r   r   r   rc   r   r   r4   r   r   ro   r   r   )r	   rE   r~   r   r%   r   rG   rH   r   r*   r*   r+   test_iloc_setitem_list  s       z.TestiLocBaseIndependent.test_iloc_setitem_listc                 C   sx   t ddddg}t ddddg}| }ddg|jt ddg< t|| | }ddg|jtddg< t|| d S )Nr   r   r   r4   r   )r   rB   r%   rG   rs   r
   )r'   Zs_origrL   rv   r*   r*   r+   test_iloc_setitem_pandas_object  s    z7TestiLocBaseIndependent.test_iloc_setitem_pandas_objectc                 C   sf  t d dddddg}t ddddddg}t||gdd}|d}t|jd d df }|| j}|j|df |j|df< t|| t ddgddgd}d	d	g|_	|d
= t|| |jddgddgf |jddgddgf< t|| |jddgddgf j
dd|jddgddgf< |jddgddgf j
dd|jddgddgf< t|| d S )Nr   r   r   r4   rO   r   r   r<   r   rd   T)Zdrop)r	   r   ZfillnarE   isnanr%   rV   rG   rH   r_   Zreset_index)r'   r   r   rK   rL   Zindsmaskr*   r*   r+   test_iloc_setitem_dups  s"    


(00z.TestiLocBaseIndependent.test_iloc_setitem_dupsc                 C   s   t ddgddggddgd}|jd d df d|jd d df< |sZt|jjdksZt|jd d df d |jd d df< |st|jjdkst| }|jddgddgf |jddgddgf< t	|| d S )	Nr   r   r   r4   r   r^   Zf8g      ?)
r	   r%   rD   r{   r?   r@   rA   rB   rG   rH   )r'   rI   rK   rL   r*   r*   r+   9test_iloc_setitem_frame_duplicate_columns_multiple_blocks  s    &$(zQTestiLocBaseIndependent.test_iloc_setitem_frame_duplicate_columns_multiple_blocksc                 C   s  t tjddtdddtdddd}|jd }|jd }t|| |jd }|jd	 }||ksht	|jdd }|jdd
 }t
|| |jd d ddf }|jd d ddf }t
|| |jdddg }|jdddg }t
|| |jdddgddgf }|jdddgddgf }t
|| |jdddgddgf }|jdddgddgf }t
|| |jddddgddgf }|jddddgddgf }t
|| ttddtd}|j|j }|jddddg }t
|| d S )Nre   rO   r   r[   r   r   rn   )r   r   )rO   rO      r4   r\   r   ro   r   rh   )rV   r7   )r	   rE   rp   rt   r=   r%   locrG   rs   rA   rH   r   r>   rV   )r'   rK   rl   r   rL   rv   r*   r*   r+   test_iloc_getitem_frame   sB     
 




z/TestiLocBaseIndependent.test_iloc_getitem_framec              	   C   s   t tjddtdtdd}|jd }|jd }||ks@t|jd d dd	f }|jd d d
gf }t	|| |jd }|jd }||kstd}t
jt|d |jd  W 5 Q R X d}t
jt|d |jd  W 5 Q R X d S )Nre   rO   
abcdefghijABCDrn   r   )br   r   r4   r   )r   r   )jrx   z/index 5 is out of bounds for axis 0 with size 4r`   )re   r\   zLocation based indexing can only have \[integer, integer slice \(START point is INCLUDED, END point is EXCLUDED\), listlike of integers, boolean array\] types)r	   rE   rp   rt   rq   r%   r   rA   rG   rH   r0   rr   r&   
ValueError)r'   rK   rl   r   rL   ru   r*   r*   r+    test_iloc_getitem_labelled_frameO  s*      



z8TestiLocBaseIndependent.test_iloc_getitem_labelled_framec                 C   s  t jdd}tddd}td}t|||d}|  |jddd	d
f }t| |j	 t|ddd	d
f |dd |d	d
 d}t
|| td|_|jddd	d
f }t| |j	 t|ddd	d
f |dd tdd}t
|| t jdd}ttd	dd
}ttd	dd
}t|||d}|sJ|jjd	 j |jddd
df }t| |j	 t|ddd
df |dd |d
d d}t
|| d S )Nro   rO   Z20130101)Zperiodsr   rn   r4   r\   r   r   ZaaaaZaar   r   r   )rE   rp   rt   r   rq   r	   Zdescriber%   rj   rk   rG   rH   r_   r=   r?   r@   Zmgr_locs)r'   rI   rS   rV   r_   rK   rl   rL   r*   r*   r+   test_iloc_getitem_doc_issuep  s6    .
*.z3TestiLocBaseIndependent.test_iloc_getitem_doc_issuec                 C   sb  t tjddtdtdd}d|jd< |jd }|dks@td|jd d d	d
f< |jd d d	d
f }|jd d d	d
f }t|| t	tjdt
ddd	d}d|jd< |jd }|dkstd|jd d< |jd d }|jd d }t|| t	dgd }dd	dg|jdd d	< dd
dg|jdd d	< |}t	ddd	d
ddg}t|| d S )Nre   rO   r   r   rn   r   r   r   r   r4   r[   rU   r   ro   r\   )r	   rE   rp   rt   rq   r%   rA   rG   rH   r   r=   rs   r   r*   r*   r+   test_iloc_setitem_series  s4      



z0TestiLocBaseIndependent.test_iloc_setitem_seriesc                 C   s   t tjdddtjddddd}ddgddgg|jd	d
< t ddddd
gdddddgd}t|| t dddddgtjddddd}ddgddgg|jd	d
< t dddddgdddddgd}t|| d S )Nr\   int64r6   re   r   rg   r   r   r   rO   r   r   ro   r   r}   r   r   r   r   r   y)r	   rE   r~   r%   rG   rH   r   r*   r*   r+   test_iloc_setitem_list_of_lists  s    ""z7TestiLocBaseIndependent.test_iloc_setitem_list_of_listsvalueZc                 C   sL   t ddgddggddgd}||jd|f< |jd	 }t|rD|d
ksHtd S )Nr   r   r4   rO   rd   r   r^   r   r;   r   )r	   r%   r   rA   )r'   r5   r   rK   rl   r*   r*   r+   #test_iloc_setitem_with_scalar_index  s    
z;TestiLocBaseIndependent.test_iloc_setitem_with_scalar_indexc                 C   s  t ttdtddgd}|jd dk}d}tjt|d |j|  W 5 Q R X tt||_	d	}tjt
|d |j|  W 5 Q R X |jtjd
gt| td }t|| td}d| }dd |D }t ||d|}ddddddddd	d	}td
d tdt dD ]}	|jdkj}|	rBt|ttt||	}dD ]}
z:|
rft||
dd  }n|}tt|| d  }W n2 ttt
fk
r } zt|}W 5 d }~X Y nX |	|
f}||}||krFtd| d| d| dqFqW 5 Q R X d S )Nr\   r]   r}   rn   r   r   zBiLocation based boolean indexing cannot use an indexable as a maskr`   zDiLocation based boolean indexing on an integer type is not availableTr6   rO   c                 S   s   g | ]}t |qS r*   )bin).0numr*   r*   r+   
<listcomp>  s     z:TestiLocBaseIndependent.test_iloc_mask.<locals>.<listcomp>)locsnumsZ0b1100Z0b11ztUnalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).)	)N )N.loc)N.iloc)rV   r   )rV   r   )rV   r   )r   r   )r   r   )r   r   )recordignore)NrV   r   )r   r   r   r   r   [z] does not match [z], received [])r	   rq   r=   r}   r0   rr   r   r%   r{   rV   NotImplementedErrorrE   r   boolrG   rH   r~   r   r   UserWarningr   rC   r   reversedgetattrrj   r   sumr   getrA   )r'   rK   r   ru   rl   r   r   ZrepsrL   idxmethodaccessorZanswerr   r   rr*   r*   r+   test_iloc_mask  s^    



z&TestiLocBaseIndependent.test_iloc_maskc              	   C   s   t dgd dgd d}tdd }|j| }t|d| d| g}|j| }t|| t dgd	 dgd	 d}t|d| d| g}tjt	d
d |j
|  W 5 Q R X d S )N皙?r   r   r   rb   c   r   r4   r   znot in indexr`   )r	   rE   r~   r%   r   rG   rH   r0   rr   KeyErrorr   )r'   rK   r   rL   Zdf3rl   r   r*   r*   r+   test_iloc_non_unique_indexing  s    

z5TestiLocBaseIndependent.test_iloc_non_unique_indexingc                 C   s   t dd}t j|jd d g f |jd d d df ddd t j|jg d d f |jd dd d f ddd t j|jg  |jd dd d f ddd d S )Nr\   r   r   T)Zcheck_index_typeZcheck_column_type)rG   ZmakeCustomDataframerH   r%   r'   rK   r*   r*   r+   "test_iloc_empty_list_indexer_is_ok/  s&       z:TestiLocBaseIndependent.test_iloc_empty_list_indexer_is_okc                 C   s  t ddddgi}|jd d  }||k	s,tt|d |d sDtdddg|jd d df< |r||d dddgk stn|d dk sttddddddg}|jd d  }||k	stdd	d
g|d d< |rt|d d dddgkstn t|d d dd	d
gkstd S )Nr}   r   r   r4   rO   r\   ro   r   r   r   )r	   r%   rA   rE   rF   r   allr   )r'   rR   Zoriginal_dfZ	sliced_dfZoriginal_seriesZsliced_seriesr*   r*   r+   &test_identity_slice_returns_new_objectD  s     z>TestiLocBaseIndependent.test_identity_slice_returns_new_objectc                 C   sD   t ddgddgg}|jtd }tddgdd}t|| d S )Nr   r   r4   rO   r   r   )r	   r%   rE   r   r   rG   rs   )r'   rK   rl   rv   r*   r*   r+   test_indexing_zerodim_np_arraya  s    z6TestiLocBaseIndependent.test_indexing_zerodim_np_arrayc                 C   s,   t ddg}|jtd }|dks(td S )Nr   r   r   )r   r%   rE   r   rA   )r'   rv   rl   r*   r*   r+   %test_series_indexing_zerodim_np_arrayh  s    z=TestiLocBaseIndependent.test_series_indexing_zerodim_np_arrayc                 C   s   t dddg}t|dddgddd	}t|d |s:t|d d d
 |jd d df< t|d |sjtt dddgdddgd}t|| d S )Nrd   r   r   r   r   r4   )r   r   F)rB   r   r   
categories)r   r	   rG   rF   rA   r%   Zassert_categorical_equal)r'   rJ   rK   rL   r*   r*   r+   -test_iloc_setitem_categorical_updates_inplacen  s    zETestiLocBaseIndependent.test_iloc_setitem_categorical_updates_inplacec                 C   sB  t ddgddgddgdtjgg}|j|jdk  d9  < t ddgddgdd	gdtjgg}t|| |j|jdk  d9  < t ddgddgdd	gd
tjgg}t|| |jddddg  d9  < t ddgdd
gdd	gd
tjgg}t|| |jddddg  d  < t ddgddgddgdtjgg}t|| d S )Nr   r   r   r4   rO   r\   ro   r   re   r   TFg      @g      (@g      @)r	   rE   r   r%   rV   rG   rH   r'   rl   rL   r*   r*   r+    test_iloc_with_boolean_operation}  s    """""z8TestiLocBaseIndependent.test_iloc_with_boolean_operationc                 C   sX   t dtd i}|jd }tdgdddddgd	}t|dgdd
d}t|| d S )Nr   z	a b c d er   r}   r   r   r   r   r   category)rV   r   r7   )r	   r   splitr%   r   rG   rs   )r'   rK   rl   Zraw_catrL   r*   r*   r+   ?test_iloc_getitem_singlerow_slice_categoricaldtype_gives_series  s
    
zWTestiLocBaseIndependent.test_iloc_getitem_singlerow_slice_categoricaldtype_gives_seriesc                 C   s   t dddgd}|jdd }t ddgtdddg}t|| |jddg }t ddgtdddg}t|| |jdddg }t dgtdddg}t|| d S )Nr   r   r4   r   r   TF)r   rD   r%   r   rG   rs   )r'   rY   rl   rL   r*   r*   r+   $test_iloc_getitem_categorical_values  s    z<TestiLocBaseIndependent.test_iloc_getitem_categorical_valuesc                 C   s>   t dddgdd}||jd< t tddgdd}t|| d S )Nr   r   r   ztimedelta64[ns]r6   )r   r%   r   rG   rs   )r'   r   r   rL   r*   r*   r+   %test_iloc_setitem_td64_values_cast_na  s    
z=TestiLocBaseIndependent.test_iloc_setitem_td64_values_cast_nanot_nar}   g      ?c                 C   sX   t |gd}t||||g|d}|||g|jd d< t||||g|d}t|| d S )Nr   r6   r4   )r   r   r%   rG   rs   )r'   r   Znulls_fixturer7   rY   r   r*   r*   r+   $test_setitem_mix_of_nan_and_interval  s    
 z<TestiLocBaseIndependent.test_setitem_mix_of_nan_and_intervalc              	   C   sl   t g }ttjt|t|||d}tjjddd}d|j }tj	t
|d d|j|< W 5 Q R X d S )Nrn   r\   )r   r   r   r   zCannot set values with ndim > r`   r   )r
   r	   rE   rp   rt   r{   r   ndimr0   rr   r   r%   )r'   r   r)   Znd3ru   r*   r*   r+   4test_iloc_setitem_empty_frame_raises_with_3d_ndarray  s     zLTestiLocBaseIndependent.test_iloc_setitem_empty_frame_raises_with_3d_ndarrayc                 C   s   t d}t|}t d}|jdd t|}t||dddg ||dddg  t||dg ||dg  t||d ||d  t||dd ||dd  d S )Nre   F)writer   r   r4   )rE   Zeyer	   ZsetflagsrG   rH   rs   )r'   r5   Zrw_arrayZrw_dfZro_arrayZro_dfr*   r*   r+   "test_iloc_getitem_read_only_values  s    

( z:TestiLocBaseIndependent.test_iloc_getitem_read_only_valuesc                 C   s   t dtjdddi}tdddg}d|j_|j| }|jdddg }t	|| |d j| }|d jdddg }t
|| d S )	Ndatarc   float64r6   r   r4   ro   F)r	   rE   Zonesr   flagsZ	writeabler%   r   rG   rH   rs   )r'   rK   indicesrl   rL   r*   r*   r+   test_iloc_getitem_readonly_key  s    
z6TestiLocBaseIndependent.test_iloc_getitem_readonly_keyc                 C   sV   t dgdgd}tdddg|jd< t dtdddggidgdgd}t|| d S )Nr}   r   r_   rV   r   r   r4   r;   )r	   r   r%   rG   rH   r   r*   r*   r+   "test_iloc_assign_series_to_df_cell  s    "z:TestiLocBaseIndependent.test_iloc_assign_series_to_df_cellklassc                 C   sn   t dddgdddgd}|dd	d	g}|j|df d
 |j|df< t dddgd
ddgd}t|| d S )Nr   r   zr   r4   rO   )flagr   TFr   r   )r'   r  rK   r5   rL   r*   r*   r+   test_iloc_setitem_bool_indexer  s
    z6TestiLocBaseIndependent.test_iloc_setitem_bool_indexerc                 C   s   t dddgdddgd}t dd	d
gdddgdddgd}|jd d dgf |jd d |f< t dd	d
gdddgdddgd}t|| d S )Nrg   r   r   r         )Za2Zb2r   r   r4   rO   r\   ro   r   r   r   )r}   r   r   r   r   )r'   r5   r   r   rL   r*   r*   r+   %test_iloc_setitem_pure_position_based  s
    """z=TestiLocBaseIndependent.test_iloc_setitem_pure_position_basedc                 C   s   t ddgddgd}ddd}||jd< t ddgddgd}t|| t ddgddgd}||jd< t ddgddgd}t|| d S )Nr   r   )r   r   r   r   g       @g     X@r   )r'   rK   rhsrL   r*   r*   r+   "test_iloc_setitem_dictionary_value  s    


z:TestiLocBaseIndependent.test_iloc_setitem_dictionary_valuec                 C   st  t tjdddddgtdd}|jdd  }t|jd | |jdd df }t	|jd | dddg|_
|jdd  }t|jd | |jdd df }t	|jd | t tjd	dddddgtdd}|jdd
 }t|jd | |jdd
df }t	|jd | ddddg|_
|jdd
g }t|jd | |jdd
gdf }t	|jd | d S )Nr4   r   皙?abcrn   r   r   )r  r}   rO   r   r   )r	   rE   rp   rt   rq   r%   rG   rH   r   rs   rV   )r'   rK   expectr*   r*   r+   "test_iloc_getitem_float_duplicates  s8       
 z:TestiLocBaseIndependent.test_iloc_getitem_float_duplicatesc                 C   s   G dd d}t ddgdgd}|d|jd< |d|jd< t ddgdgd}|d|jd< t|| t ddgdgd}|d|jd< tj|jd< t ddgdgd}t|| d S )Nc                   @   sB   e Zd ZddddZedddZeZedddZd	d
 Z	dS )zCTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TON)returnc                 S   s
   || _ d S ri   r   )r'   r   r*   r*   r+   __init__3  s    zLTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__init__c                 S   s   d| j  dS )Nr   r   r  r'   r*   r*   r+   __str__6  s    zKTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__str__c                 S   s   | j |j kS ri   r  )r'   otherr*   r*   r+   __eq__;  s    zJTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__eq__c                 S   s   | S ri   r*   r  r*   r*   r+   view>  s    zHTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.view)
r-   r.   r/   r  rj   r  __repr__r   r  r   r*   r*   r*   r+   TO2  s
   r"  r   r   rn   rW   r   )r	   r%   rG   rH   rE   r   )r'   r"  rK   rl   r*   r*   r+   test_iloc_setitem_custom_object0  s    z7TestiLocBaseIndependent.test_iloc_setitem_custom_objectc                 C   s   t tjddtdtdd}|jd }t|ts8tt	
|j|jd  |jjd d df }t|tsntt	
|j|jd  d S )Nr4   ABCZaabr
  r   )r	   rE   rp   Zrandrq   r%   
isinstancer   rA   rG   assert_almost_equalrC   T)r'   rK   rl   r*   r*   r+   !test_iloc_getitem_with_duplicatesR  s     
z9TestiLocBaseIndependent.test_iloc_getitem_with_duplicatesc                 C   sV   t dddgdddggdddgd}|jd d dgf }|jdgdd	}t|| d S )
Nr   r   r4   rO   r\   ro   r^   r   r   )r	   r%   ZtakerG   rH   r'   rK   rl   rL   r*   r*   r+   "test_iloc_getitem_with_duplicates2]  s    "z:TestiLocBaseIndependent.test_iloc_getitem_with_duplicates2c                 C   s   t tddddgi}|jd }ttdddidd}t|| |jd d df }tddgtddd}t|| | }|jd d df  d7  < t tddddgi}t|| d S )Nr   r   r   r   r4   )r	   r   r%   r   rG   rs   rB   rH   r)  r*   r*   r+   test_iloc_intervald  s    
z*TestiLocBaseIndependent.test_iloc_intervalindexing_funcrhs_funcc                 C   s   t dddg}|ddg|j|dddg< t dddg}t|| tddddgi}|dgdgg|j|dddg< tddddgi}t|| d S )	Nr   r   r   r\   re   TFr}   )r   r%   rG   rs   r	   rH   )r'   r-  r,  rY   rL   rK   r*   r*   r+   test_loc_setitem_boolean_listu  s     z5TestiLocBaseIndependent.test_loc_setitem_boolean_listc                 C   s   t ddddgidd}|jd d d d df }t|| d|d	< |jd d d d df }t |d	 |d d
}t|| d S )Nrd   r   r   r4   Int64r6   r   Zfoor   )r   rd   r   )r'   rK   resrL   r*   r*   r+   .test_iloc_getitem_slice_negative_step_ea_block  s    zFTestiLocBaseIndependent.test_iloc_getitem_slice_negative_step_ea_blockc                 C   sp   t ddddgidd}tdgdgg|jtddgtdgf< t ddddgi|d jd}t|| d S )	Nstatusr}   r   r   r   r6   r   r   )r	   rE   r   r%   r7   rG   rH   r   r*   r*   r+   *test_iloc_setitem_2d_ndarray_into_ea_block  s    .zBTestiLocBaseIndependent.test_iloc_setitem_2d_ndarray_into_ea_blockc                 C   sV   t ddj}t|}|jd }|d |d ks2t|d |d< |d |d ksRtd S )Nr   g      $@r   r   r   )r   Z_valuesr	   r%   rA   )r'   rS   rK   rY   r*   r*   r+   *test_iloc_getitem_int_single_ea_block_view  s    
zBTestiLocBaseIndependent.test_iloc_getitem_int_single_ea_block_viewc                 C   sl   t ddgddgd}t dtddgi|jd d dgf< t tdtd	gddgd}tj||d
d d S )Nz
2022-01-01z
2022-01-02Z2021Z2022r   rd   r   z2021-01-01 00:00:00z2022-01-01 00:00:00F)Zcheck_dtype)r	   r   r%   r   rG   rH   r   r*   r*   r+   )test_iloc_setitem_multicolumn_to_datetime  s    $	zATestiLocBaseIndependent.test_iloc_setitem_multicolumn_to_datetime)Pr-   r.   r/   __doc__r0   r1   r2   slicer=   r
   rE   ZasarrayrG   r   r%   rM   r   r   rT   rZ   rw   r~   rq   r   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r#  r(  r*  r+  r.  r1  r3  tdZ&skip_array_manager_not_yet_implementedr4  r5  r*   r*   r*   r+   r3   @   s   
!

e		
/!* $F	


	


!"
r3   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestILocErrorsc              	   C   sd   |}|t kr| }d}tjt|d |jd  W 5 Q R X tjttd d|jd< W 5 Q R X d S )Nz5Cannot index by location index with a non-integer keyr`   g      @r   )r	   rX   r0   rr   r   r%   r&   _slice_iloc_msg)r'   Zseries_with_simple_indexrQ   r)   ru   r*   r*   r+   test_iloc_float_raises  s    z%TestILocErrors.test_iloc_float_raisesc              	   C   sp   t jtdd" |jd d d d d d f  W 5 Q R X t jtdd" d|jd d d d d d f< W 5 Q R X d S )NzToo many indexersr`   ztoo many indices for arrayr   )r0   rr   r   r%   r&   )r'   Zfloat_framer*   r*   r+   *test_iloc_getitem_setitem_fancy_exceptions  s    &z9TestILocErrors.test_iloc_getitem_setitem_fancy_exceptionsc              	   C   sx   t ddddgi}t ddddgi}d}tjt|d d|j|< W 5 Q R X d	}tjt|d |j|  W 5 Q R X d S )
Nr}   r   r   r4   TFzADataFrame indexer for .iloc is not supported. Consider using .locr`   zWDataFrame indexer is not allowed for .iloc
Consider using .loc for automatic alignment.)r	   r0   rr   r   r%   r&   )r'   rK   r5   ru   r*   r*   r+   test_iloc_frame_indexer  s    z&TestILocErrors.test_iloc_frame_indexerN)r-   r.   r/   r;  r<  r=  r*   r*   r*   r+   r9    s   r9  c                   @   sD   e Zd Zdd Zdd Zdd Zejddd	gd
dgdd Z	dS )TestILocSetItemDuplicateColumnsc                 C   s   t d dddddg}t ddddddg}t||gdd}d|jd< |jd dks\t|jd	 dksnt|jjd tjkstd S )
Nr   r   r   r4   rO   r   r   r;   )r   r   )r	   r   r%   rA   rk   rE   r   )r'   r   r   rK   r*   r*   r+   *test_iloc_setitem_scalar_duplicate_columns  s    
zJTestILocSetItemDuplicateColumns.test_iloc_setitem_scalar_duplicate_columnsc                 C   sX   t dddggdddgd}dg|jd d df< t dddggdddgd}t|| d S )	Nr   rj   str2r}   r   r^   Zstr3r   r   r   r*   r*   r+   (test_iloc_setitem_list_duplicate_columns  s    zHTestILocSetItemDuplicateColumns.test_iloc_setitem_list_duplicate_columnsc                 C   sj   t tjdtjdddddddgd}|jd d df tj|jd d df< |jjd tjksft	d S )	Nr   r6   r   rO   rd   r   r^   r   )
r	   rE   r~   r   r   r%   rD   r  rk   rA   r   r*   r*   r+   *test_iloc_setitem_series_duplicate_columns  s     
(zJTestILocSetItemDuplicateColumns.test_iloc_setitem_series_duplicate_columnsrk   
init_valueexpected_value)r   0r   )floatz1.2g333333?c                 C   sl   t |ddggdddgd}|jd d df ||jd d df< t |ddggdddgtd}t|| d S )Nrj   r@  r}   r   r^   r   )r_   r7   )r	   r%   rD   r>   rG   rH   )r'   rk   rC  rD  rK   Zexpected_dfr*   r*   r+   *test_iloc_setitem_dtypes_duplicate_columns  s    &
zJTestILocSetItemDuplicateColumns.test_iloc_setitem_dtypes_duplicate_columnsN)
r-   r.   r/   r?  rA  rB  r0   r1   r2   rG  r*   r*   r*   r+   r>    s   	r>  c                   @   s   e Zd Zdd Zdd ZdS )TestILocCallablec                 C   s  t ddddgtddtdd}|jd	d
  }t||jddg  |jdd
 d d f }t||jddgd d f  |jdd
 dd
 f }t||jddgdf  |jdd
 dd
 f }t||jddgdgf  |jddgdd
 f }t||jddgdf  |jddgdd
 f }t||jddgdgf  |jdd
 df }t||jddgdf  |jdd
 dgf }t||jddgdgf  d S )Nr   r   r4   rO   aabbXYr   rU   c                 S   s   ddgS Nr   r4   r*   r   r*   r*   r+   r     r   zCTestILocCallable.test_frame_iloc_getitem_callable.<locals>.<lambda>c                 S   s   ddgS rM  r*   r   r*   r*   r+   r      r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   #  r   c                 S   s   dS Nr   r*   r   r*   r*   r+   r   #  r   r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   &  r   c                 S   s   dgS rN  r*   r   r*   r*   r+   r   &  r   c                 S   s   dS rN  r*   r   r*   r*   r+   r   *  r   c                 S   s   dgS rN  r*   r   r*   r*   r+   r   -  r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   0  r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   3  r   )r	   rq   r%   rG   rH   rs   )r'   rK   r0  r*   r*   r+    test_frame_iloc_getitem_callable  s"    "z1TestILocCallable.test_frame_iloc_getitem_callablec                 C   sF  t ddddgtddtdd}| }d	|jd
d < | }d	|jddg< t|| | }d|jdd d d f< | }d|jddgd d f< t|| | }d|jdd dd f< | }d|jddgd	f< t|| | }d|jdd dd f< | }d|jddgd	gf< t|| | }d|jddgdd f< | }d|jddgd	f< t|| | }d|jddgdd f< | }d|jddgd	gf< t|| | }d|jdd d	f< | }d|jddgd	f< t|| | }ddg|jdd d	gf< | }ddg|jddgd	gf< t|| d S )Nr   r   r4   rO   rI  rJ  r   rU   r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   <  r   zCTestILocCallable.test_frame_iloc_setitem_callable.<locals>.<lambda>r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   B  r   r\   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   H  r   c                 S   s   dS rN  r*   r   r*   r*   r+   r   H  r      c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   N  r   c                 S   s   dgS rN  r*   r   r*   r*   r+   r   N  r   r   c                 S   s   dS rN  r*   r   r*   r*   r+   r   U  r   c                 S   s   dgS rN  r*   r   r*   r*   r+   r   [  r   re   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   a  r   c                 S   s   ddgS rM  r*   r   r*   r*   r+   r   g  r   )r	   rq   rB   r%   rG   rH   )r'   rK   r0  r   r*   r*   r+    test_frame_iloc_setitem_callable6  sR    "z1TestILocCallable.test_frame_iloc_setitem_callableN)r-   r.   r/   rO  rR  r*   r*   r*   r+   rH    s   rH  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestILocSeriesc              	   C   s  t tjdttdddd}| }tt|D ](}|j| }||j	|  }t
|| q4|jtdd }|jdd }t
|| t
d  d|d d < W 5 Q R X |rt
|| n|jdd dk st|jddddd	g }||j	ddddd	g }t
|| d S )
Nre   r   r[   r   rU   r   r4   rO   r\   )r   rE   rp   rt   rq   r=   rB   r{   r%   rV   rG   r&  r7  r   rs   Zassert_produces_warningr   rA   Zreindex)r'   rR   rY   Zser_originalirl   r   rL   r*   r*   r+   	test_ilocn  s"     
zTestILocSeries.test_ilocc                 C   s.   t dddgdddgd}|jd dks*td S )Nr   r   r   rU   )r   r%   rA   )r'   rY   r*   r*   r+   test_iloc_getitem_nonunique  s    z*TestILocSeries.test_iloc_getitem_nonuniquec                 C   s\   t dddg}t dddgdddgd}|jdd |jdd< t dddg}t|| d S )	Nr   r   r4   rO   r\   ro   r   rU   )r   r%   rG   rs   )r'   Zser1Zser2rL   r*   r*   r+   r    s
    z4TestILocSeries.test_iloc_setitem_pure_position_basedc                 C   sd   t dgtjgd}|jd d df d|jd d df< t dgttgddd}t|| d S )Ntest)r}   r   r   r/  r6   )	r	   rE   r   r   rD   r   r   rG   rH   r   r*   r*   r+   #test_iloc_nullable_int64_size_1_nan  s    &z2TestILocSeries.test_iloc_nullable_int64_size_1_nanN)r-   r.   r/   rU  rV  r  rX  r*   r*   r*   r+   rS  m  s   rS  ).r6  r   rewarningsr   r   ZnumpyrE   r0   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsr8  Zpandasr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingrG   Zpandas.api.typesr   Zpandas.tests.indexing.commonr   escaper:  r   r3   r9  r>  rH  rS  r*   r*   r*   r+   <module>   s:   D          .2V