U
    >vfѹ                 	   @   s  d Z ddlmZ ddlmZmZmZmZ ddlZddlm	Z	 ddl
ZddlZddlmZ ddlm  mZ ddl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#m$Z$m%Z%m&Z& ddl'm(Z) ddl*m+Z+m,Z, dd	l-m.Z. dd
l/m0Z0 ej12dej3ej3dgdej3ej3gdddggej3dgdej3gddgggdd Z4G dd dZ5G dd dZ6G dd dZ7G dd dZ8G dd dZ9G 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?ej12d(d)d*d+gd)d*gdd,gfd)d*d-gd)d*gdd,gfd)d*d-gd)d-gdd.gfgd/d0 Z@d1d2 ZAd3d4 ZBd5d6 ZCd7d8 ZDd9d: ZEd;d< ZFd=d> ZGd?d@ ZHdAdB ZIdCdD ZJdEdF ZKej12dGdHeLdHeMdHgdIdJ ZNej12dKe"dLdMfe"dNdOdPdQfgdRdS ZOdTdU ZPdVdW ZQG dXdY dYZRdS )Zz$ test label based indexing with loc     )
namedtuple)datedatetimetime	timedeltaN)gettz)IndexingError)CategoricalCategoricalDtypeCategoricalIndex	DataFrameDatetimeIndexIndex
IndexSlice
MultiIndexPeriodPeriodIndexSeriesSparseDtype	Timedelta	Timestamp
date_rangetimedelta_rangeto_datetimeto_timedelta)is_bool_dtype	is_scalar)_one_ellipsis_message)"check_indexing_smoketest_or_raisesz series, new_series, expected_serbaFTc                 C   sP   t d| i}||jd d df< t d|i}t| | t| |  d S NA)r   loctmassert_frame_equalisnaZnotna)seriesZ
new_seriesZexpected_serdfexpected r*   B/tmp/pip-unpacked-wheel-vdrwu74i/pandas/tests/indexing/test_loc.pytest_not_change_nan_loc0   s
    	r,   c                   @   s  e Zd Zejdddgdd Zejdddgdd Zejdd	d
ddddgdgd	dgdgdd
ddgdgddgdgddgdgddgdggejdddgdd Zejddddgd
ddggdddgd
ddgggejdddgdd Z	ejddddgdgdgdddgd
ddgdgddd gd
ddgdgd!d"d#gd$gdggejdddgd%d& Z
ejd'd
dgejdddgd(d) Zd*d+ Zejdddgd,d- Zejd.edddddddgdeged/d0dgdegedd1dgdegedd1dgdegedd2ddgdeggejdddgd3d4 Zd5d6 Zd7d8 Zejd9edgged:gd;eddd:f edgd:d<fedged:gd=d:dgfedgged:gd=d:edgd:d<fgd>d? ZdS )@TestLockindr'   framec                 C   s$   | | d}t|ddtd d S )NZ_labelsr#      failsgetfixturevaluer   KeyErrorselfr.   requestobjr*   r*   r+   test_loc_getitem_intA   s    zTestLoc.test_loc_getitem_intc                 C   s$   | | d}t|ddtd d S )N_emptyr#   cr1   r3   r6   r*   r*   r+   test_loc_getitem_labelG   s    zTestLoc.test_loc_getitem_labelzkey, typs, axesfZintsZuintslabelsmixedtsNZfloats   r   c                 C   s4   |D ]*}| | d| }t|d||td qd S N_r#   axesr2   r3   r7   keytypsrF   r.   r8   typr9   r*   r*   r+   #test_loc_getitem_label_out_of_rangeM   s        z+TestLoc.test_loc_getitem_label_out_of_rangez	key, typs   r0         @r"   c                 C   s2   |D ](}| | d| }t|d|td qd S )NrD   r#   r1   r3   )r7   rH   rI   r.   r8   rJ   r9   r*   r*   r+   test_loc_getitem_label_lista   s    	z#TestLoc.test_loc_getitem_label_listempty
            )rL   rQ   )rL      )r0      Zmultic                 C   s4   |D ]*}| | d| }t|d||td qd S rC   r3   rG   r*   r*   r+   (test_loc_getitem_label_list_with_missingo   s        z0TestLoc.test_loc_getitem_label_list_with_missingrI   c                 C   s0   | | d| }t|ddddgdtd d S )NrD   r#   rB      (   rL   rE   r3   )r7   rI   r.   r8   r9   r*   r*   r+   !test_loc_getitem_label_list_fails   s        z)TestLoc.test_loc_getitem_label_list_failsc                 C   s   d S Nr*   r7   r*   r*   r+   !test_loc_getitem_label_array_like   s    z)TestLoc.test_loc_getitem_label_array_likec                 C   s0   | | d}ddddg}t|d|td d S )Nr;   TFr#   r1   )r4   r   
IndexError)r7   r.   r8   r9   r   r*   r*   r+   test_loc_getitem_bool   s    zTestLoc.test_loc_getitem_boolzslc, typs, axes, failsZ20130102Z20130104   rT   c           	      C   s4   |D ]*}| | d| }t|d|||d qd S rC   )r4   r   )	r7   ZslcrI   rF   r2   r.   r8   rJ   r9   r*   r*   r+   test_loc_getitem_label_slice   s    z$TestLoc.test_loc_getitem_label_slicec                 C   st   t ddgddgddggddgdddgd}td	|jd
< t ddgddgddggddgdddgd}t|| d S )NrB   r       col1col2rP   rL   columnsindexr0   )rL   rb   r   )r   nparanger#   r$   r%   r7   r(   r)   r*   r*   r+    test_setitem_from_duplicate_axis   s      z(TestLoc.test_setitem_from_duplicate_axisc                 C   s   t dddgdtjdgtdtjtdgdd	}t d
gtdgdd	}|j|j|d  ddgf< t dddgdd
dgtdtdtdgdd	}t	
|| d S )NrL   r0   rQ   zString 1zString 2z2019-06-11 11:00:00z2019-06-11 12:00:00)Zchannelr"   B)datazString 3r"   rk   r"   rk   )r   rg   NaNr   pdNaTvaluesr#   r&   r$   r%   )r7   r(   df2r)   r*   r*   r+   test_column_types_consistent   s.    
z$TestLoc.test_column_types_consistentzobj, key, expFre   namerf   c                 C   s6   |j | }t|ttfr&t|| n||ks2td S rZ   )r#   
isinstancer   r   r$   assert_equalAssertionError)r7   r9   rH   expresr*   r*   r+   #test_loc_getitem_single_boolean_arg   s    
z+TestLoc.test_loc_getitem_single_boolean_arg)__name__
__module____qualname__pytestmarkparametrizer:   r=   rK   rN   rV   rY   r\   r^   slice	TypeErrorr5   r`   rj   rs   r   r   r   r   r}   r*   r*   r*   r+   r-   @   s   







$r-   c                   @   sP  e Zd Zdd Zejddedddffdedd	dffd
edddffdededdffdeddd	ffdeddedffdedddffgdd Zdd Z	dd Z
dd Zdd Zdd Zd d! Zd"d# Zejd$d%d&gd%d&d%d&ggd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zejd7d8 Zejd9d:ejd:ejd;ejd:d:d:d:d:gejd;gd<d= Zd>d? Zd@dA ZdBdC Z dDdE Z!dFdG Z"ejdHdIdJdKdLdMdNdOdPgdQdR Z#dSdT Z$dUdV Z%dWdX Z&dYdZ Z'd[d\ Z(d]d^ Z)d_d` Z*dadb Z+dcdd Z,ejdedfge-dgdfdgedfggejdhdigediggdjdk Z.ejdld:dmgdfdndodKgfdpe/dpdpdpdpgdqdrej0ej0gdpdpdpdpggdfdndodKgdsfdtdodKgfdpduge/dtdmej0ej0gdqdrdpdugdvdwej0ej0ggdfdndodKgdsfdtdfdndogfejdpdudxgejd;e/dtdmej0gdpdudxgdvdwej0ggdfdndogdsfe-dtdqdgdndodKgfdpdudxgdydzd{gge/dtdmej0ej0gdqdpdudxgdvdydzd{ggdfdndodKgdsfe-dtdqdgdodfdKgfejdpdudxgdydzd{ggejd;e/dtdmej0ej0gdudrdpdxgdzdwdyd{ggdfdndodKgdsfe-dgdgdgdfdogfe/dpdugdxdygdzd{ggdfdogdse/dpdmdugdxdrdygdzdwd{ggdfdndogdsfgd|d} Z1d~d Z2dd Z3dd Z4dd Z5dd Z6ejj7ejdddgddggdd Z8dd Z9dd Z:dd Z;dd Z<dd Z=dd Z>dd Z?dd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGejddddgejdejejHeIgeJjKdd ZLdd ZMeJjKdd ZNdd ZOejdeddgdd ZPejdeQejeReSgdd ZTdd ZUejddeRdtgfdeRdmgfgddǄ ZVddɄ ZWejdd:ddtdmdqdrdvdwdpdudxg
fe-drdud:dtdmdqdddddudxg
fdqdvgd:dtdmddrddwdpdudxg
fgdd̈́ ZXddτ ZYddф ZZddӄ Z[ejdddggddׄ Z\ddل Z]ejddfdfgdfe-dgfgdd܄ Z^ddބ Z_dd Z`dd Zadd Zbdd Zcejdddgdd Zddd Zedd Zfdd Zgdd Zhdd ZidgS )TestLocBaseIndependentc                 C   sH   t tddd}|jtdgd d  }|jdd  }t|| d S )NZ20212022rw   z2021/6/1r      )r   r   r#   rg   arrayilocr$   r%   r7   r(   resultr)   r*   r*   r+   test_loc_npstr   s    z%TestLocBaseIndependent.test_loc_npstrzmsg, keyz'Period\('2019', 'A-DEC'\), 'foo', 'bar'  foobarz&Period\('2019', 'A-DEC'\), 'y1', 'bar'y1z&Period\('2019', 'A-DEC'\), 'foo', 'z1'z1z;Period\('2018', 'A-DEC'\), Period\('2016', 'A-DEC'\), 'bar'    z&Period\('2018', 'A-DEC'\), 'foo', 'y1'z;Period\('2017', 'A-DEC'\), 'foo', Period\('2015', 'A-DEC'\)    z&Period\('2017', 'A-DEC'\), 'z1', 'bar'c              	   C   sz   t tdddgtdtddgtddtd	gd
ddgdddgddddg}tjt|d |j|  W 5 Q R X dS )a(  
        parse_datetime_string_with_reso return parameter if type not matched.
        PeriodIndex.get_loc takes returned value from parse_datetime_string_with_reso
        as a tuple.
        If first argument is Period and a tuple has 3 items,
        process go on not raise exception
        r   x1Zx2r   r   r   r   r   r   rL   r0   rQ   rP   rB   rW   )r"   rk   CZV1ZV2r"   rk   r   matchN)r   r   	set_indexr   raisesr5   r#   )r7   msgrH   r(   r*   r*   r+   ;test_contains_raise_error_if_period_index_is_in_multi_index  s    	zRTestLocBaseIndependent.test_contains_raise_error_if_period_index_is_in_multi_indexc              	   C   s>   t ddgi}tjtdd |jd d df  W 5 Q R X d S )Nr    rL   u   אr   )r   r   r   r5   r#   r7   r(   r*   r*   r+   $test_loc_getitem_missing_unicode_key(  s    z;TestLocBaseIndependent.test_loc_getitem_missing_unicode_keyc                 C   sT   t tjddd tdD d}|jd }|jd d df jd }t|| d S )	N)rB   rU   c                 S   s   g | ]}d |d  qS )ZABCDErU   r*   .0xr*   r*   r+   
<listcomp>1  s     z@TestLocBaseIndependent.test_loc_getitem_dups.<locals>.<listcomp>rB   rw   )r"   r   r   r"   )r   rg   randomZrandom_sampleranger#   r$   assert_series_equalr7   r(   r)   r   r*   r*   r+   test_loc_getitem_dups-  s    
 
z,TestLocBaseIndependent.test_loc_getitem_dupsc                 C   s   t ddddtdggdddddgdgd}tddddtdgdddddgdd}|jd	 }t|| |jd }t|| d S )
NrL   r0   r   r   20130101r    rd   rf   rv   r   )r   r   r   r   r$   r   r#   r   r*   r*   r+   test_loc_getitem_dups27  s    

z-TestLocBaseIndependent.test_loc_getitem_dups2c                 C   s  t tdtdtjdddd d tjdddd d d	d
}dddgf}| }|j|  d9  < t|j| d|j|   d}| }|j|  d9  < |j| d|j|  kst	dddgf}| }|j|  d9  < t
|j| d|j|   d S )NZrtttiZaaaderU   float64dtypegq=
ףp?r0   g(\տ)mer   r   bar2r   rr   r          @)r   r   t)r   listrg   rh   r   copyr#   r$   r   rz   r%   )r7   df_origindexerr(   r*   r*   r+   test_loc_setitem_dupsK  s2    
z,TestLocBaseIndependent.test_loc_setitem_dupsc                 C   s   t dddgtdddgddd}|d	 dk}|j|d
f d }||j|d
f< t dddgtdddgddd}t|| t dddgdddgddd}|d	 dk}|j|d
f }||j|d
f< t dddgdddgddd}t|| d S )Nr   rL   d   ra   ,  Zuint32r   r    r   r    r      i-  uint64)r   r   r#   r$   r%   )r7   Zdf1ixZnewb1r)   rr   Znewb2r*   r*   r+   test_loc_setitem_slicen  s    "z-TestLocBaseIndependent.test_loc_setitem_slicec                 C   s   t dgdgdgdgd}dddg}|jd d |f d	|jd d |f< t dgtjdgd
dtjdgd
dtjdgd
dd}t|| d S )Nr"   333333?        g      )idr    r   r<   r    r   r<   Zfloat32r   r   )r   r#   astyperg   r   r$   r%   )r7   r(   colsr)   r*   r*   r+   test_loc_setitem_dtype  s    
&	z-TestLocBaseIndependent.test_loc_setitem_dtypec              	   C   sr   t tddddgd}tjtdd |ddg  W 5 Q R X t td}tjtdd |d	dg  W 5 Q R X d S )
NrQ   r    r   r<   rw   not in indexr   dr   )r   r   r   r   r5   )r7   sr*   r*   r+   $test_getitem_label_list_with_missing  s    z;TestLocBaseIndependent.test_getitem_label_list_with_missingrf   TFc              	   C   sN   t dddg}dt| dt| }tjt|d |j|  W 5 Q R X d S )NrL   r0   rQ   z Boolean index has wrong length: z instead of r   )r   lenr   r   r]   r#   )r7   rf   r   r   r*   r*   r+   test_loc_getitem_bool_diff_len  s    z5TestLocBaseIndependent.test_loc_getitem_bool_diff_lenc                 C   s   d S rZ   r*   r[   r*   r*   r+   test_loc_getitem_int_slice  s    z1TestLocBaseIndependent.test_loc_getitem_int_slicec              	   C   sh   t tjddddgdddgd}d	t j d
}tjt|d |jddgddgf  W 5 Q R X d S )N)rQ   rQ   r    r   r<   er>   grf   re   z$\"None of \[Index\(\[1, 2\], dtype=''\)\] are in the \[index\]\"r   rL   r0   )	r   rg   r   int_r   r   r   r5   r#   r7   r(   r   r*   r*   r+   test_loc_to_fail  s    
  z'TestLocBaseIndependent.test_loc_to_failc              	   C   sH  t td}d|jd< d|jd< tjtdd |jd  W 5 Q R X dt j d	}tjt|d |jdd
g  W 5 Q R X d}tjt|d |jdg  W 5 Q R X d|jd< tjtdd |jdd
g  W 5 Q R X d|d< dt j d	}tjt|d |jd
g  W 5 Q R X |d= tjt|d d|jd
g< W 5 Q R X d S )Nr   rL   r0   r    z^-1$r   z&\"None of \[Index\(\[-1, -2\], dtype='r   zE\"None of \[Index\(\['4'\], dtype='object'\)\] are in the \[index\]\"4rQ   r   z"\"None of \[Index\(\[-2\], dtype='r   )	r   objectr#   r   r   r5   rg   r   r   r7   r   r   r*   r*   r+   test_loc_to_fail2  s.    



z(TestLocBaseIndependent.test_loc_to_fail2c              	   C   s   t dgdggddgdgd}dt j d}tjt|d	 |jd
gd d f  W 5 Q R X tjt|d	 |jd
g  W 5 Q R X d S )Nr    r   rL   r0   valuer   z!\"None of \[Index\(\[3\], dtype='r   r   rQ   )r   rg   r   r   r   r   r5   r#   r   r*   r*   r+   test_loc_to_fail3  s    z(TestLocBaseIndependent.test_loc_to_fail3c              	   C   s   t dddg}|jdg  dt j d}tjtt	|d |jdg  W 5 Q R X tjtdd |jddg  W 5 Q R X d S )NrL   r0   rQ   z"None of [Index([3], dtype='z')] are in the [index]r   r   )
r   r#   rg   r   r   r   r   r5   reescaper   r*   r*   r+   test_loc_getitem_list_with_fail  s    z6TestLocBaseIndependent.test_loc_getitem_list_with_failc                 C   s   t tjjdddddddgd}|jd	d
 }|jt| }|j| }t|| |j|j	 }t|| |jt
j|dd }t|| d S )N)rU   rP   sizeZalpha_0Zalpha_1Zalpha_2Zbeta_0Zbeta_1rw   c                 S   s   d| kS )Nalphar*   r   r*   r*   r+   <lambda>	      z7TestLocBaseIndependent.test_loc_index.<locals>.<lambda>booleanr   )r   rg   r   rf   mapr#   r   r$   r%   rq   ro   )r7   r(   maskr)   r   r*   r*   r+   test_loc_index   s    
z%TestLocBaseIndependent.test_loc_indexc                 C   s   t tjddddddgddddgd}|jd d ddf jddd d f }|jddgk sft|j	ddgk s|tt t
d	gd
gdjd }tt
d	d
gddgdd}t|| |jtkstd S )NrT   r"   rk   r   Drd   r   r0   r   rL   r   r    r   r   )r   rg   r   randr#   r   re   allrz   rf   r   r   r$   r   r   r   r   r*   r*   r+   test_loc_general  s    

(z'TestLocBaseIndependent.test_loc_generalc                 C   s"   t tddttdtjddS )N
2000-01-01	2000-01-5rU   r   r   val)r   r   r   r   rg   int64r[   r*   r*   r+   frame_for_consistency'  s
    z,TestLocBaseIndependent.frame_for_consistencyr   r   r   c                 C   sV   t tdtdtjdttdtjdd}| }||jd d df< t|| d S )Nr   rU   rf   r   r   r   r   	r   r   r   rg   r   r   r#   r$   r%   )r7   r   r   r)   r(   r*   r*   r+   test_loc_setitem_consistency0  s    z3TestLocBaseIndependent.test_loc_setitem_consistencyc                 C   sR   t tdtddttdtjdd}| }d|jd d df< t|| d S )Nr   rU   rw   r   r   r   r   r7   r   r)   r(   r*   r*   r+   (test_loc_setitem_consistency_dt64_to_strA  s    z?TestLocBaseIndependent.test_loc_setitem_consistency_dt64_to_strc                 C   sR   t tdtddttdtjdd}| }d|jd d df< t|| d S )N      ?rU   rw   r   r   r   r   r   r*   r*   r+   *test_loc_setitem_consistency_dt64_to_floatO  s    zATestLocBaseIndependent.test_loc_setitem_consistency_dt64_to_floatc                 C   sJ   t dttdgi}d|jd d df< t dtdgi}t|| d S )Nr   Z20180101string)r   r   r   r#   r$   r%   ri   r*   r*   r+   'test_loc_setitem_consistency_single_row\  s    z>TestLocBaseIndependent.test_loc_setitem_consistency_single_rowc              	   C   s   t ddgd}t ddgd}td  d|jd d df< W 5 Q R X t|| t ddgd}d|d< |d tj|d< t|| d S )Nr   yrt   rL   )r   r$   Zassert_produces_warningr#   r%   r   rg   r   r7   r)   r(   r*   r*   r+   "test_loc_setitem_consistency_emptyd  s    z9TestLocBaseIndependent.test_loc_setitem_consistency_emptyc                 C   s  dgd ddddgddddgg}t j|d	d
dgd}dddddgdddddgg}t j|ddgd}ddddtjgdddddgddddtjgddddd gg}t|||d!}t|jd d d"f |jd d d"f< t|jd d d#f |jd d d#f< |jd$d%}|jd d d#f |jd d d"f  |jd d d&f< |jd d d&f td' |jd d d&f< t	d(d)d*d+g|j
d&d,}t|d& | d S )-NZRegion_1rT   ZSite_1ZSite_2l   BP[ l   _Z l   q=.Z l   <.Z ZRegionZSiteZRespondentIDnames
RespondentZOtherCatZ	Something	StartDateEndDatezYes/NoZSomethingElseZLevel_0ZLevel_1r"   z5/25/2015 10:59z5/25/2015 11:22ZYesz5/21/2015 9:40z5/21/2015 9:52z5/20/2015 8:27z5/20/2015 8:41z5/20/2015 8:33z5/20/2015 9:09ZNor   )r  r  )r  r  F)r   )r  ZDurationl    Xp7 g      7@      (@g      ,@g      B@r   )r   from_arraysrg   nanr   r   r#   Zinfer_objectsr   r   rf   r$   r   )r7   levelsmiZclevelsr   rq   r(   r)   r*   r*   r+   -test_loc_setitem_consistency_slice_column_lent  sJ    



  zDTestLocBaseIndependent.test_loc_setitem_consistency_slice_column_lenunitYMr   hmr   msusc                 C   s   t dtdtdgi}|jd d df jd| d|jd d |f< |jd d df jd| d|d< t|jd d df |d}t|jd d |f | d S )N	timestampz2017-02-11 12:41:29z1991-11-07 04:22:37zdatetime64[]r)   ru   )	r   rg   
datetime64r#   rq   r   r   r$   r   )r7   r  r(   r)   r*   r*   r+   test_loc_assign_non_ns_datetime  s    	0&z6TestLocBaseIndependent.test_loc_assign_non_ns_datetimec                 C   s   t dddddgi}t|d ddd|d	< |jd d d	f |jd d d
f< |jddgd	f |jddgd
f< t dddgdddgdddgdddggdd	d
gd}d	d
g}|| t||< t|| d S )Nr   l   CO!gl   s~!gl    4	8l   A{?r  T)r  cacheZdate_dtZ
date_dt_cpr0   rQ   z2017-01-24 13:26:12.711z2017-01-24 13:52:05.110z2018-10-22 13:44:05.888z2018-10-23 08:08:41.025rt   )r   	from_dictr   r#   applyr$   r%   )r7   r(   r)   re   r*   r*   r+   test_loc_modify_datetime  s"      
z/TestLocBaseIndependent.test_loc_modify_datetimec                 C   sp   t dddgdgtd}tjdddgdd	|jdddgdf< tdddgdddgtd
}t d|i}t|| d S )NrQ   rU   rT   r"   rf   re   r   rL   r0   r   r   r   )r   floatrg   r   r#   r   r$   r%   r7   r(   serr)   r*   r*   r+   #test_loc_setitem_frame_with_reindex  s
    $z:TestLocBaseIndependent.test_loc_setitem_frame_with_reindexc                 C   s   t dddgddgtd}d|d< tjdd	dgd
d|jdddgdf< td	ddgdddgd
d}t d|ti}d|d< t|| d S )NrQ   rU   rT   r"   rk   r  r   rL   r0   r   r   r   )	r   r  rg   r   r#   r   r   r$   r%   r  r*   r*   r+   )test_loc_setitem_frame_with_reindex_mixed  s    $z@TestLocBaseIndependent.test_loc_setitem_frame_with_reindex_mixedc                 C   st   t dddgddgtd}d|d< tjdddgdd	|jtdd
ddf< t dddgdddddgd}t|| d S )NrL   r0   rQ   r"   rk   r  r   r   r   r   r   rM   r   r   rm   rw   )r   r  rg   r   r#   r   r$   r%   ri   r*   r*   r+   *test_loc_setitem_frame_with_inverted_slice  s
    &zATestLocBaseIndependent.test_loc_setitem_frame_with_inverted_slicec           
      C   s   dd t dD }tjddd}dd t dD }tjddd}tt||}t|d}tj|d	< ||j|d	f< tj|d
< ||j|d
f< t	||tj
d}t	||d}t||dj|d}	t||	 d S )Nc                 S   s   g | ]}d t | qS @strr   ir*   r*   r+   r     s     zGTestLocBaseIndependent.test_loc_setitem_empty_frame.<locals>.<listcomp>rU   r   r   c                 S   s   g | ]}d t | qS r!  r#  r%  r*   r*   r+   r     s     rT   rw   r"   rk   r   rm   )r   rg   rh   r   setunionr   r  r#   r   r   reindexr$   r%   )
r7   Zkeys1Zval1keys2Zval2rf   r(   ZseraZserbr)   r*   r*   r+   test_loc_setitem_empty_frame  s    


z3TestLocBaseIndependent.test_loc_setitem_empty_framec                 C   s   t tjddtdtdd}|jd }d|jd< |jd }|dksJt|jd }|dks`td|jd d d	d
f< |jd d d	d
f }|jd d dd f }t	|| d S )NrT   ZabcdABCDr   r   r   rL   )r    r"   r   rk   r   )
r   rg   r   randnr   r   r#   rz   r$   r%   r   r*   r*   r+   test_loc_setitem_frame	  s     



z-TestLocBaseIndependent.test_loc_setitem_framec                 C   sT   t dddgtjd}|j|j|j|jkdf< t dddgtjd}t|| d S )NrL   r0   rQ   rm   rk   )r   rg   r  r"   r#   rk   r$   r%   ri   r*   r*   r+   /test_loc_setitem_frame_nan_int_coercion_invalid  s    zFTestLocBaseIndependent.test_loc_setitem_frame_nan_int_coercion_invalidc                 C   s   t ddgddgddgd}|jdddgf }tddgtddgtd	tdd
}t|| t ddgddgddgd}ddg|jdddgf< t|| d S )NrL   r0   rQ   rT   r    r   )rL   r0   r    r   r   rf   r   rv   rU   rR   )r   r#   r   r   r   r$   r   r%   r   r*   r*   r+   #test_loc_setitem_frame_mixed_labels"  s       z:TestLocBaseIndependent.test_loc_setitem_frame_mixed_labelsc                 C   s  t dddgttdtjdd}|jdd }|jd	d |_||jd	d< t dddgtdddgtjdd}t|| t t	d
dttdtjdd}t t
dt
dt
dt
dt
dgtd	dd	ddgtjdd}|jd	d }|jdd |_||jdd< t|| d S )Nr   r   bazrQ   r   rm   rL   r0   r   r   r   rU   r   Z20000101Z20000102Z20000103rT   )r   r   r   rg   r   r#   rf   r$   r%   r   r   )r7   r(   rhsr)   r*   r*   r+    test_loc_setitem_frame_multiples1  s:    z7TestLocBaseIndependent.test_loc_setitem_frame_multiplesr   r"   Nr   Zc                 C   sL   t ddgddggddgd}||jd|f< |jd	 }t|rD|d
ksHtd S )NrL   r0   rQ   rT   r"   rk   rt   r   )r   r"   r6  )r   r#   r   rz   )r7   r   r   r(   r   r*   r*   r+   "test_loc_setitem_with_scalar_indexV  s    	
z9TestLocBaseIndependent.test_loc_setitem_with_scalar_indexzindex,box,expectedr0   rk   r   rS   rQ   rT   rt   rL   r_   rU   rR   	   rP         c                 C   s<   t ddgddgddggddgd	}||j|< t|| d S )
NrL   r0   rQ   rT   rU   rR   r"   rk   rt   r   r#   r$   r%   )r7   rf   boxr)   r(   r*   r*   r+    test_loc_setitem_missing_columnse  s    5"
z7TestLocBaseIndependent.test_loc_setitem_missing_columnsc                 C   sZ   t dtddtjgi}|j}|jdg }t|j| |jdg }t|j| d S )Nr   r   UTCr   rL   )	r   r   tz_localizero   rp   dtypesr   r$   r   r   r*   r*   r+   test_loc_coercion  s    z(TestLocBaseIndependent.test_loc_coercionc                 C   s^   t dtdddtdddgi}|j}|jdg }t|j| |jdg }t|j| d S )Nr     rL   i  r0   r   )r   r   r@  r   r$   r   r   r*   r*   r+   test_loc_coercion2  s     z)TestLocBaseIndependent.test_loc_coercion2c                 C   sZ   t ddgd gd  i}|j}|jdd }t|j| |jdd  }t|j| d S )Ntextz
some wordsr8  r   r0   rQ   )r   r@  r   r$   r   r   r*   r*   r+   test_loc_coercion3  s    z)TestLocBaseIndependent.test_loc_coercion3c                 C   sf   t ddt ddg}t|ddgd}ttd}|d ||d< |d	 ||d< t|| d S )
N*   r>  i  r   r   rw   r   r   rL   )r   r?  r   r   r$   r   )r7   Z
indexer_slvalsr)   r  r*   r*   r+   test_setitem_new_key_tz  s    
z.TestLocBaseIndependent.test_setitem_new_key_tzc              	   C   s  t ddddddgddddddgd	d
dd
dddgd}d}tjt|d |jdd   W 5 Q R X d}tjt|d |jd
d   W 5 Q R X d}tjt|d |jdd  W 5 Q R X t ddddddgddddddgd	d
dd
dddgdjd
d}|jdd  }t ddddgddddgd	ddddgd}t|| |jd
d  }t|| |jdd }t dddgdddgd	dddgd}t|| d S )NrL   r0   rQ   rT   rU   rR   rS   r_   rm   r   rw   z5'Cannot get left slice bound for non-unique label: 1'r   z5'Cannot get left slice bound for non-unique label: 0'axis)r   r   r   r5   r#   
sort_indexr$   r%   )r7   r(   r   r   r)   r*   r*   r+   test_loc_non_unique  s6        *$z*TestLocBaseIndependent.test_loc_non_uniquez
length, l2  r   i 順 c              	   C   s   t d}tttj|t|t||dtt	|t|fdg| |dg}|j
jdksbtt|}|j| }t|dgtt	t|t|fdgt| |d||dd  g}t|| d S )NZABCDEFGr   r   FrL   )r   ro   concatr   rg   r   r.  r   rh   onesrf   Z	is_uniquerz   r#   taker$   r%   )r7   lengthl2re   r(   r   r   r)   r*   r*   r+    test_loc_non_unique_memory_error  s0     


z7TestLocBaseIndependent.test_loc_non_unique_memory_errorc                 C   s\   t ddgddgg}d|j_|jddg jj}|dks:t|jddg jj}|dksXtd S )NrL   Z
index_namer   )r   rf   rv   r   rz   r#   r7   r(   r   r*   r*   r+   test_loc_name  s    z$TestLocBaseIndependent.test_loc_namec                 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 )NrU   r0   r   T)check_index_typecheck_column_type)r$   ZmakeCustomDataframer%   r#   r   r   r*   r*   r+   !test_loc_empty_list_indexer_is_ok  s&             z8TestLocBaseIndependent.test_loc_empty_list_indexer_is_okc                 C   s  t ddddgi}|jd d  }||k	s,t|d d  |k	s@t|jd d d d f |k	s^tt|d j|d jsztdddg|jd d df< |r|d dddgk stn|d dk stt tjdd}|r|d |jd d df k	stn |d |jd d df kstt	dddddd	g}|jd d  }||k	sLt|d d  |k	sbtd
ddg|d d< |rt|d d dddgkstn t|d d d
ddgkstd S )Nr    rL   r0   rQ   rT   rP   r   rU   rR   rS   r_   r8  )
r   r#   rz   rg   Zshares_memory_valuesr   r   r.  r   )r7   using_copy_on_writeZoriginal_dfZ	sliced_dfr(   Zoriginal_seriesZsliced_seriesr*   r*   r+   &test_identity_slice_returns_new_object-  s,      "z=TestLocBaseIndependent.test_identity_slice_returns_new_objectc                 C   s   |st jjdd}|j| tttdtdddgd}| }|j	d d df }|d7 }t
|| | }|j	|jdf }|d7 }t
|| d S )Nz!accidental fix reverted - GH37497)reasonrQ   r    r   rt   r0   )r   r   ZxfailnodeZ
add_markerr   zipr   r   r#   r$   r%   rf   )r7   r8   r[  r   r   r   qzr*   r*   r+   test_loc_copy_vs_viewT  s    z,TestLocBaseIndependent.test_loc_copy_vs_viewc                 C   s   t dj}tddg|d |gd}|j|d  }|jd }||ksHt|j|d g }|jdg }t|| |j|d |g }t|| d S )Nr   rL   r0   rw   r   )	rg   iinfomaxr   r#   r   rz   r$   r   )r7   umaxr  r   r)   r*   r*   r+   test_loc_uint64h  s    
z&TestLocBaseIndependent.test_loc_uint64c              	   C   sr   t dj}tddg|d |gd}tjtdd |jd  W 5 Q R X tjtdd |jdg  W 5 Q R X d S )Nr   rL   r0   rw   z-1r   r   )rg   rc  rd  r   r   r   r5   r#   )r7   re  r  r*   r*   r+   !test_loc_uint64_disallow_negativey  s    z8TestLocBaseIndependent.test_loc_uint64_disallow_negativec                 C   sR   dddg}t |d gt| d}t ddgd}||jd d df< t|| d S NrL   r0   rQ   r   r   r   r   rt   )r   r   r#   r$   r%   r7   rl   r)   r(   r*   r*   r+   *test_loc_setitem_empty_append_expands_rows  s
    
zATestLocBaseIndependent.test_loc_setitem_empty_append_expands_rowsc                 C   sf   dddg}t |d gt| d}t ddgd}|d tj|d< ||jd d df< t|| d S rh  )r   r   r   rg   r   r#   r$   r%   rj  r*   r*   r+   6test_loc_setitem_empty_append_expands_rows_mixed_dtype  s    
zMTestLocBaseIndependent.test_loc_setitem_empty_append_expands_rows_mixed_dtypec                 C   sD   t dgtjgd}t ddgtd}|jd |jd< t|| d S )Nr   ri  r   r   re   r   )r   r   )r   rg   r  r  r#   r$   r%   r   r*   r*   r+   *test_loc_setitem_empty_append_single_value  s    zATestLocBaseIndependent.test_loc_setitem_empty_append_single_valuec              	   C   s   ddg}t ddgd}|jtj|_dt j d}tjt	|d ||j
d	dgdf< W 5 Q R X d
dddg}tjt|d ||j
d	ddf< W 5 Q R X d S )NrL   r0   r   r   rt   z"None of \[Index\(\[0, 1\], dtype='z'\)\] are in the \[index\]r   r   |z?cannot copy sequence with size 2 to array axis with dimension 0zCcould not broadcast input array from shape \(2,\) into shape \(0,\)z@Must have equal len keys and value when setting with an iterable)r   rf   r   rg   r   r   r   r   r   r5   r#   join
ValueError)r7   rl   r(   r   r*   r*   r+   $test_loc_setitem_empty_append_raises  s    z;TestLocBaseIndependent.test_loc_setitem_empty_append_raisesc                 C   sD   t ddgddgg}|jtd }tddgdd}t|| d S )NrL   r0   rQ   rT   r   ru   )r   r#   rg   r   r   r$   r   )r7   r(   r   r   r*   r*   r+   test_indexing_zerodim_np_array  s    z5TestLocBaseIndependent.test_indexing_zerodim_np_arrayc                 C   s,   t ddg}|jtd }|dks(td S )NrL   r0   r   )r   r#   rg   r   rz   )r7   r   r   r*   r*   r+   %test_series_indexing_zerodim_np_array  s    z<TestLocBaseIndependent.test_series_indexing_zerodim_np_arrayc                 C   sl   ddddddgd gd  }t |tddd	}t tddtjd
}ddddddg|jddd< t|| d S )NrL   r0   rQ   rT   rU   rR   i  i  rw   r   r   r   )r   r   rg   r   r#   r$   r   )r7   rl   r)   r   r*   r*   r+   test_loc_reverse_assignment  s
    z2TestLocBaseIndependent.test_loc_reverse_assignmentc                 C   s   t jd dd tdD }t|dgd}t|dgtd}t|| dd |D |j|j	df< t|dgt
dt}t|| d	d |D |d< t|dgt
d}t|| d S )
N   c                 S   s   g | ]}t tj d  qS )g-q=)r$  rg   r   )r   rD   r*   r*   r+   r     s     z^TestLocBaseIndependent.test_loc_setitem_str_to_small_float_conversion_type.<locals>.<listcomp>rU   r"   rt   rm  c                 S   s   g | ]}t |qS r*   r  r   r*   r*   r+   r     s     c                 S   s   g | ]}t |qS r*   rw  r   r*   r*   r+   r     s     )rg   r   seedr   r   r   r$   r%   r#   rf   r  r   )r7   Zcol_datar   r)   r*   r*   r+   3test_loc_setitem_str_to_small_float_conversion_type  s    zJTestLocBaseIndependent.test_loc_setitem_str_to_small_float_conversion_typec           	      C   s   t dddd}|jdk|jdk@ }ttjt|d|d}t	||}|j
tdd }|j
| }t|| |j
d	d  }|j
tdd }|d
d  }|jd |_|jd |_t|| d S )N1/1/2000z1/5/2000Z5minfreqr8  rW   rQ   rw   z1/4/2000r   )r   hourminuter   rg   r   r.  r   r$   get_objr#   r   ry   rf   
_with_freq)	r7   frame_or_seriesrngr   r9   r   r{   chunkr)   r*   r*   r+   test_loc_getitem_time_object  s    
z3TestLocBaseIndependent.test_loc_getitem_time_object
spmatrix_tZ
coo_matrixZ
csc_matrixZ
csr_matrixr   c                 C   s   dd l }t|j|}d\}}|tj|||d|d}tj|}td|}|j| j	}	|
 | }
t|	|
 |j| jj	}	t|t|dd}
t|	|
 d S )Nr   )rU   rS   r   r0   )Z
fill_value)scipy.sparsegetattrsparserg   eyer   from_spmatrixr   r#   rq   Ztoarrayr$   Zassert_numpy_array_equalr@  fullr   )r7   r  r   ZscipyZrowsr   Zspmatrixr(   Zitr_idxr   r)   r*   r*   r+   $test_loc_getitem_range_from_spmatrix  s    
z;TestLocBaseIndependent.test_loc_getitem_range_from_spmatrixc                 C   s<   t dtjddgtddi}|jddg }t|| d S )Nr"   r   r   r   rL   )r   ro   r   r   r#   r$   r%   rU  r*   r*   r+   ,test_loc_getitem_listlike_all_retains_sparse  s    zCTestLocBaseIndependent.test_loc_getitem_listlike_all_retains_sparsec                 C   s   ddl m} tj|d}|jtd }tdddddgdddddggtddd}t	|| |jtd jtd	 }tdddddggtddd}t	|| d S )
Nr   )r  rU   r0   r   r   r   r   rL   )
r  r  r   r  r  r#   r   r   r$   r%   )r7   r  r(   r   r)   r*   r*   r+   test_loc_getitem_sparse_frame  s     z4TestLocBaseIndependent.test_loc_getitem_sparse_framec                 C   s   t dddddgtddd}|jtd }t ddgtddd}t|| |jtd jtd }t ddgtddd}t|| d S )Nr   r   r   r   r0   rQ   )r   r   r#   r   r$   r   )r7   r   r   r)   r*   r*   r+   test_loc_getitem_sparse_series+  s    z5TestLocBaseIndependent.test_loc_getitem_sparse_seriesr#   r   c                 C   sV   t dddgdddggttd}t||d }tdddgttdd}t|| d S )Nr   r         ?r   r   r   )r   rv   )r   r   r  r  r   r$   r   )r7   r   r(   r   r)   r*   r*   r+   !test_getitem_single_row_sparse_df7  s     z8TestLocBaseIndependent.test_getitem_single_row_sparse_dfkey_typec                 C   sH   |dddg}|j d d |f }|j d d dddgf }t|| d S )Nr"   rk   r   )r#   r$   r%   )r7   float_framer  idxr   r)   r*   r*   r+   test_loc_getitem_iterable?  s    z0TestLocBaseIndependent.test_loc_getitem_iterablec                 C   sb   t tjjdd}tdddd|_|jtdd d d f }|jdd d d f }t	|| d S )NrP   rT   r   Z0srP   r   startperiodsr|  )
r   rg   r   normalr   rf   r#   r   r$   r%   r   r*   r*   r+   #test_loc_getitem_timedelta_0secondsF  s
    z:TestLocBaseIndependent.test_loc_getitem_timedelta_0secondsval,expected                c                 C   s4   t ddgddgd}|j| }||_t|| d S )NrL   r0   r  r  rw   )r   r#   rv   r$   r   )r7   r   r)   r(   r   r*   r*   r+   test_loc_getitem_uint64_scalarN  s    
z5TestLocBaseIndependent.test_loc_getitem_uint64_scalarc                 C   sP   |}t dddgtdddg|dd}| }d	|jd< d	|jd
< t|| d S )Nr    r   r<   r         ?rL   r   rw   Zzoor0   )r   r   r   r#   r   r$   r   )r7   float_numpy_dtyper   r  r)   r*   r*   r+   +test_loc_setitem_int_label_with_float_indexY  s     

zBTestLocBaseIndependent.test_loc_setitem_int_label_with_float_indexzindexer, expectedrB   c                 C   s\   t tddd}tdtdid|d}d|j|j| df< t||dgdd}t|| d S )	NrP   r   r  r   r   r   rf   rB   r  )r   r   r   r#   rf   r$   r%   )r7   r   r)   tdir(   r*   r*   r+   /test_loc_setitem_listlike_with_timedelta64indexd  s    zFTestLocBaseIndependent.test_loc_setitem_listlike_with_timedelta64indexc                 C   s   t dddddgtdd}t dddddgtdd}tddgddgd|jdddf< tddgddgd|jdd	df< t|| d S )
NrL   Zaaaaar   r   Zaabbar    
categoriesr0   rQ   )r   r   r	   r#   r$   r%   )r7   r(   r{   r*   r*   r+   8test_loc_setitem_categorical_values_partial_column_slice~  s
    ""zOTestLocBaseIndependent.test_loc_setitem_categorical_values_partial_column_slicec                 C   s   t dgdgd}t|d dddgd}||jd d df< |d }t||jddt}t|| ||d< t|d t|dd	 d S )
Nr    r   )AlphaZNumericr  r   r<   r  r   ru   )	r   r	   r#   r   rf   r   r   r$   r   )r7   r(   r  r   r)   r*   r*   r+   'test_loc_setitem_single_row_categorical  s    z>TestLocBaseIndependent.test_loc_setitem_single_row_categoricalc                 C   s   t dtdgd i}td|jdddf< td|jd ksDttd|jd ksZttd	d
d
|jd< td |jd kstd S )Nr<   z
2010-10-01rQ   z
2008-08-08r   rL   )r   r<   )rL   r<   i  rU   )r0   r<   z
2005-05-05)r   r   rg   r  r#   rz   r   r   r*   r*   r+   "test_loc_setitem_datetime_coercion  s    z9TestLocBaseIndependent.test_loc_setitem_datetime_coercionidxervarc                 C   sX   |}t ddd|d}td|dgd}t|dgtjd}||jd d |f< t|| d S )	Nz
2015-07-12rQ   H)r  r  r|  tzr   r  r   r  )r   r   rg   r   r#   r$   r%   )r7   r  Ztz_naive_fixturer  r  r)   r   r*   r*   r+   !test_loc_setitem_datetimeindex_tz  s    z8TestLocBaseIndependent.test_loc_setitem_datetimeindex_tzc           
      C   s|  t dddd}ttjt|d|d}tddd}ttd	ddtd
dd}ddddg}ddddddddddddg}| }d|j	|< |j	| }|j	|  }	d|	j	d d < |r|	
t}	t||	 | }d|j	|< |j| |j	|< t|| | }d|j	|< |j	| }|j	|  }	d|	j	d d < |r>|	
t}	t||	 | }d|j	|< |j| |j	|< t|| d S )Nz
2012-01-01z
2012-01-05Z30minr{  rU   rw   r:  r   rv        H   x               J   K   L   z   {   |            )r   r   rg   r   r.  r   r   r   r   r#   r   r  r$   r%   r   )
r7   Zusing_array_managerrf   r(   ZakeyZbkeyZaindsZbindsr   r)   r*   r*   r+   test_loc_setitem_time_key  s<    







z0TestLocBaseIndependent.test_loc_setitem_time_keyrH   c                 C   s   t dddg}tdddgddd	gg|d
}| }tjddd|jd d |f< tdddgdddgg|d
}t|| |j	dd}tjddd|jd d |f< |j	dd}t|| d S )N)r"   rT   )rk   3)r"   2rL   r0   rQ   rT   rU   rR   rt   )r0   r0   r   r   r   rI  )
r   from_tuplesr   r   rg   zerosr#   r$   r%   rK  )r7   rH   r	  r(   r9   r)   r*   r*   r+   ,test_loc_setitem_unsorted_multiindex_columns  s    zCTestLocBaseIndependent.test_loc_setitem_unsorted_multiindex_columnsc                 C   s>   t dddg|d}d|jd< t dddg|d}t|| d S )NrL   r0   rQ   r   rT   r   r   r#   r$   r   )r7   Zany_int_numpy_dtyper'   r)   r*   r*   r+   test_loc_setitem_uint_drop  s    
z1TestLocBaseIndependent.test_loc_setitem_uint_dropc                 C   sp   t dtddg }tdd|jdddg< t dtddg }ttdd|jdddg< t|| d S )NrP   r  rB   rL   r0   rQ   )r   rg   timedelta64r#   r   r$   r   )r7   r  r)   r*   r*   r+   test_loc_setitem_td64_non_nano  s
    z5TestLocBaseIndependent.test_loc_setitem_td64_non_nanoc              	   C   s   t jdd}ttd}dddg}tjt|d ||j	td< W 5 Q R X d}tjt|d ||j	d d < W 5 Q R X d S )Nr0   ro  z,shape mismatch: value array of shape \(2,2\)z0cannot reshape array of size 4 into shape \(2,\)r   zEcould not broadcast input array from shape \(2,2\) into shape \(2,?\))
rg   r   r.  r   r   rp  r   r   rq  r#   )r7   rl   r  r   r*   r*   r+    test_loc_setitem_2d_to_1d_raises  s    z7TestLocBaseIndependent.test_loc_setitem_2d_to_1d_raisesc                 C   sX   t jddd}tdddgdddgd	d
dgg|dddgd}d}|jd }t|| d S )Nr   rQ   )r  r  rL   r0   rT   rU   rR   rS   r_   r8  r"   rk   r   r   )r  r"   )ro   interval_ranger   r#   r$   assert_almost_equal)r7   rf   r(   r)   r   r*   r*   r+   test_loc_getitem_interval_index  s      
z6TestLocBaseIndependent.test_loc_getitem_interval_indexc                 C   sz   t jdddd}tdddgddd	gd
ddgg|dddgd}t jddddd}tddg|dd}|jd }t|| d S )Nr   rQ   Zboth)r  r  closedrL   r0   rT   rU   rR   rS   r_   r8  r"   rk   r   r   )r  r  r|  r  r   rL   r"   )ro   r  r   r   r#   r$   r   )r7   rf   r(   Z	index_expr)   r   r*   r*   r+    test_loc_getitem_interval_index2  s      
z7TestLocBaseIndependent.test_loc_getitem_interval_index2tplrL   rL   r0   c                 C   sR   t ddgddd}t|d}|j|g }t |gddd}t|d}t|| d S )Nr  r  r"   Frv   Ztupleize_colsrw   )r   r   r#   r$   r%   )r7   r  r  r(   r   r)   r*   r*   r+   +test_loc_getitem_index_single_double_tuples  s    

zBTestLocBaseIndependent.test_loc_getitem_index_single_double_tuplesc                 C   sn   t dddg}|dd}|dd}t||gdd	d
}tddg|ddgd}|j|dd d }|dksjtd S )N	IndexTyper    r   r   r   r3  ZbofZcomposite_indexFr  r  )rQ   rT   r"   rk   r   rL   )r   r   r   r#   rz   )r7   r  Zidx1Zidx2rf   r(   r   r*   r*   r+   !test_loc_getitem_index_namedtuple)  s    

z8TestLocBaseIndependent.test_loc_getitem_index_namedtuplec                 C   s   t tjdddddddgdd	d
gd}d|d< tj|j|jd d d df< tjtjdtjdtjgtd}t	
|d j| d S )NrU   rQ   r    r   r<   r   r   r   r   r3  r   quxr$  r0   r   )r   rg   r   r.  r  r#   rf   r   r   r$   r  rq   ri   r*   r*   r+   $test_loc_setitem_single_column_mixed3  s    z;TestLocBaseIndependent.test_loc_setitem_single_column_mixedc                 C   sp   t tjddtdd}tj|d< d|jd< |j}tt	dgd t	d	g d
dddgd}t
|| d S )NrW   rQ   ABCrt   eventr   )rP   r  r   r   r"   rk   r   rw   )r   rg   r   r   tupler  r#   r@  r   r   r$   r   r   r*   r*   r+   test_loc_setitem_cast2>  s    


z-TestLocBaseIndependent.test_loc_setitem_cast2c                 C   sb   t dtjdtjdi}d|jd< |jjttjks:ttd|_|jjttjks^td S )NonerR   r   )rL   r  rS   )	r   rg   rh   Zint8r#   r@  r  r   rz   r   r*   r*   r+   test_loc_setitem_cast3K  s
    
z-TestLocBaseIndependent.test_loc_setitem_cast3c                 C   st   |t ddddddgd}dd	d
g}|jdkr>dgd	gd
gg}||jt d< |ddd	dd
g|jd}t|| d S )NrU   rQ   rT   rL   r   r0   rw   r8  rP   r9  )r   ndimr#   rf   r$   ry   )r7   r  r9   rq   r)   r*   r*   r+   test_loc_setitem_range_keyS  s    

z1TestLocBaseIndependent.test_loc_setitem_range_key)jr~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   fixturer   rg   r   r   r   r   r   r   r   r
  r  r  r  r  r   r+  r/  r0  r2  r5  r   r7  r   r  r=  rA  rC  rE  rH  rL  Zarm_slowrT  rV  rY  r\  rb  rf  rg  rk  rl  rn  rr  rs  rt  ru  ry  r  r   complextdZskip_if_no_scipyr  r  r  r  r  iterr   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      sf  

#
'
*
1

% $
	
(
	 $
	$
	  3
""
'



 
 

		
&


r   c                   @   sN   e Zd Zejejejgddd Zejdd Z	dd Z
dd	 Zd
d ZdS )TestLocWithEllipsis)paramsc                 C   s   |j S rZ   )param)r7   r8   r*   r*   r+   r   b  s    zTestLocWithEllipsis.indexerc                 C   s   |}|t k	r| }|S rZ   )r   to_frame)r7   series_with_simple_indexr  r9   r*   r*   r+   r9   g  s    zTestLocWithEllipsis.objc                 C   s   ||d }t || d S )N.)r$   ry   )r7   r9   r   r   r*   r*   r+   test_loc_iloc_getitem_ellipsisn  s    z2TestLocWithEllipsis.test_loc_iloc_getitem_ellipsisc           
   	   C   s  |}|t jkst|dkrdn|jd }|t jkr@t|jr@d S |t jkrt|jtrd}tj	t
|d ||d|gf }W 5 Q R X n8t|dkr||d|gf }|||g }t || |t jkrdn|j}| }	||	d|gf }||	d d |gf }t || d S )Nr   z2MultiIndex does not support indexing with Ellipsisr   .)r$   r   r   rf   r#   r   rx   r   r   r   NotImplementedErrorr   rv   r  r%   )
r7   r  r   r9   rH   r   r   r)   key2r(   r*   r*   r+   &test_loc_iloc_getitem_leading_ellipsesr  s"    $z:TestLocWithEllipsis.test_loc_iloc_getitem_leading_ellipsesc              	   C   s   |t jkst|dkrdn|jd }tjttd ||d  W 5 Q R X tjttd ||d|gdf  W 5 Q R X tjttd ||dd|f  W 5 Q R X tjtdd |||ddf  W 5 Q R X d S )Nr   r   )...Too many indexers)r$   r   r   rf   r   r   r   r   )r7   r9   r   rH   r*   r*   r+   0test_loc_iloc_getitem_ellipses_only_one_ellipsis  s    $zDTestLocWithEllipsis.test_loc_iloc_getitem_ellipses_only_one_ellipsisN)r~   r   r   r   r  r$   r#   r   r   r9   r  r  r  r*   r*   r*   r+   r  a  s   

r  c                   @   s  e Zd Zejdddgddddgddddggfddgddddgddddggfddgddgfddddgddddggfddgddgfddddgddddggfddgddgfddddgddddggfddgddgfddddgddddggfddgddgfdddgdddggfgejddd	gd
d Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zejd ejejd!ejfd"d# Zd$d% Zejd&d'd(gd)d* Zd+d, Zd-d. Zd!S )/TestLocWithMultiIndexzkeys, expectedr   r    rL   r0   r<   dimrf   re   c                 C   s   |dddddgdddddggi}t tdddf|}t|}|dkrn|j|d d f }t|j	| n(|d	kr|jd d |f }t|j
| d S )
Nr<   r    r   rL   r0      rU   rf   re   )r   rg   rh   reshaper   r  r#   r$   assert_index_equalrf   re   )r7   r  keysr)   kwargsr(   	exp_indexr|   r*   r*   r+   'test_loc_getitem_multilevel_index_order  s     
z=TestLocWithMultiIndex.test_loc_getitem_multilevel_index_orderc                 C   s   |}|j d }|d j d }|jj|jjdd  ks8t|jj|jjdd  ksTt|j d }|d j d }|jj|jjd kst|jj|jjd kstd S )N  r"   rL   )r  r0   r0   )r#   rf   r  rz   rv   )r7   Z/multiindex_year_month_day_dataframe_random_dataZymdr   result2r*   r*   r+   test_loc_preserve_names  s    

z-TestLocWithMultiIndex.test_loc_preserve_namesc                 C   sf   t dgddgg}td|d}|jg  }|d d }t|| |j|jdd  }t|| d S )Nr   rL   rw   )r   from_productr   r#   r$   r   r   )r7   r	  r  r|   r)   Zres2r*   r*   r+   .test_loc_getitem_multiindex_nonunique_len_zero  s    
zDTestLocWithMultiIndex.test_loc_getitem_multiindex_nonunique_len_zeroc                 C   s   t d gtdgdgg}|jd }|d ks0ttdgddgg}t d gt| t|d}|jd }|d ksrtt dgt| t|d}|jd }|dkstd S )	NLevel1Level2)r  r  Level2_aZLevel2_br  )r  r  rL   )r   r   r  r#   rz   r   r   r   )r7   r  r   Zmidxr*   r*   r+   0test_loc_getitem_access_none_value_in_multiindex  s    


zFTestLocWithMultiIndex.test_loc_getitem_access_none_value_in_multiindexc                 C   s   t jtddddddddgddddddddgddgd	}td
d
d
d
d
d
d
d
g|d}d|jdd< td
d
ddddd
d
g|d}t|| d S )Nr   r3  r   r  r  twofirstsecondr   rL   rw   r   )r3  r  )r   r  )r   r  r_  r   r#   r$   r   )r7   rf   r   r)   r*   r*   r+   !test_loc_setitem_multiindex_slice  s    z7TestLocWithMultiIndex.test_loc_setitem_multiindex_slicec                 C   sJ   t dddd}ttd|}|jtdddtddd }t|| d S )Nr   Z10minrN  r|  r  il  rL   i4  )r   r   r   r#   r   r$   r   )r7   timesr  r   r*   r*   r+   7test_loc_getitem_slice_datetime_objs_with_datetimeindex  s    zMTestLocWithMultiIndex.test_loc_getitem_slice_datetime_objs_with_datetimeindexc                 C   sh   t tdtddtddd}|jddgddgf }t d	d
gd	d
gdtddgd}t|| d S )NrP   r   z
2010-01-01z
2010-01-10rw   z
2010-01-05r    r   r   rT   )r   r   r   r#   r   r$   r%   r   r*   r*   r+   3test_loc_getitem_datetime_string_with_datetimeindex  s    
zITestLocWithMultiIndex.test_loc_getitem_datetime_string_with_datetimeindexc                 C   s   t jddddddgddgd}tddgdd	gd
dgddgddgddgg|ddgd}|jdd}tddgdd	gddggddg|dddgd}|jd }t|| d S )N)r   r   )ZbahZbamr"   rk   r   r   rL   r   r0   rM   rQ         @rT         @rU         @rR   r   r   r   r   )levelrd   )r   r  r   rK  rQ  r#   r$   r%   )r7   r	  r(   r)   r   r*   r*   r+   3test_loc_getitem_sorted_index_level_with_duplicates  s:      
zITestLocWithMultiIndex.test_loc_getitem_sorted_index_level_with_duplicatesc                 C   s@   t dddgdd}d|jd< t ddddgdd}t|| d S )	Nr    r   r<   categoryr   r   rQ   r   r  r7   r   r)   r*   r*   r+   1test_additional_element_to_categorical_series_loc*  s    
zGTestLocWithMultiIndex.test_additional_element_to_categorical_series_locc                 C   s@   t dddgdd}d|jd< t ddddgdd}t|| d S Nr    r   r<   r  r   rQ   r  r  r*   r*   r+   'test_additional_categorical_element_loc1  s    
z=TestLocWithMultiIndex.test_additional_categorical_element_locc                 C   s   t dddgttdddg|dd}tj|jd< t dddtjgttdddg|dd}t|| tj|jd< t dtjdtjgttdddg|dd}t|| d S )NrL   r0   rQ   r   )r   r
   r   rg   r  r#   r$   r   )r7   Zany_numeric_ea_dtypeZsrsr)   r*   r*   r+   &test_loc_set_nan_in_categorical_series8  s     z<TestLocWithMultiIndex.test_loc_set_nan_in_categorical_seriesnaNc                 C   sj   t dddgdd}||jd< t ddddgdd}||jd< t|| t ddd|gdd}t|| d S r  r  )r7   r  Zsrs_enlargeZsrs_setintor)   r*   r*   r+   ,test_loc_consistency_series_enlarge_set_intoM  s    

zBTestLocWithMultiIndex.test_loc_consistency_series_enlarge_set_intoc                 C   s   t tdddttddgtdgdgd dgd  tdgd	d
gdd}tddgddgdd	dd}|jjd }t	|| |j
dg jjd }t	|| d S )Nr0      r    r   rP   r   rU   rL   ZIndex1ZIndex2)r  codesr  )rl   rf   Fr  )r  orderedrv   r   )r   rg   rh   r   r   r   rf   r  r$   r  r#   r   r*   r*   r+   5test_loc_getitem_preserves_index_level_category_dtypeZ  s&    	zKTestLocWithMultiIndex.test_loc_getitem_preserves_index_level_category_dtypelt_valuerW   rP   c              	   C   sp   t dddddgitdddd	d
ggd}tjtdd0 |j|d |k d d f jdgd d f  W 5 Q R X d S )Nr    r:     "   -   aabbr   rL   r0   rQ   rw   z\['b'\] not in indexr   r   )r   r   r   r   r5   r#   )r7   r  r(   r*   r*   r+   >test_loc_multiindex_levels_contain_values_not_in_index_anymores  s    (zTTestLocWithMultiIndex.test_loc_multiindex_levels_contain_values_not_in_index_anymorec                 C   sl   t t jt jg}ddg}t||g}tddg|d}|jd d df }tdgt jgd}t|| d S )Nr   r3  r   rL   rw   )	rg   r   r  r   r  r   r#   r$   r   )r7   lev1lev2r	  r  r   r)   r*   r*   r+   'test_loc_multiindex_null_slice_na_levelz  s    z=TestLocWithMultiIndex.test_loc_multiindex_null_slice_na_levelc                 C   st   t jtdtdddggdddgd}ttd|d}|jd	d d d d f }|jd
d d }t	|j| d S )NabZxyrL   r0   numr   r_   rw   r    r   rT   )
r   r   r   r   r   r#   rf   Z	droplevelr$   r  )r7   r	  r  Z
loc_resultr)   r*   r*   r+   test_loc_drops_level  s     z*TestLocWithMultiIndex.test_loc_drops_level)r~   r   r   r   r   r   r  r  r  r  r	  r  r  r  r  r  r  rg   r  ro   ZNArp   r  r  r$  r'  r*  r*   r*   r*   r+   r    s<   &&&&""

r  c                	   @   s   e Zd Zejjdd Zdd Zdd Zdd Z	d	d
 Z
ejjddd dd dd dd gddddgddd Zdd Zdd Zdd Zdd Zejd d!d" Zejd#d$d%d&d'd(d)gd*d+ Zd,S )-TestLocSetitemWithExpansionc                 C   sN   t dtdidd}t|d |jt|< t dtdidd}t|| d S )Nr   i@B r   r   rL   iAB )r   r   r   r#   r$   r%   r  r*   r*   r+   /test_loc_setitem_with_expansion_large_dataframe  s    zKTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_large_dataframec                 C   sV   t td}d|jd< t|t dgdgd d|jd< t|t ddgddgd d S )Nr   rL   rw   rQ   r   r   r#   r$   r   r7   r  r*   r*   r+   test_loc_setitem_empty_series  s
    


z9TestLocSetitemWithExpansion.test_loc_setitem_empty_seriesc                 C   sV   t td}d|jd< t|t dgdgd d|jd< t|t ddgddgd d S )Nr   r   rL   rw   rM   rQ   r-  r.  r*   r*   r+   #test_loc_setitem_empty_series_float  s
    


z?TestLocSetitemWithExpansion.test_loc_setitem_empty_series_floatc                 C   s   t td}d|jd< t|t dgdgd d|jd< t|t ddgddgd d|jd< t|t dddgdddgd d S )Nr   rL   r   rw   rQ   r   rT   r-  r.  r*   r*   r+   %test_loc_setitem_empty_series_str_idx  s    



zATestLocSetitemWithExpansion.test_loc_setitem_empty_series_str_idxc                    sn   t dddtdd  fddtdD }td	g|d	 gd
}|D ]}d|j|< qBtd|d
}t|| d S )Nr   r9  rL   
US/Pacific)tzinfoc                    s   g | ]} t |d  d qS )rM  )seconds)r   r%  baser*   r+   r     s     zUTestLocSetitemWithExpansion.test_loc_setitem_incremental_with_dst.<locals>.<listcomp>   r   rw   )r   r   r   r   r#   r$   r   )r7   Zidxsr   rA   r)   r*   r5  r+   %test_loc_setitem_incremental_with_dst  s    zATestLocSetitemWithExpansion.test_loc_setitem_incremental_with_dstconvc                 C   s   | S rZ   r*   r   r*   r*   r+   r     r   z$TestLocSetitemWithExpansion.<lambda>c                 C   s   |   S rZ   )to_datetime64r   r*   r*   r+   r     r   c                 C   s   |   S rZ   )to_pydatetimer   r*   r*   r+   r     r   c                 C   s
   t | S rZ   )rg   r  r   r*   r*   r+   r     r   r7   r:  r;  znp.datetime64)idsc                 C   sb   t d}t d}t }d|j||df< d|j||df< tdddgi||gd}t|| d S )	Nz20130101 09:00:00z20130101 10:00:00r   r  ra   g      Y@g      i@rw   )r   r   r#   r$   r%   )r7   r9  Zdt1Zdt2r(   r)   r*   r*   r+   #test_loc_setitem_datetime_keys_cast  s    z?TestLocSetitemWithExpansion.test_loc_setitem_datetime_keys_castc                 C   sT   t ddgi}tdg|d|jd d df< t dgtdg|dd}t|| d S )Nr"   rL   r   )r  rk   rm   )r   r	   r#   r$   r%   )r7   r  r   r)   r*   r*   r+   1test_loc_setitem_categorical_column_retains_dtype  s    zMTestLocSetitemWithExpansion.test_loc_setitem_categorical_column_retains_dtypec                 C   s   t ddd}t ddd}t ddd}t||ddd}||ks@tt|d	gd
}d|j|d	f< ttjgt| dg |t	|gd	gt
d}t|| d S )Nz2017-10-29 00:00:00+0200zEurope/Madridr  z2017-10-29 03:00:00+0100z2016-10-10 03:00:00leftr  )Z	inclusiver|  r   r   r:  r  )r   r   rz   r   r#   rg   r  r   appendr   r   r$   r%   )r7   r  endrA   r  r   r)   r*   r*   r+   0test_loc_setitem_with_expansion_and_existing_dst  s    zLTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_and_existing_dstc                 C   s   t tddgdgd}ddg|d< |djd|_||jdk djd	}| }||j	|jdkdf< t
|d
 d|j	d gdd}t|j| |j	|jdkdf td }||j	|jdkdf< t|j	|jdkdf | d S )Nz2015-03-30 20:12:32z2015-03-12 00:11:11r   )rl   re   newoldnew_colr>  r2  r   )rL   r   ru   Z1s)r   r   r   rf   r?  r   rF  Z
tz_convertr   r#   r   r$   r   r   )r7   r(   vrr   r)   r*   r*   r+   test_setitem_with_expansion  s    
 z7TestLocSetitemWithExpansion.test_setitem_with_expansionc                 C   sV   t  }d|jd< d|jd< d|jdtjf< |j}tddtjgtjd}t|| d S )NrL   r-  r0   )rL   rL   rQ   r   r   )	r   r#   rg   infre   r   r   r$   r  r   r*   r*   r+   0test_loc_setitem_with_expansion_inf_upcast_empty
  s    

zLTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_inf_upcast_emptyz"ignore:indexing past lexsort depthc                 C   s`  t |sd S |d}t |}t|tj}t||dgd}d}||ksPt|t ||}t	|t
r|d d |kstn|d |kstt|d tj}t||dgd}| }	||	j|df< t|	| | d }
||
j|< |d tj}t|
| | }	||	j|df< tt|tjg tjg| t|g d|d}t|	| d S )	Nr0   r   r   Zkapowr   rL   r   rL   rw   )r   repeatrg   rh   r   r   r   rz   insertrx   r   r   r   r#   r$   r%   r   r   r  r  )r7   rf   NarrorigrH   r  Zexp_datar)   r(   r  r*   r*   r+   /test_loc_setitem_with_expansion_nonunique_index  s8    


&zKTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_nonunique_indexr   ZInt32Int64ZUInt32ZUInt64ZFloat32ZFloat64c                 C   sv   t ddddg|d}td|i}t|jd}||j|jdf< t|| t|jd}|j|j|jdf< t|| d S )Nr   rL   r0   rQ   r   rl   rw   )r   r   rf   r#   r$   r%   rZ  )r7   r   r  r(   r   r*   r*   r+   6test_loc_setitem_with_expansion_preserves_nullable_intC  s    zRTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_preserves_nullable_intN)r~   r   r   r   r   Zslowr,  r/  r0  r1  r8  r   r=  r>  rC  rH  rJ  filterwarningsrQ  rS  r*   r*   r*   r+   r+    s6   








- r+  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestLocCallablec                 C   s  t ddddgtdddddgd}|jdd  }t||j|jdk  |jd	d d d f }t||j|jd
kd d f  |jdd dd f }t||j|jdkdddgf  |jdd dd f }t||j|jdkdf  |jdd dd f }t||j|jdkddgf  |jdd dd f }t||j|jdkddgf  |jdd dd f }||jd kstd S )NrL   r0   rQ   rT   r#  r"   rk   r   c                 S   s
   | j dkS Nr0   r"   r   r*   r*   r+   r   \  r   zATestLocCallable.test_frame_loc_getitem_callable.<locals>.<lambda>c                 S   s
   | j dkS )Nr   )rk   r   r*   r*   r+   r   _  r   r   c                 S   s
   | j dkS rW  rX  r   r*   r*   r+   r   b  r   c                 S   s
   | j dkS Nrk   rt   r   r*   r*   r+   r   b  r   FTc                 S   s
   | j dkS rW  rX  r   r*   r*   r+   r   e  r   c                 S   s   dS rY  r*   r   r*   r*   r+   r   e  r   rk   c                 S   s
   | j dkS rW  rX  r   r*   r*   r+   r   h  r   c                 S   s   ddgS Nr"   rk   r*   r   r*   r*   r+   r   h  r   r"   c                 S   s
   | j dkS rW  rX  r   r*   r*   r+   r   k  r   c                 S   s   ddgS rZ  r*   r   r*   r*   r+   r   k  r   c                 S   s   dS )NrL   r*   r   r*   r*   r+   r   o  r   c                 S   s   dS r!   r*   r   r*   r*   r+   r   o  r   r  )	r   r   r#   r$   r%   r"   rk   r   rz   r7   r(   r|   r*   r*   r+   test_frame_loc_getitem_callableV  s    $ "  z/TestLocCallable.test_frame_loc_getitem_callablec                 C   s   t ddddgtdddddgd}|jdd d	d
gf }t||j|jdkd	d
gf  |jddgdd f }t||jddgd	d
gf  |jddd f }t||jdd	d
gf  d S )NrL   r0   rQ   rT   r#  rV  c                 S   s
   | j dkS rW  rX  r   r*   r*   r+   r   v  r   zITestLocCallable.test_frame_loc_getitem_callable_mixture.<locals>.<lambda>r"   rk   c                 S   s   ddgS rZ  r*   r   r*   r*   r+   r   y  r   c                 S   s   ddgS rZ  r*   r   r*   r*   r+   r   |  r   )r   r   r#   r$   r%   r"   r   r[  r*   r*   r+   'test_frame_loc_getitem_callable_mixturer  s    $ z7TestLocCallable.test_frame_loc_getitem_callable_mixturec                 C   s  t ddddgtddtdd}|jd	d
  }t||jddg  |jdd
 d d f }t||jddgd d f  |jdd
 dd
 f }t||jddgdf  |jdd
 dd
 f }t||jddgdgf  |jddgdd
 f }t||jddgdf  |jddgdd
 f }t||jddgdgf  |jdd
 df }t||jddgdf  |jdd
 dgf }t||jddgdgf  d S )NrL   r0   rQ   rT   r#  Xr  r,  rw   c                 S   s   ddgS Nr"   r   r*   r   r*   r*   r+   r     r   zHTestLocCallable.test_frame_loc_getitem_callable_labels.<locals>.<lambda>r"   r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   dS Nr_  r*   r   r*   r*   r+   r     r   r_  c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   dgS ra  r*   r   r*   r*   r+   r     r   c                 S   s   dS ra  r*   r   r*   r*   r+   r     r   c                 S   s   dgS ra  r*   r   r*   r*   r+   r     r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   )r   r   r#   r$   r%   r   r[  r*   r*   r+   &test_frame_loc_getitem_callable_labels  s"    "z6TestLocCallable.test_frame_loc_getitem_callable_labelsc                 C   sZ  t ddddgtddtdd}| }d	|jd
d < | }d	|jddg< t|| | }d|jdd d d f< | }d|jddgd d f< t|| | }d|jdd dd f< | }d|jddgdf< t|| | }ddg|jdd dd f< | }ddg|jddgdgf< t|| | }tddg|jddgdd f< | }tddg|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|jdd dgf< | }d|jddgdgf< t|| d S )NrL   r0   rQ   rT   r#  r^  r,  rw   ic                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   zATestLocCallable.test_frame_loc_setitem_callable.<locals>.<lambda>r"   r   rB   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   dS ra  r*   r   r*   r*   r+   r     r   r_  rU   rP   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   dgS ra  r*   r   r*   r*   r+   r     r   r   c                 S   s   dS ra  r*   r   r*   r*   r+   r     r   c                 S   s   dgS ra  r*   r   r*   r*   r+   r     r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   c                 S   s   ddgS r`  r*   r   r*   r*   r+   r     r   )r   r   r   r#   r$   r%   rg   r   )r7   r(   r|   r{   r*   r*   r+   test_frame_loc_setitem_callable  sR    " z/TestLocCallable.test_frame_loc_setitem_callableN)r~   r   r   r\  r]  rb  rd  r*   r*   r*   r+   rU  U  s   rU  c                   @   sF   e Zd Zdd Zdd Zdd Zdd Zej	d	d
dgdd Z
d
S )TestPartialStringSlicingc                 C   sd   t dddgdddgdtdd	d
gd}t ddgddgdtdd
gd}|jd }t|| d S )Nr    r   r<   rL   r0   rQ   )rb   rc   z
2020-08-01z
2020-07-02z
2020-08-05rw   z2020-08)r   r   r#   r$   r%   r   r*   r*   r+   5test_loc_getitem_partial_string_slicing_datetimeindex  s    

zNTestPartialStringSlicing.test_loc_getitem_partial_string_slicing_datetimeindexc                 C   sD   t jdddd}| }|jd d }|jd d }t|| d S )N
2017-01-01
2018-01-01r  r  rB  r|  z2017-12r   )ro   period_range	to_seriesr#   r   r$   r   )r7   pir  r   r)   r*   r*   r+   8test_loc_getitem_partial_string_slicing_with_periodindex  s
    zQTestPartialStringSlicing.test_loc_getitem_partial_string_slicing_with_periodindexc                 C   sB   t dddd}| }|jd d }|jd d }t|| d S )N1 day2 days1Hri  z1 daysr   )r   rk  r#   r   r$   r   )r7   r   r  r   r)   r*   r*   r+   ;test_loc_getitem_partial_string_slicing_with_timedeltaindex  s
    zTTestPartialStringSlicing.test_loc_getitem_partial_string_slicing_with_timedeltaindexc                 C   sD   t dtdittdddd}|jd }|jd }t|| d S )Nr   rQ   daysr  rw   r   0 days)r   r   r   r   r#   r$   r   )r7   r(   r)   Zslicedr*   r*   r+   #test_loc_getitem_str_timedeltaindex  s     

z<TestPartialStringSlicing.test_loc_getitem_str_timedeltaindexindexer_endN2020-01-02 23:59:59.999999999c              	   C   s   |dgd t tdtdtdtdtdg|dd	}|dgd
 t tdtdg|dd	}td|}|| }t|| |j| }t|| d S )NrL   rU   z
2019-12-30z
2020-01-01z
2019-12-25rv  z
2019-12-19r?  rw   r0   )r   r   r   r$   ry   r#   )r7   Ztz_aware_fixtureru  r  r9   r)   r   r   r*   r*   r+   /test_loc_getitem_partial_slice_non_monotonicity  s4    


zHTestPartialStringSlicing.test_loc_getitem_partial_slice_non_monotonicity)r~   r   r   rf  rm  rq  rt  r   r   r   rw  r*   r*   r*   r+   re    s   re  c                
   @   s   e Zd Zdd Zdd Zejdej	dddd	e
d
ddd	gdd Zdd Zdd Zejdedddeddgeddeddeddgdeddeddggdd Zejd d!d"gd#d$ Zejd%dd&gd'd( Zd)d* ZdS )+TestLabelSlicingc                 C   s  t tjddddd dD d}t tjdddd	d d
D d}||fD ]}|jtddddd  }t|| |jd tdddd }t|| |jtddddtdddd }t|| |jtddddd  }|jdd  }t|| |jdd  }t|| qHd S )Nr  r   r   c                 S   s   g | ]}t d d|ddqS   rL   rP   r   r   r%  r*   r*   r+   r   %	  s     zMTestLabelSlicing.test_loc_getitem_slicing_datetimes_frame.<locals>.<listcomp>)rL   r0   rQ   rT   rw   r  c                 S   s   g | ]}t d d|ddqS ry  r{  r%  r*   r*   r+   r   +	  s     )rL   r0   r0   rQ   rT   rz  rL   rP   rT   r9  z20010101 11)r   rg   rh   r#   r   r$   r%   r   )r7   Z	df_uniqueZdf_dupsr(   r   r)   r*   r*   r+   (test_loc_getitem_slicing_datetimes_frame	  s(    "z9TestLabelSlicing.test_loc_getitem_slicing_datetimes_framec                 C   s   t ddddd}tdddd	d
g|d}tddd}tddd}|j|| }tdd	g|dd
 d}t|| || }d}||kstd S )Nz2017-10-29 01:30:00zEurope/BerlinrU   z30 min)r  r  r|  r   rL   r0   rQ   rT   rw   z2017-10-29 02:30:00+02:00r?  z2017-10-29 02:00:00+01:00)r   r   r   r#   r$   r   rz   )r7   r  Zseries2Zt_1Zt_2r   r)   r*   r*   r+   'test_loc_getitem_label_slice_across_dst<	  s       z8TestLabelSlicing.test_loc_getitem_label_slice_across_dstrf   rg  rh  r  ri  rn  ro  rp  c                 C   s8   |  }|jd |d  }|jd d }t|| d S )Nr   r   )rk  r#   r   r$   r   )r7   rf   r  r   r)   r*   r*   r+   -test_loc_getitem_label_slice_period_timedeltaM	  s    z>TestLabelSlicing.test_loc_getitem_label_slice_period_timedeltac                 C   s~   dddg}t tjdd|d}|jdd }t|dks>t|jdd	 }t|dks\t|jdd
 }t|dksztd S )Ngx"p|@g\Va|@g|@rQ   r0   rw   g3333c|@g    |@g3333|@g|@)r   rg   r   r   r#   r   rz   )r7   rf   r(   s1r*   r*   r+   %test_loc_getitem_slice_floats_inexact[	  s    
z6TestLabelSlicing.test_loc_getitem_slice_floats_inexactc                 C   s   |}t tjdtjdd|dd}t|jdd  dks>tt|jdd  dksXttjdd|d}d	|d
< ||_t|jdd  dkstt|jdd  dkstd S )NrP   rB   r   rw   r  r_   g      )@rS   gffffff(@r0   )	r   rg   r   r   rh   r   r#   rz   rf   )r7   r  r   r  r  r*   r*   r+   'test_loc_getitem_float_slice_floatindexh	  s     z8TestLabelSlicing.test_loc_getitem_float_slice_floatindexzstart,stop, expected_slicer   nsNr9  rL   r   rR   rS   rT   rU   c                 C   s>   t tdtdd}|jt|| }|j| }t|| d S )Nr9  rs  z10 days)r   r   r   r#   r   r   r$   r   )r7   r  stopZexpected_slicer  r   r)   r*   r*   r+   $test_loc_getitem_slice_label_td64obju	  s    

z5TestLabelSlicing.test_loc_getitem_slice_label_td64objr  Z2018Z2020c              	   C   sP   |dddgt dt dt dgd}tjtdd	 |j|d
  W 5 Q R X d S )NrL   r0   rQ   Z2016Z2019Z2017rw   z,Value based partial slicing on non-monotonicr   r   )r   r   r   r5   r#   )r7   r  r  r9   r*   r*   r+   )test_loc_getitem_slice_unordered_dt_index	  s     z:TestLabelSlicing.test_loc_getitem_slice_unordered_dt_indexr   r  c                 C   sN   |t d|dddgd}|j|d }|t d|dddgd}t|| d S )NrT   r  r0   thirdrw   )r   r#   r$   ry   )r7   r  r   r9   r   r)   r*   r*   r+   1test_loc_getitem_slice_labels_int_in_object_index	  s    zBTestLabelSlicing.test_loc_getitem_slice_labels_int_in_object_indexc                 C   sZ   t dddddgd}t ddggdgtddgtdd}t|jd d dd f | d S )	NrL   r0   rQ   )testrL   r0   r   rw   r   )rl   rf   re   )r   r   r   r$   r%   r#   ri   r*   r*   r+   *test_loc_getitem_slice_columns_mixed_dtype	  s      z;TestLabelSlicing.test_loc_getitem_slice_columns_mixed_dtype)r~   r   r   r|  r}  r   r   r   ro   rj  r   r~  r  r  rg   r  r   r  r  r  r  r*   r*   r*   r+   rx  	  s0   




rx  c                   @   sH   e Zd Zejdddgdd Zejdddgdd Zdd	 Zd
S )TestLocBooleanLabelsAndSlices
bool_valueTFc              	   C   sH   | d}|j dkrD||dd}tjt|d |j|  W 5 Q R X d S )Nz7: boolean label can not be used without a boolean indexr   r   r   r   )Zinferred_typer   r   r5   r#   )r7   rf   r  r  messager9   r*   r*   r+   'test_loc_bool_incompatible_index_raises	  s
    

zETestLocBooleanLabelsAndSlices.test_loc_bool_incompatible_index_raisesc                 C   s&   |t ddgdddd}|j|  d S )NTFr   r   r   r   )r   r#   )r7   r  r  r9   r*   r*   r+   test_loc_bool_should_not_raise	  s
     z<TestLocBooleanLabelsAndSlices.test_loc_bool_should_not_raisec              	   C   s<   d}||dd}t jt|d |jdd  W 5 Q R X d S )NzEslice\(True, False, None\): boolean values can not be used in a slicer   r   r   TF)r   r   r   r#   )r7   rf   r  r  r9   r*   r*   r+   test_loc_bool_slice_raises	  s
    z8TestLocBooleanLabelsAndSlices.test_loc_bool_slice_raisesN)	r~   r   r   r   r   r   r  r  r  r*   r*   r*   r+   r  	  s
   


r  c                   @   sd   e Zd Zdd Zejdddgdd Zdd	 Zd
d Z	e
jdd Zdd Zdd Zdd ZdS )TestLocBooleanMaskc                 C   s   t dtdi}ttddd|_|d dk|d dk|d dk g}ddddddddddg
ddddd	d
ddddg
ddddd	d
ddddg
g}t||D ]H\}}| }d|j|df< t |ttddddgdd}t|| qd S )Nr   rP   r   r  rQ   r   rL   r0   rT   rU   rR   rS   r_   r8  r   r  )	r   r   r   rf   r_  r   r#   r$   r%   )r7   r(   Z
conditionsexpected_dataZcondrl   r   r)   r*   r*   r+   )test_loc_setitem_bool_mask_timedeltaindex	  s"    "z<TestLocBooleanMask.test_loc_setitem_bool_mask_timedeltaindexr  Nr>  c                 C   s   t ddddg}tdd|d}tdt di|dd}| }|j|d d f |j|d d f< t	|| | }|j| |j|< t	|| d S )	NTFZ20010101rT   r  r  r    rw   r   )
rg   r   r   r   rh   r   r   r#   r$   r%   )r7   r  r   r  r(   r   r*   r*   r+   +test_loc_setitem_mask_with_datetimeindex_tz	  s     z>TestLocBooleanMask.test_loc_setitem_mask_with_datetimeindex_tzc                 C   s~   t tdddtdtddddd}| }|jd	 gtj	tj	g |d
< |j
dk }|j| j|j|d
f< t|| d S )Nr  rQ   r0   ZABrz  rp  )r  r|  rd   r   r   rL   )r   rg   rh   r  r   r   r   rf   ro   rp   r"   r#   r$   r%   )r7   r(   r)   r   r*   r*   r+   2test_loc_setitem_mask_and_label_with_datetimeindex	  s    
zETestLocBooleanMask.test_loc_setitem_mask_and_label_with_datetimeindexc                 C   s   t d}t d}tdt||gi}| }t|g}|d jd j}||jddg< |d jd j}||ksptt	|| d S )Nr   l   ,GsO1colrL   TF)
r   r   r   r   r   _valuer#   rz   r$   r%   )r7   Ztd1Ztd2r(   Zdf_copyr  r)   r   r*   r*   r+   'test_loc_setitem_mask_td64_series_value	  s    
z:TestLocBooleanMask.test_loc_setitem_mask_td64_series_valuec                 C   s\   |  }|d dk}d|j|df< |j  }d||jdf< t||j|jd}t|| d S )Nr"   r   rk   rL   r   )r   r#   rq   r   rf   re   r$   r%   )r7   r  r)   r   rq   r*   r*   r+   #test_loc_setitem_boolean_and_column
  s    
z6TestLocBooleanMask.test_loc_setitem_boolean_and_columnc                 C   s~  t dddgdddgd}t dd	d
dgidddgd|jdddgdgf< t ddd	gdddgd}t|| t dddgdddgd}td	ddgdddgd|jdddgdgf< t|| t dddgdddgd}td	ddgdddgd|jdddgdf< t|| t dddgdddgd}| }|d }td	ddgdddgd|jdddg< |rnt|| nt|| d S )NrL   r0   rQ   rT   rU   rR   r   r    rP   rB   rW   r   rw   FTr9  r:  )r   r#   r$   r%   r   r   )r7   r[  r(   r)   r   r  r*   r*   r+   )test_loc_setitem_ndframe_values_alignment
  s(     *($z<TestLocBooleanMask.test_loc_setitem_ndframe_values_alignmentc                 C   sJ   t g g dtd}| }|d |jtjg tjddgf< t|| d S )Nr   r   r    	r   r   r   r#   rg   r   Zbool_r$   r%   ri   r*   r*   r+    test_loc_indexer_empty_broadcast,
  s     z3TestLocBooleanMask.test_loc_indexer_empty_broadcastc                 C   sP   t dgdgdtd}| }|d |jtjdgtjddgf< t|| d S )Nr   r   r   r   r   Fr    r  ri   r*   r*   r+   $test_loc_indexer_all_false_broadcast3
  s    "z7TestLocBooleanMask.test_loc_indexer_all_false_broadcast)r~   r   r   r  r   r   r   r  r  r  r  skip_array_manager_invalid_testr  r  r  r  r*   r*   r*   r+   r  	  s   

r  c                   @   s`   e Zd Zejddd ejegdd Z	dd Z
dd	 Zejd
ddgdd Zdd ZdS )TestLocListliker<  c                 C   s   | S rZ   r*   r   r*   r*   r+   r   <
  r   zTestLocListlike.<lambda>c              	   C   s  t ddtjg}ttd|d}|j|| }t|| ||| }t|| | j|| }t	||  |d d }|dd  }d}t
jt|d |j||  W 5 Q R X t
jt|d |||  W 5 Q R X t
jt|d | j||  W 5 Q R X d S )	Nr"   rk   rQ   rw   r   rL   r   r   )r   rg   r  r   r   r#   r$   r   r  r%   r   r   r5   )r7   r<  cir  r   Zser2Zci2r   r*   r*   r+   8test_loc_getitem_list_of_labels_categoricalindex_with_na<
  s"    zHTestLocListlike.test_loc_getitem_list_of_labels_categoricalindex_with_nac              	   C   sZ   t jddddgdd}tdddd	gtd
ddd}tjtdd |j|  W 5 Q R X d S )Nz
2001-01-04z
2001-01-02z
2001-01-14r  r   r0   rU   r_   r9  z
2001-01-01r   rT   r
  r   r   )rg   r   r   r   r   r   r5   r#   )r7   rH   r  r*   r*   r+   1test_loc_getitem_series_label_list_missing_valuesX
  s    
 zATestLocListlike.test_loc_getitem_series_label_list_missing_valuesc              	   C   sR   t tddgtddgd}tjtdd |jtddg  W 5 Q R X d S )Nl   PF
AHl   UBeNl   P2$$nrf   rl   r   r   l   NZ4FG)r   rg   r   r   r   r5   r#   r.  r*   r*   r+   9test_loc_getitem_series_label_list_missing_integer_valuesa
  s    zITestLocListlike.test_loc_getitem_series_label_list_missing_integer_values	to_periodTFc              	   C   sD  t ddddd}|r|d}tddg|dd	}tdtdg}|rRd
d |D }|j| }tddg|dd	}|s|jd |_tj||dd tdtdtdg}|rdd |D }tdddgt	|d|j
ddd	}|j| }tj||dd tdtdtdg}|rdd |D }tjtdd |j|  W 5 Q R X d S )N
2011-01-01z
2011-01-02r   r  )r|  rv   g?g?r   r   c                 S   s   g | ]}| d qS r   r  r   r*   r*   r+   r   u
  s     zRTestLocListlike.test_loc_getitem_listlike_of_datetimelike_keys.<locals>.<listcomp>T)rW  c                 S   s   g | ]}| d qS r  r  r   r*   r*   r+   r   
  s     )rv   r   
2011-01-03c                 S   s   g | ]}| d qS r  r  r   r*   r*   r+   r   
  s     r   r   )r   r  r   r   r#   rf   r  r$   r   r   r   r   r   r5   )r7   r  r  r  r  r   r{   r*   r*   r+   .test_loc_getitem_listlike_of_datetimelike_keysj
  sB    

  
z>TestLocListlike.test_loc_getitem_listlike_of_datetimelike_keysc                 C   sf   t ddgddgddggddd	gd
dgd}|jd d }d|j_|jtddgdd }t|| d S )NrL   r0   rT   rU   rS   r_   ZcobraZviperZ
sidewinderZ	max_speedZshieldr   r   ru   )r   r   rf   rv   r#   r   r$   r%   r   r*   r*   r+   test_loc_named_index
  s    z$TestLocListlike.test_loc_named_indexN)r~   r   r   r   r   r   rg   Zasarrayr   r  r  r  r  r  r*   r*   r*   r+   r  ;
  s   
		
)r  z%columns, column_key, expected_columnsi  rB  i  rL   ZAllr0   c                 C   sV   t tjdd| tdd}|jd d |f }|jdddg|f }tj||dd d S )	NrQ   r  rd   r"   rk   r   T)rX  )	r   rg   r   r   r   r   r#   r$   r%   )re   Z
column_keyZexpected_columnsr(   r)   r   r*   r*   r+   *test_loc_getitem_label_list_integer_labels
  s    
r  c                  C   s   t jdd} t| }t j|jd d df< t | t t jgd ddf}t|dddddgd	}t	
|| t| }t j|jd d df< t	
|| d S )
Nr_   rT   r  rL   r   r   r   rM   rt   )rg   r   r.  r   r  r#   Zhstackr   r  r$   r%   )Z	rand_datar   r  r)   r*   r*   r+   test_loc_setitem_float_intindex
  s    $r  c               	   C   sv   dd dD } t tdtdt| d}|jddd	d
 }t tdtdtd	ddd
gd}t|| d S )Nc                 S   s   g | ]}d D ]}||fqqS ))rS   r_   r8  rP   r*   )r   yrr  r*   r*   r+   r   
  s       z)test_loc_axis_1_slice.<locals>.<listcomp>)  r   )rP   r_   Z
ABCDEFGHIJr   rL   rI  )r  r8  )r   r_   r  )r  rP   )r   rS   )	r   rg   rP  r  r   r  r#   r$   r%   )r   r(   r   r)   r*   r*   r+   test_loc_axis_1_slice
  s    r  c                  C   sX   t dtdttdtdgd} |  }|jddgf |jddgf< t||  d S )Nr    r0   r   r   rK  )r   r   r   r   r   r#   r$   r%   )r)   r   r*   r*   r+   !test_loc_set_dataframe_multiindex
  s      r  c                  C   s4   t tdtddgtd} | jd }|dks0td S )Nr0   rL   r   r   r   )r   r   r   r   r#   rz   )r  r   r*   r*   r+   test_loc_mixed_int_float
  s    
r  c               	   C   sD   t tdddddgd} tjtdd d	| jd d
< W 5 Q R X d S )NrT   r"   rk   r   r   rw   $Slicing a positional slice with .locr   r0   rQ   )r   r   r   r   r   r#   )r  r*   r*   r+   %test_loc_with_positional_slice_raises
  s    r  c               
   C   s   t ddd} ttjd| d}|d }d}||fD ]T}tjt|d |jd	d  W 5 Q R X tjtd
d d	|jd	d< W 5 Q R X q4tjt|d |jd	dd	f  W 5 Q R X tjtd
d d|jd	dd	f< W 5 Q R X d S )Nz
2016-01-01rQ   r  )rQ   r0   rw   r   zOcannot do slice indexing on DatetimeIndex with these indexers \[1\] of type intr   rL   r  r0   )r   r   rg   r   r   r   r   r#   )dtir(   r  r   r9   r*   r*   r+   #test_loc_slice_disallows_positional
  s    r  c               	   C   s   t tjdddddgtddddd	} | jd
dddg  } | j}t	|j
}d}tjt|d | j|  W 5 Q R X tjt|d | d j|  W 5 Q R X d S )NrU   rQ   r    r   r<   Z2012r  r
  rd   r   r0   z/None of \[TimedeltaIndex.* are in the \[index\]r   )r   rg   r   r.  r   r   r   rf   ro   ZTimedeltaIndexZasi8r   r   r5   r#   )r(   r  r  r   r*   r*   r+   'test_loc_datetimelike_mismatched_dtypes  s    r  c                  C   s   t jdddd} ttjdd| d}t||j|   t||jt	|   t||jt	|   t|j
dd	 |j| dd	   t||jt	|   d S )
Nz2002-01z2003-12r  r{  r  rP   rw   r   rU   )ro   rj  r   rg   r   r.  r$   r%   r#   r   r   )r  r(   r*   r*   r+   "test_loc_with_period_index_indexer  s    $r  c                  C   s~   t jdd} tddd}ddddd	d
g}t| ||d}t j|j|jd df< t j| d dd< t| ||d}t	|| d S )Nr_   rR   rz  r  r"   rk   r   r   EFr   rL   rm   r   r0   )
rg   r   r.  r   r   r  r#   rf   r$   r%   )rG  r  r   r{   r|   r*   r*   r+   %test_loc_setitem_multiindex_timestamp(  s    r  c                  C   s:  dddg} ddg}ddg}t j| ||gdd	d
gd}tdtd|d}|jd d | d |d |d ff }|jd d d df }t|| |j| d |d |d fdddgdd}t|| |jd }|jd d }	|j| d |d |d fdddgdd}
t	|
|	 |j| d |d |d f }|dks6t
d S )Nr    r   r<   rK  )rL   r   r   rL   r   r   ra  r   rR   rU   r   r0   )r  rJ  )r   r   r   r   r#   r   r$   r%   xsr   rz   )r%  r&  Zlev3r   r(   r   r)   Zaltr  Z	expected2Zalt2r  r*   r*   r+   'test_loc_getitem_multiindex_tuple_level4  s     
$(
(r  c               	   C   s   t tddddgddddgddtjtjggjd	d
dgdd} | d}|jjdksXt|j	d }t
ddg|jddd}t|| |jt|_|j	d }t|| d S )NrL   r0   rQ   rT   rU   rR   rS   r_   r    r   r<   rR  )rl   re   r   r1  )r   rg   r   r  Tr   rf   r   rz   r#   r   re   r$   r   r   r   )r(   rr   r|   r)   r*   r*   r+   /test_loc_getitem_nullable_index_with_duplicatesR  s    ,


r  r   r   c                 C   sJ   t ddddgdgdd}| |jd< t ddd	dgdgd
d}t|| d S )NrL   r0   rQ   rT   rb   Zuint8rm  )r0   rb   r   uint16r;  )r   r(   r)   r*   r*   r+   test_loc_setitem_uint8_upcastf  s    
r  zfill_val,exp_dtypez
2022-01-06zdatetime64[ns]z
2022-01-07
US/Easternr?  zdatetime64[ns, US/Eastern]c                 C   sn   ddd|   g}t|| j|d}tddddgd	g|d
}d|jd< |d t||d}tj|j|dd d S )Nz
2022-01-02z
2022-01-03z
2022-01-04)r  r   rP   r9  r:  r  r    rd   rv  )
2022-01-08r    r  r   T)exact)	r   r   r  r   r#   rA  r$   r  rf   )Zfill_valZ	exp_dtyperl   rf   r(   Zexpected_indexr*   r*   r+   0test_loc_setitem_using_datetimelike_str_as_indexq  s    

r  c                  C   sJ   t tdg} d| jd d df< t dgdgdgdgd}t| | d S )NabcrU   rb   r    r   r<   )r   rL   r0   rb   )r   r   r#   r$   r%   )r(   r)   r*   r*   r+   test_loc_set_int_dtype  s    r  c                  C   s   t ddddgddd} tddd	gdd
dgdddgdddgg| dddgd}|jddgddd }|j| d ddf d	ks|td S )Nz20181101 1100z20181101 1200z20181102 1300z20181102 1400r   rk   )rv   r|  r"   r   r   r   r6  QrM   Wr  r  ZONEZTWOZVALUESr   T)rA  r   )r   r   r   r#   rz   )Zp_indexZ	mi_seriesr*   r*   r+   test_loc_periodindex_3_levels  s    
"r  c                   @   s  e Zd Zejdddgdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zejdejejeegejdddddgdd Zejd ed!d"d"f d!ed"fgd#d$ Zd%d& Zejd'd(d)gd*d+ Zejd,d- Zd.d/ Zd0d1 Zd"S )2TestLocSeriesr  )r  rQ   )r  rT   c                 C   s$   t ddd}|j| |ks td S )NrQ   rT   )r  r  )r   r#   rz   )r7   r   r)   r  r*   r*   r+   rf    s    zTestLocSeries.test_loc_uint64c           	      C   s   |j dddg }t|j| || t|jdd d |dd d  |j ddg \}}|j|| }|||}t|| || k}t|j| ||  |j| || kst|j| || kstd S )NrQ   rT   rS   rU   r0      )	rf   r$   r   r#   r)  r   truncatemedianrz   )	r7   string_seriesdatetime_seriesindsd1d2r   r)   r   r*   r*   r+   test_loc_getitem  s    "zTestLocSeries.test_loc_getitemc              	   C   s   |j ddg \}}|d d d dddg }d}tjt|d |j||  W 5 Q R X tjt|d d|j||< W 5 Q R X d S )NrU   r  r0   rL   r   z"Timestamp\('2000-01-10 00:00:00'\)r   )rf   r   r   r5   r#   )r7   r  r  r  Zts2r   r*   r*   r+   test_loc_getitem_not_monotonic  s    z,TestLocSeries.test_loc_getitem_not_monotonicc              	   C   s>  t tjdttdddd}| }d|jdd< |jdd dk sPt	| }d|jdd< |jdd dkj
 st	|jdd	 }|jdd }|dd	d
dg}t|| t|| |jttdttddd  }tjtdd |jdd  W 5 Q R X tjtdd d|jdd< W 5 Q R X d S )NrP   r   rB   r0   rw   rT   rQ   r9  rR   r_   rU   r8  r   z^3$r   )r   rg   r   r.  r   r   r   r   r   rz   rq   r#   r)  r$   r   r   r   r5   )r7   r  cpr   r  r)   s2r*   r*   r+   0test_loc_getitem_setitem_integer_slice_keyerrors  s"     "z>TestLocSeries.test_loc_getitem_setitem_integer_slice_keyerrorsc                 C   s4   t |jd d }|j| }t||d d  d S )NrP   )r  rf   r#   r$   r   )r7   r  r  r   r*   r*   r+   test_loc_getitem_iterator  s    
z'TestLocSeries.test_loc_getitem_iteratorc                 C   s:   ||  k}| }d|j|< |}d||< t|| d S )Nr   )r  r   r#   r$   r   )r7   r  r   r   r)   r*   r*   r+   test_loc_setitem_boolean  s    
z&TestLocSeries.test_loc_setitem_booleanc              	   C   sP   t |jdddg }d|j|< d}tjt|d d|j|dg < W 5 Q R X d S )NrU   r_   r:  z\['foo'\] not in indexr   r   )r   rf   r#   r   r   r5   )r7   r  r  r   r*   r*   r+   test_loc_setitem_corner  s
    
z%TestLocSeries.test_loc_setitem_cornerc                 C   s   |j dddg }| }| }d||< d|j|< t|| | }| }d||d |d < d|j|d |d < t|| d S )NrU   rP   r  r   r0   )rf   r   r#   r$   r   )r7   r  indicesr  r{   r*   r*   r+   test_basic_setitem_with_labels  s    
z,TestLocSeries.test_basic_setitem_with_labelsc           	   	   C   s   t tjdttdddd}dddg}tdddg}| }| }d||< d|j|< t	
|| | }| }d||< d|j|< t	
|| ddddg}tddddg}d	}tjt|d
 d||< W 5 Q R X tjt|d
 d||< W 5 Q R X d S )NrP   r   rB   r0   rw   rT   rR   rU   z\[5\] not in indexr   )r   rg   r   r.  r   r   r   r   r#   r$   r   r   r   r5   	Exception)	r7   r  r  Zarr_indsr  r{   Zinds_notfoundZarr_inds_notfoundr   r*   r*   r+   !test_loc_setitem_listlike_of_ints  s(     


z/TestLocSeries.test_loc_setitem_listlike_of_intsc                 C   s   t tdddddddgd}| }td	dd
}||jd< |jd }||ksPt| }||jd< |jd }||ksxt| }||d< |d }||kstd S )Nr  rQ   r  r  r    r   r<   rw   r  r?  r   )r   r   r   r   r#   rz   r   )r7   r  r  r)   r   r*   r*   r+   test_loc_setitem_dt64tz_values  s"    



z,TestLocSeries.test_loc_setitem_dt64tz_valuesarray_fnr   r   rT   rU   rR   c                 C   s~   |dg| }t |ddddgtdtd}t dtdtd}||jd< t|| t dtdtd}||jd< t|| d S )Nr   Zabcder   r    )r   r   r   r#   r$   r   r   )r7   r   r  rO  r)   r  r*   r*   r+   #test_loc_iloc_setitem_with_listlike1  s    

z1TestLocSeries.test_loc_iloc_setitem_with_listliker   r"   Nc              	   C   s~   t tdddgdddgd}d}tjt|d	 |j|d d f  W 5 Q R X tjt|d	 d
|j|d d f< W 5 Q R X d S )N)r"   0)r"   1)rk   r     r  r   r  r  r   rL   )r   r   r  r   r   r   r#   )r7   r   r  r   r*   r*   r+   +test_loc_series_getitem_too_many_dimensionsC  s    z9TestLocSeries.test_loc_series_getitem_too_many_dimensionsc                 C   s   |j dddg }| }d|j|< | }d|dddg< t|| d|jdd< d|dd< t|| |j ddg \}}d|j||< d|dd< t|| d|j|< d|j|< || dkst|| dkstd S )	NrQ   rT   rS   rU   rP   r  rR   r7  )rf   r   r#   r$   r   r   rz   )r7   r  r  r   r)   r  r  r*   r*   r+   test_loc_setitemQ  s"    


zTestLocSeries.test_loc_setitemr   r   r   c                 C   s\   t ddgddgd|d}ddd|jd	d d f< t ddgddgd|d}t|| d S )
Nr  defZghiZjklrm   r   ZnewAZnewBr   r;  )r7   r   r(   r)   r*   r*   r+   test_loc_assign_dict_to_rowk  s    z)TestLocSeries.test_loc_assign_dict_to_rowc                 C   sp   t ddgd}tddddd|jd	< tddddd|jd	< t tddddggddgd	gd
}t|| d S )Nr   r   rt   rR   r   r  r   )r   r   rL   rd   )r   r   r#   r$   r%   r  r*   r*   r+   ,test_loc_setitem_dict_timedelta_multiple_setu  s      z:TestLocSeries.test_loc_setitem_dict_timedelta_multiple_setc                 C   sl   t ddgdgd}ddg|jdddgf< t ttjtjgd	d
dtjgdtjgdddgd}t|| d S )NrL   r0   r    r   rR   rS   r   r<   r   r   )r    r   r<   rw   )r   r#   r   rg   r  r$   r%   ri   r*   r*   r+   3test_loc_set_multiple_items_in_multiple_new_columns  s    	zATestLocSeries.test_loc_set_multiple_items_in_multiple_new_columnsc                 C   s6   t jdddd}ttd|d}|jd dks2td S )N2000rB   rk   r  rw   z
2000-01-14r8  )ro   rj  r   r   r#   rz   )r7   rf   r'   r*   r*   r+    test_getitem_loc_str_periodindex  s    z.TestLocSeries.test_getitem_loc_str_periodindex) r~   r   r   r   r   r   rf  r  r  r  r  r  r  r  r  r  rg   r   ro   r   r  r  r   r   r  r  r  r  r  r  r  r  r*   r*   r*   r+   r    s.   
	$

	

r  )S__doc__collectionsr   r   r   r   r   r   Zdateutil.tzr   Znumpyrg   r   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsr  Zpandasro   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingr$   Zpandas.api.typesr   r   Zpandas.core.indexingr   Zpandas.tests.indexing.commonr   r   r   r  r,   r-   r   r  r  r+  rU  re  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Zint16r  r  r  r  r  r*   r*   r*   r+   <module>   s   P"
	 9          s< w CJ ~f
	




	