o
    vhQ8                  	   @   s"  d dl Zd dlZd dlm  mZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZ d dlm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d Z&dd  Z'd!d" Z(ej)ej*+d#d$d%gej*+d&d'd ed gd(d) Z,d*d+ Z-d,d- Z.ej*+d.ed/d0ed1d0ged/d0ed1d0d2gd3d3gd3d3ej/gfed/d0ed1d0ged/d0ed1d0gd3d3gd3d3gfgd4d5 Z0d6d7 Z1d8d9 Z2d:d; Z3ej*+d<d=gd>ggg g ggd?d@ Z4dAdB Z5dCdD Z6ej*+d#dEdFgdGdH Z7dS )I    N)NACategoricalFloat64DtypeIndex
MultiIndexNaTPeriodPeriodIndex
RangeIndexSeries	Timedelta	Timestamp
date_rangeisnac                 C   s(  | |j}t|j|jsJ |j|jsJ |j|js"J |jdd }| |}| D ]\}}||| ks>J q2| jdd }|  |}| D ]\}}|| | ks[J qO|  |}	t|		 sjJ | jd d d }
|  |
}| D ]\}}|| | ksJ q{|   }|| usJ d S )N
         )
reindexindextmshares_memoryis_	identicalitemsnpisnanall)datetime_seriesstring_seriesidentitysubIndex	subSeriesidxval	subIndex2subTSstuffSeriesnonContigIndexsubNonContigresult r*   f/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pandas/tests/series/methods/test_reindex.pytest_reindex   s(   



r,   c                  C   s   t g dddtjdgd} tjdtjddtjgg d}}t| || j|  | jd| _tj| || j| dd	 d S )
N)r                     r   )r   r   r   r-   r0   r   objectF)check_index_type)	r   r   nanr   assert_series_equalr   ilocr   astype)tsijr*   r*   r+   test_reindex_nan;   s
     r=   c                  C   sp   t dddd} t| }|td}t|jtdsJ | }|dd   s,J |d d 	 r6J d S )Nz1/1/2000 00:00:00r   10speriodsfreq   zM8[ns])
r   r   r   ranger   
issubdtypedtyper   r   any)rngseriesr)   maskr*   r*   r+   test_reindex_series_add_natG   s   rK   c                  C   s   t ddd} ttjdd| d}|t|jdd }|dd }|j	d |_t
|| |t|jdd  }t
|| d S )Nz1/1/2000r   r@   r   r3   r.   r   )r   r   r   randomdefault_rngstandard_normalr   listr   
_with_freqr   r7   )rH   r:   r)   expectedr*   r*   r+   test_reindex_with_datetimesS   s   rS   c                 C   s   t g d}|j| jdd |j| jdd}| t| j}| jd | _t| | | d d d }d}tjt	|d |j| jdd W d    d S 1 sNw   Y  d S )Nr3   padmethodr   zVInvalid fill method\. Expecting pad \(ffill\), backfill \(bfill\) or nearest\. Got foomatchfoo)
r   r   r   rP   rQ   r   r7   pytestraises
ValueError)r   empty	reindexedr:   msgr*   r*   r+   test_reindex_corner`   s   
"r`   c                  C   sh   t tddd} | d d d }|j| jdd}|j| jdd}t|| t g d}t|| d S )	Nr   int64rF   r   rT   rU   ffill)
r   r   r   r   r1   r1      rd   r2   r2   )r   r   aranger   r   r   r7   )ss2r^   
reindexed2rR   r*   r*   r+   test_reindex_padw   s   ri   c                  C   s   t g dg dd} g d}t g d|d}| | }t||d d}tjt|d | |jd	d
}W d    n1 sCw   Y  t|| t g d|d}| j|dd}t|| d S )Nr0   r   r-   r1   r.   )abcder3   )rk   grm   f)r0   r0   r-   r-   float64z-The 'downcast' keyword in ffill is deprecatedrW   infer)downcast)r0   r.   r-   r.   rc   rU   )r   r   rc   r   r7   r9   assert_produces_warningFutureWarning)rf   	new_indexrR   r)   r_   r*   r*   r+   test_reindex_pad2   s   rx   c                  C   s   t g dtdd} d}d}tjt|d | t| }W d    n1 s)w   Y  t g dt|d}t|| d S )N)TFFTabcdr3   agc"Downcasting object dtype arrays onrW   )TTF)r   rP   r   ru   rv   r   rc   r7   )rf   rw   r_   r)   rR   r*   r*   r+   test_reindex_inference   s   r|   c                  C   sp   t dtdd} d}tjt|d | d }W d    n1 s#w   Y  t dtdd}t|| d S )NFr.   r3   r{   rW   r0   )r   rD   r   ru   rv   shiftbfillr7   )rf   r_   r)   rR   r*   r*   r+   test_reindex_downcasting   s   r   c                  C   s   t tjddd} g d}| j|dd}t t|d|}t|| | j|ddd}t d	d
tjdg|}t|| | j|dg dd}t d	tjtjdg|}t|| d S )Nr   ra   rb   )g?g?g      ?       @nearestrU   g?)rV   	tolerancer   r0   r   )g333333?g{Gz?g?r-   )	r   r   re   r   aroundr9   r   r7   r6   )rf   targetr)   rR   r*   r*   r+   test_reindex_nearest   s   r   c                 C   st   | d d d }t tjt|td|jd}|| j}|jtjks#J ||jd d d }|jttks8J d S Nr   rb   r3   )	r   r   zeroslenintr   r   rF   rr   )r   r:   int_tsreindexed_intr*   r*   r+   test_reindex_int   s   r   c                 C   sp   | d d d }t tjt|td|jd}|| j}|jtjks#J ||jd d d }|jtj	ks6J d S r   )
r   r   r   r   boolr   r   rF   object_bool_)r   r:   bool_tsreindexed_boolr*   r*   r+   test_reindex_bool   s   r   c                 C   sT   | dd  }t tjt|td|jd}|j| jdd}t|d d  s(J d S )Nr.   rb   r3   rT   rU   )	r   r   r   r   r   r   r   r   r   )r   r:   r   filled_boolr*   r*   r+   test_reindex_bool_pad   s   r   c                  C   s   t ddd} tg ddd}|| }tttjtjtjgg dd}| |_t|| ttdd	gg dd}d
dg|_|d
dg}t|| ttd	tjgg dd}ddg|_|ddg}t|| d S )N20000101r-   rL   )rk   rl   rm   categoryrb   )values
categoriesrl   rm   r0   r   )	r   r   r   r   r   r6   r   r   r7   )r   rf   r)   rR   r*   r*   r+   test_reindex_categorical   s    


r   c                  C   s`   t g dg dd} g d}d}t}| |||}| |||}t|| d S )Nr0   r   r-   )r   r   r0   r3   )r   r0   r   r   )r   strr   r9   r   r7   )serrw   
temp_dtype	new_dtyper)   rR   r*   r*   r+   %test_reindex_astype_order_consistency   s   r   c                  C   s  t g d} | g d}t ddtjgg dd}t|| | jg ddd}t g dg dd}t|| t g d}|g d}t ddtjgg dd}t|| |jg ddd}t g d	g dd}t|jjtj	stJ t|| t g dt
d
}|g d}t ddtjgg dt
d}t|| |jg ddd}t g dg dt
d}t|| t g d}|g d}t ddtjgg dt
d}t|| |jg ddd}t g dg dd}t|| d S )N)      ?r         @r   r   r   r3   r   
fill_value)r   r   r   )r   r-   r   rb   r   r-   r   rF   rY   )r   r-   rY   )TFTFT)FTF)r   r   r   r6   r   r7   
issubclassrF   typeintegerr4   )floatsr)   rR   intsobjectsboolsr*   r*   r+   test_reindex_fill_value  s:   r   rF   zdatetime64[ns]timedelta64[ns]r   stringc                 C   sb   | dkr|t dkrtd}ttg| d}|jddg|d}tt|gddgtd}t|| d S )Nr   r   rb   r0   r   r   )r   r   r   r   r   r4   r   r7   )rF   r   using_array_managerr   r)   rR   r*   r*   r+   +test_reindex_fill_value_datetimelike_upcast9  s   r   c                  C   sr   t dddd} t dddd}ttd| d	}d
}tjt|d |j|dd W d    d S 1 s2w   Y  d S )N20131101zAmerica/Chicagor/   )tzr@   20131103r   hr?   r3   zLCannot compare dtypes datetime64\[ns, America/Chicago\] and datetime64\[ns\]rW   rc   rU   )r   r   rD   rZ   r[   	TypeErrorr   )r"   newidxrf   r_   r*   r*   r+   /test_reindex_datetimeindexes_tz_naive_and_awareI  s   "r   c                  C   s6   t ddddg} t tgd dd}t| | d S )Nzdatetime64[ns, UTC]rb   r   r0   r   )r   r   r   r   assert_equal)r)   rR   r*   r*   r+   "test_reindex_empty_series_tz_dtypeV  s   r   z+p_values, o_values, values, expected_values2019Q1zQ-DEC2019Q2Allr   c           	      C   sB   t | }t|}t||d}||}t||d}t|| d S )Nr3   )r	   r   r   r   r   r7   )	p_valueso_valuesr   expected_valuesperiod_indexobject_indexr   r)   rR   r*   r*   r+   $test_reindex_periodindex_with_object]  s   
r   c                  C   sT   t ddg} d}tjt|d | ddgd W d    d S 1 s#w   Y  d S )Nr0   r   zCreindex\(\) takes from 1 to 2 positional arguments but 3 were givenrW   r-   Fr   rZ   r[   r   r   r   r_   r*   r*   r+   test_reindex_too_many_argsy  s
   "r   c                  C   sZ   t ddg} d}tjt|d | jddgddgd W d    d S 1 s&w   Y  d S )Nr0   r   z4reindex\(\) got multiple values for argument 'index'rW   r-   r1   r3   r   r   r*   r*   r+   test_reindex_double_index  s
   "r   c                  C   s@   t ddg} | jddgd}t ddgddgd}t|| d S )Nr0   r   r   r3   )r   r   r   r7   )r   r)   rR   r*   r*   r+   test_reindex_no_posargs  s   r   r   rk   xc                 C   sh   t tt| d t| dd}|jtdgdd}t tdg| d gg g gddd}t	|| d S )Nr   r4   r   rl   )levelr0   )levelscodes)
r   rD   r   r   from_arraysr   r   arrayr   r7   )r   r   r)   rR   r*   r*   r+   test_reindex_empty_with_level  s   r   c                  C   sZ   t g ddd} d}tjt|d | jg ddd W d    d S 1 s&w   Y  d S )	N)r0   r   r-   r0   r   rb   z:Cannot setitem on a Categorical with a new category \(-1\)rW   rj   r   r   r   r*   r*   r+   test_reindex_missing_category  s
   "r   c                  C   s   t dtgt d} | td}|jj}tdtj	tj	g}t
|| t
d   t|}t dtj	tj	gt d}t
|| W d    d S 1 sLw   Y  d S )Nr   rb   r-   r0   r   )r   r   r   r   rD   r   _datar   r   r6   r   assert_numpy_array_equalru   logr7   )rf   	s_reindexr)   rR   
result_logexpected_logr*   r*   r+   #test_reindexing_with_float64_NA_log  s   
"r   timedelta64
datetime64c                 C   s`   t tjdg|  dd}|td}t tjdtt| ddg|  dd}t|| d S )Nr0   z[s]rb   r   natrf   )r   r   r   r   r
   getattrr   r7   )rF   r   r)   rR   r*   r*   r+   test_reindex_expand_nonnano_nat  s   "r   )8numpyr   rZ   pandas.util._test_decoratorsutil_test_decoratorstdpandasr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   pandas._testing_testingr   r,   r=   rK   rS   r`   ri   rx   r|   r   r   r   r   r   r   r   r   &skip_array_manager_not_yet_implementedmarkparametrizer   r   r   r6   r   r   r   r   r   r   r   r   r*   r*   r*   r+   <module>   sf    @"
3


