o
    թZh8                  	   @   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npZmay_share_memoryis_Z	identicalitemsisnanall)datetime_seriesZstring_seriesidentityZsubIndexZ	subSeriesidxvalZ	subIndex2ZsubTSZstuffSeriesZnonContigIndexZsubNonContigresult r!   _/var/www/html/lang_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$   r'   r   objectF)Zcheck_index_type)	r   r   nantmassert_series_equalr   Zilocr   astype)tsijr!   r!   r"   test_reindex_nan@   s
     r3   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   Z10speriodsfreq   zM8[ns])
r   r   r   ranger   Z
issubdtypedtyper   r   any)rngZseriesr    maskr!   r!   r"   test_reindex_series_add_natL   s   r>   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   r5   r   r*   r%   r   )r   r   r   randomZdefault_rngZstandard_normalr   listr   
_with_freqr-   r.   )r<   r0   r    expectedr!   r!   r"   test_reindex_with_datetimesX   s   rD   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 )Nr*   padmethodr   zVInvalid fill method\. Expecting pad \(ffill\), backfill \(bfill\) or nearest\. Got foomatchfoo)
r   r   r   rA   rB   r-   r.   pytestraises
ValueError)r   empty	reindexedr0   msgr!   r!   r"   test_reindex_cornere   s   
"rQ   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r:   r   rE   rF   ffill)
r   r   r   r   r(   r(      rU   r)   r)   )r   r   aranger   r   r-   r.   )ss2rO   Z
reindexed2rC   r!   r!   r"   test_reindex_pad|   s   rY   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r'   r   r$   r(   r%   )abcder*   )r[   gr]   f)r'   r'   r$   r$   float64z-The 'downcast' keyword in ffill is deprecatedrH   Zinfer)Zdowncast)r'   r%   r$   r%   rT   rF   )r   r   rT   r-   r.   r/   assert_produces_warningFutureWarning)rW   	new_indexrC   r    rP   r!   r!   r"   test_reindex_pad2   s   rf   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abcdr*   Zagc"Downcasting object dtype arrays onrH   )TTF)r   rA   r-   rc   rd   r   rT   r.   )rW   re   rP   r    rC   r!   r!   r"   test_reindex_inference   s   ri   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%   r*   rh   rH   r'   )r   r9   r-   rc   rd   shiftZbfillr.   )rW   rP   r    rC   r!   r!   r"   test_reindex_downcasting   s   rk   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   rR   rS   )g?g?g      ?       @ZnearestrF   g?)rG   Z	tolerancer   r'   r   )g333333?g{Gz?g?r$   )	r   r   rV   r   Zaroundr/   r-   r.   r,   )rW   targetr    rC   r!   r!   r"   test_reindex_nearest   s   rn   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   rS   r*   )	r   r   zeroslenintr   r   r:   rb   )r   r0   Zint_tsZreindexed_intr!   r!   r"   test_reindex_int   s   rs   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 ro   )
r   r   rp   rq   boolr   r   r:   Zobject_Zbool_)r   r0   bool_tsZreindexed_boolr!   r!   r"   test_reindex_bool   s   rv   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%   rS   r*   rE   rF   )	r   r   rp   rq   rt   r   r   r   r   )r   r0   ru   Zfilled_boolr!   r!   r"   test_reindex_bool_pad   s   rw   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 )NZ20000101r$   r?   )r[   r\   r]   categoryrS   )values
categoriesr\   r]   r'   r   )	r   r   r   r   r   r,   r   r-   r.   )r   rW   r    rC   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r'   r   r$   )r   r   r'   r*   )r   r'   r   rx   )r   strr   r/   r-   r.   )serre   Z
temp_dtypeZ	new_dtyper    rC   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)      ?rl         @r|   rl   r   r*   r   
fill_value)rl   r   r   )r   r$   r   rS   r   r$   r   r:   rJ   )r   r$   rJ   )TFTFT)FTF)r   r   r   r,   r-   r.   
issubclassr:   typeintegerr+   )Zfloatsr    rC   ZintsobjectsZboolsr!   r!   r"   test_reindex_fill_value  s:   r   r:   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   rS   r'   r   r   )r   r   r   r   r   r+   r-   r.   )r:   r   Zusing_array_managerr~   r    rC   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 )NZ20131101zAmerica/Chicagor&   )tzr5   Z20131103r   hr4   r*   zLCannot compare dtypes datetime64\[ns, America/Chicago\] and datetime64\[ns\]rH   rT   rF   )r   r   r9   rK   rL   	TypeErrorr   )r   ZnewidxrW   rP   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]rS   r   r'   r   )r   r   r   r-   Zassert_equal)r    rC   r!   r!   r"   "test_reindex_empty_series_tz_dtype[  s   r   z+p_values, o_values, values, expected_valuesZ2019Q1zQ-DECZ2019Q2ZAllr   c           	      C   sB   t | }t|}t||d}||}t||d}t|| d S )Nr*   )r
   r   r   r   r-   r.   )	Zp_valuesZo_valuesry   Zexpected_valuesZperiod_indexZobject_indexr~   r    rC   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 )Nr'   r   zCreindex\(\) takes from 1 to 2 positional arguments but 3 were givenrH   r$   Fr   rK   rL   r   r   r~   rP   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 )Nr'   r   z4reindex\(\) got multiple values for argument 'index'rH   r$   r(   r*   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 )Nr'   r   r   r*   )r   r   r-   r.   )r~   r    rC   r!   r!   r"   test_reindex_no_posargs  s   r   ry   r[   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   r+   r   r\   )levelr'   )Zlevelscodes)
r   r9   rq   r   Zfrom_arraysr   r   arrayr-   r.   )ry   r~   r    rC   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)r'   r   r$   r'   rx   rS   z:Cannot setitem on a Categorical with a new category \(-1\)rH   rZ   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   rS   r$   r'   r   )r   r   r   r   r9   ry   _datar   r   r,   r-   Zassert_numpy_array_equalrc   logr.   )rW   Z	s_reindexr    rC   Z
result_logZexpected_logr!   r!   r"   #test_reindexing_with_float64_NA_log  s   
"r   Ztimedelta64Z
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 )Nr'   z[s]rS   r   ZnatrW   )r   r   r   r   r   getattrr-   r.   )r:   r~   r    rC   r!   r!   r"   test_reindex_expand_nonnano_nat  s   "r   );numpyr   rK   Zpandas._configr   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   Zpandas._testingZ_testingr-   markZxfailr#   r3   r>   rD   rQ   rY   rf   ri   rk   rn   rs   rv   rw   r{   r   r   Z&skip_array_manager_not_yet_implementedZparametrizer   r   r   r,   r   r   r   r   r   r   r   r   r!   r!   r!   r"   <module>   sn    @
"
3


