o
    %j                  	   @   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)Zcheck_namesi        g333333(@DateValuecolumns)r   Z
_with_freqr   nprandomdefault_rnglenreset_indexdtypesilocdtype	set_indextmassert_frame_equalr   r   )selfZdtiZd1Zd2Zd3Zstampdf r&   m/var/www/html/Deteccion_Ine/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   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   )      ZABCDr    c                 S   s   g | ]}d | qS )zi-r&   ).0ir&   r&   r'   
<listcomp>(   s    z3TestResetIndex.test_reset_index.<locals>.<listcomp>r*   r   r      T)Zfuture_stackhashcategoryvalueZ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   r   ZarangeZreshaper   listobjectrangestackr   namesr6   r   r"   assert_series_equalr   r   r   r   standard_normalr   r   Zassert_index_equalZ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   rG   r   r   r6   r$   rN   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 )NrS   )r+   r1   rA   )ABCr   rX   rY   r   r>   rZ   rB   TrD   zLevel E matchEzToo many levels)r   r>   r   r+   r7   )r   r!   r   r"   r#   pytestraisesKeyErrorrJ   
IndexErrorr   rG   )r$   r%   r?   rN   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   rX   int64)r6   r    r   r>   r   )stopr0   )	r   rG   r   rL   r   r   r   r"   r#   )r$   rN   Zseries_resultZ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 )Nr+   zdoes not match index namer[   ZwrongTr7   r>   r   r   z	not found)r   rG   r^   r_   r`   r   r   from_productrV   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)r:   r:   bazrj   quxrk   foorl   )r;   r<   r;   r<   r;   r<   r;   r<   r      r   rT   r>   Tr7   )zipr   from_tuplesr   r   r   rK   r   nanr   r   rL   r   r   r   r   r?   r6   )r$   ZarraysZtuplesr   datarM   Z	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   rG   r   r"   rJ   )r$   rM   rc   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 )NZpyarrow)abcr,   zfuture.infer_stringTr7   )r^   Zimportorskipr   rF   r	   r   r"   rJ   )r$   rM   rb   r&   r&   r'   "test_reset_index_drop_infer_string   s   
z1TestResetIndex.test_reset_index_drop_infer_stringN)__name__
__module____qualname__r(   rR   rW   rd   rg   ri   rr   ru   ry   r&   r&   r&   r'   r
      s    $*
r
   zarray, dtyperv   rw   z	12-1-2000r   zQ-DEC)Z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   r>   g      ?g      ?)r    r   str)Zlevel_0level_1Zlevel_2r   )r   rh   r   rF   r   r   r   re   Zfloat64r"   rJ   )arrayr    Zusing_infer_stringidxrb   exprc   r&   r&   r'   7test_reset_index_dtypes_on_empty_series_with_multiindex   s   r   znames, expected_namesrX   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>   )rI   r   T)r   )r>   r>   r>   r   r   zcannot insertr[   )
r   r   Zfrom_arraysr   r   r"   r#   r^   r_   
ValueError)rI   Zexpected_namesr   rN   rb   rc   r&   r&   r'   test_column_name_duplicates   s    

"r   )r   numpyr   r^   Zpandaspdr   r   r   r   r   r   r	   Zpandas._testingZ_testingr"   r
   markZparametrizerF   Zperiod_rangeZPeriodDtyper   r   r&   r&   r&   r'   <module>   s2    $	 "



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