o
    dD                     @   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                   @   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tsfloatsemptyc                 C   s(   | | d| }t|d|td d S )N_iloc)fails)getfixturevaluer   
IndexError)selfr   r   r    requestobj r.   d/var/www/html/visualizacion-main/env/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parametrizer0   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-dMdN Z.dOdP Z/dQdR Z0dSdT Z1dUdV Z2dWdX Z3dYdZ Z4d[d\ Z5d]d^ Z6d_d` Z7ejdIde8e
j9gdadb Z:ejdce;dHddddegdfdg Z<dhdi Z=ejdejejgdjdk Z>dldm Z?dndo Z@ejdpee
jgdqdr ZAejddgeddsgdtdu ZBdvdw ZCdxdy ZDdzd{ ZEd|d} ZFd~d ZGdd 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   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}| }|j}||||df< t |	ttdd}t|| d S )	Nr   r8   dtype)alphabetagammar>   r   r   r   r   r   )r	   rangeobjectr   _mgrblocks_can_hold_elementcopyvaluesastypenpshares_memorytmassert_frame_equalr'   r   )	r+   r9   r   using_array_managerr   catdf	orig_valsexpectedr.   r.   r/   %test_iloc_setitem_fullcol_categoricalC   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 r-||dd  |jd d< n||dd  |jd ddf< |tj g ddd}t	|| |tu rn|re|j|usZJ t
|j|scJ d S |j|u slJ d S t
|d j|syJ d S )Nr   r   r8      i8r   r   )r8   rU   r8   rU   r:   )r   to_numpyr   rG   rC   arraysr'   rI   rK   assert_equalrJ   )r+   frame_or_seriesrS   using_copy_on_writearrr-   rG   rQ   r.   r.   r/   test_iloc_setitem_ea_inplacep   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   r8   index)r   r   r   )r
   r   rA   r'   _is_scalar_accessto_frame)r+   r_   serrO   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 g df  W d    n1 s+w   Y  tjt|d |jddg  W d    n1 sIw   Y  tjt|d |jdd	g  W d    n1 sgw   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 s6w   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 sw   Y  d}tjt|d |jd d df  W d    d S 1 sw   Y  d S ) N)      ABCDEcolumnsz%positional indexers are out-of-boundsmatchr   r   r   r8   rU   rf   r      id   Aiz*single positional indexer is out-of-boundsrU   
   ir   r   i      c                 S   s   t |  | j t| | d S N)strdtypesrK   rL   )resultrQ   r.   r.   r/   check   s   z?TestiLocBaseIndependent.test_iloc_exceeds_bounds.<locals>.checkrf   r   ABr8   r_   ri      rU   rf   r{   )r	   rI   randomrandom_samplelistr4   raisesr*   r'   rK   rL   assert_series_equalrandnr_   )r+   rO   msgsrw   rQ   rx   dflr.   r.   r/   test_iloc_exceeds_bounds   s   &,$z0TestiLocBaseIndependent.test_iloc_exceeds_boundszindex,columnsre   rg   zindex_vals,column_valsro   D12i  r   c                 C   sf   t tjt|t|||d}d}tjt|d |j||f  W d    d S 1 s,w   Y  d S )Nrz   z$.iloc requires numeric indexers, gotrj   )	r	   rI   r}   r   lenr4   r   r*   r'   )r+   r_   ri   
index_valscolumn_valsrO   r   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 )Nrn   rp   zCannot index by location indexrj   a)
r	   rI   arangereshaperK   get_objr4   r   	TypeErrorr'   )r+   rZ   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   )rn   e   f   )g   h   i   )j   k   l   ro   BCr   r   r8   r^   )rI   r   rF   r	   r'   rK   assert_numpy_array_equal)r+   array_with_neg_numbers
array_copyrO   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   r8   rf   )   rr      ro   r   ro   r   r   r^   r   )r	   r'   rK   r   rL   r   )r+   rO   r   rQ   rw   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   r8   rU   axisr?   r   ro   r   ro   r   )r_   name)	r	   r   r'   r   r   rI   nanrK   r   )r+   df1df2rO   rw   rQ   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   r8   r   rn      ,        r   )r   r   r^   )r	   rK   rL   r'   r+   rO   rQ   rw   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   r8   r   rn   r   r   r   r   r   )TTFr   r^   c                 S   s   | j d dkS )Nr   r   r^   xr.   r.   r/   <lambda>q  s    z@TestiLocBaseIndependent.test_iloc_getitem_bool.<locals>.<lambda>r	   r'   rK   rL   r   r.   r.   r/   test_iloc_getitem_boola  s   


z.TestiLocBaseIndependent.test_iloc_getitem_boolr_   TF)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 rj   )r   r   r4   r   r*   r'   )r+   r_   r   r   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   r8   r   rn   r   r   r   r   r   r   r^   r   )ro   r   c                 S      ddgS )Nr   r   r.   )rO   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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 )Nrp   rU   )ro   ro   r   r   rh   r   re   sizer   ro   r   r   r   r8   )
r	   rI   r}   r   randintr   r   rK   rL   r'   )r+   r   r   rO   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s&J 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 )NrU   r      r      r8   rz   r   r   r   r|   r^   r   r   r   )
r	   rI   r}   r   r   r'   rK   rL   r   r   r+   rO   rw   rQ   r   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)r{   crp   )r   drr   )r   er   )rf   rf   rf   rf   r   r   r   )r{   r   rf   )r   r   rf   )r   r   rf   r   r   r+   rO   rQ   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	   )r8   r8   r   rz   r   r   r   rn   )	r   r   r   r8   r   r   r{   r   r   )r	   rI   r   r   r'   r   rK   rL   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   r8   )r   r   r8   r   r   r   r   )r   rF   r'   rK   r   r
   )r+   s_origrQ   r   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   r8   rU   r   r   r@   r   ro   T)drop)r	   r   fillnarI   isnanr'   r_   rK   rL   ri   reset_index)r+   r   r   rO   rQ   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 |jd d df d |jd d df< |sKt|jjdksKJ | }|jddgddgf |jddgddgf< t|| d S )	Nr   r   r   r8   r   rh   f8g      ?)	r	   r'   rH   r   rC   rD   rF   rK   rL   )r+   rM   rO   rQ   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s4J |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 )Nrp   rU   r   re   r   r   rz   )r   r   )rU   rU      r8   rf   )r   r   r8   )r   r   r{   r   )r   r   r8   r   )rs   r   r{   r{   )r   r   r   r8   )rs   rs   r   r{   )r_   r;   )r   rU   r{   r   )r	   rI   r}   r   rA   r'   locrK   r   rL   r   rB   r_   )r+   rO   rw   r   rQ   r   r.   r.   r/   test_iloc_getitem_frame   s>    



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sKJ d}t	j
t|d |jd  W d    n1 sdw   Y  d}t	j
t|d |jd  W d    d S 1 sw   Y  d S )Nrp   rU   
abcdefghijABCDrz   r   )br   r   r8   r   )r   r   )jr   z/index 5 is out of bounds for axis 0 with size 4rj   )rp   rf   zLocation based indexing can only have \[integer, integer slice \(START point is INCLUDED, END point is EXCLUDED\), listlike of integers, boolean array\] types)r	   rI   r}   r   r   r'   r   rK   rL   r4   r   r*   
ValueError)r+   rO   rw   r   rQ   r   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}|s|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{   rU   20130101)periodsr   rz   r8   rf   r   r   aaaaaar   r   r   )rI   r}   r   r   r   r	   describer'   ru   rv   rK   rL   ri   rA   rC   rD   mgr_locs)r+   rM   r\   r_   ri   rO   rw   rQ   r.   r.   r/   test_iloc_getitem_doc_issuep  s6   .
*.z3TestiLocBaseIndependent.test_iloc_getitem_doc_issuec                 C   sV  t tjddtdt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t	ddd	d}d|jd< |jd }|dkseJ 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 )Nrp   rU   r   r   rz   r   r   r   r   r8   re   r^   r   r{   )r   r   rU   )r   r8   rf   rl   )r	   rI   r}   r   r   r'   rK   rL   r   rA   r   r   r.   r.   r/   test_iloc_setitem_series  s0   



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 )Nrf   int64r:   rp   r   rr   r   r   r   rU   )r   r   rp   r   rU   )rf   r{   rr   r   r   r   r   r   r   r   r   y)r   r   r   r   r   )r	   rI   r   r'   rK   rL   r   r.   r.   r/   test_iloc_setitem_list_of_lists  s   z7TestiLocBaseIndependent.test_iloc_setitem_list_of_listsr   valueZc                 C   sL   t ddgddggddgd}||jd|f< |jd	 }t|r"|d
ks$J d S )Nr   r   r8   rU   ro   r   rh   r   r?   r   )r	   r'   r   )r+   r9   r   rO   rw   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 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	}td
d~ tdt dD ]m}	|jdkj}|	rt|t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qqW d    d S 1 sw   Y  d S )Nrf   rg   r   rz   r   r   zBiLocation based boolean indexing cannot use an indexable as a maskrj   zDiLocation based boolean indexing on an integer type is not availableTr:   rU   c                 S   s   g | ]}t |qS r.   )bin).0numr.   r.   r/   
<listcomp>  s    z:TestiLocBaseIndependent.test_iloc_mask.<locals>.<listcomp>)locsnums0b11000b11ztUnalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).)	)N )N.loc)N.iloc)r_   r   )r_   r   )r_   r  )r   r   )r   r   )r   r  )recordignore)Nr_   r   )r   r   r  r   r   [z] does not match [z], received [])r	   r   rA   r   r4   r   r   r'   r   r_   NotImplementedErrorrI   r   boolrK   rL   r   r   r   UserWarningr   rG   r   reversedgetattrru   r   sumr   getAssertionError)r+   rO   r   r   rw   r   r   repsrQ   idxmethodaccessoranswerr   r   rr.   r.   r/   test_iloc_mask  sn   



$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   rm   c   r   r8   r   znot in indexrj   )r	   rI   r   r'   r   rK   rL   r4   r   KeyErrorr   )r+   rO   r  rQ   df3rw   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 )Nrf   r   r   T)check_index_typecheck_column_type)rK   makeCustomDataframerL   r'   r+   rO   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 s!J g d|jd d df< |r;|d g dk s:J n
|d dk sEJ tg d}|jd d  }||usXJ g d|d d< |rrt|d d g dkspJ d S t|d d g dksJ d S )Nr   r   )rU   rU   rU   rU   )r   r   r8   rU   rf   r{   r   r   r   r8   )r	   r'   rI   rJ   r   allr   )r+   r[   original_df	sliced_dforiginal_series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   r8   rU   r   r   )r	   r'   rI   r   r   rK   r   )r+   rO   rw   r   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J d S )Nr   r   r   )r   r'   rI   r   )r+   r   rw   r.   r.   r/   %test_series_indexing_zerodim_np_arrayh  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)rF   r   r   r   )r   r   ro   
categories)r   r	   rK   rJ   r'   assert_categorical_equal)r+   rN   rO   rQ   r.   r.   r/   -test_iloc_setitem_categorical_updates_inplacen  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   r8   rU   rf   r{   r   rp   r   )TTFF)FFTTg      @g      (@g      @)r	   rI   r   r'   r_   rK   rL   r+   rw   rQ   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)r_   r   r;   )r	   r   splitr'   r   rK   r   )r+   rO   rw   raw_catrQ   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   rH   r'   r   rK   r   )r+   rc   rw   rQ   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]r:   r   r   r   )r   r'   r   rK   r   )r+   r   r   rQ   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)  r:   r8   )r   r   r'   rK   r   )r+   r6  nulls_fixturer;   rc   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t|t|||d}tjjddd}d|j }tj	t
|d d|j|< W d    d S 1 s:w   Y  d S )Nrz   rf   )r   r   r   r   zCannot set values with ndim > rj   r   )r
   r	   rI   r}   r   r   r   ndimr4   r   r   r'   )r+   r  r-   nd3r   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 )Nrp   F)writer   r   r8   )rI   eyer	   setflagsrK   rL   r   )r+   r9   rw_arrayrw_dfro_array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datarn   float64r:   )r   r8   r{   F)r	   rI   onesr   flags	writeabler'   r   rK   rL   r   )r+   rO   indicesrw   rQ   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   ri   r_   r   r?   )r	   r   r'   rK   rL   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   r8   rU   )flagr   r3  r   r   )r   r8   rU   r   )r+   rM  rO   r9   rQ   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)rr   r   r   )r         )a2b2r   r|   r  r   r   r   r   r   )r+   r9   r   r   rQ   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+   rO   rhsrQ   r.   r.   r/   "test_iloc_setitem_dictionary_value  s   


z:TestiLocBaseIndependent.test_iloc_setitem_dictionary_valuec                 C   sh  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 )Nr8   )r  皙?rY  abcrz   r   rY  r   )rY  r   )r   rY  rY  rU   )r   rY  rY  r   r   )r  rY  r   rY  )r	   rI   r}   r   r   r'   rK   rL   r   r   r_   )r+   rO   expectr.   r.   r/   "test_iloc_getitem_float_duplicates  s0   

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 rt   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 rt   r^  )r+   otherr.   r.   r/   __eq__;  s   zJTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__eq__c                 S   s   | S rt   r.   r`  r.   r.   r/   view>  s   zHTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.view)r]  N)
r1   r2   r3   r_  ru   ra  __repr__r  rc  rd  r.   r.   r.   r/   TO2  s    
rf  r   r   rz   r`   r   )r	   r'   rK   rL   rI   r   )r+   rf  rO   rw   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sJ t	|j
|j
d  |jjd d df }t|ts7J t	|j
|j
d  d S )Nr8   ABCaabrK  r   )r	   rI   r}   randr   r'   
isinstancer   rK   assert_almost_equalrG   T)r+   rO   rw   r.   r.   r/   !test_iloc_getitem_with_duplicatesR  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   r|   )r   r   r   rh   r   r   r   )r	   r'   takerK   rL   r+   rO   rw   rQ   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&  r8   )r	   r   r'   r   rK   r   rF   rL   rp  r.   r.   r/   test_iloc_intervald  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   rf   rp   TFT)rf   r   rp   r   )r   r'   rK   r   r	   rL   )r+   rt  rs  rc   rQ   rO   r.   r.   r/   test_loc_setitem_boolean_listu  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 )	Nro   r   Int64r:   r   foor   )r   ro   r   )r+   rO   resrQ   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statusrU  r/  r:   r   r   r   )r   r   r   )r	   rI   r   r'   r;   rK   rL   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   _valuesr	   r'   )r+   r\   rO   rc   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-0220212022r   ro   r   z2021-01-01 00:00:00z2022-01-01 00:00:00F)check_dtype)r	   r   r'   r   rK   rL   r   r.   r.   r/   )test_iloc_setitem_multicolumn_to_datetime  s   $	zATestiLocBaseIndependent.test_iloc_setitem_multicolumn_to_datetime)Pr1   r2   r3   __doc__r4   r5   r6   slicerA   r
   rI   asarrayrK   r   r'   rR   r   r   r]   rd   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.  r2  r4  r   r   r5  r   r8  r;  rC  rJ  rL  rP  rV  rX  r\  rg  rn  rq  rr  rv  rz  r|  td&skip_array_manager_not_yet_implementedr~  r  r.   r.   r.   r/   r7   @   s    
!

e		
/!* $F	


	


!"
r7   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 s#w   Y  tjttd d|jd< W d    d S 1 s@w   Y  d S )Nz5Cannot index by location index with a non-integer keyrj   g      @r   )r	   rb   r4   r   r   r'   r*   _slice_iloc_msg)r+   series_with_simple_indexrZ   r-   r   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 w   Y  t jtdd d|jd d d d d d f< W d    d S 1 sFw   Y  d S )NzToo many indexersrj   ztoo many indices for arrayr   )r4   r   r   r'   r*   )r+   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 s)w   Y  d}tjt|d |j|  W d    d S 1 sHw   Y  d S )Nr   r   ru  zADataFrame indexer for .iloc is not supported. Consider using .locrj   r   zWDataFrame indexer is not allowed for .iloc
Consider using .loc for automatic alignment.)r	   r4   r   r   r'   r*   )r+   rO   r9   r   r.   r.   r/   test_iloc_frame_indexer  s   "z&TestILocErrors.test_iloc_frame_indexerN)r1   r2   r3   r  r  r  r.   r.   r.   r/   r    s    r  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   r8   rU   r   r   r?   )r   r   )r	   r   r'   rv   rI   r   )r+   r   r   rO   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   ru   str2r   r   r   rh   str3r   )r   ru   r  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s1J d S )Nr   r:   r   rU   r   rh   r   )	r	   rI   r   r   r   r'   rH   rE  rv   r  r.   r.   r/   *test_iloc_setitem_series_duplicate_columns  s
   (zJTestILocSetItemDuplicateColumns.test_iloc_setitem_series_duplicate_columns)rv   
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 )Nru   r  r  rh   r   )ri   r;   )r	   r'   rH   rB   rK   rL   )r+   rv   r  r  rO   expected_dfr.   r.   r/   *test_iloc_setitem_dtypes_duplicate_columns  s   &
zJTestILocSetItemDuplicateColumns.test_iloc_setitem_dtypes_duplicate_columnsN)
r1   r2   r3   r  r  r  r4   r5   r6   r  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 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 )NrT   aabbXYr   r^   c                 S   r   Nr   r8   r.   r   r.   r.   r/   r     r   zCTestILocCallable.test_frame_iloc_getitem_callable.<locals>.<lambda>r   r8   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   *  r  c                 S   r  r  r.   r   r.   r.   r/   r   -  r  c                 S   r   r  r.   r   r.   r.   r/   r   0  r   c                 S   r   r  r.   r   r.   r.   r/   r   3  r   )r	   r   r'   rK   rL   r   )r+   rO   ry  r.   r.   r/    test_frame_iloc_getitem_callable  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 )NrT   r  r  r   r^   r   c                 S   r   r  r.   r   r.   r.   r/   r   <  r   zCTestILocCallable.test_frame_iloc_setitem_callable.<locals>.<lambda>r   r8   r   c                 S   r   r  r.   r   r.   r.   r/   r   B  r   rf   c                 S   r   r  r.   r   r.   r.   r/   r   H  r   c                 S   r  r  r.   r   r.   r.   r/   r   H  r     c                 S   r   r  r.   r   r.   r.   r/   r   N  r   c                 S   r  r  r.   r   r.   r.   r/   r   N  r  r   c                 S   r  r  r.   r   r.   r.   r/   r   U  r  c                 S   r  r  r.   r   r.   r.   r/   r   [  r  rp   c                 S   r   r  r.   r   r.   r.   r/   r   a  r   c                 S   r   r  r.   r   r.   r.   r/   r   g  r   )r	   r   rF   r'   rK   rL   )r+   rO   ry  r   r.   r.   r/    test_frame_iloc_setitem_callable6  sR   z1TestILocCallable.test_frame_iloc_setitem_callableN)r1   r2   r3   r  r  r.   r.   r.   r/   r    s    r  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
|| q|jtdd }|jdd }t
|| t
d  d|d d < W d    n1 sZw   Y  |rht
|| n|jdd dk suJ |jg d	 }||j	g d	 }t
|| d S )
Nrp   r   re   r   r^   r   r8   rU   )r   r   r8   rU   rf   )r   rI   r}   r   r   rA   rF   r   r'   r_   rK   rl  r  r   r   assert_produces_warningr   reindex)r+   r[   rc   ser_originalirw   r   rQ   r.   r.   r/   	test_ilocn  s$    
zTestILocSeries.test_ilocc                 C   s*   t g dg dd}|jd dksJ d S )Nr   r   r^   r   )r   r'   )r+   rc   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   r|   )r   r   r   r^   r   r8   )r   rf   r{   )r   r'   rK   r   )r+   ser1ser2rQ   r.   r.   r/   rV    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   rw  r:   )	r	   rI   r   r   rH   r   r   rK   rL   r-  r.   r.   r/   #test_iloc_nullable_int64_size_1_nan  s   &z2TestILocSeries.test_iloc_nullable_int64_size_1_nanN)r1   r2   r3   r  r  rV  r  r.   r.   r.   r/   r  m  s
    r  ).r  r   rewarningsr   r   numpyrI   r4   pandas.errorsr   pandas.util._test_decoratorsutil_test_decoratorsr  pandasr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   pandas._testing_testingrK   pandas.api.typesr   pandas.tests.indexing.commonr   escaper  r   r7   r  r  r  r  r.   r.   r.   r/   <module>   s:    D        .2V