o
    _~#g8                  	   @   s@  d dl Zd dlZd dlm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 ejje dd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. Z0d/d0 Z1ej.d1ed2d3ed4d3ged2d3ed4d3d5gd6d6gd6d6ej2gfed2d3ed4d3ged2d3ed4d3gd6d6gd6d6gfgd7d8 Z3d9d: Z4d;d< Z5d=d> Z6ej.d?d@gdAggg g ggdBdC Z7dDdE Z8dFdG Z9ej.d&dHdIgdJdK Z:dS )L    N)using_pyarrow_string_dtype)NACategoricalFloat64DtypeIndex
MultiIndexNaTPeriodPeriodIndex
RangeIndexSeries	Timedelta	Timestamp
date_rangeisnaz#share memory doesn't work for arrow)reasonc                 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npmay_share_memoryis_	identicalitemsisnanall)datetime_seriesstring_seriesidentitysubIndex	subSeriesidxval	subIndex2subTSstuffSeriesnonContigIndexsubNonContigresult r+   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/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.   r1   r   objectF)check_index_type)	r   r   nantm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_natL   s   rM   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   rB   r   r4   r/   r   )r   r   r   randomdefault_rngstandard_normalr   listr   
_with_freqr8   r9   )rJ   r<   r*   expectedr+   r+   r,   test_reindex_with_datetimesX   s   rU   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 )Nr4   padmethodr   zVInvalid fill method\. Expecting pad \(ffill\), backfill \(bfill\) or nearest\. Got foomatchfoo)
r   r   r   rR   rS   r8   r9   pytestraises
ValueError)r   empty	reindexedr<   msgr+   r+   r,   test_reindex_cornere   s   
"rb   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rH   r   rV   rW   ffill)
r   r   r   r   r2   r2      rf   r3   r3   )r   r   aranger   r   r8   r9   )ss2r`   
reindexed2rT   r+   r+   r,   test_reindex_pad|   s   rk   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r1   r   r.   r2   r/   )abcder4   )rm   gro   f)r1   r1   r.   r.   float64z-The 'downcast' keyword in ffill is deprecatedrY   infer)downcast)r1   r/   r.   r/   re   rW   )r   r   re   r8   r9   r;   assert_produces_warningFutureWarning)rh   	new_indexrT   r*   ra   r+   r+   r,   test_reindex_pad2   s   rz   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abcdr4   agc"Downcasting object dtype arrays onrY   )TTF)r   rR   r8   rw   rx   r   re   r9   )rh   ry   ra   r*   rT   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/   r4   r}   rY   r1   )r   rF   r8   rw   rx   shiftbfillr9   )rh   ra   r*   rT   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   rc   rd   )g?g?g      ?       @nearestrW   g?)rX   	tolerancer   r1   r   )g333333?g{Gz?g?r.   )	r   r   rg   r   aroundr;   r8   r9   r7   )rh   targetr*   rT   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   rd   r4   )	r   r   zeroslenintr   r   rH   rt   )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   rH   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/   rd   r4   rV   rW   )	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.   rN   )rm   rn   ro   categoryrd   )values
categoriesrn   ro   r1   r   )	r   r   r   r   r   r7   r   r8   r9   )r   rh   r*   rT   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r1   r   r.   )r   r   r1   r4   )r   r1   r   r   )r   strr   r;   r8   r9   )serry   
temp_dtype	new_dtyper*   rT   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   r4   r   
fill_value)r   r   r   )r   r.   r   rd   r   r.   r   rH   r[   )r   r.   r[   )TFTFT)FTF)r   r   r   r7   r8   r9   
issubclassrH   typeintegerr5   )floatsr*   rT   intsobjectsboolsr+   r+   r,   test_reindex_fill_value  s:   r   rH   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   rd   r1   r   r   )r   r   r   r   r   r5   r8   r9   )rH   r   using_array_managerr   r*   rT   r+   r+   r,   +test_reindex_fill_value_datetimelike_upcast>  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/Chicagor0   )tzrB   20131103r   hrA   r4   zLCannot compare dtypes datetime64\[ns, America/Chicago\] and datetime64\[ns\]rY   re   rW   )r   r   rF   r\   r]   	TypeErrorr   )r#   newidxrh   ra   r+   r+   r,   /test_reindex_datetimeindexes_tz_naive_and_awareN  s   "r   c                  C   s6   t ddddg} t tgd dd}t| | d S )Nzdatetime64[ns, UTC]rd   r   r1   r   )r   r   r   r8   assert_equal)r*   rT   r+   r+   r,   "test_reindex_empty_series_tz_dtype[  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 )Nr4   )r
   r   r   r   r8   r9   )	p_valueso_valuesr   expected_valuesperiod_indexobject_indexr   r*   rT   r+   r+   r,   $test_reindex_periodindex_with_objectb  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 )Nr1   r   zCreindex\(\) takes from 1 to 2 positional arguments but 3 were givenrY   r.   Fr   r\   r]   r   r   r   ra   r+   r+   r,   test_reindex_too_many_args~  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 )Nr1   r   z4reindex\(\) got multiple values for argument 'index'rY   r.   r2   r4   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 )Nr1   r   r   r4   )r   r   r8   r9   )r   r*   rT   r+   r+   r,   test_reindex_no_posargs  s   r   r   rm   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   r5   r   rn   )levelr1   )levelscodes)
r   rF   r   r   from_arraysr   r   arrayr8   r9   )r   r   r*   rT   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)r1   r   r.   r1   r   rd   z:Cannot setitem on a Categorical with a new category \(-1\)rY   rl   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   rd   r.   r1   r   )r   r   r   r   rF   r   _datar   r   r7   r8   assert_numpy_array_equalrw   logr9   )rh   	s_reindexr*   rT   
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 )Nr1   z[s]rd   r   natrh   )r   r   r   r   r   getattrr8   r9   )rH   r   r*   rT   r+   r+   r,   test_reindex_expand_nonnano_nat  s   "r   );numpyr   r\   pandas._configr   pandas.util._test_decoratorsutil_test_decoratorstdpandasr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   pandas._testing_testingr8   markxfailr-   r?   rM   rU   rb   rk   rz   r~   r   r   r   r   r   r   r   r   &skip_array_manager_not_yet_implementedparametrizer   r   r   r7   r   r   r   r   r   r   r   r   r+   r+   r+   r,   <module>   sn    @
"
3


