a
    Pf]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   b/var/www/ai-form-bot/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)paramsZ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parametrizer4   rB   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   r6   r7   )r   	intersectr9   r)   r:   r;   	Exception)r+   r   r	   r,   r-   r.   r/   r0   r1   r2   r3   expectedZlonger_indexresultrA   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'   rI   r9   to_block_index)r+   r2   r3   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   )rI   r9   rN   )r+   rP   r   r   r   test_intersect_identical   s    z1TestSparseIndexIntersect.test_intersect_identicalN)rC   rD   rE   tdZskip_if_windowsrM   rO   r:   rF   rG   r   r%   r&   r'   rQ   r   r   r   r   rH      s   
rH   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   blockrV   r   rX   r   r   r   r   r   r%   r&   r'   r!   r   rZ   r"   r#   r$   r(   r[   r   r   r   test_block_internal   s(    z)TestSparseIndexCommon.test_block_internalrW   rU   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   rV   r   r   r   rX   r`   )r   r%   r&   r'   lookuprange)r+   rW   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   rV   )rc   r   r   )rc   rc   r   )r   r   r   r   )rc   r   rc   r   )rc   r   r   r   )rc   rc   rc   rc   rX   )rc   r   r   r   r`   )r   r   r   r   )r   rc   r   r   )r   r   r   r   )rc   rc   r   rc   )r   r%   r&   r'   Zlookup_arrayr"   r#   )r+   rW   r\   r?   r@   r   r   r   test_lookup_array-  s2    z'TestSparseIndexCommon.test_lookup_arrayzidx, expectedr   rc   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   rd   r)   )r+   r\   rK   ZbindexZiindexr   r   r   test_lookup_basicsP  s    z(TestSparseIndexCommon.test_lookup_basicsN)rC   rD   rE   r]   rb   r:   rF   rG   rg   rh   rk   r   r   r   r   rS      s*   

"rS   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^   ra   r[   r   r   r   rb   h  s(    z"TestBlockIndex.test_block_internalrf   )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_   rV   )
r   r%   aranger'   r"   r#   r$   r(   Zoneslen)r+   rf   r\   r@   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   r9   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 endr7   r   r   zBlock 0 overlapsr   r   )r   r:   r;   r<   )r+   locslengthsrA   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   ri   r   r   r   r   r   r   )r   r)   r"   r#   r*   r%   r&   r'   )r+   ru   rv   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   rN   rr   r   r   r   test_to_block_index  s    z"TestBlockIndex.test_to_block_indexN)rC   rD   rE   rb   r:   rF   rG   rq   rt   rw   rx   ry   r   r   r   r   rl   g  s   

rl   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 indicesr7   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+   rA   r   r   r   rw     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 rT   rY   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   r5   rX   )r   r9   rr   r   r   r   rt     s    zTestIntIndex.test_equalsc                 C   sn   |\}}}}}}t |||}t |||}	|  }
|	  }t|
t sNJ |
|s\J ||	sjJ d S r   )r   r)   rN   r!   r9   )r+   r   r	   r,   r-   r.   r/   _r2   r3   ZxbindexZybindexr   r   r   ry     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)   rr   r   r   r   rx     s    zTestIntIndex.test_to_int_indexN)rC   rD   rE   rw   r]   rt   ry   rx   r   r   r   r   rz     s
   %rz   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%   ro   rZ   r9   r"   r#   r   r*   ZreindexZfillnavalues)r+   r   r   r	   r,   r-   r.   r/   r}   Z	sparse_opZ	python_opr2   r3   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)rC   rD   rE   r:   rF   rG   r   r   r   r   r   r~     s   r~   )r   numpyr%   r:   Zpandas._libs.sparseZ_libssparser   Zpandas.util._test_decoratorsutilZ_test_decoratorsrR   Zpandasr   Zpandas._testingZ_testingr"   Zpandas.core.arrays.sparser   r   r   Zfixturer	   r   r   rH   rS   rl   rz   r~   r   r   r   r   <module>   s~   
					2<
[0 IN