o
    թZh                     @   s|   d dl Z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mZ d dlmZ d dlmZ G dd dZdS )    N)PerformanceWarning)CategoricalDtype	DataFrameIndex
MultiIndexSeries)BooleanDtypec                   @   s   e Zd Zd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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dg}tt |jd  W d    n1 s-w   Y  |j	g d	 }tt |jd
  W d    d S 1 sOw   Y  d S )N)r   r      r
   )xr   zy      )jimjoeZjolier   r   )r
   r   )r   r
      r   )r   )
r   nprandomdefault_rng	set_indextmZassert_produces_warningr   locZilocselfdf r   g/var/www/html/lang_env/lib/python3.10/site-packages/pandas/tests/indexing/multiindex/test_multiindex.pytest_multiindex_perf_warn   s   
"z-TestMultiIndexBasic.test_multiindex_perf_warnoffset   c              	   C   s   d}|| }|  ; |td| tt|tdg| t|f}|d dks-J |d dks5J |d d	ks=J W d    d S 1 sHw   Y  d S )
N   Z_SIZE_CUTOFFa)r#   r!   r!   )r#      r$   )r#      r%   )contextsetattrlibindexr   r   Zaranger   from_arrays)r   Zmonkeypatchr   Zsize_cutoffn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"   r#   bcr#   r1   F)Zdropnameindex)r   r   nanr   r   r   assert_frame_equal)r   r   resultexpectedr   r   r   test_multi_nan_indexing2   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"   r0   r#   r1   r2   r3   r5   )	r   pdZNaTr   r7   r   r   r   r8   )r   r   r:   r   r   r   "test_exclusive_nat_column_indexingI   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)20190101r>   Z20190102)r#   r#   r2   Zindex1index2namesr
   r   r   )c1c2r5   rC         ?T)deepr   r#   rD   )r<   to_datetimer   r   r)   r   r   r7   copyr   r   r8   )r   dtiidxmir   r:   Zdf2Zdf3r   r   r   test_nested_tuples_duplicates_   s   "z1TestMultiIndexBasic.test_nested_tuples_duplicatesc                 C   sv   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s9J d S )Nr   Ar3   z
2020-01-01r%   DB)Zperiodsfreqr4   )   r   r5   r   )r   ranger<   Z
date_ranger   Zfrom_productr   r   r   r   Zstandard_normalr   r6   r   assert_index_equalrP   )r   rJ   rI   rK   r   r9   r   r   r   2test_multiindex_with_datatime_level_preserves_freqr   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   r@   r5   )r   r   r   r)   r   r8   )r   Zcomplex_dataZnon_complex_datar9   r:   r   r   r   test_multiindex_complex|   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))rM   catrO   rV   rW   r5   rM   Appler   )r6   level))rX   rV   rW   rW   )r   from_tuplesr   renamer   r8   )r   rK   r   mi2r:   r   r   r   &test_rename_multiindex_with_duplicates   s   

z:TestMultiIndexBasic.test_rename_multiindex_with_duplicatesc           
      C   s   t dtjgtjtjgg}t tjdgtjtjgg}tddg|d}tddg|d}||\}}t ddtjgtjtjtjgg}tdtjdg|d}ttjddg|d}	t|| t||	 d S )N     @T@g     T@r
   r   r5   rE   g       @r   r)   r   r7   r   alignr   assert_series_equal
r   Zmi1r\   Zser1Zser2Zresult1Zresult2rK   Z	expected1Z	expected2r   r   r   2test_series_align_multiindex_with_nan_overlap_only   s   "zFTestMultiIndexBasic.test_series_align_multiindex_with_nan_overlap_onlyc           
      C   s   t dtjgtjtjgg}t tjdgtjtjgg}tddg|d}tddg|d}||\}}t dtjgtjtjgg}tddg|d}tddg|d}	t|| t||	 d S )Nr^   r
   r   r5   r_   rb   r   r   r   %test_series_align_multiindex_with_nan   s   z9TestMultiIndexBasic.test_series_align_multiindex_with_nanc                 C   s4   t ddgddggddgj }|dksJ d S )Nr
   r   r   )r   r   r6   Znunique)r   r*   r   r   r   test_nunique_smoke   s   $z&TestMultiIndexBasic.test_nunique_smokec              	   C   sF   t tddgtddggjg d tg dtg dg d S )Nr
   r   r#   r1   )r#   r#   r1   r1   )r
   r
   r   r   )r   ra   r   r   r)   r   )r   r   r   r   test_multiindex_repeated_keys   s   z1TestMultiIndexBasic.test_multiindex_repeated_keysc                 C   s\   t g dg dg dd}tjtdd |dg  W d    d S 1 s'w   Y  d S )NrB   )r!   r$   r%   )   	   r   ))foo)bar)Nmissing_key)match)rk   )r   	from_dictpytestZraisesKeyErrorr   r   r   r   #test_multiindex_with_na_missing_key   s   "z7TestMultiIndexBasic.test_multiindex_with_na_missing_keyc                 C   s   t jdgddgd}tdg|dd}|d }t|d	 jts"J td
dgdd
ggddgddgddggdjtddgddd}t|d jt	sKJ d S )N)rM   rO   Zlvl1Zlvl2r@   value)columnscategoryrM   rO   r
   r   ri   locationr   r   TFboolean)dtype)boolsrw   )
r   rZ   r   Zastype
isinstancerv   r   Zassignr   r   )r   rr   r   Zdf_no_multiindexr   r   r   "test_multiindex_dtype_preservation   s   z6TestMultiIndexBasic.test_multiindex_dtype_preservationc                 C   s>   t dtjdg}t dtjtjtjfdg}t|| d S )Nr0   )d r{   )r   rZ   r   r7   r   rS   )r   r9   r:   r   r   r   $test_multiindex_from_tuples_with_nan   s
   z8TestMultiIndexBasic.test_multiindex_from_tuples_with_nanN)__name__
__module____qualname__r   rn   markZparametrizer,   r;   r=   rL   rT   rU   r]   rc   rd   re   rf   rp   ry   r|   r   r   r   r   r	      s"    


	r	   )numpyr   rn   Zpandas._libs.indexZ_libsr6   r(   Zpandas.errorsr   Zpandasr<   r   r   r   r   r   Zpandas._testingZ_testingr   Zpandas.core.arrays.booleanr   r	   r   r   r   r   <module>   s    