a
    GGb~                     @   sd   d dl Zd dlm  mZ d dlmZ d dlZ	d dlm
Z
mZmZmZ d dlmZ G dd dZdS )    N)PerformanceWarning)	DataFrameIndex
MultiIndexSeriesc                   @   sL   e Z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S )TestMultiIndexBasicc                 C   s   t g dg dtjddddg}tt |jd  W d    n1 sT0    Y  |j	g d }tt |jd	  W d    n1 s0    Y  d S )
N)r   r      r   )xr	   zy   )jimjoeZjolier   r   )r   r
   )   r      r   )r   )
r   nprandomZrand	set_indextmZassert_produces_warningr   locZiloc)selfdf r   Olib/python3.9/site-packages/pandas/tests/indexing/multiindex/test_multiindex.pytest_multiindex_perf_warn   s    
(z-TestMultiIndexBasic.test_multiindex_perf_warnc                 C   sp   d}t j}dt _tt|tdg| t|f}|d dksFJ |d dksVJ |d d	ksfJ |t _d S )
Ni'  i N  a)r      r   )r      r   )r      r   )_indexZ_SIZE_CUTOFFr   r   Zaranger   from_arrays)r   nZ
old_cutoffsr   r   r   (test_indexing_over_hashtable_size_cutoff!   s    &z<TestMultiIndexBasic.test_indexing_over_hashtable_size_cutoffc                 C   s   t ddtjdgg dddtjdgd}|jd	d
gdd}t ddtjdgg dddtjdgdtddtjdgd	dtg dd
dgd}t|| d S )NZR1ZR2ZR4ZC1ZC2ZC3ZC4
         r   bcr   r)   F)Zdropnameindex)r   r   nanr   r   r   assert_frame_equal)r   r   resultexpectedr   r   r   test_multi_nan_indexing0   s"    z+TestMultiIndexBasic.test_multi_nan_indexingc                 C   s   t tjtjtjtjgg dddtjdgd}|ddg}t dddtjdgittjtjtjtjgdd	tg ddd	gd
}t|| d S )Nr$   r%   r&   r'   r(   r   r)   r*   r+   r-   )	r   pdZNaTr   r/   r   r   r   r0   )r   r   r2   r   r   r   "test_exclusive_nat_column_indexingG   s    	z6TestMultiIndexBasic.test_exclusive_nat_column_indexingc                 C   s   t g d}tg d}tj||gddgd}tg dtjtjtjgd|d}t|d	 d
d
tjgd|d}|jdd}d
|j	|d dfdf< t
|| |jdd}d
|j	|d dfgdf< t
|| d S )N)20190101r6   Z20190102)r   r   r*   Zindex1Zindex2names)r   r   r   )c1c2r-   r9   g      ?T)Zdeepr   r   r:   )r4   Zto_datetimer   r   r    r   r   r/   copyr   r   r0   )r   dtiidxmir   r2   Zdf2Zdf3r   r   r   test_nested_tuples_duplicates]   s    "z1TestMultiIndexBasic.test_nested_tuples_duplicatesc                 C   sr   t tddd}tjddddd}t||g}ttj	d	d|d
}|j
d j}t|| |j|jksnJ d S )Nr   Ar+   z
2020-01-01r   DB)Zperiodsfreqr,      r-   r   )r   ranger4   Z
date_ranger   Zfrom_productr   r   r   Zrandnr   r.   r   Zassert_index_equalrC   )r   r=   r<   r>   r   r1   r   r   r   2test_multiindex_with_datatime_level_preserves_freqp   s    zFTestMultiIndexBasic.test_multiindex_with_datatime_level_preserves_freqc                 C   s`   g d}g d}t |||d}|jddgdd t d|itj||gd	d
d}t|| d S )N)y      ?       @y      @      y      $@      )r   r   r   )r	   r   r
   r	   r   T)Zinplacer
   )r	   r   r7   r-   )r   r   r   r    r   r0   )r   Zcomplex_dataZnon_complex_datar1   r2   r   r   r   test_multiindex_complexz   s"    z+TestMultiIndexBasic.test_multiindex_complexc                 C   sR   t g d}t|d}|jddidd}t g d}t|d}t|| d S )N))r@   catrB   rH   rI   r-   r@   Appler   )r.   level))rJ   rH   rI   rI   )r   Zfrom_tuplesr   renamer   r0   )r   r>   r   Zmi2r2   r   r   r   &test_rename_multiindex_with_duplicates   s    

z:TestMultiIndexBasic.test_rename_multiindex_with_duplicatesN)__name__
__module____qualname__r   r#   r3   r5   r?   rF   rG   rM   r   r   r   r   r      s   
r   )Znumpyr   Zpandas._libs.indexZ_libsr.   r   Zpandas.errorsr   Zpandasr4   r   r   r   r   Zpandas._testingZ_testingr   r   r   r   r   r   <module>   s   