a
    j=ic3                     @   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e%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)Basezuonly integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indicesc                   @   s,   e Zd Zejdddg dgdd ZdS )TestiLockey   r      r   c                 C   s   | j d|g dtd d S )Niloc)labelsmixedtsZfloatsempty)ZtypsZfails)Zcheck_result
IndexError)selfr    r$   p/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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-dMdN Z.dOdP Z/dQdR Z0dSdT Z1dUdV Z2dWdX Z3e4j5dYdZ Z6d[d\ Z7d]d^ Z8d_d` Z9ejdIde:e
j;gdadb Z<ejdce=dHddddegdfdg Z>dhdi Z?ejdejejgdjdk Z@dldm ZAdndo ZBejdpee
jgdqdr ZCejddgeddsgdtdu ZDdvdw ZEdxdy ZFdzd{ ZGd|d} ZHd~d ZIdd ZJejdee
jgejdee
jgdd ZKdd ZLdd ZMe4j5dd 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}t	|t
o\|t
d k}d }	|rjt}	d}
tj|	|
d  ||||df< W d    n1 s0    Y  |rt d|i}t|j|rJ n,t d|it}|st|d j|sJ t|| d|jd< |d dks$J t tjg d	tdtdd
}| }|j}tjt|
d  ||||df< W d    n1 s0    Y  t |tdd
}t|| d S )Nr   r.   dtype)alphabetagamma.will attempt to set the values inplace insteadmatchr4   r   r   r   r   r   )r	   rangeobjectr   _mgrblocksZ_can_hold_elementcopyvalues
isinstancesliceFutureWarningtmassert_produces_warningnpshares_memoryastypeassert_frame_equalr   r   )r#   r/   r   using_array_managerframecatdfZ	orig_vals	overwritewarnmsgexpectedr$   r$   r%   %test_iloc_setitem_fullcol_categorical=   s:    .
 0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|j|u sJ nt
|d j|sJ d S )Nr   r   r.      i8r   r   )r.   rT   r.   rT   r0   )r   Zto_numpyr   r?   r<   Zarraysr   rE   rC   Zassert_equalrF   )r#   frame_or_seriesrR   arrobjr?   rP   r$   r$   r%   test_iloc_setitem_ea_inplacet   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   r.   index)r   r   r   )r
   r   r:   r   Z_is_scalar_accessto_frame)r#   r[   serrL   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 sV0    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 sN0    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 s<0    Y  tjt|d |jd	  W d    n1 sv0    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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 ) N)      ABCDEcolumnsz%positional indexers are out-of-boundsr6   r   r   r   r.   rT   ra   r      id   Aiz*single positional indexer is out-of-boundsrT   
   ir   r   i      c                 S   s   t |  | j t| | d S N)strdtypesrC   rH   )resultrP   r$   r$   r%   check   s    z?TestiLocBaseIndependent.test_iloc_exceeds_bounds.<locals>.checkra   r   ZABr.   rZ      rT   ra   rr   )r	   rE   randomZrandom_samplelistr*   raisesr"   r   rC   rH   assert_series_equalrandnr[   )r#   rL   rO   srp   rP   rq   Zdflr$   r$   r%   test_iloc_exceeds_bounds   s    4,,,,,****$,.z0TestiLocBaseIndependent.test_iloc_exceeds_boundszindex,columnsr`   rb   zindex_vals,column_valsrh   D12i  r   c                 C   sd   t tjt|t|||d}d}tjt|d |j||f  W d    n1 sV0    Y  d S )Nr[   rd   z$.iloc requires numeric indexers, gotr6   )	r	   rE   rt   rx   lenr*   rv   r"   r   )r#   r[   rd   Z
index_valsZcolumn_valsrL   rO   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 )Nrg   ri   zCannot index by location indexr6   a)
r	   rE   arangereshaperC   get_objr*   rv   	TypeErrorr   )r#   rV   rX   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   )rg   e   f   )g   h   i   )j   k   l   rh   BCr   r   r.   rZ   )rE   r   r>   r	   r   rC   Zassert_numpy_array_equal)r#   Zarray_with_neg_numbersZ
array_copyrL   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   r.   ra   )   rk      rh   r   rh   r   r   rZ   r   )r	   r   rC   rw   rH   r   )r#   rL   ry   rP   rp   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   r.   rT   Zaxisr8   r   rh   r   rh   r   )r[   name)	r	   r   r   r   r   rE   nanrC   rw   )r#   df1df2rL   rp   rP   r$   r$   r%   test_iloc_getitem_dupsB  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   r.   r   rg      ,        r   )r   r   rZ   )r	   rC   rH   r   r#   rL   rP   rp   r$   r$   r%   test_iloc_getitem_arrayP  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   r.   r   rg   r   r   r   r   r   )TTFr   rZ   c                 S   s   | j d dkS )Nr   r   rZ   xr$   r$   r%   <lambda>s      z@TestiLocBaseIndependent.test_iloc_getitem_bool.<locals>.<lambda>r	   r   rC   rH   r   r$   r$   r%   test_iloc_getitem_boolc  s    


z.TestiLocBaseIndependent.test_iloc_getitem_boolr[   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 r6   )r   r   r*   rv   r"   r   )r#   r[   ry   rO   r$   r$   r%   test_iloc_getitem_bool_diff_lenv  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   r.   r   rg   r   r   r   r   r   r   rZ   r   )rh   r   c                 S   s   ddgS )Nr   r   r$   )rL   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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 )Nri   rT   )rh   rh   r   r   rc   r   r`   sizer   rh   r   r   r   r.   )
r	   rE   rt   rx   randintr   r   rC   rH   r   )r#   r   r   rL   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sLJ 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 )NrT   r      r      r.   r~   r   r   r   rs   rZ   r   r   r   )
r	   rE   rt   rx   r   r   rC   rH   r   rw   r#   rL   rp   rP   ry   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)rr   cri   )r   drk   )r   er   )ra   ra   ra   ra   r   r   r   )rr   r   ra   )r   r   ra   )r   r   ra   r   r   r#   rL   rP   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	   )r.   r.   r   r~   r   r   r   rg   )	r   r   r   r.   r   r   rr   r   r   )r	   rE   r   r   r   r   rC   rH   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   r.   )r   r   r.   r   r   r   r   )r   r>   r   rC   rw   r
   )r#   Zs_origrP   ry   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   r.   rT   r   r   r9   r   rh   T)Zdrop)r	   r   ZfillnarE   isnanr   r[   rC   rH   rd   Zreset_index)r#   r   r   rL   rP   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   r.   r   rc   Zf8g      ?)	r	   r   rG   r   r<   r=   r>   rC   rH   r#   rI   rL   rP   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shJ |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 )Nri   rT   r   r`   r   r   r~   )r   r   )rT   rT      r.   ra   )r   r   r.   )r   r   rr   r   )r   r   r.   r   )rl   r   rr   rr   )r   r   r   r.   )rl   rl   r   rr   )r[   r1   )r   rT   rr   r   )r	   rE   rt   rx   r:   r   locrC   rw   rH   r   r;   r[   )r#   rL   rp   r   rP   ry   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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 )Nri   rT   
abcdefghijABCDr~   r   )br   r   r.   r   )r   r   )jr{   z/index 5 is out of bounds for axis 0 with size 4r6   )ri   ra   zLocation based indexing can only have \[integer, integer slice \(START point is INCLUDED, END point is EXCLUDED\), listlike of integers, boolean array\] types)r	   rE   rt   rx   ru   r   r   rC   rH   r*   rv   r"   
ValueError)r#   rL   rp   r   rP   rO   r$   r$   r%    test_iloc_getitem_labelled_frameT  s&    



(z8TestiLocBaseIndependent.test_iloc_getitem_labelled_framec                 C   s  t jdd}tddd}td}t|||d}|  |jddd	d
f }t| |j	 t|ddd	d
f |dd |d	d
 d}t
|| td|_|jddd	d
f }t| |j	 t|ddd	d
f |dd tdd}t
|| t jdd}ttd	dd
}ttd	dd
}t|||d}|sJ|jjd	 j |jddd
df }t| |j	 t|ddd
df |dd |d
d d}t
|| d S )Nrr   rT   Z20130101)Zperiodsr   r~   r.   ra   r   r   ZaaaaZaar   r   r   )rE   rt   rx   r   ru   r	   Zdescriber   rn   ro   rC   rH   rd   r:   r<   r=   Zmgr_locs)r#   rI   rW   r[   rd   rL   rp   rP   r$   r$   r%   test_iloc_getitem_doc_issueu  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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 )Nri   rT   r   r   r~   r   r   r   r   r.   r`   rZ   r   rr   )r   r   rT   )r   r.   ra   re   )r	   rE   rt   rx   ru   r   rC   rH   r   r:   rw   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 )Nra   int64r0   ri   r   rk   r   r   r   rT   )r   r   ri   r   rT   )ra   rr   rk   r   r   r   r   r   r   r   r   y)r   r   r   r   r   )r	   rE   r   r   rC   rH   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|rD|d
ksHJ d S )Nr   r   r.   rT   rh   r   rc   r   r8   r   )r	   r   r   )r#   r/   r   rL   rp   r$   r$   r%   #test_iloc_setitem_with_scalar_index  s    
z;TestiLocBaseIndependent.test_iloc_setitem_with_scalar_indexc                 C   sH  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	}td
d tdt dD ]}	|jdkj}|	rlt|t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rptd| d| d| dqpq>W d    n1 s:0    Y  d S )Nra   rb   r   r~   r   r   zBiLocation based boolean indexing cannot use an indexable as a maskr6   zDiLocation based boolean indexing on an integer type is not availableTr0   rT   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)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	   ru   r:   r   r*   rv   r   r   r   r[   NotImplementedErrorrE   r   boolrC   rH   r   r   r   UserWarningr   r?   r   reversedgetattrrn   r   sumr   getAssertionError)r#   rL   r   rO   rp   r   r   ZrepsrP   idxmethodaccessor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   rf   c   r   r.   r   znot in indexr6   )r	   rE   r   r   r   rC   rH   r*   rv   KeyErrorr   )r#   rL   r   rP   Zdf3rp   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 )Nra   r   r   T)Zcheck_index_typeZcheck_column_type)rC   ZmakeCustomDataframerH   r   r#   rL   r$   r$   r%   "test_iloc_empty_list_indexer_is_ok8  s      z:TestiLocBaseIndependent.test_iloc_empty_list_indexer_is_okc           	      C   s&  |rt jjdd}|j| tdg di}|jd d  }||usHJ t|d |d s`J g d|j	d d df< |r|d g dk
 sJ n|d dk
 sJ tg d}|jd d  }||usJ g d|d d	< |rt
|d d	 g dks"J nt
|d d	 g dks"J d S )
Nz0setting with .loc[:, 'a'] does not alter inplace)reasonr   r   )rT   rT   rT   rT   )r   r   r.   rT   ra   rr   r   r   r   r.   )r*   r+   ZxfailnodeZ
add_markerr	   r   rE   rF   r   allr   )	r#   rI   using_copy_on_writerequestr+   Zoriginal_dfZ	sliced_dfZoriginal_seriesZsliced_seriesr$   r$   r%   &test_identity_slice_returns_new_objectN  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   r.   rT   r   r   )r	   r   rE   r   r   rC   rw   )r#   rL   rp   ry   r$   r$   r%   test_indexing_zerodim_np_arrays  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   rE   r   )r#   ry   rp   r$   r$   r%   %test_series_indexing_zerodim_np_arrayz  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}tjt|d, |d d d	 |jd d d
f< W d    n1 s0    Y  |st|d |sJ t g dg dd}n|}t|| d S )Nr   r   )r   r   F)r>   r   r5   r6   r   r   )r   r   rh   
categories)	r   r>   r	   rC   rF   rD   rB   r   Zassert_categorical_equal)r#   r   rK   Zcat_originalrL   rO   rP   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   r.   rT   ra   rr   r   ri   r   )TTFF)FFTTg      @g      (@g      @)r	   rE   r   r   r[   rC   rH   r#   rp   rP   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   r1   )r	   r   splitr   r   rC   rw   )r#   rL   rp   Zraw_catrP   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   rG   r   r   rC   rw   )r#   r^   rp   rP   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]r0   r   r   r   )r   r   r   rC   rw   )r#   r   ZseriesrP   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  r0   r.   )r   r   r   rC   rw   )r#   r  Znulls_fixturer1   r^   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    n1 sr0    Y  d S )Nr~   ra   )r   r   r   r   zCannot set values with ndim > r6   r   )r
   r	   rE   rt   rx   r   r   ndimr*   rv   r   r   )r#   r   rX   Znd3rO   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 )Nri   F)writer   r   r.   )rE   eyer	   ZsetflagsrC   rH   rw   )r#   r/   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datarg   float64r0   )r   r.   rr   F)r	   rE   Zonesr   flagsZ	writeabler   r   rC   rH   rw   )r#   rL   indicesrp   rP   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   rd   r[   r   r8   )r	   r   r   rC   rH   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   r.   rT   )flagr   r  r   r   )r   r.   rT   r   )r#   r  rL   r/   rP   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)rk   r   r   )r         )Za2b2r   rs   r   r   r   r   r   r   )r#   r/   r   r   rP   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#   rL   rhsrP   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 )Nr.   )r   皙?r)  abcr~   r   r)  r   )r)  r   )r   r)  r)  rT   )r   r)  r)  r   r   )r   r)  r   r)  )r	   rE   rt   rx   ru   r   rC   rH   r   rw   r[   )r#   rL   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                   @   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 rm   r   )r#   r   r$   r$   r%   __init__L  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__O  s    zKTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__str__c                 S   s   | j |j kS rm   r.  )r#   otherr$   r$   r%   __eq__T  s    zJTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.__eq__c                 S   s   | S rm   r$   r0  r$   r$   r%   viewW  s    zHTestiLocBaseIndependent.test_iloc_setitem_custom_object.<locals>.TO.view)
r'   r(   r)   r/  rn   r1  __repr__r   r3  r4  r$   r$   r$   r%   TOK  s
   r6  r   r   r~   r\   r   )r	   r   rC   rH   rE   r   )r#   r6  rL   rp   r$   r$   r%   test_iloc_setitem_custom_objectI  s    z7TestiLocBaseIndependent.test_iloc_setitem_custom_objectc                 C   s   t tjddtdtdd}|jd }t|ts8J t	|j
|j
d  |jjd d df }t|tsnJ t	|j
|j
d  d S )Nr.   ABCZaabr  r   )r	   rE   rt   Zrandru   r   r@   r   rC   assert_almost_equalr?   T)r#   rL   rp   r$   r$   r%   !test_iloc_getitem_with_duplicatesk  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   rs   )r   r   r   rc   r   r   r   )r	   r   takerC   rH   r#   rL   rp   rP   r$   r$   r%   "test_iloc_getitem_with_duplicates2w  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  r.   )r	   r   r   r   rC   rw   r>   rH   r=  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   ra   ri   TFT)ra   r   ri   r   )r   r   rC   rw   r	   rH   )r#   rA  r@  r^   rP   rL   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 )	Nrh   r   Int64r0   r   Zfoor   )r   rh   r   )r#   rL   resrP   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
  r0   r   r   r   )r   r   r   )r	   rE   r   r   r1   rC   rH   r   r$   r$   r%   *test_iloc_setitem_2d_ndarray_into_ea_block  s    .zBTestiLocBaseIndependent.test_iloc_setitem_2d_ndarray_into_ea_blockc                 C   sV   t ddj}t|}|jd }|d |d ks2J |d |d< |d |d ksRJ d S )Nr   g      $@r   r   r   )r   Z_valuesr	   r   )r#   rW   rL   r^   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 S )Nz
2022-01-01z
2022-01-02Z2021Z2022r   rh   r   z2021-01-01 00:00:00z2022-01-01 00:00:00)Zcheck_dtype)r	   r   r   r   rC   rH   r   r$   r$   r%   )test_iloc_setitem_multicolumn_to_datetime  s    $	zATestiLocBaseIndependent.test_iloc_setitem_multicolumn_to_datetime)Pr'   r(   r)   __doc__r*   r+   r,   rA   r:   r
   rE   ZasarrayrC   r   r   rQ   r   r   rY   r_   rz   r   ru   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  tdZ&skip_array_manager_not_yet_implementedr  r	  r  r  r   r   r  r   r  r  r  r  r  r!  r&  r(  r,  r7  r;  r>  r?  rC  rF  rH  rI  rJ  r$   r$   r$   r%   r-   :   s   
+

f		
/!+ $G%
	


	


!"
r-   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 keyr6   g      @r   )r	   r]   r*   rv   r   r   r"   _slice_iloc_msg)r#   Zseries_with_simple_indexrV   rX   rO   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 indexersr6   ztoo many indices for arrayr   )r*   rv   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}tt d|j|< W d    n1 sJ0    Y  d}tjt|d |j|  W d    n1 s0    Y  d S )Nr   r   rB  r   zWDataFrame indexer is not allowed for .iloc
Consider using .loc for automatic alignment.r6   )r	   rC   rD   rB   r   r*   rv   r"   )r#   rL   r/   rO   r$   r$   r%   test_iloc_frame_indexer  s    (z&TestILocErrors.test_iloc_frame_indexerN)r'   r(   r)   rO  rP  rQ  r$   r$   r$   r%   rM    s   rM  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   r.   rT   r   r   r8   )r   r   )r	   r   r   ro   rE   r   )r#   r   r   rL   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   rn   str2r   r   r   rc   str3r   )r   rn   rV  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   r0   r   rT   r   rc   r   )	r	   rE   r   r   r   r   rG   r  ro   r   r$   r$   r%   *test_iloc_setitem_series_duplicate_columns  s
    (zJTestILocSetItemDuplicateColumns.test_iloc_setitem_series_duplicate_columns)ro   
init_valueexpected_value)r   0r   )floatz1.2g333333?c                 C   s   t |ddggg dd}d}tjt|d6 |jd d df ||jd d df< W d    n1 sf0    Y  t |ddggg dd}t|| d S )Nrn   rT  rU  rc   r5   r6   r   )r	   rC   rD   rB   r   rG   rH   )r#   ro   rY  rZ  rL   rO   Zexpected_dfr$   r$   r%   *test_iloc_setitem_dtypes_duplicate_columns  s    DzJTestILocSetItemDuplicateColumns.test_iloc_setitem_dtypes_duplicate_columnsN)
r'   r(   r)   rS  rW  rX  r*   r+   r,   r]  r$   r$   r$   r%   rR    s   	rR  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 )NrS   aabbXYr   rZ   c                 S   s   ddgS Nr   r.   r$   r   r$   r$   r%   r   4  r   zCTestILocCallable.test_frame_iloc_getitem_callable.<locals>.<lambda>r   r.   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   7  r   c                 S   s   ddgS rc  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 rc  r$   r   r$   r$   r%   r   =  r   c                 S   s   dgS rd  r$   r   r$   r$   r%   r   =  r   c                 S   s   dS rd  r$   r   r$   r$   r%   r   A  r   c                 S   s   dgS rd  r$   r   r$   r$   r%   r   D  r   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   G  r   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   J  r   )r	   ru   r   rC   rH   rw   )r#   rL   rE  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 )NrS   r_  r`  r   rZ   r   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   S  r   zCTestILocCallable.test_frame_iloc_setitem_callable.<locals>.<lambda>r   r.   r   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   Y  r   ra   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   _  r   c                 S   s   dS rd  r$   r   r$   r$   r%   r   _  r      c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   e  r   c                 S   s   dgS rd  r$   r   r$   r$   r%   r   e  r   r   c                 S   s   dS rd  r$   r   r$   r$   r%   r   l  r   c                 S   s   dgS rd  r$   r   r$   r$   r%   r   r  r   ri   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   x  r   c                 S   s   ddgS rc  r$   r   r$   r$   r%   r   ~  r   )r	   ru   r>   r   rC   rH   )r#   rL   rE  r   r$   r$   r%    test_frame_iloc_setitem_callableM  sR    z1TestILocCallable.test_frame_iloc_setitem_callableN)r'   r(   r)   re  rh  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
|| q4|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 )
Nri   r   r`   r   rZ   r   r.   rT   )r   r   r.   rT   ra   )r   rE   rt   rx   ru   r:   r>   r   r   r[   rC   r9  rA   r   rw   rD   r   Zreindex)r#   r   r^   Zser_originalirp   r   rP   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   rZ   r   )r   r   )r#   r^   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   rs   )r   r   r   rZ   r   r.   )r   ra   rr   )r   r   rC   rw   )r#   Zser1Zser2rP   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   rD  r0   )	r	   rE   r   r   rG   r   r   rC   rH   r  r$   r$   r%   #test_iloc_nullable_int64_size_1_nan  s    &z2TestILocSeries.test_iloc_nullable_int64_size_1_nanN)r'   r(   r)   rk  rl  r&  rn  r$   r$   r$   r%   ri    s   ri  ).rK  r   rewarningsr   r   numpyrE   r*   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsrL  Zpandasr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingrC   Zpandas.api.typesr   Zpandas.tests.indexing.commonr   escaperN  r   r-   rM  rR  r^  ri  r$   r$   r$   r%   <module>   s:   D         !-/V