o
    ŀg                  	   @   s   d dl m Z  d dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZ d dlmZ G dd dZejdddgefejd	d
ddejddfgdd Zejdddgddgfddgddgfgejdddgdd ZdS )    )datetimeN)	DataFrameIndex
MultiIndex
RangeIndexSeries
date_rangeoption_contextc                   @   sT   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d ZdS )TestResetIndexc                 C   s   t ddddd }tdtjdt|i|d}| }|jj	d t
d	ks,J |d
}tj||dd tddd}t|dggddgd}|d}|jd |ksXJ | d j	d |kseJ d S )Nz1/1/2001z6/1/2001D)startendfreqv   indexr   zM8[ns]r   F)check_namesi        g333333(@DateValuecolumns)r   
_with_freqr   nprandomdefault_rnglenreset_indexdtypesilocdtype	set_indextmassert_frame_equalr   r   )selfdtid1d2d3stampdf r-   `/var/www/html/myenv/lib/python3.10/site-packages/pandas/tests/series/methods/test_reset_index.pytest_reset_index_dti_round_trip   s   "

z.TestResetIndex.test_reset_index_dti_round_tripc                 C   sj  t dtdd ttdtdtdd tdD tdd	d d
 }|jdd}ddg|j	_
d|_| }d|v s=J |jdd}d|v sIJ |jdd}|}|jddd}|d u s^J t|| tdgg dddggg dg dg dgd}ttjdd|d}|jdd}t|jdksJ |jddgdd }t|j	t|d t|tsJ d S )!Ng?x   )      ABCDr"   c                 S   s   g | ]}d | qS )zi-r-   ).0ir-   r-   r.   
<listcomp>(   s    z3TestResetIndex.test_reset_index.<locals>.<listcomp>r1   r   r      T)future_stackhashcategoryvaluevalue2namedrop)rB   inplacebar)onetwothreer      )r   r   r   r   r   r   )r   rH   r   r   rH   r   )r   rH   r   rH   r   rH   )levelscodesr      r   levelrM   rB   )r   r   arangereshaper   listobjectrangestackr   namesr@   r   r$   assert_series_equalr   r   r   r   standard_normalr   r   assert_index_equalget_level_values
isinstance)r&   r,   serss2return_valuer   rsr-   r-   r.   test_reset_index$   s:   zTestResetIndex.test_reset_indexc                 C   sL   t g dttdddd}| jjd u sJ |jddjjd u s$J d S )NrH   r      rb   xr?   r   TrA   )r   r   rS   r   r   r@   r&   r\   r-   r-   r.   test_reset_index_nameH   s   z$TestResetIndex.test_reset_index_namec              	   C   s  t g dg dgg dd}ddgddgfD ]}|ddgd	 }|j|d d
}t||d |j|d d d
}t||d |j|d
}t|| |ddgj|dd}t||d	g  tjtdd |jddgd
 W d    n1 sw   Y  |dd }|j|d d
}t||ddg  |j|d d d
}t||ddg  |j|d dd}t||d  tjt	dd |jg dd
 W d    n1 sw   Y  qt
tdjg dd}t
td}t|| d S )Nra   )r2   r9   rK   )ABCr   rf   rg   r   rH   rh   rL   TrN   zLevel E matchEzToo many levels)r   rH   r   r2   rA   )r   r#   r   r$   r%   pytestraisesKeyErrorrV   
IndexErrorr   rS   )r&   r,   rI   r\   resultexpectedr-   r-   r.   test_reset_index_levelM   s8   z%TestResetIndex.test_reset_index_levelc                 C   s^   t tdddd}| }t|jtsJ tddgddggddgtddd	}t|| d S )
Nr   rf   int64)r@   r"   r   rH   r   )stopr8   )	r   rS   r   rZ   r   r   r   r$   r%   )r&   r\   series_resultseries_expectedr-   r-   r.   test_reset_index_rangew   s   z%TestResetIndex.test_reset_index_rangec                 C   s   t td}tjtdd |jddd W d    n1 sw   Y  tjtdd |d W d    n1 s;w   Y  t tdtddggd d	}tjtd
d |jddd W d    d S 1 sjw   Y  d S )Nr2   zdoes not match index nameri   wrongTrA   rH   r   r   z	not found)r   rS   rl   rm   rn   r   r   from_productrd   r-   r-   r.   test_reset_index_drop_errors   s    "z+TestResetIndex.test_reset_index_drop_errorsc                 C   s   g dg dg}t | }t|}tjdd}t||d}tj|j	d< |
 }t|ts1J t|jt|jjd ks@J |jj|jjksJJ |j
dd	}t|tsWJ |jj|jjksaJ d S )
N)rD   rD   bazr{   quxr|   foor}   )rE   rF   rE   rF   rE   rF   rE   rF   r      r   rb   rH   TrA   )zipr   from_tuplesr   r   r   rW   r   nanr!   r   rZ   r   r   r   r   rI   r@   )r&   arraystuplesr   datar[   	deleveledr-   r-   r.   test_reset_index_with_drop   s   
z)TestResetIndex.test_reset_index_with_dropc                 C   s@   t tddd}|jdddd t tddd}t|| d S )Nr   oldr?   newT)r@   rB   rC   )r   rS   r   r$   rV   )r&   r[   rq   r-   r-   r.   -test_reset_index_inplace_and_drop_ignore_name   s   z<TestResetIndex.test_reset_index_inplace_and_drop_ignore_namec                 C   s`   t d tg dtd}tdd |jdd}W d    n1 s#w   Y  t|| d S )Npyarrow)abcr4   zfuture.infer_stringTrA   )rl   importorskipr   rR   r	   r   r$   rV   )r&   r[   rp   r-   r-   r.   "test_reset_index_drop_infer_string   s   
z1TestResetIndex.test_reset_index_drop_infer_stringN)__name__
__module____qualname__r/   r`   re   rr   rw   rz   r   r   r   r-   r-   r-   r.   r
      s    $*
r
   zarray, dtyper   r   z	12-1-2000r   zQ-DEC)periodsr   )r   c                 C   sp   t ddgddg| g}tt|dd d  j}|rdnt}ttjtj|tkr*|n|td}t	
|| d S )Nr   rH   g      ?g      ?)r"   r   string)level_0level_1level_2r   )r   ry   r   rR   r   r    r   rs   float64r$   rV   )arrayr"   using_infer_stringidxrp   exprq   r-   r-   r.   7test_reset_index_dtypes_on_empty_series_with_multiindex   s   r   znames, expected_namesrf   r   allow_duplicatesFTc                 C   s   t dgtjdgdgg| dd}|r,|jdd}tg dg|dg d}t|| d S tjt	d	d
 |  W d    d S 1 sCw   Y  d S )NrH   )rU   r   T)r   )rH   rH   rH   r   r   zcannot insertri   )
r   r   from_arraysr   r   r$   r%   rl   rm   
ValueError)rU   expected_namesr   r\   rp   rq   r-   r-   r.   test_column_name_duplicates   s    

"r   )r   numpyr   rl   pandaspdr   r   r   r   r   r   r	   pandas._testing_testingr$   r
   markparametrizerR   period_rangePeriodDtyper   r   r-   r-   r-   r.   <module>   s2    $	 "



