o
    Ti@>                     @   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 sJ tj|jd< |d jjd u s+J |jdks2J |d |ks:J 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   g/var/www/html/evchargy.com/venv/lib/python3.10/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sJ t|| d|d< t|jjdks0J | }|d u s:J t|jjdksDJ d S )N      @Er   g       @Fr   )Z_consolidatelenr   blocksr!   r"   Z_consolidate_inplace)r   r%   ZconsolidatedZrecons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   |r+t jtdd d|jd< W d    n1 sw   Y  |jd dk s)J d S d|jd< |jd dk s;J d|d< |d }d|jd< |jd dk rSJ |dk s[J 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      ?rC   y      ?       @r   g      @)       @r   TNrG   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sCJ |d
 jdksLJ |j}ttdgd tdtdtdg t	dg d d}t
|| d S )N  r   r8   rC   i  r   zdatetime64[us]r   )dayssecondsr   zM8[us]zm8[us]rK      objectztimedelta64[us]ZABCD)Zfoor   r   index)r   r#   rJ   r   dtypesr   nowr   r   listr!   rI   )r   float_string_framedatar   rL   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sKJ |jd dksTJ ttdd}t d|d< t jg ddd|d< t|| d S )Nr   rC   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   r1   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w   Y  t jtdd |d W d    n1 s9w   Y  t jtdd |d W d    n1 sTw   Y  d	}t jt|d |d
 W d    d S 1 srw   Y  d S )Nc                 S   s0   t ttdddddfd}t|g d| dS )NrN   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 constructorr6   ))r/   zdatetime64[h])r   str)rf   r$   zargument must berH   rK   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endingmeasurer   UTCrz   r{   )r   r   to_datetimerz   r>   rT   Ztz_localizeZ
tz_convertrF   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 x ttjddddd}t| |d d|d< |r?t  tj	|d	 d
< W d    n1 s9w   Y  ntj	|d	 d
< t| |
  |d	 
  |rbt|d	 d
 raJ nt|d	 d
 smJ W d    d S W d    d S 1 sw   Y  d S )NZchained_assignmentrC   )rQ   rQ   abcd)erj   gh)rT   rg   r   rR   r   r   )r
   r   r#   randomZdefault_rngrr   ra   r!   raises_chained_assignment_errorrJ   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7 t|jD ])\}}tddD ]}||vr1d||< tj||< |r;||j	||f< q"||| |< q"qW d    n1 sMw   Y  d}t
|j	t|| |gf }t
|j	t|| |gf }	||	  kr}dksJ  J d S )Nr   r   rS   d      )r   r#   rJ   r!   Zassert_produces_warningr   	enumeraterT   r1   locr+   r   r   )
r   r@   r   ZwasColidtrA   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s&J |jjd j	s/J d S )Nr[   r/   r   )
r   r`   r   r!   r"   
isinstancer   r,   r   Z
is_numeric)r   rb   rL   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sJJ t|d jj	d t
ksXJ |d jj	d jscJ t|| d S )	N)r   rC   r   rQ   r   )r   r   )r   rC   Nr   r   r   )r   r   r   r   )r   r   ZarraysZNumpyExtensionArrayr#   r`   rR   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.   r5   rB   rE   rM   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}| r,t  |d jddd W d    n1 s&w   Y  n	|d jddd t|jjd jt	sAJ | sO|
   dksQJ d S d S )	Nr   )r   rC   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   
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sBJ d S )	Nr   r   col1r   col2r/   )r   r   )r   r   )r   r   rR   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