o
    ҷh                  	   @   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 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_rangec                   @   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 )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/venv/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   s2  t  d d }|jdd}ddg|j_d|_| }d|v s!J |jdd}d|v s-J |jdd	}|}|jddd
}|d u sBJ 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s{J |jddgdd}t |jt|d t|t	sJ d S )N   T)future_stackhashcategoryvaluevalue2namedrop)r8   inplacebar)onetwothreer      )r   r   r   r   r   r   )r   r>   r   r   r>   r   )r   r>   r   r>   r   r>   )levelscodesr      r   levelrC   r8   )r#   makeDataFramestackr   namesr6   r   assert_series_equalr   r   r   r   r   standard_normalr   r   assert_index_equalr   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r>   r      rT   xr5   r   Tr7   )r   r   ranger   r   r6   r%   rN   r,   r,   r-   test_reset_index_nameC   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 )NrS   )   r/   rA   )ABCr   rZ   r[   r   r>   r\   rB   TrD   zLevel E matchEzToo many levels)r   r>   r   rY   r7   )r   r"   r   r#   r$   pytestraisesKeyErrorrH   
IndexErrorr   rV   )r%   r+   r?   rN   resultexpectedr,   r,   r-   test_reset_index_levelH   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   rZ   int64)r6   r!   r   r>   r   )stop)r   r   )	r   rV   r   rL   r   r   r   r#   r$   )r%   rN   series_resultseries_expectedr,   r,   r-   test_reset_index_ranger   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 )NrY   zdoes not match index namer]   wrongTr7   r>   r   r   z	not found)r   rV   r`   ra   rb   r   r   from_productrW   r,   r,   r-   test_reset_index_drop_errors|   s    "z+TestResetIndex.test_reset_index_drop_errorsc                 C   s~   |}|  }t|tsJ t|jt|jjd ksJ |jj|jjks&J |j dd}t|ts3J |jj|jjks=J d S )Nr>   Tr7   )	r   rL   r   r   r   r   r?   r6   r   )r%   series_with_multilevel_indexrM   	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   oldr5   newT)r6   r8   r9   )r   rV   r   r#   rH   )r%   rM   re   r,   r,   r-   -test_reset_index_inplace_and_drop_ignore_name   s   z<TestResetIndex.test_reset_index_inplace_and_drop_ignore_nameN)__name__
__module____qualname__r.   rR   rX   rf   rk   rn   rq   rt   r,   r,   r,   r-   r	      s     *
r	   zarray, dtypeabz	12-1-2000r   zQ-DEC)periodsr   )r   c                 C   sX   t ddgddg| g}tt|dd d  j}ttjtj|td}t	
|| d S )Nr   r>   g      ?g      ?)r!   r   )level_0level_1level_2r   )r   rm   r   objectr   r   r   rg   float64r#   rH   )arrayr!   idxrd   re   r,   r,   r-   7test_reset_index_dtypes_on_empty_series_with_multiindex   s   r   znames, expected_namesrZ   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 )Nr>   )rG   r   T)r   )r>   r>   r>   r   r   zcannot insertr]   )
r   r   from_arraysr   r   r#   r$   r`   ra   
ValueError)rG   expected_namesr   rN   rd   re   r,   r,   r-   test_column_name_duplicates   s    

"r   )r   numpyr   r`   pandaspdr   r   r   r   r   r   pandas._testing_testingr#   r	   markparametrizer~   period_rangePeriodDtyper   r   r,   r,   r,   r-   <module>   s2      



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