o
    թZh]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   `/var/www/html/lang_env/lib/python3.10/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 sJ t|
jtj|tjd t|
j	tj|tjd |
 }|	
 }||}t|tsFJ 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}||s2J 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}||sbJ t dtjg tjd}t dtjg tjd}||}t dtg tj}||sJ 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    d S 1 sw   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   s4   



"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 |	 |
 }|| s@J d}tjt|d |	| W d    n1 sYw   Y  tjt|d |	 |  W d    d S 1 szw   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}|||s"J |||s,J | }| }|||s>J |||sHJ 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 | }| ||sJ 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     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s@J |jdksGJ t|j	tjg tjd t dtjg dtjddd}t|tsjJ |jdksqJ 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      "z'TestSparseIndexCommon.test_int_internalc                 C     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sMJ |jdksTJ 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sJ |jdksJ 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   (   "z)TestSparseIndexCommon.test_block_internalrX   rV   rb   c                 C   s  t dtjddgtjd|d}|ddksJ |ddks!J |ddks*J |ddks3J |ddks<J |ddksEJ t dtjg tjd|d}tdd	D ]}||dksbJ qWt dtjg d
tjd|d}|ddks{J |ddksJ |ddksJ |ddksJ |ddksJ |ddksJ 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   rc   )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   )rg   r   r   )rg   rg   r   )r   r   r   r   )rg   r   rg   r   )rg   r   r   r   )rg   rg   rg   rg   rY   )rg   r   r   r   rc   )r   r   r   r   )r   rg   r   r   )r   r   r   r   )rg   rg   r   rg   )r   r%   r&   r'   Zlookup_arrayr"   r#   )r+   rX   r]   r?   r@   r   r   r   test_lookup_array-  s2   z'TestSparseIndexCommon.test_lookup_arrayzidx, expectedr   rg   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   rh   r)   )r+   r]   rK   ZbindexZiindexr   r   r   test_lookup_basicsP  s   z(TestSparseIndexCommon.test_lookup_basicsN)rC   rD   rE   r^   re   r:   rF   rG   rk   rl   ro   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   r`   ra   rd   r\   r   r   r   re   h  rf   z"TestBlockIndex.test_block_internalrj   )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   rb   rW   )
r   r%   aranger'   r"   r#   r$   r(   Zoneslen)r+   rj   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 s,w   Y  d}tjt|d t dddgdd	g W d    d S 1 sPw   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   rm   r   r   r   r   r   r   )r   r)   r"   r#   r*   r%   r&   r'   )r+   ry   rz   Zexp_indsrb   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   rv   r   r   r   test_to_block_index  s   z"TestBlockIndex.test_to_block_indexN)rC   rD   rE   re   r:   rF   rG   ru   rx   r{   r|   r}   r   r   r   r   rp   g  s    

rp   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 sw   Y  d}t jt|d tdg dd W d    n1 s=w   Y  d}t jt|d tdg dd W d    n1 s^w   Y  d	}t jt|d tdg d
d W d    n1 sw   Y  t jt|d tdg dd W d    n1 sw   Y  d}t jt|d tdg dd W d    n1 sw   Y  t jt|d tdg dd W d    d S 1 sw   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   r{     s4   "z!TestIntIndex.test_check_integrityc                 C   rT   rU   rZ   r\   r   r   r   r^     r_   zTestIntIndex.test_int_internalc                 C   s8   t dg d}||sJ |t dg drJ d S )Nr   r5   rY   )r   r9   rv   r   r   r   rx     s   zTestIntIndex.test_equalsc                 C   sn   |\}}}}}}t |||}t |||}	|  }
|	  }t|
t s'J |
|s.J ||	s5J d S r   )r   r)   rN   r!   r9   )r+   r   r	   r,   r-   r.   r/   _r2   r3   ZxbindexZybindexr   r   r   r}     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)   rv   r   r   r   r|     s   zTestIntIndex.test_to_int_indexN)rC   rD   rE   r{   r^   rx   r}   r|   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}|	||||||\}}}|	||||||\}}}| |scJ t	
|| ||ksoJ 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%   rs   r[   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   rp   r~   r   r   r   r   r   <module>   s    
					2
<[0 IN