o
    Eh                 	   @   sH  d Z ddlmZ ddl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Z ddlm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/m0Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ej89dej:ej:dgdej:ej:gg dgej:dgdej:gddggg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@G d d! d!ZAG d"d# d#ZBG d$d% d%ZCG d&d' d'ZDG d(d) d)ZEG d*d+ d+ZFej89d,g d-d.d/gdd0gfg d1d.d/gdd0gfg d1d.d2gdd3gfgd4d5 ZGd6d7 ZHd8d9 ZId:d; ZJd<d= ZKd>d? ZLd@dA ZMdBdC ZNdDdE ZOdFdG ZPdHdI ZQdJdK ZRej89dLdMeSdMeTdMgdNdO ZUej89dPe*dQdRfe*dSdTdUdVfgdWdX ZVdYdZ ZWej8Xd[ej8Xd\d]d^ ZYd_d` ZZG dadb dbZ[dS )cz$ test label based indexing with loc     )
namedtupleN)datedatetimetime	timedelta)gettz)using_string_dtypeindex)np_version_gt2)IndexingError)CategoricalCategoricalDtypeCategoricalIndex	DataFrameDatetimeIndexIndex
IndexSlice
MultiIndexPeriodPeriodIndexSeriesSparseDtype	Timedelta	Timestamp
date_rangetimedelta_rangeto_datetimeto_timedelta)	is_scalar)_one_ellipsis_message)"check_indexing_smoketest_or_raisesz series, new_series, expected_serba)FTTFTc                 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-   >lib/python3.10/site-packages/pandas/tests/indexing/test_loc.pytest_not_change_nan_loc2   s
   	r/   c                   @   s  e Zd Zdd Zejdddgdd Zejdddgdd	 Zejd
dg ddgddgdgdg d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g dg dgg dg dggejdddgdd Z
ejd
g ddgdgg dg ddgg dg ddgg d 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.g d/deged0d1dgdeged2d3d4gdeged2d3d4gdeged2d5d2d4gdeggejdddgd6d7 Zd8d9 Zd:d; Zejd<e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dAdB ZdS )CTestLocc                 C   sl   t g ddgtd}|jd d u sJ t g ddgdd}|r+t|jd s)J d S |jd d u s4J d S )N)12Nr#   columnsdtype)   r#   str)r   objectr&   npZisnan)selfusing_infer_stringr+   r-   r-   r.   "test_none_values_on_string_columnsC   s   z*TestLoc.test_none_values_on_string_columnskindr*   framec                 C   $   | | d}t|ddtd d S )NZ_labelsr&   r6   failsgetfixturevaluer!   KeyErrorr:   r=   requestobjr-   r-   r.   test_loc_getitem_intN      zTestLoc.test_loc_getitem_intc                 C   r?   )N_emptyr&   cr@   rB   rE   r-   r-   r.   test_loc_getitem_labelT   rI   zTestLoc.test_loc_getitem_labelzkey, typs, axesf)intsuintslabelsmixedtsNfloats   )rN   rO   rQ   rP   rR   r   c                 C   4   |D ]}| | d| }t|d||td qd S N_r&   axesrA   rB   r:   keytypsrY   r=   rF   typrG   r-   r-   r.   #test_loc_getitem_label_out_of_rangeZ   s   
z+TestLoc.test_loc_getitem_label_out_of_rangez	key, typsr      r6   )rN   rO   rS   )r`         @r%   c                 C   s2   |D ]}| | d| }t|d|td qd S )NrW   r&   r@   rB   )r:   r[   r\   r=   rF   r]   rG   r-   r-   r.   test_loc_getitem_label_listn   s   	z#TestLoc.test_loc_getitem_label_listempty)r   r6   
   )         r`   ))r`   re   )r`      )r6      Zmultic                 C   rU   rV   rB   rZ   r-   r-   r.   (test_loc_getitem_label_list_with_missing|   s   
z0TestLoc.test_loc_getitem_label_list_with_missingr\   rN   rO   c                 C   s.   | | d| }t|dg ddtd d S )NrW   r&   )rT      (   r`   rX   rB   )r:   r\   r=   rF   rG   r-   r-   r.   !test_loc_getitem_label_list_fails   s   
z)TestLoc.test_loc_getitem_label_list_failsc                 C      d S Nr-   r:   r-   r-   r.   !test_loc_getitem_label_array_like   s   z)TestLoc.test_loc_getitem_label_array_likec                 C   s,   | | d}g d}t|d|td d S )NrJ   TFTFr&   r@   )rC   r!   
IndexError)r:   r=   rF   rG   r"   r-   r-   r.   test_loc_getitem_bool   s   zTestLoc.test_loc_getitem_boolzslc, typs, axes, failsre   )rP   rQ   rc   rR   rS   Z20130102Z20130104r6      rQ   rh   c           	      C   s4   |D ]}| | d| }t|d|||d qd S rV   )rC   r!   )	r:   Zslcr\   rY   rA   r=   rF   r]   rG   r-   r-   r.   test_loc_getitem_label_slice   s   z$TestLoc.test_loc_getitem_label_slicec                 C   sp   t ddgddgddggddgg dd}td|jd	< t ddgd
dgddggddgg dd}t|| d S )NrT   r#      col1col2)rd   r`   r`   r4   r
   r6   )r`   rx   r   r`   )r   r9   aranger&   r'   r(   r:   r+   r,   r-   r-   r.    test_setitem_from_duplicate_axis   s    z(TestLoc.test_setitem_from_duplicate_axisc                 C   s   t g d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 g dg dtdtdtdgdd}t	
|| d S )Nr`   r6   re   String 1String 2z2019-06-11 11:00:00z2019-06-11 12:00:00)Zchannelr%   B)dataString 3r%   r   r%   r   )r   r   r   )r   r9   nanr   pdNaTvaluesr&   r)   r'   r(   )r:   r+   df2r,   r-   r-   r.   test_column_types_consistent   s.   
z$TestLoc.test_column_types_consistentzobj, key, expFr4   namer	   c                 C   s8   |j | }t|ttfrt|| d S ||ksJ d S ro   )r&   
isinstancer   r   r'   assert_equal)r:   rG   r[   expresr-   r-   r.   #test_loc_getitem_single_boolean_arg   s   
z+TestLoc.test_loc_getitem_single_boolean_arg)__name__
__module____qualname__r<   pytestmarkparametrizerH   rL   r^   rb   rj   rm   rq   rt   slice	TypeErrorrD   rv   r}   r   r   r   r   r   r   r-   r-   r-   r.   r0   B   s    







$r0   c                   @   s<  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g d'gd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zejd8d9 Zejd:d;ejd;ejd<ejg d=ejd<gd>d? Zd@dA ZdBdC ZdDdE Z dFdG Z!ejj"e# dHdIdJdK Z$ejdLg dMdNdO Z%dPdQ Z&ej'dRejdSd%d&gdTdU Z(dVdW Z)dXdY Z*ej'dRejdSd%d&gdZd[ Z+ej'dRejdSd%d&gd\d] Z,d^d_ Z-d`da Z.ej'dRdbdc Z/ejdddege0dfdedfedeggejdgdhgedhggdidj Z1ejdkd;dlgg dmfdne2g dodpdqej3ej3gg dogg dmdrfdsdtdugfdndvge2dsdlej3ej3gg dwdxdyej3ej3ggg dmdrfdsg dzfejg d{ejd<e2dsdlej3gg d{dxdyej3ggg dzdrfe0dsdpdfg d|fg d{g d}ge2dsdlej3ej3gg d~g dgg dmdrfe0dsdpdfg dfejg d{g d}gejd<e2dsdlej3ej3gg dg dgg dmdrfe0dfdfdfdedtgfe2dndvgddgddggdedtgdre2g dg dg dgg dzdrfgdd Z4dd Z5dd Z6dd Z7dd Z8dd Z9ejj:ejdddgddggdd Z;dd Z<dd Z=dd Z>dd Z?dd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJejdg dejdejejKeLgdd ZMdd ZNddÄ ZOddń ZPejddddgddɄ ZQejdeRejeSeTgdd̄ ZUdd΄ ZVejddeSdsgfdeSdlgfgddӄ ZWddՄ ZXejdd;g dעfe0dqdvg dآfdpdxgg d٢fgddۄ ZYdd݄ ZZdd߄ Z[dd Z\ejdddggdd Z]dd Z^ejddedegdee0dffgdd Z_dd Z`dd Zadd Zbdd Zcdd Zdejdddgdd Zedd Zfdd Zgdd Zhd d Zidd Zjdd ZkdfS (  TestLocBaseIndependentc                 C   sH   t tddd}|jtdgd d  }|jdd  }t|| d S )NZ20212022r	   z2021/6/1r      )r   r   r&   r9   arrayilocr'   r(   r:   r+   resultr,   r-   r-   r.   test_loc_npstr  s   z%TestLocBaseIndependent.test_loc_npstrzmsg, keyz'Period\('2019', 'Y-DEC'\), 'foo', 'bar'  foobarz&Period\('2019', 'Y-DEC'\), 'y1', 'bar'y1z&Period\('2019', 'Y-DEC'\), 'foo', 'z1'z1z;Period\('2018', 'Y-DEC'\), Period\('2016', 'Y-DEC'\), 'bar'    z&Period\('2018', 'Y-DEC'\), 'foo', 'y1'z;Period\('2017', 'Y-DEC'\), 'foo', Period\('2015', 'Y-DEC'\)    z&Period\('2017', 'Y-DEC'\), 'z1', 'bar'c                 C   s   t tdddgtdtddgtddtd	gg d
g ddg d}tjt|d |j|  W d   dS 1 s>w   Y  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   Zx1Zx2r   r   r   r   r   r   r~   rd   rT   rk   )r%   r   CZV1ZV2r%   r   r   matchN)r   r   	set_indexr   raisesrD   r&   )r:   msgr[   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   sT   t ddgi}tjtdd |jd d df  W d    d S 1 s#w   Y  d S )Nr#   r`   u   אr   )r   r   r   rD   r&   r:   r+   r-   r-   r.   $test_loc_getitem_missing_unicode_key5  s   "z;TestLocBaseIndependent.test_loc_getitem_missing_unicode_keyc                 C   sZ   t tjdddd tdD d}|jd }|jd d df jd	 }t|| d S )
Nr6   )rT   ri   c                 S   s   g | ]}d |d  qS )ZABCDEri   r-   .0xr-   r-   r.   
<listcomp>?      z@TestLocBaseIndependent.test_loc_getitem_dups.<locals>.<listcomp>rT   r	   )r%   r   r   r%   )r   r9   randomdefault_rngranger&   r'   assert_series_equalr:   r+   r,   r   r-   r-   r.   test_loc_getitem_dups:  s   
z,TestLocBaseIndependent.test_loc_getitem_dupsc                 C   st   t ddddtdggg ddgd}tddddtdgg ddd}|jd	 }t|| |jd }t|| d S )
Nr`   r6   r   r   20130101r#   r#   r#   r#   r#   rz   r
   r   r   )r   r   r   r   r'   r   r&   r   r-   r-   r.   test_loc_getitem_dups2E  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s`J dddgf}| }|j|  d9  < t	|j| d|j|   d S )NZrtttiZaaaderi   float64r5   gq=
ףp?r6   g(\տ)mer   r   bar2r   rr   r          @)r   r   t)
r   listr9   r{   r   copyr&   r'   r   r(   )r:   df_origindexerr+   r-   r-   r.   test_loc_setitem_dupsY  s2   
 z,TestLocBaseIndependent.test_loc_setitem_dupsc                 C   s  t g dtg dddd}|d dk}|j|df d }||j|df< t g dtg d	ddd}t|| t g dg ddd
d}|d dk}|j|df }tjtdd ||j|df< W d    n1 smw   Y  t g dg ddd
d}t|| d S )N)r   r`   r`   )d   rw   ,  Zuint32r   r#   r"   r#   r`   r"   )r      i-  uint64item of incompatible dtyper   )r   r   r&   r'   r(   assert_produces_warningFutureWarning)r:   Zdf1ixZnewb1r,   r   Znewb2r-   r-   r.   test_loc_setitem_slice|  s$   z-TestLocBaseIndependent.test_loc_setitem_slicec                 C   s   t dgdgdgdgd}g d}|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"   rK   r#   r"   rK   Zfloat32r   r   )r   r&   astyper9   r   r'   r(   )r:   r+   colsr,   r-   r-   r.   test_loc_setitem_dtype  s   &	z-TestLocBaseIndependent.test_loc_setitem_dtypec                 C   s   t tdg dd}tjtdd |ddg  W d    n1 s"w   Y  t td}tjtdd |ddg  W d    d S 1 sFw   Y  d S )	Nre   r   r	   not in indexr   r#   dr   )r   r   r   r   rD   )r:   sr-   r-   r.   $test_getitem_label_list_with_missing  s   "z;TestLocBaseIndependent.test_getitem_label_list_with_missingr
   TFrr   c                 C   sb   t g d}dt| dt| }tjt|d |j|  W d    d S 1 s*w   Y  d S )Nr~   z Boolean index has wrong length: z instead of r   )r   lenr   r   rs   r&   )r:   r
   r   r   r-   r-   r.   test_loc_getitem_bool_diff_len  s
   "z5TestLocBaseIndependent.test_loc_getitem_bool_diff_lenc                 C   rn   ro   r-   rp   r-   r-   r.   test_loc_getitem_int_slice  s   z1TestLocBaseIndependent.test_loc_getitem_int_slicec                 C   s   t tjddg dg dd}dtt d}tjt|d |j	d	dgd	dgf  W d    d S 1 s9w   Y  d S )
Nr6   re   re   r   )erM   gr
   r4   z$\"None of \[Index\(\[1, 2\], dtype=''\)\] are in the \[index\]\"r   r`   )
r   r9   r   r   r5   intr   r   rD   r&   r:   r+   r   r-   r-   r.   test_loc_to_fail  s   "z'TestLocBaseIndependent.test_loc_to_failc                 C   s  t td}d|jd< d|jd< tjtdd |jd  W d    n1 s&w   Y  dtt d	}tjt|d |jdd
g  W d    n1 sMw   Y  d}tjt|d |jt	dgtd  W d    n1 spw   Y  d|jd< tjtdd |jdd
g  W d    n1 sw   Y  d|d< dtt d	}tjt|d |jd
g  W d    n1 sw   Y  |d= tjt|d d|jd
g< W d    d S 1 sw   Y  d S )Nr   r`   r6   r#   z^-1$r   z&\"None of \[Index\(\[-1, -2\], dtype='r   zE\"None of \[Index\(\['4'\], dtype='object'\)\] are in the \[index\]\"4re   r   z"\"None of \[Index\(\[-2\], dtype='r   )
r   r8   r&   r   r   rD   r9   r5   r   r   r:   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t d}tjt|d	 |jd
gd d f  W d    n1 s3w   Y  tjt|d	 |jd
g  W d    d S 1 sQw   Y  d S )Nr#   r"   r`   r6   valuer   z!\"None of \[Index\(\[3\], dtype='r   r   re   )r   r9   r5   r   r   r   rD   r&   r   r-   r-   r.   test_loc_to_fail3  s   "z(TestLocBaseIndependent.test_loc_to_fail3c                 C   s   t g d}|jdg  dtt d}tjtt	|d |jdg  W d    n1 s0w   Y  tjtdd |jddg  W d    d S 1 sOw   Y  d S )Nr~   r6   z"None of [Index([3], dtype='z')] are in the [index]r   re   r   )
r   r&   r9   r5   r   r   r   rD   reescaper   r-   r-   r.   test_loc_getitem_list_with_fail  s   "z6TestLocBaseIndependent.test_loc_getitem_list_with_failc                 C   s   t tjdjddg dd}|jdd }|jt| }|j| }t	|| |j|j
 }t	|| |jtj|dd	 }t	|| d S )
Nr6   )ri   rd   size)Zalpha_0Zalpha_1Zalpha_2Zbeta_0Zbeta_1r	   c                 S   s   d| v S )NZalphar-   r   r-   r-   r.   <lambda>      z7TestLocBaseIndependent.test_loc_index.<locals>.<lambda>booleanr   )r   r9   r   r   r
   mapr&   r   r'   r(   r   r   )r:   r+   maskr,   r   r-   r-   r.   test_loc_index  s   
z%TestLocBaseIndependent.test_loc_indexc                 C   s   t tjddg dg dd}|jd d ddf jddd d f }|jddgk s1J |jddgk s<J t t	dgd	gd
jd }t
t	dd	gddgdd}t|| |jtksdJ d S )Nr6   rh   rh   r%   r   r   Drz   r%   r   r   r   r`   r   r#   r"   r   )r   r9   r   r   r&   r   r4   allr
   r   r   r'   r   r5   r8   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-5ri   r   r   val)r   r   r   r   r9   int64rp   r-   r-   r.   frame_for_consistency:  s
   z,TestLocBaseIndependent.frame_for_consistencyr  r   r   )r   r   r   r   r   c                 C   s   t tdtdtjdttdtjdd}| }tjtdd ||j	d d df< W d    n1 s5w   Y  t
|| d S )	Nr   ri   r
   r5   r   r  incompatible dtyper   r   r   r   r   r9   r  r   r'   r   r   r&   r(   )r:   r  r  r,   r+   r-   r-   r.   test_loc_setitem_consistencyC  s   z3TestLocBaseIndependent.test_loc_setitem_consistencyc                 C      t tdtddttdtjdd}| }tjtdd d|j	d d df< W d    n1 s3w   Y  t
|| d S )	Nr   ri   r	   r   r  r  r   r   r  r:   r  r,   r+   r-   r-   r.   (test_loc_setitem_consistency_dt64_to_strU  s   z?TestLocBaseIndependent.test_loc_setitem_consistency_dt64_to_strc                 C   r  )	N      ?ri   r	   r   r  r  r   r   r  r  r-   r-   r.   *test_loc_setitem_consistency_dt64_to_floatd  s   zATestLocBaseIndependent.test_loc_setitem_consistency_dt64_to_floatc                 C   sx   t dttdgi}tjtdd d|jd d df< W d    n1 s&w   Y  t dtdgi}t|| d S )Nr   Z20180101r  r   string)r   r   r   r'   r   r   r&   r(   r|   r-   r-   r.   'test_loc_setitem_consistency_single_rowr  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 d    n1 s'w   Y  t|| t ddgd}d|d< |d tj|d< t|| d S )Nr   yr   r`   )r   r'   r   r&   r(   r   r9   r  r:   r,   r+   r-   r-   r.   "test_loc_setitem_consistency_empty{  s   z9TestLocBaseIndependent.test_loc_setitem_consistency_emptyzTODO(infer_string)reasonc           
      C   s  dgd g dg dg}t j|g dd}g dg dg}t j|d	d
gd}ddddtjgg dddddtjgg dg}t|||d}t }|rPtjt	dd}| t
|jd d df |jd d df< W d    n1 sow   Y  | t
|jd d df |jd d df< W d    n1 sw   Y  |rd S | }|jd d df |jd d df  |jd d df< tjtdd |jd d df td |jd d df< W d    n1 sw   Y  tg d|jdd}	t|d |	 d S )NZRegion_1rh   )Site_1r   Site_2r!  )l   BP[ l   _Z l   q=.Z l   <.Z )ZRegionZSiteZRespondentIDnames)
Respondentr$  r$  OtherCatr%  )Z	Something	StartDateEndDatezYes/NoZSomethingElseZLevel_0ZLevel_1r%   z5/25/2015 10:59z5/25/2015 11:22Yes)r%   z5/21/2015 9:40z5/21/2015 9:52r(  r(  z5/20/2015 8:27z5/20/2015 8:41)r%   z5/20/2015 8:33z5/20/2015 9:09r(  ZNor   Invalid valuer   )r$  r&  )r$  r'  )r$  ZDurationr  l    Xp7 )g      7@      (@g      ,@g      B@r   )r   from_arraysr9   r   r   
contextlibnullcontextr   r   r   r   r&   Zinfer_objectsr'   r   r   r   r   r
   r   )
r:   r;   levelsmiZclevelsr   r   r+   ctxr,   r-   r-   r.   -test_loc_setitem_consistency_slice_column_len  s\   
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 )NZ	timestampz2017-02-11 12:41:29z1991-11-07 04:22:37zdatetime64[]r,   r   )	r   r9   
datetime64r&   r   r   r   r'   r   )r:   r2  r+   r,   r-   r-   r.   test_loc_assign_non_ns_datetime  s   0	&z6TestLocBaseIndependent.test_loc_assign_non_ns_datetimec                 C   s   t dg d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 g d
g dg dg dgg dd}ddg}|| t||< t|| d S )Nr   )   CO!g   s~!g    4	8   A{?r7  T)r2  cachedate_dt
date_dt_cpr6   re   )r<  2017-01-24 13:26:12.711rC  )r=  2017-01-24 13:52:05.110rD  )r>  2018-10-22 13:44:05.888rE  )r?  2018-10-23 08:08:41.025rF  )r   rA  rB  r   )r   Z	from_dictr   r&   Zapplyr'   r(   )r:   r+   r,   r4   r-   r-   r.   test_loc_modify_datetime  s"   
  
z/TestLocBaseIndependent.test_loc_modify_datetimez.ignore:Setting a value on a view:FutureWarninghas_refc                 C   sv   t g ddgtd}|r|d d  }tjg ddd|jg ddf< tg dg dtd	}t d|i}t|| d S )
Nre   ri   rh   r%   r
   r4   r5   r~   r  r   rh   re   ri   r6   re   r`   r  )r   floatr9   r   r&   r   r'   r(   )r:   rH  r+   viewserr,   r-   r-   r.   #test_loc_setitem_frame_with_reindex  s    z:TestLocBaseIndependent.test_loc_setitem_frame_with_reindexc                 C   s~   t g dddgtd}d|d< tjg ddd|jg d	df< tg d
g ddd}t d|ti}d|d< t|| d S )NrI  r%   r   rJ  r  r~   r  r   rK  rL  r  )	r   rM  r9   r   r&   r   r   r'   r(   )r:   r+   rO  r,   r-   r-   r.   )test_loc_setitem_frame_with_reindex_mixed  s    z@TestLocBaseIndependent.test_loc_setitem_frame_with_reindex_mixedc                 C   sl   t g dddgtd}d|d< tjg ddd|jtdd	d
df< t g dddg dd}t|| d S )Nr~   r%   r   rJ  r  r  r   re   r   r   )ra   r   r  r   r	   )r   rM  r9   r   r&   r   r'   r(   r|   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	< |r;|d d  }||j|d	f< tj|d
< ||j|d
f< t	||tj
d}	t	||d}
t|	|
dtd	d
gdj|d}t|| d S )Nc                 S      g | ]}d t | qS @r7   r   ir-   r-   r.   r     r   zGTestLocBaseIndependent.test_loc_setitem_empty_frame.<locals>.<listcomp>ri   r  r   c                 S   rS  rT  rV  rW  r-   r-   r.   r   "  r   rh   r	   r%   r   r  r   r   )r   r9   r{   r   setunionr   r   r&   r   r   r   reindexr'   r(   )r:   rH  Zkeys1Zval1Zkeys2Zval2r
   r+   rN  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}|r|d d  }|jd }d|jd< |jd }|dks/J |jd }|dks:J d	|jd d d
df< |jd d d
df }|jd d dd f }t	|| d S )Nr6   r  ZabcdABCDr   r   r   r`   )r#   r%   r   r   r  )
r   r9   r   r   standard_normalr   r   r&   r'   r(   )r:   rH  r+   rN  r   r,   r-   r-   r.   test_loc_setitem_frame8  s"   



z-TestLocBaseIndependent.test_loc_setitem_framec                 C   sP   t g dtjd}|j|j|j|jkdf< t g dtjd}t|| d S )Nr~   r   r   )r   r9   r   r%   r&   r   r'   r(   r|   r-   r-   r.   /test_loc_setitem_frame_nan_int_coercion_invalidQ  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 )Nr`   r6   re   rh   r#   r"   )r`   r6   r#   r   r   r
   r5   r   ri   rf   )r   r&   r   r   r8   r'   r   r(   r   r-   r-   r.   #test_loc_setitem_frame_mixed_labelsY  s   z:TestLocBaseIndependent.test_loc_setitem_frame_mixed_labelsc                 C   s  t g dttdtjdd}|jdd }|jdd |_||jdd< t g dtg d	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g dtjdd}|jdd }|jdd |_||jdd< t|| d S )Nr   r   bazre   r   r   r`   r6   r   )r   re  re  )r`   r6   r6   r
  r  ri   r  Z20000101Z20000102Z20000103)r   r`   r   r`   r6   rh   )r   r   r   r9   r  r&   r
   r'   r(   r   r   )r:   warn_copy_on_writer+   Zrhsr,   r-   r-   r.    test_loc_setitem_frame_multiplesh  s:   z7TestLocBaseIndependent.test_loc_setitem_frame_multiplesr   r%   Nr   Zc                 C   sV   t ddgddggddgddti}||jd|f< |jd	 }t|r'|d
ks)J d S )Nr`   r6   re   rh   r%   r   r   r   )r   r%   rh  )r   r   r8   r&   r   )r:   r   r   r+   r   r-   r-   r.   "test_loc_setitem_with_scalar_index  s   &

z9TestLocBaseIndependent.test_loc_setitem_with_scalar_indexzindex,box,expectedr6   r  rg   )rg   rg   rg   rg   re   rh   r   r`   r   r  ru   )re   rh   rg   ru   ri   rf   r   rg   ru   	   )r   r   r  rd         )re   rg   ru   rk  )ri   rd   rm  rn  )r   r%   r  )ru   rh   rg   rk  )rm  rf   rd   rn  rk  rd   rm  rn  )rg   r6   ru   )rk  rh   rd   )rm  rf   rn  c                 C   s<   t ddgddgddggddgd	}||j|< t|| d S )
Nr`   r6   re   rh   ri   rf   r%   r   r   r   r&   r'   r(   )r:   r
   boxr,   r+   r-   r-   r.    test_loc_setitem_missing_columns  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   r`   )	r   r   tz_localizer   r   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     r`   i  r6   r   )r   r   rt  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 wordsrk  r   r6   re   )r   rt  r   r'   r   r   r-   r-   r.   test_loc_coercion3  s   z)TestLocBaseIndependent.test_loc_coercion3c                 C   sj   t ddt ddg}t|tddgd}ttd}|d ||d< |d	 ||d< t|| d S )
N*   rr  i  r   r   r	   r   r   r`   )r   rs  r   r   r8   r'   r   )r:   Z
indexer_slvalsr,   rO  r-   r-   r.   test_setitem_new_key_tz  s   
z.TestLocBaseIndependent.test_setitem_new_key_tzc                 C   s  t g dg ddg dd}d}tjt|d |jdd   W d    n1 s*w   Y  d	}tjt|d |jd
d   W d    n1 sJw   Y  d}tjt|d |jdd  W d    n1 sjw   Y  t g dg ddg ddjd
d}|jdd  }t g dg ddg dd}t|| |jd
d  }t|| |jdd }t g dg ddg dd}t|| d S )Nr`   r6   re   rh   ri   rf   )re   rh   ri   rf   rg   ru   r   )r   r`   r   r`   r6   re   r	   z5'Cannot get left slice bound for non-unique label: 1'r   r`   z5'Cannot get left slice bound for non-unique label: 0'r   r6   axis)r6   rh   ri   rf   )rh   rf   rg   ru   )r`   r`   r6   re   )r6   rh   ri   )rh   rf   rg   )r`   r`   r6   )r   r   r   rD   r&   
sort_indexr'   r(   )r:   r+   r   r   r,   r-   r-   r.   test_loc_non_unique  s8   z*TestLocBaseIndependent.test_loc_non_uniquez
length, l2  r   i 順 c              	   C   s   t d}tttjd|t|ft	||dtt
|t|fdg| |dg}|jjdu s5J t	|}|j| }t|dgtt
t|t|fdgt| |d||dd  g}t|| d S )NZABCDEFGr6   r   r   Fr`   )r   r   concatr   r9   r   r   r_  r   r{   onesr
   Z	is_uniquer&   taker'   r(   )r:   lengthl2r4   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J |jddg jj}|dks,J d S )Nr`   Z
index_namer   )r   r
   r   r   r&   r:   r+   r   r-   r-   r.   test_loc_nameM  s   z$TestLocBaseIndependent.test_loc_namec                 C   s   t tdtdd tdD ddtdd tdD ddd	}tj|jd d g f |jd d d d
f ddd tj|jg d d f |jd d
d d f ddd tj|jg  |jd d
d d f ddd d S )N)ri   r6   c                 S      g | ]}d | qS zi-r-   rW  r-   r-   r.   r   Z      zLTestLocBaseIndependent.test_loc_empty_list_indexer_is_ok.<locals>.<listcomp>ri   r#   r   c                 S   r  r  r-   rW  r-   r-   r.   r   [  r  r6   r   r   T)check_index_typecheck_column_type)	r   r9   r  r   r   r'   r(   r&   r   r   r-   r-   r.   !test_loc_empty_list_indexer_is_okW  s   (( 
z8TestLocBaseIndependent.test_loc_empty_list_indexer_is_okc                 C   s  t dg di}|jd d  }||usJ |d d  |usJ |jd d d d f |us.J t|d j|d js<J t| g d|jd d df< W d    n1 sWw   Y  |rk|d g dk sjJ n
|d dk suJ t tj	d
d}|s|r|d |jd d df usJ n|d |jd d df u sJ tg d}|jd d  }||usJ |d d  |usJ t| g d	|d d
< W d    n1 sw   Y  |rt|d d
 g dksJ d S t|d d
 g d	ksJ d S )Nr#   r~   )rh   rh   rh   rh   r6   rd   rh   r   r}  rj  re   )r   r&   r9   Zshares_memory_valuesr'   assert_cow_warningr  r   r   r_  r   )r:   using_copy_on_writerf  Zoriginal_dfZ	sliced_dfr+   Zoriginal_seriesZsliced_seriesr-   r-   r.   &test_identity_slice_returns_new_objectj  s4      z=TestLocBaseIndependent.test_identity_slice_returns_new_objectc                 C   s   |st jjdd}|| 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 - GH37497r  re   r#   r"   r   r6   )r   r   xfailZapplymarkerr   zipr   r   r&   r'   r(   r
   )r:   rF   r  r   r   r  qzr-   r-   r.   test_loc_copy_vs_view  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s$J |j|d g }|jdg }t|| |j|d |g }t|| d S )Nr   r`   r6   r	   r   )r9   iinfomaxr   r&   r   r'   r   )r:   umaxrO  r   r,   r-   r-   r.   test_loc_uint64  s   
z&TestLocBaseIndependent.test_loc_uint64c                 C   s   t dj}tddg|d |gd}tjtdd |jd  W d    n1 s)w   Y  tjtdd |jdg  W d    d S 1 sGw   Y  d S )Nr   r`   r6   r	   z-1r   r   )r9   r  r  r   r   r   rD   r&   )r:   r  rO  r-   r-   r.   !test_loc_uint64_disallow_negative  s   "z8TestLocBaseIndependent.test_loc_uint64_disallow_negativec                 C   s\   g d}t |tjtjgt| tdd}t ddgd}||jd d df< t|| d S Nr~   r   r   r  r   r  r   )	r   r9   r   r   r   r8   r&   r'   r(   r:   r   r,   r+   r-   r-   r.   *test_loc_setitem_empty_append_expands_rows  s   zATestLocBaseIndependent.test_loc_setitem_empty_append_expands_rowsc                 C   sp   g d}t |tjtjgt| tdd}t ddgd}|d tj|d< ||jd d df< t	
|| d S r  )r   r9   r   r   r   r8   r   r  r&   r'   r(   r  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  r  r   r  r3   )r   r   )r   r9   r   rM  r&   r'   r(   r  r-   r-   r.   *test_loc_setitem_empty_append_single_value     zATestLocBaseIndependent.test_loc_setitem_empty_append_single_valuec                 C   s   ddg}t ddgd}|jtj|_dtt d}tjt	|d ||j
d	dgdf< W d    n1 s7w   Y  d
}tjt|d ||j
d	ddf< W d    d S 1 sZw   Y  d S )Nr`   r6   r   r  r   z"None of \[Index\(\[0, 1\], dtype='z'\)\] are in the \[index\]r   r   )setting an array element with a sequence.)r   r
   r   r9   r  r5   r   r   r   rD   r&   
ValueError)r:   r   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 )Nr`   r6   re   rh   r   r   )r   r&   r9   r   r   r'   r   )r:   r+   r   r   r-   r-   r.   test_indexing_zerodim_np_array  r  z5TestLocBaseIndependent.test_indexing_zerodim_np_arrayc                 C   s,   t ddg}|jtd }|dksJ d S )Nr`   r6   r   )r   r&   r9   r   )r:   r   r   r-   r-   r.   %test_series_indexing_zerodim_np_array   s   z<TestLocBaseIndependent.test_series_indexing_zerodim_np_arrayc                 C   s\   g dd gd  }t |tddd}t tddtjd}g d|jddd	< t|| d S )
Nr}  rh   i  i  r	   r  )rf   ri   rh   re   r6   r`   r   r   )r   r   r9   r   r&   r'   r   )r:   r   r,   r   r-   r-   r.   test_loc_reverse_assignment  s
   z2TestLocBaseIndependent.test_loc_reverse_assignmentc                 C   s   dd t dD }t|dgd}t|dgd}t|| |rDtjtdd dd |D |j|jdf< W d    n1 s>w   Y  n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 )Nc                 S   s$   g | ]}t tjd  d qS )r6   g-q=)r7   r9   r   r   )r   rW   r-   r-   r.   r     s   $ z^TestLocBaseIndependent.test_loc_setitem_str_to_small_float_conversion_type.<locals>.<listcomp>ri   r%   r   r)  r   c                 S      g | ]}t |qS r-   rM  r   r-   r-   r.   r         c                 S   r  r-   r  r   r-   r-   r.   r     r  r3   c                 S   r  r-   r  r   r-   r-   r.   r   $  r  )r   r   r'   r(   r   r   r   r&   r
   rM  r   r8   )r:   r;   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dt|df|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freqrk  rk   r6   re   r	   z1/4/2000r   )r   ZhourZminuter   r9   r   r   r_  r   r'   Zget_objr&   r   r   r
   
_with_freq)	r:   frame_or_seriesrngr  rG   r   r   chunkr,   r-   r-   r.   test_loc_getitem_time_object(  s   
z3TestLocBaseIndependent.test_loc_getitem_time_object
spmatrix_t)Z
coo_matrixZ
csc_matrixZ
csr_matrixr5   c                 C   s   t d}t||}d\}}|tj|||d|d}tj|}td|}|j	| j
}	| | }
t|	|
 |j	| jj
}	t|t|dd}
t|	|
 d S )Nscipy.sparse)ri   rg   r   r6   r   )Z
fill_value)r   importorskipgetattrr9   eyer   sparsefrom_spmatrixr   r&   r   Ztoarrayr'   Zassert_numpy_array_equalrt  Zfullr   )r:   r  r5   	sp_sparseZ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   r`   )r   r   r   r   r&   r'   r(   r  r-   r-   r.   ,test_loc_getitem_listlike_all_retains_sparseW  s   zCTestLocBaseIndependent.test_loc_getitem_listlike_all_retains_sparsec                 C   s   t d}tj|d}|jtd }tg dg dgtddd}t	
|| |jtd jtd	 }tg dgtddd}t	
|| d S )
Nr  ri   r6   r  r   r   r   r   )r   r  r   r   r   r   r   r   r`   )r   r  r   r  r  r  r&   r   r   r'   r(   )r:   r  r+   r   r,   r-   r-   r.   test_loc_getitem_sparse_frame\  s   
z4TestLocBaseIndependent.test_loc_getitem_sparse_framec                 C   s   t g d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   r6   r  re   )r   r   r&   r   r'   r   )r:   r   r   r,   r-   r-   r.   test_loc_getitem_sparse_seriesn  s   z5TestLocBaseIndependent.test_loc_getitem_sparse_seriesr&   r   c                 C   sP   t g dg dgttd}t||d }tg dttdd}t|| d S )N)r  r         ?)r   r   r   r   r   )r5   r   )r   r   rM  r  r   r'   r   )r:   r   r+   r   r,   r-   r-   r.   !test_getitem_single_row_sparse_dfz  s   z8TestLocBaseIndependent.test_getitem_single_row_sparse_dfkey_typec                 C   sD   |g d}|j d d |f }|j d d g df }t|| d S )Nr   )r&   r'   r(   )r:   float_framer  idxr   r,   r-   r-   r.   test_loc_getitem_iterable  s   z0TestLocBaseIndependent.test_loc_getitem_iterablec                 C   sh   t tjdjdd}tdddd|_|jtdd d d f }|jdd d d f }t	
|| d S )Nr6   r  r   Z0srd   r   startperiodsr  )r   r9   r   r   Znormalr   r
   r&   r   r'   r(   r   r-   r-   r.   #test_loc_getitem_timedelta_0seconds  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 )Nr`   r6   r  r  r	   )r   r&   r   r'   r   )r:   r  r,   r+   r   r-   r-   r.   test_loc_getitem_uint64_scalar  s   
z5TestLocBaseIndependent.test_loc_getitem_uint64_scalarc                 C   sL   |}t g dtg d|dd}| }d|jd< d|jd< t|| d S )Nr   )r         ?r`   r   r	   Zzoor`   r6   )r   r   r   r&   r   r'   r   )r:   float_numpy_dtyper5   rO  r,   r-   r-   r.   +test_loc_setitem_int_label_with_float_index  s   

zBTestLocBaseIndependent.test_loc_setitem_int_label_with_float_indexzindexer, expected)
rT   r`   r6   re   rh   ri   rf   rg   ru   rk  )
r   r`   r6   re   rT   rT   rT   rT   ru   rk  )
r   r`   r6   rT   rh   rT   rf   rg   ru   rk  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 )	Nrd   r   r2  r   r  r5   r
   rT   rJ  )r   r   r   r&   r
   r'   r(   )r:   r   r,   tdir+   r-   r-   r.   /test_loc_setitem_listlike_with_timedelta64index  s   zFTestLocBaseIndependent.test_loc_setitem_listlike_with_timedelta64indexc                 C   s   t g dtdd}t g dtdd}tj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< W d    n1 sJw   Y  t|| d S )Nr`   r`   r`   r`   r`   Zaaaaar   )r`   r"   r"   r`   r`   Zaabbar   r   r"   r#   
categoriesr`   r6   re   )r   r   r'   r   r   r   r&   r(   )r:   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 g dd}||jd d df< |d }t||jdd|s,tnd}t|| ||d< t|d t|dd	 d S )
Nr#   r   )AlphaZNumericr  r   r  r   r7   r   )	r   r   r&   r   r
   r   r8   r'   r   )r:   r;   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s"J td|jd ks-J tjtd	d
 tddd|jd< W d    n1 sHw   Y  td |jd ksZJ d S )NrK   z
2010-10-01re   z
2008-08-08r   r`   )r   rK   )r`   rK   r  r   i  ri   )r6   rK   z
2005-05-05)	r   r   r9   r:  r&   r'   r   r   r   r   r-   r-   r.   "test_loc_setitem_datetime_coercion  s   z9TestLocBaseIndependent.test_loc_setitem_datetime_coercionidxervarc                 C   s   |}t ddd|d}td|dgd}t|dgtjd}tj|dkr#tnd d	d
 ||jd d |f< W d    n1 s<w   Y  t|| d S )Nz
2015-07-12re   r5  )r  r  r  tzr   r  r   rJ  r  r   )	r   r   r9   r   r'   r   r   r&   r(   )r:   r  Ztz_naive_fixturer  r  r,   r   r-   r-   r.   !test_loc_setitem_datetimeindex_tz  s   z8TestLocBaseIndependent.test_loc_setitem_datetimeindex_tzc           
      C   sj  t dddd}ttjdt|df|d}tdd	d	}ttd
d	d	tdd	d	}g d}g d}|	 }d	|j
|< |j
| }|j
| 	 }	d	|	j
d d < |rV|	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  r6   ri   r	   rn  r         )   H   x      )         J   K   L   z   {   |            )r   r   r9   r   r   r_  r   r   r   r   r&   r   rM  r'   r(   r   )
r:   Zusing_array_managerr
   r+   ZakeyZbkeyZaindsZbindsr   r,   r-   r-   r.   test_loc_setitem_time_key  s@   







z0TestLocBaseIndependent.test_loc_setitem_time_keyr[   c                 C   s   t g d}tg dg dg|d}| }tjddd|jd d |f< tg dg d	g|d}t|| |j	d
d}tjddd|jd d |f< |j	d
d}t|| d S )N))r%   rh   )r   3)r%   r2   r~   rh   ri   rf   r   r6   r6   r  r   )r   r6   r   )r   ri   r   r`   r~  )
r   from_tuplesr   r   r9   Zzerosr&   r'   r(   r  )r:   r[   r/  r+   rG   r,   r-   r-   r.   ,test_loc_setitem_unsorted_multiindex_columns"  s   zCTestLocBaseIndependent.test_loc_setitem_unsorted_multiindex_columnsc                 C   s:   t g d|d}d|jd< t g d|d}t|| d S )Nr~   r   rh   r   )rh   r6   re   r   r&   r'   r   )r:   Zany_int_numpy_dtyper*   r,   r-   r-   r.   test_loc_setitem_uint_drop1  s   
z1TestLocBaseIndependent.test_loc_setitem_uint_dropc                 C   sl   t dtddg }tdd|jg d< t dtddg }ttdd|jg d< t|| d S )Nrd   r6  rT   r~   )r   r9   timedelta64r&   r   r'   r   )r:   rO  r,   r-   r-   r.   test_loc_setitem_td64_non_nano9  s
   z5TestLocBaseIndependent.test_loc_setitem_td64_non_nanoc                 C   s   t jdd}ttddd}d}tjt|d ||j	td< W d    n1 s,w   Y  tjt|d ||j	d d < W d    d S 1 sKw   Y  d S )Nr6   r  r   r   r  r   )
r9   r   r   r_  r   r   r   r   r  r&   )r:   r   rO  r   r-   r-   r.    test_loc_setitem_2d_to_1d_raisesA  s   "z7TestLocBaseIndependent.test_loc_setitem_2d_to_1d_raisesc                 C   sP   t jddd}tg dg dg dg|g dd}d	}|jd
 }t|| d S )Nr   re   )r  r  r~   r  rj  r   r   r`   )r  r%   )r   interval_ranger   r&   r'   assert_almost_equal)r:   r
   r+   r,   r   r-   r-   r.   test_loc_getitem_interval_indexM  s   
z6TestLocBaseIndependent.test_loc_getitem_interval_indexc                 C   sr   t jdddd}tg dg dg dg|g dd	}t jdd
ddd}tddg|dd}|jd }t|| d S )Nr   re   Zboth)r  r  closedr~   r  rj  r   r   r6   r`   )r  r  r  r  rh   r%   r   r`   r%   )r   r  r   r   r&   r'   r   )r:   r
   r+   Z	index_expr,   r   r-   r-   r.    test_loc_getitem_interval_index2X  s   
z7TestLocBaseIndependent.test_loc_getitem_interval_index2tplr`   r`   r6   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r   Ztupleize_colsr	   )r   r   r&   r'   r(   )r:   r
  r  r+   r   r,   r-   r-   r.   +test_loc_getitem_index_single_double_tuplesd  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s5J d S )N	IndexTyper#   r"   r   r   re  ZbofZcomposite_indexFr  r  )re   rh   r%   r   r   r`   )r   r   r   r&   )r:   r  Zidx1Zidx2r
   r+   r   r-   r-   r.   !test_loc_getitem_index_namedtuples  s   

z8TestLocBaseIndependent.test_loc_getitem_index_namedtuplec                 C   s   t tjddg dg dd}d|d< tj|j|jd d d df< ttjdtjdtjg|s2t	nddj
}t|d j
| d S )	Nr6   ri   re   )r#   r"   rK   r   r   rd  r   quxr7   r   )r   r9   r   r   r_  r   r&   r
   r   r8   r   r'   r  )r:   r;   r+   r,   r-   r-   r.   $test_loc_setitem_single_column_mixed}  s   
z;TestLocBaseIndependent.test_loc_setitem_single_column_mixedc                 C   s   t tjddtdd}tj|d< tjtdd d|j	d	< W d    n1 s+w   Y  |j
}ttd
gd tdg g dd}t|| d S )Nr6   )rk   re   ABCr   eventr   r   r   )rd   r  r   re   r8   )r%   r   r   r  r	   )r   r9   r   r   tupler   r'   r   r   r&   rt  r   r5   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J td|_|jjttjks/J d S )Nonerf   r   )r`   r  rg   )r   r9   r{   Zint8r&   rt  r  r5   r   r-   r-   r.   test_loc_setitem_cast3  s
   
z-TestLocBaseIndependent.test_loc_setitem_cast3c                 C   sf   |t dg dd}g d}|jdkrdgdgdgg}||jt d	< |g d
|jd}t|| d S )Nri   )re   rh   r`   r   r6   r	   )rk  rd   rm  r6   rk  rd   rm  re   )r   r`   rd   rk  rm  )r   ndimr&   r
   r'   r   )r:   r  rG   r   r,   r-   r-   r.   test_loc_setitem_range_key  s   
z1TestLocBaseIndependent.test_loc_setitem_range_keyc                 C   s^   t g dg dd}tddgddgd|jdddf< t g dg dd}t|| d S )	Nr  r   r   r6   r`   r  r#   )r`   r6   r6   r`   r`   r   r   r&   r'   r(   r|   r-   r-   r.   .test_loc_setitem_numpy_frame_categorical_value  s   "zETestLocBaseIndependent.test_loc_setitem_numpy_frame_categorical_value)lr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  fixturer  r9   r   r  r  r  r  r  r  r  r   r1  r;  rG  filterwarningsrP  rQ  rR  r\  r`  ra  rc  rg  r   ri  r   r   rq  ru  rw  ry  r|  r  Zarm_slowr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   complexr  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.   r     sn   
#
'
$
	
=






%
	$
	"		 
3""
+








(


r   c                   @   sZ   e Zd Zejejejgddd Zejdd Z	dd Z
ejdd	d
 Zdd ZdS )TestLocWithEllipsis)paramsc                 C   s   |j S ro   )Zparam)r:   rF   r-   r-   r.   r     s   zTestLocWithEllipsis.indexerc                 C   s   |}|t ur
| }|S ro   )r   to_frame)r:   series_with_simple_indexr  rG   r-   r-   r.   rG     s   zTestLocWithEllipsis.objc                 C   s   ||d }t || d S )N.)r'   r   )r:   rG   r   r   r-   r-   r.   test_loc_iloc_getitem_ellipsis  s   z2TestLocWithEllipsis.test_loc_iloc_getitem_ellipsis3ignore:PeriodDtype\[B\] is deprecated:FutureWarningc           
      C   s*  |}|t ju st|dkrdn|jd }|t ju r!|jjdkr!d S |t ju rOt|jtrOd}tj	t
|d ||d|gf }W d    n1 sIw   Y  nt|dkrk||d|gf }|||g }t || |t ju rrdn|j}| }	||	d|gf }||	d d |gf }t || d S )Nr   r  z2MultiIndex does not support indexing with Ellipsisr   .)r'   r   r   r
   r&   inferred_typer   r   r   r   NotImplementedErrorr   r   r$  r(   )
r:   r%  r   rG   r[   r   r   r,   Zkey2r+   r-   r-   r.   &test_loc_iloc_getitem_leading_ellipses  s&   $z:TestLocWithEllipsis.test_loc_iloc_getitem_leading_ellipsesc                 C   s&  |t ju st|dkrdn|jd }tjttd ||d  W d    n1 s*w   Y  tjttd ||d|gdf  W d    n1 sKw   Y  tjttd ||dd|f  W d    n1 skw   Y  tjtdd |||ddf  W d    d S 1 sw   Y  d S )Nr   r   )...Too many indexers)r'   r   r   r
   r   r   r   r    )r:   rG   r   r[   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   rG   r&  r   r  r*  r,  r-   r-   r-   r.   r"    s    



r"  c                   @   s  e Zd Zejdddgg dg dgfddgg dg dgfddgddgfg dg dgfddgddgfg dg d	gfddgddgfg dg d	gfddgddgfg dg dgfd
dgddgfg dg d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/d0 Zd1d2 Zd3d4 Zd'S )5TestLocWithMultiIndexzkeys, expectedr"   r#   )r"   r"   r#   r#   )r`   r6   r`   r6   )r#   r#   r"   r"   r`   r6   )r6   r`   r6   r`   rK   )rK   r#   r#   )r`   r6   r`   dimr
   r4   c                 C   s   |g dg dgi}t tdddfi |}t|}|dkr4|j|d d f }t|j	| d S |dkrJ|jd d |f }t|j
| d S d S )N)rK   r#   r#   r"   r"   )r`   r`   r6   r`   r6      ri   r
   r4   )r   r9   r{   reshaper   r+  r&   r'   assert_index_equalr
   r4   )r:   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sJ |jj|jjdd  ks*J |j d }|d j d }|jj|jjd ksBJ |jj|jjd ksNJ d S )N  r%   r`   )r6  r6   r6   )r&   r
   r#  r   )r:   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   r`   r	   )r   from_productr   r&   r'   r   r   )r:   r/  rO  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 u sJ tdgddgg}t d gt| t|d}|jd }|d u s9J t dgt| t|d}|jd }|dksPJ d S )	NLevel1Level2)r;  r<  Level2_aZLevel2_br  )r;  r=  r`   )r   r   r+  r&   r9  r   r8   )r:   rO  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g dg dddgd}tg d|d}d|jd	d
< tg d|d}t|| d S )N)r   r   re  re  r   r   r  r  )r  twor  r?  r  r?  r  r?  firstsecondr"  )r`   r`   r`   r`   r`   r`   r`   r`   r	   r   )re  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.   !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10minr  r  r  il  r`   i4  )r   r   r   r&   r   r'   r   )r:   timesrO  r   r-   r-   r.   7test_loc_getitem_slice_datetime_objs_with_datetimeindexN  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 )Nrd   r   z
2010-01-01z
2010-01-10r	   z
2010-01-05r#   r"   r   rh   )r   r   r   r&   r   r'   r(   r   r-   r-   r.   3test_loc_getitem_datetime_string_with_datetimeindexT  s   
zITestLocWithMultiIndex.test_loc_getitem_datetime_string_with_datetimeindexc                 C   s   t jg d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|g dd}|jd }t|| d S )N)r   r   rG  ZbahZbamrH  rG  rH  r%   r   r"  r  r`   r   r6   ra   re         @rh         @ri         @rf   r   r  r   r   )level)r   r`   rh   rz   rG  )r   r  r   r  r  r&   r'   r(   )r:   r/  r+   r,   r   r-   r-   r.   3test_loc_getitem_sorted_index_level_with_duplicatesa  s*   &
zITestLocWithMultiIndex.test_loc_getitem_sorted_index_level_with_duplicatesc                 C   s:   t g ddd}d|jd< t g ddd}t|| d S )Nr   categoryr   r   re   )r#   r"   rK   r   r8   r  r:   r   r,   r-   r-   r.   1test_additional_element_to_categorical_series_loc     
zGTestLocWithMultiIndex.test_additional_element_to_categorical_series_locc                 C   s:   t g ddd}d|jd< t g ddd}t|| d S )Nr   rN  r   r#   re   r#   r"   rK   r#   r  rO  r-   r-   r.   'test_additional_categorical_element_loc  rQ  z=TestLocWithMultiIndex.test_additional_categorical_element_locc                 C   s   t g dttg d|dd}tj|jd< t dddtjgttg d|dd}t|| tj|jd< t dtjdtjgttg d|dd}t|| d S )Nr~   r   re   r`   r6   )r   r   r   r9   r   r&   r'   r   )r:   Zany_numeric_ea_dtypeZsrsr,   r-   r-   r.   &test_loc_set_nan_in_categorical_series  s    z<TestLocWithMultiIndex.test_loc_set_nan_in_categorical_seriesnaNc                 C   sd   t g ddd}||jd< t g ddd}||jd< t|| t ddd|gdd}t|| d S )	Nr   rN  r   re   rR  r#   r"   rK   r  )r:   rU  Zsrs_enlargeZsrs_setintor,   r-   r-   r.   ,test_loc_consistency_series_enlarge_set_into  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 )Nr6      r#   r"   rd   r   ri   r`   ZIndex1ZIndex2)r.  Zcodesr#  )r   r
   FrN  )r  orderedr   r5   )r   r9   r{   r   r   r   r
   r.  r'   r1  r&   r   r-   r-   r.   5test_loc_getitem_preserves_index_level_category_dtype  s&   	zKTestLocWithMultiIndex.test_loc_getitem_preserves_index_level_category_dtypelt_valuerk   rd   c                 C   s~   t dg ditdg dgd}tjtdd |j|d |k d d f jdgd d f  W d    d S 1 s8w   Y  d S )	Nr#   )rn     "   -   aabbr   r`   r6   re   r	   z\['b'\] not in indexr   r"   )r   r   r   r   rD   r&   )r:   rZ  r+   r-   r-   r.   >test_loc_multiindex_levels_contain_values_not_in_index_anymore  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   re  r   r`   r	   )	r9   r   r   r   r+  r   r&   r'   r   )r:   lev1lev2r/  rO  r   r,   r-   r-   r.   'test_loc_multiindex_null_slice_na_level  s   z=TestLocWithMultiIndex.test_loc_multiindex_null_slice_na_levelc                 C   sr   t jtdtdddggg dd}ttd|d}|jd	d d d d f }|jd
d d }t	|j| d S )Nabxyr`   r6   )rd  re  Znumr"  ru   r	   r#   r   rh   )
r   r9  r   r   r   r&   r
   Z	droplevelr'   r1  )r:   r/  rO  Z
loc_resultr,   r-   r-   r.   test_loc_drops_level  s   z*TestLocWithMultiIndex.test_loc_drops_level)r   r   r   r   r   r   r5  r8  r:  r>  rB  rE  rF  rM  rP  rS  rT  r9   r   r   ZNAr   rV  rY  r`  rc  rf  r-   r-   r-   r.   r-    s>    "

r-  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	j
ddd dd dd dd gg dddd Zdd Zdd Zdd Zdd Zej	dej	
ddd gd!d" Zej	
d#g d$d%d& Zd'd( Zd)S )*TestLocSetitemWithExpansionc                 C   s   d}|   |td| tdt|idd}||j|< W d    n1 s'w   Y  tdt|d idd}t|| d S )N2   Z_SIZE_CUTOFFr   r  r   r`   )contextsetattrlibindexr   r   r&   r'   r(   )r:   ZmonkeypatchZsize_cutoffr   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   r`   r	   re   r   r8   r&   r'   r   r:   rO  r-   r-   r.   test_loc_setitem_empty_series  
   


 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  r`   r	   ra   re   rm  rn  r-   r-   r.   #test_loc_setitem_empty_series_float  rp  z?TestLocSetitemWithExpansion.test_loc_setitem_empty_series_floatc                 C   s   t td}d|jd< t|t dgtdgd d|jd< t|t ddgtddgd d|jd< t|t g dtg d	d d S )
Nr   r`   r   r	   re   r   rh   )r`   re   rh   )r   r   re   )r   r8   r&   r'   r   r   rn  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|< q!td|d
}t|| d S )Nr   rm  r`   
US/Pacific)Ztzinfoc                    s   g | ]} t |d  d qS )r  )Zseconds)r   rW  baser-   r.   r         zUTestLocSetitemWithExpansion.test_loc_setitem_incremental_with_dst.<locals>.<listcomp>   r   r	   )r   r   r   r   r&   r'   r   )r:   Zidxsr   rR   r,   r-   rt  r.   %test_loc_setitem_incremental_with_dst  s   zATestLocSetitemWithExpansion.test_loc_setitem_incremental_with_dstconvc                 C      | S ro   r-   r   r-   r-   r.   r   $      z$TestLocSetitemWithExpansion.<lambda>c                 C      |   S ro   )to_datetime64r   r-   r-   r.   r   %  r   c                 C   r|  ro   )to_pydatetimer   r-   r-   r.   r   &  r   c                 C   s
   t | S ro   )r9   r:  r   r-   r-   r.   r   '     
 )r:   r}  r~  znp.datetime64)idsc                 C   s   t d}t d}t }d|j||df< d|j||df< |r-|jjjdks(J |jj}nd}tddd	git||g|d
tdgd}t|| d S )Nz20130101 09:00:00z20130101 10:00:00r   r  rw   r4  datetime64[ns]g      Y@g      i@r   r   )	r   r   r&   r
   r5   r=   r   r'   r(   )r:   ry  r;   Zdt1Zdt2r+   	exp_dtyper,   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%   r`   r"   )rX  r   r   r  )r:   rX  r   r,   r-   r-   r.   1test_loc_setitem_categorical_column_retains_dtypeB  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}||vs J 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leftr5  )Z	inclusiver  r   r   rn  rJ  )r   r   r   r&   r9   r   r   appendr   r8   r'   r(   )r:   r  endrR   r  r   r,   r-   r-   r.   0test_loc_setitem_with_expansion_and_existing_dstI  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   )r   r4   newoldnew_colrr  rs  r   )r`   r   r   Z1s)r   r   r   r
   rs  r   r  Z
tz_convertr   r&   r   r'   r   r   )r:   r+   vr   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 )Nr`   r^  r6   )r`   r`   re   r   r   )	r   r&   r9   infr4   r   r   r'   r1  r   r-   r-   r.   0test_loc_setitem_with_expansion_inf_upcast_emptyq  s   

zLTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_inf_upcast_emptyz"ignore:indexing past lexsort depthrH  TFc                 C   s  t |s	td |d}t |}t|tj}t||dgd}d}||vs+J |	t ||}t
|trC|d d |ksBJ n|d |ksKJ t|d tj}t||dgd}	| }
|rj|
d d  }||
j|df< t|
|	 | d }|r|d d  }||j|< |	d tj}	t||	 | }
|r|
d d  }||
j|df< tt|tjg tjg| t|g d|d	}	t|
|	 d S )
NzNot relevant for empty Indexr6   r   r   Zkapowr   r`   r   r`   r	   )r   r   skiprepeatr9   r{   r   r  r   insertr   r   r   r   r&   r'   r(   r   r   r   rM  )r:   r
   rH  NarrZorigr[   r4  Zexp_datar,   r+   rN  rO  r-   r-   r.   /test_loc_setitem_with_expansion_nonunique_index|  sD   



&zKTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_nonunique_indexr5   )ZInt32Int64ZUInt32ZUInt64ZFloat32ZFloat64c                 C   sz   t g d|d}td|i}t|jd}||j|jdf< tj||dd t|jd}|j|j|jdf< tj||dd d S )Nr_  r   r   r	   Fr  )r   r   r
   r&   r'   r(   r  )r:   r5   rO  r+   r   r-   r-   r.   6test_loc_setitem_with_expansion_preserves_nullable_int  s   zRTestLocSetitemWithExpansion.test_loc_setitem_with_expansion_preserves_nullable_intc                 C   s   t dtdi}tdddd}||jg ddf< |ttjtjg|jd	}t td|d
}|j	d |jks9J t
|| d S )Nr%   ri   
2016-01-01re   rs  r  r  r_   r   r   r   )r   r   r   r&   r  r   r   r   r5   rt  r'   r(   )r:   r+   r  Zbexr,   r-   r-   r.   #test_loc_setitem_ea_not_full_column  s   z?TestLocSetitemWithExpansion.test_loc_setitem_ea_not_full_columnN)r   r   r   rl  ro  rq  rr  rx  r   r   r   r  r  r  r  r  r  r  r  r  r-   r-   r-   r.   rg    s8    






3
rg  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestLocCallablec                 C   sx  t g dtdg d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g d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sJ d S )Nr`   r6   re   rh   r^  r   c                 S   
   | j dkS Nr6   r%   r   r-   r-   r.   r     r  zATestLocCallable.test_frame_loc_getitem_callable.<locals>.<lambda>r6   c                 S   
   | j dkS )Nr"   )r   r   r-   r-   r.   r     r  r"   c                 S   r  r  r  r   r-   r-   r.   r     r  c                 S   r  Nr   r   r   r-   r-   r.   r     r  )FTFc                 S   r  r  r  r   r-   r-   r.   r     r  c                 S      dS r  r-   r   r-   r-   r.   r     r{  r   c                 S   r  r  r  r   r-   r-   r.   r     r  c                 S      ddgS Nr%   r   r-   r   r-   r-   r.   r     r   r%   c                 S   r  r  r  r   r-   r-   r.   r     r  c                 S   r  r  r-   r   r-   r-   r.   r     r   c                 S   r  )Nr`   r-   r   r-   r-   r.   r     r{  c                 S   r  r$   r-   r   r-   r-   r.   r     r{  r  )r   r   r&   r'   r(   r%   r   r   r:   r+   r   r-   r-   r.   test_frame_loc_getitem_callable  s       z/TestLocCallable.test_frame_loc_getitem_callablec                 C   s   t g dtdg d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 )Nr  r^  r   c                 S   r  r  r  r   r-   r-   r.   r     r  zITestLocCallable.test_frame_loc_getitem_callable_mixture.<locals>.<lambda>r%   r   r6   re   c                 S   r  r  r-   r   r-   r-   r.   r     r   c                 S   r  r  r-   r   r-   r-   r.   r     r   )r   r   r&   r'   r(   r%   r   r  r-   r-   r.   'test_frame_loc_getitem_callable_mixture  s    z7TestLocCallable.test_frame_loc_getitem_callable_mixturec                 C   s  t g dtddtdd}|jdd  }t||jdd	g  |jd
d d d f }t||jdd	gd d f  |jdd dd f }t||jdd	gdf  |jdd dd f }t||jdd	gdgf  |jdd	gdd f }t||jdd	gdf  |jdd	gdd f }t||jdd	gdgf  |jdd df }t||jdd	gdf  |jdd dgf }t||jdd	gdgf  d S )Nr  r^  Xr3  r]  r	   c                 S   r  Nr%   r   r-   r   r-   r-   r.   r     r   zHTestLocCallable.test_frame_loc_getitem_callable_labels.<locals>.<lambda>r%   r   c                 S   r  r  r-   r   r-   r-   r.   r   	  r   c                 S   r  r  r-   r   r-   r-   r.   r   	  r   c                 S   r  Nr  r-   r   r-   r-   r.   r   	  r{  r  c                 S   r  r  r-   r   r-   r-   r.   r   	  r   c                 S      dgS r  r-   r   r-   r-   r.   r   	      c                 S   r  r  r-   r   r-   r-   r.   r   	  r{  c                 S   r  r  r-   r   r-   r-   r.   r   	  r  c                 S   r  r  r-   r   r-   r-   r.   r   	  r   c                 S   r  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   s^  t g dttdtddtdd}| }d|jdd	 < | }d|jd
dg< t|| | }d|jdd	 d d f< | }d|jd
dgd d f< t|| | }d|jdd	 dd	 f< | }d|jd
dgdf< t|| | }d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 )Nr  r^  r   r  r]  r	   ic                 S   r  r  r-   r   r-   r-   r.   r   !	  r   zATestLocCallable.test_frame_loc_setitem_callable.<locals>.<lambda>r%   r   rT   c                 S   r  r  r-   r   r-   r-   r.   r   '	  r   r   c                 S   r  r  r-   r   r-   r-   r.   r   -	  r   c                 S   r  r  r-   r   r-   r-   r.   r   -	  r{  r  ri   rd   c                 S   r  r  r-   r   r-   r-   r.   r   3	  r   c                 S   r  r  r-   r   r-   r-   r.   r   3	  r  r   c                 S   r  r  r-   r   r-   r-   r.   r   :	  r{  c                 S   r  r  r-   r   r-   r-   r.   r   @	  r  c                 S   r  r  r-   r   r-   r-   r.   r   F	  r   c                 S   r  r  r-   r   r-   r-   r.   r   L	  r   )
r   r   r   r8   r   r&   r'   r(   r9   r   )r:   r+   r   r   r-   r-   r.   test_frame_loc_setitem_callable	  sX    z/TestLocCallable.test_frame_loc_setitem_callableN)r   r   r   r  r  r  r  r-   r-   r-   r.   r    s
    r  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   s^   t g dg ddtg dd}t ddgdd	gdtd
dgd}|jd }t|| d S )Nr   r~   )rx   ry   )
2020-08-01z
2020-07-02
2020-08-05r	   r#   rK   r`   re   r  r  z2020-08)r   r   r&   r'   r(   r   r-   r-   r.   5test_loc_getitem_partial_string_slicing_datetimeindexS	  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-01r4  r  r  r  z2017-12r   )r   period_range	to_seriesr&   r   r'   r   )r:   ZpirO  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1hr  z1 daysr   )r   r  r&   r   r'   r   )r:   r   rO  r   r,   r-   r-   r.   ;test_loc_getitem_partial_string_slicing_with_timedeltaindexh	  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   re   Zdaysr  r	   r   0 days)r   r   r   r   r&   r'   r   )r:   r+   r,   Zslicedr-   r-   r.   #test_loc_getitem_str_timedeltaindexp	  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 )Nr`   ri   z
2019-12-30z
2020-01-01z
2019-12-25r  z
2019-12-19r  r	   r6   )r   r   r   r'   r   r&   )r:   Ztz_aware_fixturer  r  rG   r,   r   r   r-   r-   r.   /test_loc_getitem_partial_slice_non_monotonicityw	  s4   


zHTestPartialStringSlicing.test_loc_getitem_partial_slice_non_monotonicity)r   r   r   r  r  r  r  r   r   r   r  r-   r-   r-   r.   r  R	  s    r  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 ]c}|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|| q$d S )NrI  r   r   c                 S      g | ]
}t d d|ddqS   r`   rd   r   r   rW  r-   r-   r.   r   	      zMTestLabelSlicing.test_loc_getitem_slicing_datetimes_frame.<locals>.<listcomp>r  r	   rJ  c                 S   r  r  r  rW  r-   r-   r.   r   	  r  )r`   r6   r6   re   rh   r  r`   rd   rh   rm  z20010101 11)r   r9   r{   r&   r   r'   r(   r   )r:   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g d|d}tddd	}td
dd	}|j|| }tddg|dd d}t|| || }d}||ksAJ d S )Nz2017-10-29 01:30:00zEurope/Berlinri   z30 min)r  r  r  )r   r`   r6   re   rh   r	   z2017-10-29 02:30:00+02:00r  z2017-10-29 02:00:00+01:00r6   re   rh   )r   r   r   r&   r'   r   )r:   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_dstr
   r  r  r4  r  r  r  r  c                 C   s8   |  }|jd |d  }|jd d }t|| d S )Nr   r   )r  r&   r   r'   r   )r:   r
   rO  r   r,   r-   r-   r.   -test_loc_getitem_label_slice_period_timedelta	  s   z>TestLabelSlicing.test_loc_getitem_label_slice_period_timedeltac                 C   s   g d}t tjdd|d}|jdd }t|dks J |jdd }t|dks/J |jdd }t|d	ks>J d S )
N)gx"p|@g\Va|@g|@r6   re   r6   r	   g3333c|@g    |@g3333|@g|@re   )r   r9   r   r   r&   r   )r:   r
   r+   s1r-   r-   r.   %test_loc_getitem_slice_floats_inexact	  s   z6TestLabelSlicing.test_loc_getitem_slice_floats_inexactc                 C   s   |}t tjddtjdd|dd}t|jdd  dks"J t|jdd  d	ks/J tjdd|d}d
|d< ||_t|jdd  dksKJ t|jdd  d	ksXJ d S )Nr6   rd   rT   r   r	   r*  ru   g      )@rg   gffffff(@)r   r9   r   r   r{   r   r&   r
   )r:   r  r5   rO  r  r-   r-   r.   'test_loc_getitem_float_slice_floatindex	  s   z8TestLabelSlicing.test_loc_getitem_float_slice_floatindexzstart,stop, expected_slicer   nsNrm  r`   r  rf   rg   rh   ri   c                 C   s>   t tdtdd}|jt|| }|j| }t|| d S )Nrm  r  z10 days)r   r   r   r&   r   r   r'   r   )r:   r  stopZexpected_slicerO  r   r,   r-   r-   r.   $test_loc_getitem_slice_label_td64obj	  s   

z5TestLabelSlicing.test_loc_getitem_slice_label_td64objr  Z2018Z2020c                 C   sd   |g dt dt dt dgd}tjtdd |j|d  W d    d S 1 s+w   Y  d S )	Nr~   Z2016Z2019Z2017r	   z,Value based partial slicing on non-monotonicr   r   )r   r   r   rD   r&   )r:   r  r  rG   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 )Nrh   r@  r6   Zthirdr	   )r   r&   r'   r   )r:   r  r   rG   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 )	Nr`   r6   re   )testr`   r6   r   r	   r   )r   r
   r4   )r   r   r8   r'   r(   r&   r|   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   r   r  r   r  r  r  r9   r  r   r  r  r  r  r-   r-   r-   r.   r  	  s2    




r  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   sb   | d}|j dkr/||dd}tjt|d |j|  W d    d S 1 s(w   Y  d S d S )Nz7: boolean label can not be used without a boolean indexr  r8   r  r   )r(  r   r   rD   r&   )r:   r
   r  r  messagerG   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   r8   r  )r   r&   )r:   r  r  rG   r-   r-   r.   test_loc_bool_should_not_raise,
  s   z<TestLocBooleanLabelsAndSlices.test_loc_bool_should_not_raisec                 C   sR   d}||dd}t jt|d |jdd  W d    d S 1 s"w   Y  d S )NzEslice\(True, False, None\): boolean values can not be used in a slicer8   r  r   TF)r   r   r   r&   )r:   r
   r  r  rG   r-   r-   r.   test_loc_bool_slice_raises3
  s   "z8TestLocBooleanLabelsAndSlices.test_loc_bool_slice_raisesN)	r   r   r   r   r   r   r  r  r  r-   r-   r-   r.   r   
  s    


r  c                   @   sl   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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}g dg dg dg}t||D ]$\}}| }d|j|df< t |ttddddgd	d
}t|| q2d S )Nr   rd   r   r  re   )
r   r`   r6   re   rd   rd   rd   rd   rd   rd   )
r   r`   r6   rd   rh   ri   rf   rg   ru   rk  )
rd   rd   rd   re   rh   ri   rf   rg   ru   rk  r  rJ  )	r   r   r   r
   r  r   r&   r'   r(   )r:   r+   Z
conditionsexpected_dataZcondr   r   r,   r-   r-   r.   )test_loc_setitem_bool_mask_timedeltaindex>
  s$   "z<TestLocBooleanMask.test_loc_setitem_bool_mask_timedeltaindexr  Nrr  c                 C   s   t g d}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 )Nrr   Z20010101rh   r  r#   r	   r   )
r9   r   r   r   r{   r   r   r&   r'   r(   )r:   r  r  r  r+   r   r-   r-   r.   +test_loc_setitem_mask_with_datetimeindex_tzT
  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 )NrK  re   r6   ZABr  r  )r  r  rz   r   r   r`   )r   r9   r{   r0  r   r   r   r
   r   r   r%   r&   r'   r(   )r:   r+   r,   r  r-   r-   r.   2test_loc_setitem_mask_and_label_with_datetimeindexe
  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s8J t|| d S )Nr   l   ,GsO1colr`   TF)	r   r   r   r   r   Z_valuer&   r'   r(   )r:   Ztd1Ztd2r+   Zdf_copyrO  r,   r   r-   r-   r.   'test_loc_setitem_mask_td64_series_valuet
  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   r   r`   r   )r   r&   r   r   r
   r4   r'   r(   )r:   r  r,   r  r   r-   r-   r.   #test_loc_setitem_boolean_and_column
  s   
z6TestLocBooleanMask.test_loc_setitem_boolean_and_columnc                 C   s|  t g dg dd}t dg dig dd|jg ddgf< t g d	g dd}t|| t g dg dd}tg d
g dd|jg ddgf< t|| t g dg dd}tg d
g dd|jg ddf< t|| t g dg dd}| }|d }t| tg d
g dd|jg d< W d    n1 sw   Y  |rt|| d S t|| d S )Nr~   r  r   r#   r   )r6   r`   r   r	   )FFT)r`   r6   rd   rl  )r   r&   r'   r(   r   r   r  )r:   r  rf  r+   r,   r   rO  r-   r-   r.   )test_loc_setitem_ndframe_values_alignment
  s*   $" z<TestLocBooleanMask.test_loc_setitem_ndframe_values_alignmentc                 C   sN   t g g dtd}| }|d  |jtjg tjddgf< t|| d S )Nr   r   r#   	r   r8   r   r&   r9   r   Zbool_r'   r(   r|   r-   r-   r.    test_loc_indexer_empty_broadcast
  s   $z3TestLocBooleanMask.test_loc_indexer_empty_broadcastc                 C   sT   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  r|   r-   r-   r.   $test_loc_indexer_all_false_broadcast
  s   &z7TestLocBooleanMask.test_loc_indexer_all_false_broadcastc                 C   sb   t dgdgdtd}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"   Tr#   r  r|   r-   r-   r.   test_loc_indexer_length_one
  s   &z.TestLocBooleanMask.test_loc_indexer_length_one)r   r   r   r  r   r   r   r  r  r  tdskip_array_manager_invalid_testr  r  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 )TestLocListlikerp  c                 C   rz  ro   r-   r   r-   r-   r.   r   
  r{  zTestLocListlike.<lambda>c                 C   sL  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 d    n1 saw   Y  t
jt|d |||  W d    n1 s~w   Y  t
jt|d | j||  W d    d S 1 sw   Y  d S )	Nr%   r   re   r	   r   r`   r   r   )r   r9   r   r   r   r&   r'   r   r$  r(   r   r   rD   )r:   rp  ZcirO  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   sh   t jg ddd}tg dtdddd}tjtd	d
 |j|  W d    d S 1 s-w   Y  d S )N)
2001-01-04z
2001-01-02r  z
2001-01-14r:  r   )r6   ri   ru   rm  z
2001-01-01r  rh   rC  r   r   )r9   r   r   r   r   r   rD   r&   )r:   r[   rO  r-   r-   r.   1test_loc_getitem_series_label_list_missing_values
  s   "zATestLocListlike.test_loc_getitem_series_label_list_missing_valuesc                 C   sh   t tddgtddgd}tjtdd |jtddg  W d    d S 1 s-w   Y  d S )Nl   PF
AHl   UBeNl   P2$$nr
   r   r   r   l   NZ4FG)r   r9   r   r   r   rD   r&   rn  r-   r-   r.   9test_loc_getitem_series_label_list_missing_integer_values
  s   "zITestLocListlike.test_loc_getitem_series_label_list_missing_integer_values	to_periodTFc                 C   sV  t ddddd}|r|d}tddg|dd	}tdtdg}|r)d
d |D }|j| }tddg|dd	}|s@|jd |_tj||dd tdtdtdg}|r\dd |D }tg dt	|d|j
ddd	}|j| }tj||dd tdtdtdg}|rdd |D }tjtdd |j|  W d    d S 1 sw   Y  d S )N
2011-01-01z
2011-01-02r  r  )r  r   皙?皙?r   r   c                 S      g | ]}| d qS r  r  r   r-   r-   r.   r   
  r  zRTestLocListlike.test_loc_getitem_listlike_of_datetimelike_keys.<locals>.<listcomp>T)r  c                 S   r  r  r  r   r-   r-   r.   r     r  )r  r  r  )r   r5   
2011-01-03c                 S   r  r  r  r   r-   r-   r.   r     r  r   r   )r   r  r   r   r&   r
   r  r'   r   r   r5   r   r   rD   )r:   r  r  rO  r2  r   r   r-   r-   r.   .test_loc_getitem_listlike_of_datetimelike_keys
  s@   


"z>TestLocListlike.test_loc_getitem_listlike_of_datetimelike_keysc                 C   sd   t ddgddgddggg ddd	gd
}|jd d }d|j_|jtddgdd }t|| d S )Nr`   r6   rh   ri   rg   ru   )cobraviperZ
sidewinderZ	max_speedZshieldr   r   r  r   r   )r   r   r
   r   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   r9   Zasarrayr   r  r  r  r  r  r-   r-   r-   r.   r  
  s    
		
)r  z%columns, column_key, expected_columns)  rv  i  r  rv  r`   )r  rv  Allr  r6   c                 C   sX   t tjdd| tdd}|jd d |f }|jg d|f }tj||dd d S )Nr6   r   r  rz   r   Tr  )	r   r9   r   r   r   r   r&   r'   r(   )r4   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|g dd}t
|| t| }t j|jd d df< t
|| d S )Nr6   )ru   rh   r  ru   r`   )r   r  r   ra   r  r   )r9   r   r   r_  r   r   r&   Zhstackr   r0  r'   r(   )Z	rand_datar   r  r,   r-   r-   r.   test_loc_setitem_float_intindex>  s   $r  c                  C   sr   dd dD } t tdtdt| d}|jddd	d
 }t tdtdtg dd}t|| d S )Nc                 S   s   g | ]}d D ]}||fqqS ))rg   ru   rk  rd   r-   )r   Zyrr6  r-   r-   r.   r   N  rv  z)test_loc_axis_1_slice.<locals>.<listcomp>)  r   )rd   ru   Z
ABCDEFGHIJr   r`   r~  r  rk  r   ru   r  )r  )r  rd   )r   rg   r  )	r   r9   r  r  r   r  r&   r'   r(   )r   r+   r   r,   r-   r-   r.   test_loc_axis_1_sliceL  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#   r6   r   r   r  )r   r   r   r9  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sJ d S )Nr6   r`   r   r   r   )r   r   r   r8   r&   )rO  r   r-   r-   r.   test_loc_mixed_int_floatg  s   
r  c                  C   sV   t tdg dd} tjtdd d| jd d< W d    d S 1 s$w   Y  d S )Nrh   r  r	   $Slicing a positional slice with .locr   r6   re   )r   r   r   r   r   r&   )rO  r-   r-   r.   %test_loc_with_positional_slice_raiseso  s   "r  c               	   C   s>  t ddd} ttjdd| d}|d }d}||fD ]>}tjt|d	 |jd
d  W d    n1 s8w   Y  tjtdd	 d
|jd
d< W d    n1 sVw   Y  qtjt|d	 |jd
dd
f  W d    n1 sww   Y  tjtdd	 d|jd
dd
f< W d    d S 1 sw   Y  d S )Nr  re   r  r6   r  r	   r   zOcannot do slice indexing on DatetimeIndex with these indexers \[1\] of type intr   r`   r  )	r   r   r9   r   r   r   r   r   r&   )dtir+   rO  r   rG   r-   r-   r.   #test_loc_slice_disallows_positionalw  s&   "r  c                  C   s   t tjddg dtddddd} | jg d	  } | j}t	
|j}d
}tjt|d | j|  W d    n1 s@w   Y  tjt|d | d j|  W d    d S 1 s_w   Y  d S )Nr6   r  r   Z2012r5  ri   rC  rz   )r   r6   r6   re   z/None of \[TimedeltaIndex.* are in the \[index\]r   r#   )r   r9   r   r   r_  r   r   r   r
   r   ZTimedeltaIndexZasi8r   r   rD   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-12r4  r  r6   )r  rd   r	   r   ri   )r   r  r   r9   r   r   r_  r'   r(   r&   r   r   )r  r+   r-   r-   r.   "test_loc_with_period_index_indexer  s   $r  c                  C   sz   t jdd} tddd}g d}t| ||d}t j|j|jd d	f< t j| d d
d< t| ||d}t	
|| d S )Nr6   )ru   rf   r  ru   r  )r%   r   r   r  EFr   r`   r   r   )r9   r   r   r_  r   r   r   r&   r
   r'   r(   )r{  r  r   r   r   r-   r-   r.   %test_loc_setitem_multiindex_timestamp  s   r  c                  C   s0  g d} ddg}ddg}t j| ||gg d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g ddd}t|| |jd }|jd d }	|j| d |d |d fg ddd}
t	|
|	 |j| d |d |d f }|dksJ d S )Nr   r  )r`   r   r   r`   )r   r  r  r"  rf   ri   r   r_   )rL  r  )
r   r9  r   r   r&   r   r'   r(   Zxsr   )ra  rb  Zlev3r   r+   r   r,   ZaltrO  Z	expected2Zalt2r7  r-   r-   r.   'test_loc_getitem_multiindex_tuple_level  s    $&
&r  c               	   C   s   t tg dg dddtjtjggjg ddd} | d}|jjdks'J |jd }t	dd	g|j
ddd
}t|| |jt|_|jd }t|| d S )Nr  )ri   rf   rg   ru   r`   r6   r   r  )r   r4   r5   rK   ri   rb  )r   r9   r   r   Tr   r
   r5   r&   r   r4   r'   r   r   r8   )r+   r   r   r,   r-   r-   r.   /test_loc_getitem_nullable_index_with_duplicates  s   $


r  r   r   c                 C   s   t g ddgdd}tjtdd | |jd< W d    n1 s!w   Y  tr1t| tjr1d}nd	}t g d
dg|d}t	|| d S )Nr  rx   Zuint8r3   r   r   )r6   rx   int16uint16)r`   r6   r   rh   )
r   r'   r   r   r&   r   r   r9   r  r(   )r   r+   r5   r,   r-   r-   r.   test_loc_setitem_uint8_upcast  s   r  zfill_val,exp_dtypez
2022-01-06r  z
2022-01-07
US/Easternr  zdatetime64[ns, US/Eastern]c                 C   sj   ddd|   g}t|| j|d}tg d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  r5   )rd   rm  rn  r  r#   rz   r  )
2022-01-08r#   r  r   T)exact)	r   r   r  r   r&   r  r'   r1  r
   )Zfill_valr  r   r
   r+   Zexpected_indexr-   r-   r.   0test_loc_setitem_using_datetimelike_str_as_index  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abcri   rx   r#   r"   rK   )r   r`   r6   rx   )r   r   r&   r'   r(   )r+   r,   r-   r-   r.   test_loc_set_int_dtype  s   r!  z8ignore:Period with BDay freq is deprecated:FutureWarningr'  c                  C   sr   t g dddd} tg dg dg dg dg| g d	d
}|jddgddd }|j| d ddf dks7J d S )N)z20181101 1100z20181101 1200z20181102 1300z20181102 1400r   r   )r   r  )r%   r   r  )r%   r   r   )rh  Qra   )Wr  rI  )ONETWOVALUESr   r$  r%  T)r  r&  r   r%   r  )r   r   r   r&   )Zp_indexZ	mi_seriesr-   r-   r.   test_loc_periodindex_3_levels"  s    r'  c                  C   sz   t d ttg dddtg dd} tddg}|| j| jd	f< ttg d
ddtg dd}t| | d S )NZpyarrowr   zstring[pyarrow]r   )TTF)stringsr  r  r3  r(  )r  r3  r   )r   r  r   r   r&   r  r'   r(   )r+   Z	new_valueZexpected_dfr-   r-   r.    test_loc_setitem_pyarrow_strings4  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g d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d-d. Zd/d0 Z dS )1TestLocSeriesr  )r  re   )r  rh   c                 C   s$   t ddd}|j| |ksJ d S )Nre   rh   )r  r  )r   r&   )r:   r  r,   rO  r-   r-   r.   r  K  s   zTestLocSeries.test_loc_uint64c           	      C   s   |j g d }t|j| || t|jdd d |dd d  |j ddg \}}|j|| }|||}t|| || k}t|j| ||  |j| || ks\J |j| || ksgJ d S )Nre   rh   rg   ri   r6      )r
   r'   r   r&   r[  r   truncatemedian)	r:   string_seriesdatetime_seriesindsd1d2r   r,   r  r-   r-   r.   test_loc_getitemQ  s   "zTestLocSeries.test_loc_getitemc                 C   s   |j ddg \}}|d d d jg d }d}tjt|d |j||  W d    n1 s0w   Y  tjt|d d|j||< W d    d S 1 sOw   Y  d S )Nri   r,  r6   )r`   r6   r   z"Timestamp\('2000-01-10 00:00:00'\)r   r   )r
   r   r   r   rD   r&   )r:   r0  r2  r3  Zts2r   r-   r-   r.   test_loc_getitem_not_monotonicd  s   "z,TestLocSeries.test_loc_getitem_not_monotonicc                 C   sj  t tjddttdddd}| }d|jdd< |jdd dk	 s+J | }d|jdd< |jdd dkj
	 sDJ |jdd	 }|jdd }|g d
}t|| t|| |jttdttddd  }tjtdd |jdd  W d    n1 sw   Y  tjtdd d|jdd< W d    d S 1 sw   Y  d S )Nr6   rd   r   rT   r	   rh   re   rm  rf   )rh   rf   ru   rd   ri   rk  r   z^3$r   )r   r9   r   r   r_  r   r   r   r   r  r   r&   r[  r'   r   r   r   rD   )r:   rO  cpr   r7  r,   s2r-   r-   r.   0test_loc_getitem_setitem_integer_slice_keyerrorso  s*   ""z>TestLocSeries.test_loc_getitem_setitem_integer_slice_keyerrorsc                 C   s4   t |jd d }|j| }t||d d  d S )Nrd   )r!  r
   r&   r'   r   )r:   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   )r:   r/  r  r   r,   r-   r-   r.   test_loc_setitem_boolean  s   
z&TestLocSeries.test_loc_setitem_booleanc                 C   sd   t |jg d }d|j|< d}tjt|d d|j|dg < W d    d S 1 s+w   Y  d S )N)ri   ru   rn  ri   z\['foo'\] not in indexr   r   )r   r
   r&   r   r   rD   )r:   r/  r1  r   r-   r-   r.   test_loc_setitem_corner  s   
"z%TestLocSeries.test_loc_setitem_cornerc                 C   s   |j g d }| }| }d||< d|j|< t|| | }| }d||d |d < d|j|d |d < t|| d S )N)ri   rd   r,  r   r6   )r
   r   r&   r'   r   )r:   r0  indicesr6  r   r-   r-   r.   test_basic_setitem_with_labels  s   
z,TestLocSeries.test_basic_setitem_with_labelsc           	      C   s$  t tjddttdddd}g d}tg d}| }| }d||< d|j	|< t
|| | }| }d||< d|j	|< t
|| g d}tg d}d}tjt|d	 d||< W d    n1 sow   Y  tjt|d	 d||< W d    d S 1 sw   Y  d S )
Nr6   rd   r   rT   r	   )r   rh   rf   r   rh   ri   rf   z\[5\] not in indexr   )r   r9   r   r   r_  r   r   r   r   r&   r'   r   r   r   rD   	Exception)	r:   rO  r1  Zarr_indsr6  r   Zinds_notfoundZarr_inds_notfoundr   r-   r-   r.   !test_loc_setitem_listlike_of_ints  s0   



"z/TestLocSeries.test_loc_setitem_listlike_of_intsc                 C   s   t tddddg dd}| }tddd}||jd	< |jd	 }||ks'J | }||jd
< |jd
 }||ks;J | }||d	< |d	 }||ksMJ d S )Nr  re   r  r  r   r	   r  r  r#   r   )r   r   r   r   r&   r   )r:   rO  r7  r,   r   r-   r-   r.   test_loc_setitem_dt64tz_values  s"   



z,TestLocSeries.test_loc_setitem_dt64tz_valuesarray_fnr   r>  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   r8   r&   r'   r   r   )r:   r   rB  r  r,   rO  r-   r-   r.   #test_loc_iloc_setitem_with_listlike  s   

z1TestLocSeries.test_loc_iloc_setitem_with_listliker   r%   Nc                 C   s   t tg dg dd}d}tjt|d |j|d d f  W d    n1 s*w   Y  tjt|d d|j|d d f< W d    d S 1 sKw   Y  d S )N))r%   0)r%   r1   )r   rD  )   rW  r[  r  r+  r   r`   )r   r   r  r   r   r   r&   )r:   r   rO  r   r-   r-   r.   +test_loc_series_getitem_too_many_dimensions  s   "z9TestLocSeries.test_loc_series_getitem_too_many_dimensionsc                 C   s   |j g d }| }d|j|< | }d|jg d< 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sbJ || dksjJ d S )Nr+  ri   rd   r,  rf   rw  rh   )r
   r   r&   r   r'   r   )r:   r/  r1  r   r,   r2  r3  r-   r-   r.   test_loc_setitem  s"   


zTestLocSeries.test_loc_setitemr5   r8   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jklr   r   ZnewAZnewBr   ro  )r:   r5   r+   r,   r-   r-   r.   test_loc_assign_dict_to_row  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   r   rf   r   r  r   )r   r   r`   rz   )r   r   r&   r'   r(   rO  r-   r-   r.   ,test_loc_setitem_dict_timedelta_multiple_set&  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 )Nr`   r6   r#   r   rf   rg   r"   rK   r8   r   r   r	   )r   r&   r   r9   r   r'   r(   r|   r-   r-   r.   3test_loc_set_multiple_items_in_multiple_new_columns1  s   	zATestLocSeries.test_loc_set_multiple_items_in_multiple_new_columnsc                 C   sj   d}t jt|d" tjdddd}ttd|d}|jd d	ks#J W d    d S 1 s.w   Y  d S )
Nz#Period with BDay freq is deprecatedr   Z2000rT   r   r  r	   z
2000-01-14rk  )r'   r   r   r   r  r   r   r&   )r:   r   r
   r*   r-   r-   r.    test_getitem_loc_str_periodindexA  s   "z.TestLocSeries.test_getitem_loc_str_periodindexc                 C   s   t td}t|d dd}tdtjt|tjdi|d}|j| }td|j	dd
tjitt|dddd}t|| d S )	Nrm  i  r  r   r  r	   Zstable)r=   )r   r   r   r   r9   r{   r   Zintpr&   Zargsortr   r   r  r'   r(   )r:   r  r
   r+   r   r,   r-   r-   r.   test_loc_nonunique_masked_indexI  s    
z-TestLocSeries.test_loc_nonunique_masked_index)!r   r   r   r   r   r   r  r4  r5  r8  r9  r:  r;  r=  r@  rA  r9   r   r   r   r  rC  r   r   rF  rG  rI  r  r  rJ  rK  rL  rM  r-   r-   r-   r.   r*  J  s2    
	$

	

r*  )\__doc__collectionsr   r,  r   r   r   r   r   Zdateutil.tzr   Znumpyr9   r   Zpandas._configr   Zpandas._libsr
   rk  Zpandas.compat.numpyr   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsr  Zpandasr   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   Zpandas.core.indexingr    Zpandas.tests.indexing.commonr!   r   r   r   r/   r0   r   r"  r-  rg  r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  r  r  r!  r  r'  r)  r*  r-   r-   r-   r.   <module>   s    P 
	 D           ?= w e J  	f





	
