a
    d                     @   s  d Z ddlmZ ddl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)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                   @   sP   e Zd Zejdddg dgejdddgejdg d	d
d ZdS )TestiLockey   r      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)   h/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/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g de	ede
g d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g d+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dHgeddde
dHggejdIdJge
dJggdKdL Z-ej.dMdNdO Z/dPdQ Z0dRdS Z1dTdU Z2dVdW Z3dXdY Z4dZd[ Z5d\d] Z6d^d_ Z7d`da Z8ejdIde9e
j:gdbdc Z;ejdde<dHddedfgdgdh Z=didj Z>ejdejejgdkdl Z?dmdn Z@dodp ZAejdqee
jgdrds ZBejddgeddtgdudv ZCdwdx ZDdydz ZEd{d| ZFd}d~ ZGdd ZHdd ZIejdee
jgejdee
jgdd ZJdd ZKdd ZLeMjNdd ZOdd ZPdS )TestiLocBaseIndependentzTests Independent Of Base Classr   N   r   indexerc           	      C   s  t dtditd}tg d}|s:|jjd |s:J | }|j}||||df< t d|i	t}|st
|d j|sJ t|| d|jd< |d dksJ t t
jg dtdtdd}| }|j}||||df< t |	ttdd}t|| d S )	Nr   r3   dtype)alphabetagammar9   r   r   r   r   r   )r   rangeobjectr   _mgrblocksZ_can_hold_elementcopyvaluesastypenpshares_memorytmassert_frame_equalr$   r   )	r&   r4   r   using_array_managerr   catdfZ	orig_valsexpectedr)   r)   r*   %test_iloc_setitem_fullcol_categorical?   s&    
 z=TestiLocBaseIndependent.test_iloc_setitem_fullcol_categoricalboxc                 C   s   t g d}||d}|tu r*|j}n|jjd }|tu rZ||dd  |jd d< n||dd  |jd ddf< |tj g ddd}t	|| |tu r|r|j|usJ t
|j|sJ q|j|u sJ nt
|d j|sJ d S )Nr   r   r3      i8r   r   )r3   rN   r3   rN   r5   )r   Zto_numpyr   rA   r>   Zarraysr$   rC   rE   Zassert_equalrD   )r&   frame_or_seriesrL   using_copy_on_writearrr(   rA   rJ   r)   r)   r*   test_iloc_setitem_ea_inplacel   s     z4TestiLocBaseIndependent.test_iloc_setitem_ea_inplacec                 C   sH   t g d}ttd|d}|jds,J | }|jdsDJ d S )N)r   r   r   r3   index)r   r   r   )r   r   r<   r$   Z_is_scalar_accessto_frame)r&   rU   serrI   r)   r)   r*   test_is_scalar_access   s
    z-TestiLocBaseIndependent.test_is_scalar_accessc                 C   s  t tjddtdd}d}tjt|d& |jd d g df  W d    n1 s\0    Y  tjt|d |jdd	g  W d    n1 s0    Y  tjt|d |jdd
g  W d    n1 s0    Y  tjt|d |jdg  W d    n1 s0    Y  |d }tjt|d |jdg  W d    n1 sT0    Y  tjt|d |jdg  W d    n1 s0    Y  d}tjt|d |jd	  W d    n1 s0    Y  tjt|d |jd
  W d    n1 s0    Y  tjt|d |jd	  W d    n1 sB0    Y  tjt|d |jd
  W d    n1 s|0    Y  |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g d  W d    n1 s0    Y  d}tjt|d" |jd d df  W d    n1 s0    Y  d S ) Nr   )      ABCDEcolumnsz%positional indexers are out-of-boundsmatchr   r   r   r3   rN   r[   r      id   Aiz*single positional indexer is out-of-boundsrN   
   ir   r   i      c                 S   s   t |  | j t| | d S N)strdtypesrE   rF   )resultrJ   r)   r)   r*   check   s    z?TestiLocBaseIndependent.test_iloc_exceeds_bounds.<locals>.check)r[   r   ZABr3   rU   r^      rN   r[   ro   )r   rC   randomdefault_rnglistr/   raisesr%   r$   rE   rF   assert_series_equalstandard_normalrU   )r&   rI   msgsrl   rJ   rm   Zdflr)   r)   r*   test_iloc_exceeds_bounds   s    4,,,,,****&,.z0TestiLocBaseIndependent.test_iloc_exceeds_boundszindex,columnsrZ   r\   zindex_vals,column_valsrd   D12i  r   c                 C   sl   t tjdt|t|f||d}d}tjt|d |j	||f  W d    n1 s^0    Y  d S )Nr   rn   z$.iloc requires numeric indexers, gotr_   )
r   rC   rq   rr   rv   lenr/   rt   r%   r$   )r&   rU   r^   Z
index_valsZcolumn_valsrI   rw   r)   r)   r*   test_iloc_non_integer_raises   s    z4TestiLocBaseIndependent.test_iloc_non_integer_raisesc                 C   s^   t tddd}t||}tjtdd |j	d  W d    n1 sP0    Y  d S )Nrc   re   zCannot index by location indexr_   a)
r   rC   arangereshaperE   get_objr/   rt   	TypeErrorr$   )r&   rP   r(   r)   r)   r*    test_iloc_getitem_invalid_scalar  s    z8TestiLocBaseIndependent.test_iloc_getitem_invalid_scalarc                 C   sr   t g d}| }tg dg dg ddg dd}|j|  t|| |jd d |f  t|| d S )N)r   r   r   )rc   e   f   )g   h   i   )j   k   l   rd   BCr   r   r3   rT   )rC   r   r@   r   r$   rE   Zassert_numpy_array_equal)r&   Zarray_with_neg_numbersZ
array_copyrI   r)   r)   r*   -test_iloc_array_not_mutating_negative_indices  s    
zETestiLocBaseIndependent.test_iloc_array_not_mutating_negative_indicesc                 C   s   t g dg dd}|d }|jd }|jd }t|| |jdg }|jdg }t|| |jd }|jd }||ksJ |jdg }|jdg }t|| tdgdgd}|jd	g }t|| d S )
N)r   r3   r[   )   rg      rd   r   rd   r   r   rT   r   )r   r$   rE   ru   rF   r   )r&   rI   rx   rJ   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|sVJ |jdd d f }ttjdddgg d	dd
}t|| d S )Nr   r   r   r3   rN   Zaxisr:   r   rd   r   rd   r   )rU   name)	r   r   r$   r   r   rC   nanrE   ru   )r&   df1df2rI   rl   rJ   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   r3   r   rc      ,        r   )r   r   rT   )r   rE   rF   r$   r&   rI   rJ   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g d }t|| t dddddd	d
dgddgd}|jdd  }t|| d S )Nr   r   r3   r   rc   r   r   r   r   r   )TTFr   rT   c                 S   s   | j d dkS )Nr   r   rT   xr)   r)   r*   <lambda>q      z@TestiLocBaseIndependent.test_iloc_getitem_bool.<locals>.<lambda>r   r$   rE   rF   r   r)   r)   r*   test_iloc_getitem_boola  s    


z.TestiLocBaseIndependent.test_iloc_getitem_boolrU   TF)TFTFc                 C   s`   t g d}dt| dt| }tjt|d |j|  W d    n1 sR0    Y  d S )Nr   z Boolean index has wrong length: z instead of r_   )r   r}   r/   rt   r%   r$   )r&   rU   rx   rw   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   r3   r   rc   r   r   r   r   r   r   rT   r   )rd   r   c                 S   s   ddgS )Nr   r   r)   )rI   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g dd}t tjd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 )Nr   re   rN   )rd   rd   r   r   r]   r   re   rZ   sizerd   r   r   r   rN   r3   )r   rC   rq   rr   rv   integersr   r   rE   rF   r$   )r&   r   r   rI   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sPJ d|jd d ddf< |jd d ddf }|jd d ddf }t|| t	dg d
d}|jdd  d7  < t	g dg d
d}t
|| d S )Nr   rN   rN   r         r3   rn   r   r   r   rp   rT   r   r   r   )r   rC   rq   rr   rv   r   r$   rE   rF   r   ru   r&   rI   rl   rJ   rx   r)   r)   r*   test_iloc_setitem  s     

z)TestiLocBaseIndependent.test_iloc_setitemc                 C   s   t g dg dg dg}t g dg dg dg}d|jddd< t|| t g dg dg dg}t g d	g d
g dg}d|jddd< t|| d S )N)ro   cre   )r   drg   )r   er   )r[   r[   r[   r[   r   r   r   )ro   r   r[   )r   r   r[   )r   r   r[   r   r   r&   rI   rJ   r)   r)   r*   test_iloc_setitem_axis_argument  s    z7TestiLocBaseIndependent.test_iloc_setitem_axis_argumentc                 C   s   t tddg dg dd}|jddgddgf  |jddgddgf  d7  < t tg d	dg dg dd}t|| d S )
N	   r3   r3   r   rn   r   r   r   rc   )	r   r   r   r3   r   r   ro   r   r   )r   rC   r   r   r$   r   rE   rF   r   r)   r)   r*   test_iloc_setitem_list  s    z.TestiLocBaseIndependent.test_iloc_setitem_listc                 C   sp   t g d}t g d}| }ddg|jt ddg< t|| | }ddg|jtddg< t|| d S )N)r   r   r   r3   )r   r   r3   r   r   r   r   )r   r@   r$   rE   ru   r   )r&   Zs_origrJ   rx   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   r3   rN   r   r   r;   r   rd   T)Zdrop)r   r   ZfillnarC   isnanr$   rU   rE   rF   r^   Zreset_index)r&   r   r   rI   rJ   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sZJ |jd d df d |jd d df< |st|jjdksJ | }|jddgddgf |jddgddgf< t|| d S )	Nr   r   r   r3   r   r]   Zf8g      ?)	r   r$   rB   r}   r>   r?   r@   rE   rF   )r&   rG   rI   rJ   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slJ |jdd }|jdd
 }t
|| |jd d ddf }|jd d ddf }t
|| |jg d }|jg d }t
|| |jg dddgf }|jg dddgf }t
|| |jg dddgf }|jg dddgf }t
|| |jg dddgf }|jg dddgf }t
|| ttddtd}|j|j }|jg d }t
|| d S )Nr   r   r   rZ   r   rn   rN   )r   r   r      r3   r[   )r   r   r3   )r   r   ro   r   )r   r   r3   r   )rh   r   ro   ro   )r   r   r   r3   )rh   rh   r   ro   )rU   r6   )r   rN   ro   r   )r   rC   rq   rr   rv   r<   r$   locrE   ru   rF   r   r=   rU   )r&   rI   rl   r   rJ   rx   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sDJ |jd d ddf }|jd d d	gf }t	|| |jd
 }|jd }||ksJ d}t
jt|d |jd  W d    n1 s0    Y  d}t
jt|d |jd  W d    n1 s
0    Y  d S )Nr   r   
abcdefghijABCDrn   r   )br   r3   r   )r   r   )jrz   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   rC   rq   rr   rv   rs   r$   r   rE   rF   r/   rt   r%   
ValueError)r&   rI   rl   r   rJ   rw   r)   r)   r*    test_iloc_getitem_labelled_frameW  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}|sR|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 )Nr   )ro   rN   Z20130101ro   )Zperiodsr   rn   r3   r[   r   ZaaaaZaar   r   r   rN   )rC   rq   rr   rv   r   rs   r   Zdescriber$   rj   rk   rE   rF   r^   r<   r>   r?   Zmgr_locs)r&   rG   rR   rU   r^   rI   rl   rJ   r)   r)   r*   test_iloc_getitem_doc_issuez  s6    .
*.z3TestiLocBaseIndependent.test_iloc_getitem_doc_issuec                 C   s`  t tjddtdtdd}d|jd< |jd }|dksDJ d|jd d dd	f< |jd d dd	f }|jd d dd	f }t|| t	tjdd
t
dddd}d|jd< |jd }|dksJ d|jd d< |jd d }|jd d }t|| t	dgd }g d|jdd d< g d|jdd d< |}t	g d}t|| d S )Nr   r   r   r   rn   r   r   r   r3   re   rZ   rT   rN   r   ro   )r   r   rN   )r   r3   r[   ra   )r   rC   rq   rr   rv   rs   r$   rE   rF   r   r<   ru   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 g dg dd}t|| t g dtjddddd}ddgddgg|jd	d
< t g dg dd}t|| d S )Nr[   int64r5   re   r   rg   r   r   r   rN   )r   r   re   r   rN   )r[   ro   rg   r   r   r   r   r   r   r   r   y)r   r   r   r   r   )r   rC   r   r$   rE   rF   r   r)   r)   r*   test_iloc_setitem_list_of_lists  s    z7TestiLocBaseIndependent.test_iloc_setitem_list_of_listsr   valueZc                 C   sV   t ddgddggddgddti}||jd|f< |jd	 }t|rN|d
ksRJ d S )Nr   r   r3   rN   rd   r   r]   r   r:   r   )r   rB   r=   r$   r   )r&   r4   r   rI   rl   r)   r)   r*   #test_iloc_setitem_with_scalar_index  s    &
z;TestiLocBaseIndependent.test_iloc_setitem_with_scalar_indexzignore::UserWarningc                 C   s  t ttdtddgd}|jd dk}d}tjt|d |j|  W d    n1 s\0    Y  tt||_	d	}tjt
|d |j|  W d    n1 s0    Y  |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	}dD ]}	|jdkj}|	r^t||	d d d }
t|t|
}dD ]}z:|rt||dd  }n|}tt|| d  }W n4 ttt
fy } zt|}W Y d }~n
d }~0 0 |	|f}||}||krbtd| d| d| dqbq&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 availableTr5   rN   c                 S   s   g | ]}t |qS r)   )bin).0numr)   r)   r*   
<listcomp>  r   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)rU   r   )rU   r   )rU   r   )r   r   )r   r   )r   r   )NrU   r   r   )r   r   r   r   r   [z] does not match [z], received [])r   rs   r<   r   r/   rt   r   r$   r}   rU   NotImplementedErrorrC   r   boolrE   rF   r   r   rA   getattrr   rj   r   sumr   getAssertionError)r&   rI   r   rw   rl   r   r   ZrepsrJ   idxZ
mask_index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 d    n1 s0    Y  d S )N皙?r   r   r   rb   c   r   r3   r   znot in indexr_   )r   rC   r   r$   r   rE   rF   r/   rt   KeyErrorr   )r&   rI   r   rJ   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)rE   ZmakeCustomDataframerF   r$   r&   rI   r)   r)   r*   "test_iloc_empty_list_indexer_is_ok<  s      z:TestiLocBaseIndependent.test_iloc_empty_list_indexer_is_okc                 C   s  t dg di}|jd d  }||us*J t|d |d sBJ g d|jd d df< |rv|d g dk sJ n|d dk sJ tg d}|jd d  }||usJ g d|d d< |rt|d d g dksJ nt|d d g dksJ d S )Nr   r   )rN   rN   rN   rN   )r   r   r3   rN   r[   ro   r   r   r   r3   )r   r$   rC   rD   r   allr   )r&   rQ   Zoriginal_dfZ	sliced_dfZoriginal_seriesZsliced_seriesr)   r)   r*   &test_identity_slice_returns_new_objectQ  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   r3   rN   r   r   )r   r$   rC   r   r   rE   ru   )r&   rI   rl   rx   r)   r)   r*   test_indexing_zerodim_np_arrayn  s    z6TestiLocBaseIndependent.test_indexing_zerodim_np_arrayc                 C   s,   t ddg}|jtd }|dks(J d S )Nr   r   r   )r   r$   rC   r   )r&   rx   rl   r)   r)   r*   %test_series_indexing_zerodim_np_arrayu  s    z=TestiLocBaseIndependent.test_series_indexing_zerodim_np_arrayc                 C   s   t g d}t|g dddd}t|d |s6J |d d d |jd d df< t|d |sfJ t g d	g dd
}t|| d S )Nr   r   )r   r   F)r@   r   r   r   )r   r   rd   
categories)r   r   rE   rD   r$   Zassert_categorical_equal)r&   rH   rI   rJ   r)   r)   r*   -test_iloc_setitem_categorical_updates_inplace{  s    zETestiLocBaseIndependent.test_iloc_setitem_categorical_updates_inplacec                 C   s:  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g d  d9  < t ddgdd
gdd	gd
tjgg}t|| |jg d  d  < t ddgddgddgdtjgg}t|| d S )Nr   r   r   r3   rN   r[   ro   r   re   r   )TTFF)FFTTg      @g      (@g      @)r   rC   r   r$   rU   rE   rF   r&   rl   rJ   r)   r)   r*    test_iloc_with_boolean_operation  s    """""z8TestiLocBaseIndependent.test_iloc_with_boolean_operationc                 C   sR   t dtd i}|jd }tdgg dd}t|dgddd}t|| d S )	Nr   z	a b c d er   r   r   r   category)rU   r   r6   )r   r   splitr$   r   rE   ru   )r&   rI   rl   Zraw_catrJ   r)   r)   r*   ?test_iloc_getitem_singlerow_slice_categoricaldtype_gives_series  s
    
zWTestiLocBaseIndependent.test_iloc_getitem_singlerow_slice_categoricaldtype_gives_seriesc                 C   s   t g dd}|jdd }t ddgtg d}t|| |jddg }t ddgtg d}t|| |jg d }t dgtg d}t|| d S )Nr   r  r   r   r   TFF)r   rB   r$   r   rE   ru   )r&   rX   rl   rJ   r)   r)   r*   $test_iloc_getitem_categorical_values  s    z<TestiLocBaseIndependent.test_iloc_getitem_categorical_valuesc                 C   s<   t g ddd}||jd< t tddgdd}t|| d S )Nr   ztimedelta64[ns]r5   r   r   r   )r   r$   r
   rE   ru   )r&   r   r   rJ   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   r5   r3   )r   r   r$   rE   ru   )r&   r  Znulls_fixturer6   rX   r   r)   r)   r*   $test_setitem_mix_of_nan_and_interval  s    z<TestiLocBaseIndependent.test_setitem_mix_of_nan_and_intervalc                 C   s   t g }ttjdt|t|f||d}tjdjddd}d|j }t	j
t|d d|j|< W d    n1 s0    Y  d S )	Nr   rn   r[   )r   r   r   r   zCannot set values with ndim > r_   r   )r   r   rC   rq   rr   rv   r}   r   ndimr/   rt   r   r$   )r&   r   r(   Znd3rw   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||g d ||g d  t||dg ||dg  t||d ||d  t||dd ||dd  d S )Nre   F)writer   r   r3   )rC   Zeyer   ZsetflagsrE   rF   ru   )r&   r4   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g d}d|j_|j| }|jg d }t	|| |d j| }|d jg d }t
|| d S )Ndatarc   float64r5   )r   r3   ro   F)r   rC   Zonesr   flagsZ	writeabler$   r   rE   rF   ru   )r&   rI   indicesrl   rJ   r)   r)   r*   test_iloc_getitem_readonly_key  s    
z6TestiLocBaseIndependent.test_iloc_getitem_readonly_keyc                 C   sR   t dgdgd}tg d|jd< t dtg dgidgdgd}t|| d S )Nr   r   r^   rU   r   r:   )r   r   r$   rE   rF   r   r)   r)   r*   "test_iloc_assign_series_to_df_cell  s     z:TestiLocBaseIndependent.test_iloc_assign_series_to_df_cellklassc                 C   sd   t g dg dd}|g d}|j|df d |j|df< t g dg dd}t|| d S )N)r   r   z)r   r3   rN   )flagr   r  r   r   )r   r3   rN   r   )r&   r  rI   r4   rJ   r)   r)   r*   test_iloc_setitem_bool_indexer   s
    z6TestiLocBaseIndependent.test_iloc_setitem_bool_indexerr   c                 C   s   t g dg dd}t g dg dg dd}|jd d dgf |jd d |f< t g dg dg dd}t|| d S )	N)rg   r   r   )r         )Za2b2r   rp   r   r   r   r   r   r   )r&   r4   r   r   rJ   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&   rI   rhsrJ   r)   r)   r*   "test_iloc_setitem_dictionary_value  s    


z:TestiLocBaseIndependent.test_iloc_setitem_dictionary_valuec                 C   sp  t tjddg dtdd}|jdd  }t|j	d | |jdd df }t
|j	d	 | g d
|_|jdd  }t|j	d | |jdd df }t
|j	d	 | t tjddg dtdd}|jdd }t|j	d | |jdddf }t
|j	d	 | g d|_|jddg }t|j	d | |jddgdf }t
|j	d	 | d S )Nr   r   )r   皙?r  abcrn   r   r  r   )r  r   )r   r  r  )rN   r3   )r   r  r  r   r   )r   r  r   r  )r   rC   rq   rr   rv   rs   r$   rE   rF   r   ru   rU   )r&   rI   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__H  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__K  s    zKTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__str__c                 S   s   | j |j kS ri   r$  )r&   otherr)   r)   r*   __eq__P  s    zJTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__eq__c                 S   s   | S ri   r)   r&  r)   r)   r*   viewS  s    zHTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.view)
r,   r-   r.   r%  rj   r'  __repr__r   r)  r*  r)   r)   r)   r*   TOG  s
   r,  r   r   rn   rV   r   )r   r$   rE   rF   rC   r   )r&   r,  rI   rl   r)   r)   r*   test_iloc_setitem_custom_objectE  s    z7TestiLocBaseIndependent.test_iloc_setitem_custom_objectc                 C   s   t tjddtdtdd}|jd }t|ts<J t	|j
|j
d  |jjd d df }t|tsrJ t	|j
|j
d  d S )Nr   r   ABCZaabr  r   )r   rC   rq   rr   rs   r$   
isinstancer   rE   assert_almost_equalrA   T)r&   rI   rl   r)   r)   r*   !test_iloc_getitem_with_duplicatesg  s    
z9TestiLocBaseIndependent.test_iloc_getitem_with_duplicatesc                 C   sP   t g dg dgg dd}|jd d dgf }|jdgdd}t|| d S )Nr   rp   )r   r   r   r]   r   r   r   )r   r$   ZtakerE   rF   r&   rI   rl   rJ   r)   r)   r*   "test_iloc_getitem_with_duplicates2v  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   r3   )r   r	   r$   r   rE   ru   r@   rF   r3  r)   r)   r*   test_iloc_interval}  s    
z*TestiLocBaseIndependent.test_iloc_intervalindexing_funcrhs_funcc                 C   s   t g d}|ddg|j|g d< t g d}t|| tdg di}|dgdgg|j|g d< tdg di}t|| d S )Nr   r[   re   TFT)r[   r   re   r   )r   r$   rE   ru   r   rF   )r&   r7  r6  rX   rJ   rI   r)   r)   r*   test_loc_setitem_boolean_list  s    z5TestiLocBaseIndependent.test_loc_setitem_boolean_listc                 C   s~   t dg d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   Int64r5   r   Zfoor   )r   rd   r   )r&   rI   resrJ   r)   r)   r*   .test_iloc_getitem_slice_negative_step_ea_block  s    zFTestiLocBaseIndependent.test_iloc_getitem_slice_negative_step_ea_blockc                 C   sl   t dg didd}tdgdgg|jtddgtdgf< t dg di|d jd}t|| d S )	Nstatusr  r  r5   r   r   r   )r   r   r   )r   rC   r   r$   r6   rE   rF   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s2J |d |d< |d |d ksRJ d S )Nr   g      $@r   r   r   )r   Z_valuesr   r$   )r&   rR   rI   rX   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   rE   rF   r   r)   r)   r*   )test_iloc_setitem_multicolumn_to_datetime  s    $	zATestiLocBaseIndependent.test_iloc_setitem_multicolumn_to_datetime)Qr,   r-   r.   __doc__r/   r0   r1   slicer<   r   rC   ZasarrayrE   r   r$   rK   r   r   rS   rY   ry   r   rs   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   filterwarningsr   r   r   r   r   r   r   r   r  r  r
   r   r  r	   r  r
  r  r  r  r  r  r  r"  r-  r2  r4  r5  r9  r<  r>  tdZ&skip_array_manager_not_yet_implementedr?  r@  r)   r)   r)   r*   r2   <   s   
!

g	
1#*"$

E	





%"
r2   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestILocErrorsc                 C   s   |}|t u r| }d}tjt|d |jd  W d    n1 sF0    Y  tjttd d|jd< W d    n1 s~0    Y  d S )Nz5Cannot index by location index with a non-integer keyr_   g      @r   )r   rW   r/   rt   r   r$   r%   _slice_iloc_msg)r&   Zseries_with_simple_indexrP   r(   rw   r)   r)   r*   test_iloc_float_raises  s    (z%TestILocErrors.test_iloc_float_raisesc                 C   s   t jtdd, |jd d d d d d f  W d    n1 s@0    Y  t jtdd, d|jd d d d d d f< W d    n1 s0    Y  d S )NzToo many indexersr_   ztoo many indices for arrayr   )r/   rt   r   r$   r%   )r&   Zfloat_framer)   r)   r*   *test_iloc_getitem_setitem_fancy_exceptions  s    :z9TestILocErrors.test_iloc_getitem_setitem_fancy_exceptionsc                 C   s   t dg di}t dg di}d}tjt|d d|j|< W d    n1 sR0    Y  d}tjt|d |j|  W d    n1 s0    Y  d S )Nr   r   r8  zADataFrame indexer for .iloc is not supported. Consider using .locr_   r   zWDataFrame indexer is not allowed for .iloc
Consider using .loc for automatic alignment.)r   r/   rt   r   r$   r%   )r&   rI   r4   rw   r)   r)   r*   test_iloc_frame_indexer  s    (z&TestILocErrors.test_iloc_frame_indexerN)r,   r-   r.   rG  rH  rI  r)   r)   r)   r*   rE    s   rE  c                   @   sB   e Zd Zdd Zdd Zdd Zejg d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\J |jd	 dksnJ |jjd tjksJ d S )
Nr   r   r   r3   rN   r   r   r:   )r   r   )r   r   r$   rk   rC   r   )r&   r   r   rI   r)   r)   r*   *test_iloc_setitem_scalar_duplicate_columns  s    
zJTestILocSetItemDuplicateColumns.test_iloc_setitem_scalar_duplicate_columnsc                 C   sP   t g dgg dd}dg|jd d df< t g dgg dd}t|| d S )N)r   rj   str2r   r   r   r]   str3r   )r   rj   rN  r   r   r)   r)   r*   (test_iloc_setitem_list_duplicate_columns
  s    zHTestILocSetItemDuplicateColumns.test_iloc_setitem_list_duplicate_columnsc                 C   sf   t tjdtjdddg dd}|jd d df tj|jd d df< |jjd tjksbJ d S )Nr   r5   r   rN   r   r]   r   )	r   rC   r   r   r   r$   rB   r  rk   r   r)   r)   r*   *test_iloc_setitem_series_duplicate_columns  s
    (zJTestILocSetItemDuplicateColumns.test_iloc_setitem_series_duplicate_columns)rk   
init_valueexpected_value)r   0r   )floatz1.2g333333?c                 C   sh   t |ddggg dd}|jd d df ||jd d df< t |ddggg dtd}t|| d S )Nrj   rL  rM  r]   r   )r^   r6   )r   r$   rB   r=   rE   rF   )r&   rk   rQ  rR  rI   Zexpected_dfr)   r)   r*   *test_iloc_setitem_dtypes_duplicate_columns  s    &
zJTestILocSetItemDuplicateColumns.test_iloc_setitem_dtypes_duplicate_columnsN)
r,   r-   r.   rK  rO  rP  r/   r0   r1   rU  r)   r)   r)   r*   rJ    s   	rJ  c                   @   s   e Zd Zdd Zdd ZdS )TestILocCallablec                 C   s  t g d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 )NrM   aabbXYr   rT   c                 S   s   ddgS Nr   r3   r)   r   r)   r)   r*   r   6  r   zCTestILocCallable.test_frame_iloc_getitem_callable.<locals>.<lambda>r   r3   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   9  r   c                 S   s   ddgS r[  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 r[  r)   r   r)   r)   r*   r   ?  r   c                 S   s   dgS r\  r)   r   r)   r)   r*   r   ?  r   c                 S   s   dS r\  r)   r   r)   r)   r*   r   C  r   c                 S   s   dgS r\  r)   r   r)   r)   r*   r   F  r   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   I  r   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   L  r   )r   rs   r$   rE   rF   ru   )r&   rI   r;  r)   r)   r*    test_frame_iloc_getitem_callable1  s"    z1TestILocCallable.test_frame_iloc_getitem_callablec                 C   sB  t g d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 )NrM   rW  rX  r   rT   r   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   U  r   zCTestILocCallable.test_frame_iloc_setitem_callable.<locals>.<lambda>r   r3   r   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   [  r   r[   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   a  r   c                 S   s   dS r\  r)   r   r)   r)   r*   r   a  r      c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   g  r   c                 S   s   dgS r\  r)   r   r)   r)   r*   r   g  r   r   c                 S   s   dS r\  r)   r   r)   r)   r*   r   n  r   c                 S   s   dgS r\  r)   r   r)   r)   r*   r   t  r   re   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r   z  r   c                 S   s   ddgS r[  r)   r   r)   r)   r*   r     r   )r   rs   r@   r$   rE   rF   )r&   rI   r;  r   r)   r)   r*    test_frame_iloc_setitem_callableO  sR    z1TestILocCallable.test_frame_iloc_setitem_callableN)r,   r-   r.   r]  r`  r)   r)   r)   r*   rV  0  s   rV  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dttdddd}| }tt|D ](}|j	| }||j
|  }t|| q:|j	tdd }|jdd }t|| td  d|d d < W d    n1 s0    Y  |rt|| n|j	dd dk sJ |j	g d	 }||j
g d	 }t|| d S )
Nr   re   r   rZ   rT   r   r3   rN   )r   r   r3   rN   r[   )r   rC   rq   rr   rv   rs   r<   r@   r}   r$   rU   rE   r0  rB  r   ru   Zassert_produces_warningr   Zreindex)r&   rQ   rX   Zser_originalirl   r   rJ   r)   r)   r*   	test_iloc  s&    
*zTestILocSeries.test_ilocc                 C   s*   t g dg dd}|jd dks&J d S )Nr   r   rT   r   )r   r$   )r&   rX   r)   r)   r*   test_iloc_getitem_nonunique  s    z*TestILocSeries.test_iloc_getitem_nonuniquec                 C   sT   t g d}t g dg dd}|jdd |jdd< t g d}t|| d S )Nr   rp   )r   r   r   rT   r   r3   )r   r[   ro   )r   r$   rE   ru   )r&   Zser1Zser2rJ   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:  r5   )	r   rC   r   r   rB   r   r   rE   rF   r   r)   r)   r*   #test_iloc_nullable_int64_size_1_nan  s    &z2TestILocSeries.test_iloc_nullable_int64_size_1_nanN)r,   r-   r.   rc  rd  r  rf  r)   r)   r)   r*   ra    s   ra  )+rA  r   renumpyrC   r/   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsrD  Zpandasr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingrE   Zpandas.api.typesr   Zpandas.tests.indexing.commonr   escaperF  r   r2   rE  rJ  rV  ra  r)   r)   r)   r*   <module>   s8   D         .2V