a
    d]K                     @   s  d dl Z d dlZd dlZd dlm  mZ d dlm	  m
Z d dlmZ d dlmZ d dlmZmZmZ ejdd Zejg dg dg dg d	g d
g dgd dgddgdgdgdgdggd gdgd dgddgd dgddggdgdgd dgddgdgdggd dgddgddgddgg g gd gdgg g g g ggg dddd ZG dd dZG dd dZG dd dZG d d! d!ZG d"d# d#ZG d$d% d%ZdS )&    N)Series)
BlockIndexIntIndexmake_sparse_indexc                   C   s   dS )N    r   r   r   r/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/tests/arrays/sparse/test_libsparse.pytest_length   s    r	   )r         )      r   )   	      )r   r   r   )r   r   r   )   r      r   r   r   r   
   r
            r   )Z
plain_caseZdelete_blocksZsplit_blocksZ
skip_blockZno_intersectZ	one_empty)paramsidsc                 C   s   | j S N)param)requestr   r   r   cases   s    =r   c                   @   s&  e Zd Zejddgdgdgdgdgdggddgddgddgddgg d	g d
gdgdgdgdgdgdggddgddgdgdgdgdggddgddgdgdgdgdggddgddgddgddgdgdggdgdgg dg ddgdggddgddgddgddgg dg dggdd Zdd ZdS )TestSparseIndexUnionz"xloc, xlen, yloc, ylen, eloc, elenr   r   r   r   r   r   r   )r   r   r   )r
   r   r   r   r   r
      r      r   )r   r   r   )r   r   r   )r   r   r   r   )r   r   r   r   c                 C   s   t |||}t |||}	||	}
t|
t s0J t|
jtj|tjd t|
j	tj|tjd |
 }|	
 }||}t|tsJ t|j|

 j d S )NZdtype)r   
make_union
isinstancetmassert_numpy_array_equalblocsnparrayint32blengthsto_int_indexr   indices)selfxlocxlenylocylenelocelenr	   xindexyindexZbresultZixindexZiyindexZiresultr   r   r   test_index_make_unionX   s    ,

z*TestSparseIndexUnion.test_index_make_unionc                 C   s  t dtjg dtjd}t dtjddgtjd}||}t dtg dtj}||sdJ t dtjg tjd}t dtjddgtjd}||}t dtddgtj}||sJ t dtjg tjd}t dtjg tjd}||}t dtg tj}||sJ t dtjg dtjd}t dtjg dtjd}||}t dtg dtj}||sJ t dtjddgtjd}t d	tjddgtjd}d
}tjt|d || W d    n1 s0    Y  d S )Nr   )r   r   r   r    r   r   )r   r   r   r   r   r   r   r   r   r   r   -Indices must reference same underlying lengthmatch)	r   r&   r'   r(   r!   equalspytestraises
ValueError)r,   abresexpmsgr   r   r   test_int_index_make_union   s2    



z.TestSparseIndexUnion.test_int_index_make_unionN)__name__
__module____qualname__r;   markparametrizer5   rC   r   r   r   r   r   W   s   &"&
,r   c                   @   s   e Zd Zejdd Zdd Zej	de
dejddgejd	e
dejg d
ejd	e
dejg ejd	e
dejg ejd	gdd ZdS )TestSparseIndexIntersectc                 C   s   |\}}}}}}t |||}	t |||}
t |||}t |d ||}|	|
}||s\J |	 |
 }|| sJ d}tjt|d |	| W d    n1 s0    Y  tjt|d" |	 |  W d    n1 s0    Y  d S )Nr   r7   r8   )r   	intersectr:   r*   r;   r<   	Exception)r,   r   r	   r-   r.   r/   r0   r1   r2   r3   r4   expectedZlonger_indexresultrB   r   r   r   test_intersect   s    
(z'TestSparseIndexIntersect.test_intersectc                 C   s   t dtjg tjd}t dtjddgtjd}|||sDJ |||sXJ | }| }|||s|J |||sJ d S )Nr   r    r   r   )r   r&   r'   r(   rJ   r:   to_block_index)r,   r3   r4   r   r   r   test_intersect_empty   s    z-TestSparseIndexIntersect.test_intersect_emptycaser   r   r   r    )r   r   r   r   c                 C   s4   | ||sJ | }| ||s0J d S r   )rJ   r:   rO   )r,   rQ   r   r   r   test_intersect_identical   s    z1TestSparseIndexIntersect.test_intersect_identicalN)rD   rE   rF   tdZskip_if_windowsrN   rP   r;   rG   rH   r   r&   r'   r(   rR   r   r   r   r   rI      s   
rI   c                   @   s   e Zd Zdd Zdd Zejdddgdd	 Zejdddgd
d Z	ejdddgddgddgddgddgddgddgddgddgddgg
dd Z
dS )TestSparseIndexCommonc                 C   s  t dtjddgtjddd}t|ts,J |jdks:J t|j	tjddgtjd t dtjg tjddd}t|tsJ |jdksJ t|j	tjg tjd t dtjg dtjddd}t|tsJ |jdksJ t|j	tjg dtjd d S 	Nr   r   r   r    integerkindr   r   r   r   r   
r   r&   r'   r(   r"   r   npointsr#   r$   r+   r,   idxr   r   r   test_int_internal   s    z'TestSparseIndexCommon.test_int_internalc                 C   s  t dtjddgtjddd}t|ts,J |jdks:J t|j	tjdgtjd t|j
tjdgtjd t dtjg tjddd}t|tsJ |jdksJ t|j	tjg tjd t|j
tjg tjd t dtjg dtjddd}t|ts
J |jdksJ t|j	tjdgtjd t|j
tjdgtjd t dtjg d	tjddd}t|tsJ |jdksJ t|j	tjddgtjd t|j
tjd
dgtjd d S Nr   r   r   r    blockrW   r   rY   r   r   r   r   r   r&   r'   r(   r"   r   r[   r#   r$   r%   r)   r\   r   r   r   test_block_internal   s(    z)TestSparseIndexCommon.test_block_internalrX   rV   r`   c                 C   s  t dtjddgtjd|d}|ddks0J |ddksBJ |ddksTJ |ddksfJ |ddksxJ |ddksJ t dtjg tjd|d}tdd	D ]}||dksJ qt dtjg d
tjd|d}|ddksJ |ddks
J |ddksJ |ddks2J |ddksFJ |ddksZJ t dtjg dtjd|d}|ddksJ |ddksJ |ddksJ |ddksJ |ddksJ |ddksJ d S )Nr   r   r   r    rW   r   r   r   rY   ra   )r   r&   r'   r(   lookuprange)r,   rX   r]   ir   r   r   test_lookup  s0    z!TestSparseIndexCommon.test_lookupc                 C   s  t dtjddgtjd|d}|tjg dtjd}tjg dtjd}t|| |tjg dtjd}tjg d	tjd}t|| t dtjg tjd|d}|tjg d
tjd}tjg dtjd}t|| t dtjg dtjd|d}|tjg dtjd}tjg dtjd}t|| |tjg dtjd}tjg dtjd}t|| t dtjg dtjd|d}|tjg dtjd}tjg dtjd}t|| |tjg dtjd}tjg dtjd}t|| d S )Nr   r   r   r    rW   )rd   r   r   )rd   rd   r   )r   r   r   r   )rd   r   rd   r   )rd   r   r   r   )rd   rd   rd   rd   rY   )rd   r   r   r   ra   )r   r   r   r   )r   rd   r   r   )r   r   r   r   )rd   rd   r   rd   )r   r&   r'   r(   Zlookup_arrayr#   r$   )r,   rX   r]   r@   rA   r   r   r   test_lookup_array-  s2    z'TestSparseIndexCommon.test_lookup_arrayzidx, expectedr   rd   r   r
   r   r   r   r      r   r   r      c                 C   sD   t dddgddg}|||ks&J | }|||ks@J d S )Nr   r   r   r   r   )r   re   r*   )r,   r]   rL   ZbindexZiindexr   r   r   test_lookup_basicsP  s    z(TestSparseIndexCommon.test_lookup_basicsN)rD   rE   rF   r^   rc   r;   rG   rH   rh   ri   rl   r   r   r   r   rT      s*   

"rT   c                   @   sN   e Zd Zdd Zejdg ddd Zdd Zd	d
 Z	dd Z
dd ZdS )TestBlockIndexc                 C   s  t dtjddgtjddd}t|ts,J |jdks:J t|j	tjdgtjd t|j
tjdgtjd t dtjg tjddd}t|tsJ |jdksJ t|j	tjg tjd t|j
tjg tjd t dtjg dtjddd}t|ts
J |jdksJ t|j	tjdgtjd t|j
tjdgtjd t dtjg d	tjddd}t|tsJ |jdksJ t|j	tjddgtjd t|j
tjd
dgtjd d S r_   rb   r\   r   r   r   rc   h  s(    z"TestBlockIndex.test_block_internalrg   )r   r   d   e   c                 C   sb   t |tjd|dtjddd}tjd|dtjd}t|j| t|jtjt	|tjd d S )Nr   r   r    r`   rW   )
r   r&   aranger(   r#   r$   r%   r)   Zoneslen)r,   rg   r]   rA   r   r   r   test_make_block_boundary  s    z'TestBlockIndex.test_make_block_boundaryc                 C   sD   t dddgddg}||s"J |t dddgddgr@J d S )Nr   r   r   r   r   r   )r   r:   r,   indexr   r   r   test_equals  s    zTestBlockIndex.test_equalsc                 C   s   g }g }t d|| t d|| d}tjt|d  t ddgdg W d    n1 sX0    Y  d}tjt|d$ t dddgdd	g W d    n1 s0    Y  d S )
Nr   r   zBlock 0 extends beyond endr8   r   r   zBlock 0 overlapsr   r   )r   r;   r<   r=   )r,   locslengthsrB   r   r   r   test_check_integrity  s    .z#TestBlockIndex.test_check_integrityc                 C   sJ   ddg}ddg}g d}t d||}| }t|jtj|tjd d S )Nr   r   r   r   )
r   r   r   r   r   rj   r   r   r   r   r   r    )r   r*   r#   r$   r+   r&   r'   r(   )r,   rv   rw   Zexp_indsr`   Zdenser   r   r   test_to_int_index  s    z TestBlockIndex.test_to_int_indexc                 C   s(   t dddgddg}| |u s$J d S )Nr   r   r   r   )r   rO   rs   r   r   r   test_to_block_index  s    z"TestBlockIndex.test_to_block_indexN)rD   rE   rF   rc   r;   rG   rH   rr   ru   rx   ry   rz   r   r   r   r   rm   g  s   

rm   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestIntIndexc                 C   s  d}t jt|d  tdg dd W d    n1 s80    Y  d}t jt|d  tdg dd W d    n1 sz0    Y  d}t jt|d  tdg dd W d    n1 s0    Y  d	}t jt|d  tdg d
d W d    n1 s0    Y  t jt|d  tdg dd W d    n1 s>0    Y  d}t jt|d  tdg dd W d    n1 s0    Y  t jt|d  tdg dd W d    n1 s0    Y  d S )NzToo many indicesr8   r   )r   r   r   )lengthr+   zNo index can be less than zeror   )r   r   z(All indices must be less than the length)r   r   r   )r   r   r   z#Indices must be strictly increasing)r   r   r   )r   r   r   )r;   r<   r=   r   )r,   rB   r   r   r   rx     s&    ....00z!TestIntIndex.test_check_integrityc                 C   s  t dtjddgtjddd}t|ts,J |jdks:J t|j	tjddgtjd t dtjg tjddd}t|tsJ |jdksJ t|j	tjg tjd t dtjg dtjddd}t|tsJ |jdksJ t|j	tjg dtjd d S rU   rZ   r\   r   r   r   r^     s    zTestIntIndex.test_int_internalc                 C   s8   t dg d}||sJ |t dg dr4J d S )Nr   r6   rY   )r   r:   rs   r   r   r   ru     s    zTestIntIndex.test_equalsc                 C   sn   |\}}}}}}t |||}t |||}	|  }
|	  }t|
t sNJ |
|s\J ||	sjJ d S r   )r   r*   rO   r"   r:   )r,   r   r	   r-   r.   r/   r0   _r3   r4   ZxbindexZybindexr   r   r   rz     s    z TestIntIndex.test_to_block_indexc                 C   s"   t dg d}| |u sJ d S )Nr   )r   r   r   r   r   )r   r*   rs   r   r   r   ry     s    zTestIntIndex.test_to_int_indexN)rD   rE   rF   rx   r^   ru   rz   ry   r   r   r   r   r{     s
   %r{   c                   @   s&   e Zd Zejdg ddd ZdS )TestSparseOperatorsopname)addsubmultruedivfloordivc                 C   sX  |\}}}}}}t td| d}	t t|}
t|||}t|||}| }| }t|jd d }t|jd d }d}d}|	||||||\}}}|	||||||\}}}| |sJ t	
|| ||ksJ t||j}|t||}t||j}|t||}|
||}||j}t	
||j t	
||j d S )NZsparse_Z_float64g      $@r   g      Y@r   r   )getattrspliboperatorr   r*   r&   rp   r[   r:   r#   r$   r   r+   ZreindexZfillnavalues)r,   r   r   r	   r-   r.   r/   r0   r~   Z	sparse_opZ	python_opr3   r4   ZxdindexZydindexxyZxfillZyfillZresult_block_valsZrb_indexZbfillZresult_int_valsZri_indexZifillZxseriesZyseriesZseries_resultr   r   r   test_op  s8    



zTestSparseOperators.test_opN)rD   rE   rF   r;   rG   rH   r   r   r   r   r   r     s   r   )r   numpyr&   r;   Zpandas._libs.sparseZ_libssparser   Zpandas.util._test_decoratorsutilZ_test_decoratorsrS   Zpandasr   Zpandas._testingZ_testingr#   Zpandas.core.arrays.sparser   r   r   Zfixturer	   r   r   rI   rT   rm   r{   r   r   r   r   r   <module>   s~   
					2<
[0 IN