o
    Eh                     @   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)labelsZmixedtsZfloatsemptyc                 C   s(   | | d| }t|d|td d S )N_iloc)Zfails)Zgetfixturevaluer   
IndexError)selfr   r   r   Zrequestobj r'   ?lib/python3.10/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jd
ddg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 d0d1 Z!d2d3 Z"ejd	ejd
ddgd4d5 Z#ejd	ejd
ddgd6d7 Z$ejd	ejd
ddgd8d9 Z%d:d; Z&d<d= Z'd>d? Z(d@dA Z)dBdC Z*dDdE Z+ejd	ejd
ddgdFdG Z,ejd	ejd
ddgdHdI Z-ejd	ejd
ddgejddJgeddde
dJggejdKdLge
dLggdMdN Z.ejdOdPdQ Z/dRdS Z0dTdU Z1dVdW Z2dXdY Z3dZd[ Z4d\d] Z5d^d_ Z6d`da Z7dbdc Z8ejdKde9e
j:gddde Z;ejdfe<dJddgdhgdidj Z=dkdl Z>ejdejejgdmdn Z?dodp Z@dqdr ZAejdsee
jgdtdu ZBejd	ejd
ddgejddgeddvgdwdx ZCejd	ejd
ddgdydz ZDd{d| ZEd}d~ ZFdd ZGdd 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}|sBt
|d j|sBJ t|| d|jd< |d dksUJ t t
jg dtdtdd}| }||||df< t t|	ttdtdd}t|| d S )	Nr   r1   dtype)ZalphaZbetagammar5   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   )	r%   r2   r   using_array_managerr   catdfZ	orig_valsexpectedr'   r'   r(   %test_iloc_setitem_fullcol_categorical?   s$   
  z=TestiLocBaseIndependent.test_iloc_setitem_fullcol_categorical.ignore:Setting a value on a view:FutureWarninghas_refTFboxc           
      C   s  t g d}||d}|r|d d  }|tu r|j}n|jjd }|tu r5||dd  |jd d< n||dd  |jd ddf< |tj g ddd}	t	||	 |s|tu rx|ro|j|usdJ t
|j|smJ d S |j|u svJ d S t
|d j|sJ d S d S )Nr   r   r1      Zi8r   r   )r1   rL   r1   rL   r3   )r   Zto_numpyr   r=   r:   Zarraysr#   r?   rA   Zassert_equalr@   )
r%   frame_or_seriesrJ   rI   using_copy_on_writearrr&   viewr=   rF   r'   r'   r(   test_iloc_setitem_ea_inplacek   s*   z4TestiLocBaseIndependent.test_iloc_setitem_ea_inplacec                 C   sH   t g d}ttd|d}|jdsJ | }|jds"J d S )N)r   r   r   r1   index)r   r   r   )r   r   r8   r#   Z_is_scalar_accessto_frame)r%   rS   serrE   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.w   Y  tjt|d |jdd	g  W d    n1 sLw   Y  tjt|d |jdd
g  W d    n1 sjw   Y  tjt|d |jdg  W d    n1 sw   Y  |d }tjt|d |jdg  W d    n1 sw   Y  tjt|d |jdg  W d    n1 sw   Y  d}tjt|d |jd	  W d    n1 sw   Y  tjt|d |jd
  W d    n1 sw   Y  tjt|d |jd	  W d    n	1 sw   Y  tjt|d |jd
  W d    n	1 s9w   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	|| t tjddtdd}t	
|jd d ddf t |jtg |jjdd t	
|jd d ddf |jd d dgf  t	
|jdd |jdg  d}tjt|d |jg d  W d    n	1 sw   Y  d}tjt|d |jd d df  W d    d S 1 sw   Y  d S )Nr   )      ABCDEcolumnsz%positional indexers are out-of-boundsmatchr   r   r   r1   rL   rY   r      id   Aiz*single positional indexer is out-of-boundsrL   
   ir   r   i      rY   r   ZABr1   r3   rS   r\      rL   rY   ri   )r   r?   randomdefault_rnglistr-   raisesr$   r#   rA   rB   assert_series_equalstandard_normalrS   r   r\   r4   )r%   rE   msgsresultrF   Zdflr'   r'   r(   test_iloc_exceeds_bounds   s   .$z0TestiLocBaseIndependent.test_iloc_exceeds_boundszindex,columnsrX   rZ   zindex_vals,column_valsrb   D12i  r   c                 C   sn   t tjdt|t|f||d}d}tjt|d |j	||f  W d    d S 1 s0w   Y  d S )Nr   rh   z$.iloc requires numeric indexers, gotr]   )
r   r?   rk   rl   rp   lenr-   rn   r$   r#   )r%   rS   r\   Z
index_valsZcolumn_valsrE   rq   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    d S 1 s)w   Y  d S )Nra   rc   zCannot index by location indexr]   a)
r   r?   arangereshaperA   Zget_objr-   rn   	TypeErrorr#   )r%   rM   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   )ra   e   f   )g   h   i   )j   k   l   rb   BCr   r   r1   rR   )r?   r   r<   r   r#   rA   Zassert_numpy_array_equal)r%   Zarray_with_neg_numbersZ
array_copyrE   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sAJ |jdg }|jdg }t|| tdgdgd}|jd	g }t|| d S )
N)r   r1   rY   )   re      rb   r   rb   r   rz   rR   r   )r   r#   rA   ro   rB   r   )r%   rE   rr   rF   rs   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|s+J |jdd d f }ttjdddgg d	dd
}t|| d S )Nr   r   r   r1   rL   Zaxisr6   r   rb   r   rb   r   )rS   name)	r   r   r#   r   r   r?   nanrA   ro   )r%   df1df2rE   rs   rF   r'   r'   r(   test_iloc_getitem_dupsD  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   r1   r   ra      ,        r   )r   r   rR   )r   rA   rB   r#   r%   rE   rF   rs   r'   r'   r(   test_iloc_getitem_arrayR  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   r1   r   ra   r   r   r   r   r   )TTFr   rR   c                 S   s   | j d dkS )Nr   r   rR   xr'   r'   r(   <lambda>u  s    z@TestiLocBaseIndependent.test_iloc_getitem_bool.<locals>.<lambda>r   r#   rA   rB   r   r'   r'   r(   test_iloc_getitem_boole  s   


z.TestiLocBaseIndependent.test_iloc_getitem_boolrS   )TFTFc                 C   sb   t g d}dt| dt| }tjt|d |j|  W d    d S 1 s*w   Y  d S )Nr   z Boolean index has wrong length: z instead of r]   )r   rx   r-   rn   r$   r#   )r%   rS   rr   rq   r'   r'   r(   test_iloc_getitem_bool_diff_lenx  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   r1   r   ra   r   r   r   r   r   r   rR   r   )rb   r   c                 S      ddgS )Nr   r   r'   )rE   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   rc   rL   )rb   rb   r   r   r[   r   rc   rX   sizerb   r   r   r   rL   r1   )r   r?   rk   rl   rp   integersr|   r   rA   rB   r#   )r%   r   r   rE   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}|r |d d  }d|jd	< |jd	 }|dks0J 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   rL   rL   r         r1   rh   r   r   r   rj   rR   r   r   r   )r   r?   rk   rl   rp   r{   r#   rA   rB   r   ro   )r%   warn_copy_on_writerI   rE   rP   rs   rF   rr   r'   r'   r(   test_iloc_setitem  s$   

z)TestiLocBaseIndependent.test_iloc_setitemc                 C   s  t g dg dg dg}|d t|d< |r|d d  }t g dg dg dg}|d t|d< d|jddd	< t|| t g dg dg dg}|d t|d< |r`|d d  }t g d
g dg dg}|d t|d< d|jddd	< t|| d S )N)ri   crc   )r   dre   )r   er   r   )rY   rY   rY   rY   r   r   r   )ri   r   rY   )r   r   rY   )r   r   rY   )r   r>   r9   r#   rA   rB   r%   rI   rE   rP   rF   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}|r|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	   r1   r1   r   rh   r   r   r   ra   )	r   r   r   r1   r   r   ri   r   r   )r   r?   r{   r|   r#   r   rA   rB   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   r1   )r   r   r1   r   r   r   r   )r   r<   r#   rA   ro   r   )r%   Zs_origrF   rr   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   r1   rL   r   r   r7   r   rb   T)Zdrop)r   r   Zfillnar?   Zisnanr#   rS   rA   rB   r\   Zreset_index)r%   r   r   rE   rF   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< |s-t|jjdks-J tjtdd	 |jd d df d
 |jd d df< W d    n1 sQw   Y  |sbt|jjdksbJ |	 }|jddgddgf |jddgddgf< t
|| d S )Nr   r   r   r1   r   r[   Zf8incompatible dtyper]   g      ?)r   r#   r>   rx   r:   r;   rA   assert_produces_warningFutureWarningr<   rB   )r%   rC   rE   rF   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s6J |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   rX   r   rh   rL   )r   r   r      r1   rY   )r   r   r1   )r   r   ri   r   )r   r   r1   r   )rf   r   ri   ri   )r   r   r   r1   )rf   rf   r   ri   )rS   r4   )r   rL   ri   r   )r   r?   rk   rl   rp   r8   r#   locrA   ro   rB   r   r9   rS   )r%   rE   rs   r   rF   rr   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"J |jd d ddf }|jd d d	gf }t	|| |jd
 }|jd }||ksMJ d}t
jt|d |jd  W d    n1 sfw   Y  d}t
jt|d |jd  W d    d S 1 sw   Y  d S )Nr   r   
abcdefghijABCDrh   r   )br   r1   r   )r   r   )jru   zCindex 5 is out of bounds for axis 0 with size 4|index out of boundsr]   )rc   rY   zLocation based indexing can only have \[integer, integer slice \(START point is INCLUDED, END point is EXCLUDED\), listlike of integers, boolean array\] types)r   r?   rk   rl   rp   rm   r#   r   rA   rB   r-   rn   r$   
ValueError)r%   rE   rs   r   rF   rq   r'   r'   r(    test_iloc_getitem_labelled_framen  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|dd	d
df |dd	 |d
d d}t	
|| td|_|jdd	d
df }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}|s|jjd
 j |jdd	ddf }t|dd	ddf |dd	 |dd d}t	
|| d S )Nr   )ri   rL   Z20130101ri   )Zperiodsr   rh   r1   rY   r   ZaaaaZaar   r   r   rL   )r?   rk   rl   rp   r   rm   r   Zdescriber#   rA   rB   r\   r8   r:   r;   Zmgr_locs)r%   rC   rO   rS   r\   rE   rs   rF   r'   r'   r(   test_iloc_getitem_doc_issue  s*   .
*.z3TestiLocBaseIndependent.test_iloc_getitem_doc_issuec                 C   sp  t tjddtdtdd}|r|d d  }d|jd< |jd }|dks*J 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srJ 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   rh   r   r   r   r1   rc   rX   rR   rL   r   ri   )r   r   rL   )r   r1   rY   r_   )r   r?   rk   rl   rp   rm   r#   rA   rB   r   r8   ro   )r%   rI   rE   rP   rs   rF   rr   r'   r'   r(   test_iloc_setitem_series  s8   

"

z0TestiLocBaseIndependent.test_iloc_setitem_seriesc                 C   s   t tjdddtjddddd}|r|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}|rO|d d  }ddgddgg|jd	d
< t g dg dd}t|| d S )NrY   int64r3   rc   r   re   r   r   r   rL   )r   r   rc   r   rL   )rY   ri   re   r   r   rz   r   r   r   r   r   y)rz   r   r   r   r   )r   r?   r{   r#   rA   rB   r   r'   r'   r(   test_iloc_setitem_list_of_lists  s    z7TestiLocBaseIndependent.test_iloc_setitem_list_of_listsr   valueZc                 C   sf   t ddgddggddgddti}|r|d d  }||jd|f< |jd	 }t|r/|d
ks1J d S )Nr   r   r1   rL   rb   r   r[   r   r6   r   )r   r>   r9   r#   r   )r%   rI   r2   r   rE   rP   rs   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.w   Y  tt||_	d	}tjt
|d |j|  W d    n1 sSw   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 ]r}	|jdkj}|	rt||	d d d }
t|t|
}dD ]T}z|rt||dd  }n|}tt|| d  }W n ttt
fy } z
t|}W Y d }~nd }~ww |	|f}||}||krtd| d| d| dqqd S )NrY   rZ   rz   rh   r   r   zBiLocation based boolean indexing cannot use an indexable as a maskr]   zDiLocation based boolean indexing on an integer type is not availableTr3   rL   c                 S   s   g | ]}t |qS r'   )bin).0Z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)rS   r   )rS   r   )rS   r   )r   r   )r   r   )r   r   )NrS   r   r   )r   r   r   r   r   [z] does not match [z], received [])r   rm   r8   rz   r-   rn   r   r#   rx   rS   NotImplementedErrorr?   r   boolrA   rB   r{   r   r=   getattrr   strr   sumr   getAssertionError)r%   rE   r   rq   rs   r   r   ZrepsrF   idxZ
mask_indexmethodZaccessorZanswererrr   rr'   r'   r(   test_iloc_mask  sj   


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    d S 1 s_w   Y  d S )N皙?r   r   r   r`   c   r   r1   r   znot in indexr]   )r   r?   r{   r#   r   rA   rB   r-   rn   KeyErrorr   )r%   rE   r   rF   Zdf3rs   r   r'   r'   r(   test_iloc_non_unique_indexingJ  s   

"z5TestiLocBaseIndependent.test_iloc_non_unique_indexingc                 C   s   t tdtdd tdD ddtdd tdD d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 )Nrg   c                 S      g | ]}d | qS zi-r'   r   ir'   r'   r(   r   ^      zNTestiLocBaseIndependent.test_iloc_empty_list_indexer_is_ok.<locals>.<listcomp>rY   rz   r   c                 S   r   r   r'   r   r'   r'   r(   r   _  r   r   rh   r   T)Zcheck_index_typeZcheck_column_type)r   r?   onesr   r8   rA   rB   r#   r%   rE   r'   r'   r(   "test_iloc_empty_list_indexer_is_ok[  s(    
z:TestiLocBaseIndependent.test_iloc_empty_list_indexer_is_okc                 C   sX  t dg di}|jd d  }||usJ t|d |d s!J t| g d|jd d df< W d    n1 s<w   Y  |rP|d g dk sOJ n
|d dk sZJ tg d}|jd d  }||usmJ t| g d|d d< W d    n1 sw   Y  |rt|d d g dksJ d S t|d d g dksJ d S )Nrz   r   )rL   rL   rL   rL   )r   r   r1   rL   rY   ri   r   r   r   r1   )	r   r#   r?   r@   rA   assert_cow_warningr   allr   )r%   rN   r   Zoriginal_dfZ	sliced_dfZoriginal_seriesZsliced_seriesr'   r'   r(   &test_identity_slice_returns_new_objectt  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   r1   rL   r   r   )r   r#   r?   r   r   rA   ro   )r%   rE   rs   rr   r'   r'   r(   test_indexing_zerodim_np_array  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#   r?   r   )r%   rr   rs   r'   r'   r(   %test_series_indexing_zerodim_np_array  s   z=TestiLocBaseIndependent.test_series_indexing_zerodim_np_arrayc                 C   s   t g d}t|g dddd}t|d |sJ |d d d |jd d df< t|d |s3J t g d	g dd
}t|| d S )Nr   r   )r   r   F)r<   r   r   r   )r   r   rb   
categories)r   r   rA   r@   r#   Zassert_categorical_equal)r%   rD   rE   rF   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   r1   rL   rY   ri   r   rc   r   )TTFF)FFTTg      @g      (@g      @)r   r?   r   r#   rS   rA   rB   r%   rs   rF   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   rz   r   r   category)rS   r   r4   )r   r   splitr#   r   rA   ro   )r%   rE   rs   Zraw_catrF   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   r>   r#   r   rA   ro   )r%   rV   rs   rF   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]r3   r   r   r   )r   r#   r
   rA   ro   )r%   r   r   rF   r'   r'   r(   %test_iloc_setitem_td64_values_cast_na  s   
z=TestiLocBaseIndependent.test_iloc_setitem_td64_values_cast_nanot_narz   g      ?c                 C   sX   t |gd}t||||g|d}|||g|jd d< t||||g|d}t|| d S )Nr   r3   r1   )r   r   r#   rA   ro   )r%   r  Znulls_fixturer4   rV   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    d S 1 sAw   Y  d S )	Nr   rh   rY   )r   r   r   r   zCannot set values with ndim > r]   r   )r   r   r?   rk   rl   rp   rx   r   ndimr-   rn   r   r#   )r%   r   r&   Znd3rq   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 )Nrc   F)writer   r   r1   )r?   Zeyer   ZsetflagsrA   rB   ro   )r%   r2   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datara   float64r3   )r   r1   ri   F)r   r?   r   r   flagsZ	writeabler#   r   rA   rB   ro   )r%   rE   indicesrs   rF   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 )Nrz   r   r\   rS   r   r6   )r   r   r#   rA   rB   r%   rE   rF   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   r1   rL   )flagr   r  r   r   )r   r1   rL   r   )r%   r  rE   r2   rF   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}|r!|d d  }|jd d dgf |jd d |f< t g dg dg dd}t|| d S )	N)re   r   r   )r         )Za2Zb2r   rj   r   rz   r   r   r   r   )r%   r2   rI   r   r   rP   rF   r'   r'   r(   %test_iloc_setitem_pure_position_based0  s   "z=TestiLocBaseIndependent.test_iloc_setitem_pure_position_basedc                 C   s   t ddgddgd}|r|d d  }ddd}||jd< t ddgddgd}t|| t ddgddgd}|rA|d 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   rE   rP   ZrhsrF   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"  abcrh   r   r"  r   )r"  rz   )r   r"  r"  )rL   r1   )r   r"  r"  r   r   )r   r"  r   r"  )r   r?   rk   rl   rp   rm   r#   rA   rB   r   ro   rS   )r%   rE   Zexpectr'   r'   r(   "test_iloc_getitem_float_duplicatesQ  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                   @   s>   e Zd ZdddZdefddZeZdefddZd	d
 Z	dS )zCTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TOreturnNc                 S   s
   || _ d S Nr   )r%   r   r'   r'   r(   __init__y  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__|  s   zKTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__str__c                 S   s   | j |j kS r&  r'  )r%   otherr'   r'   r(   __eq__  s   zJTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__eq__c                 S   s   | S r&  r'   r)  r'   r'   r(   rP     s   zHTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.view)r%  N)
r*   r+   r,   r(  r   r*  __repr__r   r,  rP   r'   r'   r'   r(   TOx  s    
r.  r   r   rh   rT   r   )r   r#   rA   rB   r?   r   )r%   r.  rE   rs   r'   r'   r(   test_iloc_setitem_custom_objectv  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s9J t	|j
|j
d  d S )Nr   r   ABCZaabr  r   )r   r?   rk   rl   rm   r#   
isinstancer   rA   assert_almost_equalr=   T)r%   rE   rs   r'   r'   r(   !test_iloc_getitem_with_duplicates  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   rj   )r   r   r   r[   r   r   r   )r   r#   ZtakerA   rB   r%   rE   rs   rF   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   r1   )r   r	   r#   r   rA   ro   r<   rB   r5  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   rY   rc   TFT)rY   r   rc   rz   )r   r#   rA   ro   r   rB   )r%   r9  r8  rV   rF   rE   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 )	Nrb   r   Int64r3   r   Zfoor   )r   rb   r   )r%   rE   resrF   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  r3   rz   r   r   )rz   rz   r   )r   r?   r   r#   r4   rA   rB   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sJ |d |d< |d |d ks)J d S )Nr   g      $@r   r   r   )r   Z_valuesr   r#   )r%   rO   rE   rV   r'   r'   r(   *test_iloc_getitem_int_single_ea_block_view  s   
zBTestiLocBaseIndependent.test_iloc_getitem_int_single_ea_block_viewc                 C   s   t ddgddgd}|r9tjtdd t dtddgi|jd d d	gf< W d    d S 1 s2w   Y  d S 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   z%Setting an item of incompatible dtyper]   rb   r   z2021-01-01 00:00:00z2022-01-01 00:00:00F)Zcheck_dtype)r   rA   r   r   r   r#   r   rB   )r%   Zusing_infer_stringrE   rF   r'   r'   r(   )test_iloc_setitem_multicolumn_to_datetime  s    &"$	zATestiLocBaseIndependent.test_iloc_setitem_multicolumn_to_datetime)Qr*   r+   r,   __doc__r-   r.   r/   slicer8   r   r?   ZasarrayrA   r   r#   rG   filterwarningsr   r   rQ   rW   rt   r{   rm   r   ry   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/  r4  r6  r7  r;  r>  r@  tdZ&skip_array_manager_not_yet_implementedrA  rB  r'   r'   r'   r(   r0   <   s    

 "
e	



1#
$
$
$

E!	







%"
r0   c                   @   sB   e Zd Zdd Zejdejdddg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 s#w   Y  tjttd/ t	|o7|t u  d|jd< W d    n1 sIw   Y  W d    d S W d    d S 1 saw   Y  d S )Nz5Cannot index by location index with a non-integer keyr]   g      @r   )
r   rU   r-   rn   r}   r#   r$   _slice_iloc_msgrA   r   )r%   Zseries_with_simple_indexrM   r   r&   rq   r'   r'   r(   test_iloc_float_raises
  s    

"z%TestILocErrors.test_iloc_float_raisesrH   rI   TFc                 C   s   t jtdd |jd d d d d d f  W d    n1 s w   Y  |r-|d d  }t jtdd d|jd d d d d d f< W d    d S 1 sNw   Y  d S )NzToo many indexersr]   ztoo many indices for arrayr   )r-   rn   r   r#   r$   )r%   Zfloat_framerI   rP   r'   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 s)w   Y  d}tjt|d |j|  W d    d S 1 sHw   Y  d S )Nrz   r   r:  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-   rn   r}   r#   r$   )r%   rE   r2   rq   r'   r'   r(   test_iloc_frame_indexer.  s   "z&TestILocErrors.test_iloc_frame_indexerN)
r*   r+   r,   rI  r-   r.   rE  r/   rJ  rK  r'   r'   r'   r(   rG    s    

rG  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s7J |jjd tjksBJ d S )
Nr   r   r   r1   rL   r   r   r6   )r   r   )r   r   r#   dtypesr?   r   )r%   r   r   rE   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   r   str2rz   r   r   r[   str3r   )r   r   rQ  r   r  r'   r'   r(   (test_iloc_setitem_list_duplicate_columnsJ  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s1J d S )Nr   r3   r   rL   r   r[   r   )	r   r?   r{   r   r|   r#   r>   r  rM  r   r'   r'   r(   *test_iloc_setitem_series_duplicate_columnsS  s
   (zJTestILocSetItemDuplicateColumns.test_iloc_setitem_series_duplicate_columns)rM  
init_valueexpected_value)r   0r   )floatz1.2g333333?c                 C   sj   t |ddggg dtd}|jd d df ||jd d df< t |ddggg dtd}t|| d S )Nr   rO  rP  )r\   r4   r   )r   r9   r#   r>   rA   rB   )r%   rM  rT  rU  rE   Zexpected_dfr'   r'   r(   *test_iloc_setitem_dtypes_duplicate_columnsZ  s   &
zJTestILocSetItemDuplicateColumns.test_iloc_setitem_dtypes_duplicate_columnsN)
r*   r+   r,   rN  rR  rS  r-   r.   r/   rX  r'   r'   r'   r(   rL  >  s    	rL  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 )NrK   aabbXYr   rR   c                 S   r   Nr   r1   r'   r   r'   r'   r(   r   x  r   zCTestILocCallable.test_frame_iloc_getitem_callable.<locals>.<lambda>r   r1   c                 S   r   r^  r'   r   r'   r'   r(   r   {  r   c                 S   r   r^  r'   r   r'   r'   r(   r   ~  r   c                 S      dS Nr   r'   r   r'   r'   r(   r   ~      r   c                 S   r   r^  r'   r   r'   r'   r(   r     r   c                 S      dgS r`  r'   r   r'   r'   r(   r         c                 S   r_  r`  r'   r   r'   r'   r(   r     ra  c                 S   rb  r`  r'   r   r'   r'   r(   r     rc  c                 S   r   r^  r'   r   r'   r'   r(   r     r   c                 S   r   r^  r'   r   r'   r'   r(   r     r   )r   rm   r#   rA   rB   ro   )r%   rE   r=  r'   r'   r(    test_frame_iloc_getitem_callables  s"    z1TestILocCallable.test_frame_iloc_getitem_callablec                 C   sJ  t g dtt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 )NrK   rZ  r3   r[  r   rR   r   c                 S   r   r^  r'   r   r'   r'   r(   r     r   zCTestILocCallable.test_frame_iloc_setitem_callable.<locals>.<lambda>r   r1   r   c                 S   r   r^  r'   r   r'   r'   r(   r     r   rY   c                 S   r   r^  r'   r   r'   r'   r(   r     r   c                 S   r_  r`  r'   r   r'   r'   r(   r     ra     c                 S   r   r^  r'   r   r'   r'   r(   r     r   c                 S   rb  r`  r'   r   r'   r'   r(   r     rc  r   c                 S   r_  r`  r'   r   r'   r'   r(   r     ra  c                 S   rb  r`  r'   r   r'   r'   r(   r     rc  rc   c                 S   r   r^  r'   r   r'   r'   r(   r     r   c                 S   r   r^  r'   r   r'   r'   r(   r     r   )r   r   rm   r9   r<   r#   rA   rB   )r%   rE   r=  r   r'   r'   r(    test_frame_iloc_setitem_callable  sX   z1TestILocCallable.test_frame_iloc_setitem_callableN)r*   r+   r,   rd  rg  r'   r'   r'   r(   rY  r  s    rY  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestILocSeriesc           	   	   C   sL  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 # t| d|d d < W d    n1 scw   Y  W d    n1 srw   Y  |rt|| n|j	dd dk sJ |j	g d	 }||j
g d	 }t|| d S )
Nr   rc   r   rX   rR   r   r1   rL   )r   r   r1   rL   rY   )r   r?   rk   rl   rp   rm   r8   r<   rx   r#   rS   rA   r2  rD  r   ro   r   r   r   Zreindex)	r%   rN   r   rV   Zser_originalr   rs   r   rF   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   rR   r   )r   r#   )r%   rV   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   rj   )r   r   r   rR   r   r1   )r   rY   ri   )r   r#   rA   ro   )r%   Zser1Zser2rF   r'   r'   r(   r     s
   z4TestILocSeries.test_iloc_setitem_pure_position_basedc                 C   s   t dgtjgd}tjtdd |jd d df d|jd d df< W d    n1 s/w   Y  t dgtt	gddd}t
|| d S )Ntest)rz   r   r   r]   r   r<  r3   )r   r?   r   rA   r   r   r   r>   r   r   rB   r  r'   r'   r(   #test_iloc_nullable_int64_size_1_nan  s   (z2TestILocSeries.test_iloc_nullable_int64_size_1_nanN)r*   r+   r,   ri  rj  r   rl  r'   r'   r'   r(   rh    s
    rh  )+rC  r   reZnumpyr?   r-   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsrF  Zpandasr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingrA   Zpandas.api.typesr   Zpandas.tests.indexing.commonr   escaperH  r   r0   rG  rL  rY  rh  r'   r'   r'   r(   <module>   s:    D         T74Y