a
    d@>                     @   s   d dl m Z mZ d dlZd dlZd dlZd dlmZ d dlm	  m
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 d dlmZ ejZG dd dZdd	 Zd
d ZdS )    )datetime	timedeltaN)PerformanceWarning)Categorical	DataFrameSeries	Timestamp
date_rangeoption_context)
NumpyBlockc                   @   s   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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 )$TestDataFrameBlockInternalsc                 C   sx   t dddd}|d }td|i}|d jjd u s6J tj|jd< |d jjd u sVJ |jdksdJ |d |kstJ d S )	N20130101   
US/Eastern)periodstz   B)r   r   D)r	   r   Z_valuesfreqpdZNaTZiloc)selfZdtitsdf r   p/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/tests/frame/test_block_internals.py,test_setitem_invalidates_datetime_index_freq#   s    zHTestDataFrameBlockInternals.test_setitem_invalidates_datetime_index_freqc                 C   sX   t |jtd}t |jtd}t|| t |jtjd}t |jtjd}t|| d S )Ndtype)r   _mgrintZ_seriestmassert_frame_equalnpint32)r   float_frameZcastedexpectedr   r   r   test_cast_internals4   s    z/TestDataFrameBlockInternals.test_cast_internalsc                 C   s   d|d< |  }t|jjdks$J |  }||us8J t|| d|d< t|jjdks`J | }|d u stJ t|jjdksJ d S )N      @Er   g       @Fr   )Z_consolidatelenr   blocksr!   r"   Z_consolidate_inplace)r   r%   ZconsolidatedZreconsZreturn_valuer   r   r   test_consolidate=   s    z,TestDataFrameBlockInternals.test_consolidatec                 C   s,   t tdtdD ]}t||t|< qd S )NAZ)rangeordchr)r   r%   letterr   r   r   test_consolidate_inplaceN   s    z4TestDataFrameBlockInternals.test_consolidate_inplacec                 C   s   |rVt jtdd d|jd< W d    n1 s20    Y  |jd dk sRJ d S d|jd< |jd dk svJ d|d< |d }d|jd< |jd dk rJ |dk sJ d S )Nz	read-onlymatch   r(   r)         )pytestraises
ValueErrorvaluesall)r   r%   using_copy_on_writecolr   r   r   test_modify_valuesS   s    (

z.TestDataFrameBlockInternals.test_modify_valuesc                 C   s<   d|d< |j  }d||dk< d||dk< t||j  d S )Nr(   r)      r   )r=   copyr!   Zassert_almost_equal)r   r%   r&   r   r   r   test_boolean_set_unconsg   s
    
z3TestDataFrameBlockInternals.test_boolean_set_unconsc              	   C   s  t ddgi}|d }ttdgtjdd}t|| t ddgi}|d }ttdgtjdd}t|| t dtddddgi}|d }tttddddgtj	dd}t|| t dd dgi}|d }tttj
dgtjdd}t|| t ddd	gi}|d }ttdd	gtjdd}t|| t dd
dgi}|d }ttd
dgtjdd}t|| t dd
dgi}|d }ttd
dgtjdd}t|| t dd
dgi}|d }ttd
dgtj	dd}t|| t ddd gi}|d }ttdtj
gtjdd}t|| t dd
d gi}|d }ttd
tj
gtjdd}t|| t dg di}|d }ttg dtj	dd}t|| t dddtdddd gi}|d }ttddtdddd gtj	dd}t|| d S )Nr.   l    )namel            i  r   Tg      ?rB   y      ?       @r   g      @)       @r   TNrF   i  )r   r   r#   Zasarrayint64r!   assert_series_equalZuint64r   Zobject_nanfloat64Z
complex128)r   r   resultr&   r   r   r   test_constructor_with_convertp   sh    z9TestDataFrameBlockInternals.test_constructor_with_convertc                 C   s   t dddtjt dddgt dddt dddt dddgg}t|}|j}tddi}t  |d< tddd	|d
< |d jdksJ |d
 jdksJ |j}ttdgd tdtdtdg t	dg d d}t
|| d S )N  r   r7   rB   i  r   zdatetime64[us]r   )dayssecondsr   zM8[us]zm8[us]rJ      objectztimedelta64[us]ABCD)Zfoor   r   index)r   r#   rI   r   dtypesr   nowr   r   listr!   rH   )r   float_string_framedatar   rK   r&   r   r   r   test_construction_with_mixed   s*     	z8TestDataFrameBlockInternals.test_construction_with_mixedc                 C   s   t jg ddd}ttdd}||d< tdtjdddd	itdd}t|d  | tt	d
t
d
ddddtdd}|jd dksJ |jd dksJ ttdd}t d|d< t jg ddd|d< t|| d S )Nr   rB   r   ztimedelta64[s]r   r   rS   r.   z00:00:01s)r   r   r   )r   zM8[s])dt1dt2r]   r^   
2013-01-01)r_   z
2013-01-02z
2013-01-03zdatetime64[D])r#   arrayr   r0   r   Ztimedelta_ranger!   Zassert_numpy_array_equalZto_numpyr   r	   astyperU   Z
datetime64r"   )r   arrr   r&   r   r   r   "test_construction_with_conversions   s*    	
z>TestDataFrameBlockInternals.test_construction_with_conversionsc                 C   s   dd }d}t jt|d |g d W d    n1 s<0    Y  t jtdd |d W d    n1 sr0    Y  t jtdd |d W d    n1 s0    Y  d	}t jt|d |d
 W d    n1 s0    Y  d S )Nc                 S   s0   t ttdddddfd}t|g d| dS )NrM   r   Zaa   	   )r.   r   C)rY   columnsr   )rW   	itertoolsrepeatr   r   )r   rY   r   r   r   f   s    zGTestDataFrameBlockInternals.test_constructor_compound_dtypes.<locals>.fz@compound dtypes are not implemented in the DataFrame constructorr5   ))r.   zdatetime64[h])r   str)rf   r$   zargument must berG   rJ   zD^Unknown datetime string format, unable to parse: aa, at position 0$zM8[ns])r:   r;   NotImplementedError	TypeErrorr<   )r   rj   msgr   r   r    test_constructor_compound_dtypes   s    *&&z<TestDataFrameBlockInternals.test_constructor_compound_dtypesc                 C   sP   t  }t|}t|| |jj t|}t| t|}t|| d S N)r   r!   Zround_trip_pickler"   r   ndimrepr)r   rX   Ztimezone_frameZempty_frameZ	unpickledr   r   r   test_pickle  s    


z'TestDataFrameBlockInternals.test_picklec                 C   s   t tg dtg dg dd}|j}|j|_|d}|d}d|j_|j	}|j|_|d}|d}d|j_|j|_|j|_	t
t|j|j t
t|j	|j d S )	N)z2012-06-21 00:002012-06-23 07:002012-06-23 16:302012-06-25 08:002012-06-26 12:00)rt   ru   rv   rw   z2012-06-27 08:00)M   A   rx   r   rx   )startingendingZmeasurer   UTCrz   r{   )r   r   to_datetimerz   r=   rT   Ztz_localizeZ
tz_convertrE   r{   r!   Zassert_index_equalZDatetimeIndex)r   r   Zser_startingZ
ser_endingr   r   r   test_consolidate_datetime64  s0    		



z7TestDataFrameBlockInternals.test_consolidate_datetime64c                 C   s   |j r
J |j sJ d S rp   )Z_is_mixed_type)r   r%   rX   r   r   r   test_is_mixed_typeJ  s    
z.TestDataFrameBlockInternals.test_is_mixed_typec              	   C   s   t dd  ttjddddd}t| |d d|d< |r~t  tj	|d	 d
< W d    q1 sr0    Y  ntj	|d	 d
< t| |
  |d	 
  |rt|d	 d
 rJ nt|d	 d
 sJ W d    n1 s0    Y  d S )NZchained_assignmentrB   )rP   rP   abcd)erj   gh)rT   rg   r   rQ   r   r   )r
   r   r#   randomZdefault_rngrr   ra   r!   raises_chained_assignment_errorrI   sumr   isna)r   r?   Yr   r   r    test_stale_cached_series_bug_473N  s$    
.z<TestDataFrameBlockInternals.test_stale_cached_series_bug_473c           
      C   s  t ddgd}tj|d< i }ttn t|jD ]R\}}tddD ]>}||vrbd||< tj||< |rv||j	||f< qD||| |< qDq2W d    n1 s0    Y  d}t
|j	t|| |gf }t
|j	t|| |gf }	||	  krdksn J d S )Nr   r   rS   d      )r   r#   rI   r!   Zassert_produces_warningr   	enumeraterT   r0   locr+   r   r   )
r   r?   r   ZwasColidtr@   Zmyidfirstsecondr   r   r   $test_strange_column_corruption_issuee  s     

.z@TestDataFrameBlockInternals.test_strange_column_corruption_issuec                 C   sb   t g dj}td|i}tdg di}t|| t|jjd tsLJ |jjd j	s^J d S )Nr[   r.   r   )
r   r`   r   r!   r"   
isinstancer   r,   r   Z
is_numeric)r   rb   rK   r&   r   r   r    test_constructor_no_pandas_array|  s    z<TestDataFrameBlockInternals.test_constructor_no_pandas_arrayc              	   C   s   t g dg dd}tjtjg dtd|d< t g dg dtjtjg dtdd}t|d jj	d t
ks~J |d jj	d jsJ t|d jj	d t
ksJ |d jj	d jsJ t|| d S )	N)r   rB   r   rP   r   )r   r   )r   rB   Nr   r   r   )r   r   r   r   )r   r   ZarraysZNumpyExtensionArrayr#   r`   rQ   typer   r,   r   Z	is_objectr!   r"   )r   r   Zdf2r   r   r   !test_add_column_with_pandas_array  s    	z=TestDataFrameBlockInternals.test_add_column_with_pandas_arrayN)__name__
__module____qualname__r   r'   r-   r4   rA   rD   rL   rZ   rc   ro   rs   r~   r   r   r   r   r   r   r   r   r   r   "   s"   		C#-
r   c                 C   s   t dtg dddi}| rXt " |d jddd W d    qj1 sL0    Y  n|d jddd t|jjd jt	sJ | s|
   dksJ d S )	Nr   )r   rB   Ncategoryr   r   T)Zinplacer   )r   r   r!   r   Zfillnar   r   r,   r=   r   Zisnullr   )r?   r   r   r   r   +test_update_inplace_sets_valid_block_values  s    
2r   c                  C   s   t  } tdgtd| d< tdgtd| d< | d dk | | d dk  d| jd< t dgdgdtd}t| | | jd dksJ d S )	Nr   r   col1r   col2r.   )r   r   )r   r   )r   r   rQ   atr!   r"   )r   r&   r   r   r   $test_nonconsolidated_item_cache_take  s    
r   )r   r   rh   numpyr#   r:   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr   r   r   r   r   r	   r
   Zpandas._testingZ_testingr!   Zpandas.core.internals.blocksr   Zskip_array_manager_invalid_testZ
pytestmarkr   r   r   r   r   r   r   <module>   s      z