o
    5cOJ                     @   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 dZg dg dg dg dg d	g d
gZd dgddgdgdgdgdggZd gdgd dgddgd dgddggZdgdgd dgddgdgdggZd dgddgddgddgg g gZd gdgg g g g gZg g g g g g gZeeeeeegZg 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_index   )r         )      r
   )   	      )r   r	   r
   )r   r   r   )   r	      r
   r   r   r	   
   r            r   )
plain_casedelete_blockssplit_blocks
skip_blockno_intersect	one_emptyc                   @   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 )TestSparseIndexUnion"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||}||}	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dtype)r   TEST_LENGTH
make_union
isinstancetmassert_numpy_array_equalblocsnparrayint32blengthsto_int_indexr   indices)selfxlocxlenylocylenelocelenxindexyindexbresultixindexiyindexiresult r9   _/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/arrays/sparse/test_libsparse.pytest_index_make_union[   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msgr9   r9   r:   test_int_index_make_union   s4   



"z.TestSparseIndexUnion.test_int_index_make_unionN)__name__
__module____qualname__rA   markparametrizer;   rI   r9   r9   r9   r:   r   Z   s    &"&
,r   c                   @   s   e Zd Zejejjdee	d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 )TestSparseIndexIntersectr   idsc                 C   s   t t||}t t||}t t||}	t td ||}
||}||	s&J | | }||	 s8J d}tjt|d ||
 W d    n1 sQw   Y  tjt|d | |
  W d    d S 1 srw   Y  d S )Nr   r=   r>   )r   r    	intersectr@   r*   rA   rB   	Exception)r,   r-   r.   r/   r0   r1   r2   r3   r4   expectedlonger_indexresultrH   r9   r9   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(   rR   r@   to_block_index)r,   r3   r4   r9   r9   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 N)rR   r@   rX   )r,   rZ   r9   r9   r:   test_intersect_identical   s   
z1TestSparseIndexIntersect.test_intersect_identicalN)rJ   rK   rL   tdskip_if_windowsrA   rM   rN   CASESIDSrW   rY   r   r&   r'   r(   r\   r9   r9   r9   r:   rO      s    	rO   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,   idxr9   r9   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   blockre   r   rg   r   r   r	   r   r   r&   r'   r(   r"   r   ri   r#   r$   r%   r)   rj   r9   r9   r:   test_block_internal   (   "z)TestSparseIndexCommon.test_block_internalrf   rd   rp   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   re   r   r   r
   rg   rq   )r   r&   r'   r(   lookuprange)r,   rf   rk   ir9   r9   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   re   )ru   r   r   )ru   ru   r   )r   r   r   r	   )ru   r   ru   r   )ru   r   r   r   )ru   ru   ru   ru   rg   )ru   r   r   r	   rq   )r   r   r	   r   )r   ru   r   r   )r   r   r   r
   )ru   ru   r   ru   )r   r&   r'   r(   lookup_arrayr#   r$   )r,   rf   rk   rF   rG   r9   r9   r:   test_lookup_array.  s2   z'TestSparseIndexCommon.test_lookup_arrayzidx, expectedr   ru   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   rv   r*   )r,   rk   rT   bindexiindexr9   r9   r:   test_lookup_basicsQ  s   z(TestSparseIndexCommon.test_lookup_basicsN)rJ   rK   rL   rl   rs   rA   rM   rN   ry   r{   r   r9   r9   r9   r:   ra      s,    

"ra   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   rn   ro   rr   rj   r9   r9   r:   rs   i  rt   z"TestBlockIndex.test_block_internalrx   )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   rp   re   )
r   r&   aranger(   r#   r$   r%   r)   oneslen)r,   rx   rk   rG   r9   r9   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,   indexr9   r9   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 endr>   r   r
   zBlock 0 overlapsr   r	   )r   rA   rB   rC   )r,   locslengthsrH   r9   r9   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   r|   r   r   r   r   r   r   )r   r*   r#   r$   r+   r&   r'   r(   )r,   r   r   exp_indsrp   denser9   r9   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   rX   r   r9   r9   r:   test_to_block_index  s   z"TestBlockIndex.test_to_block_indexN)rJ   rK   rL   rs   rA   rM   rN   r   r   r   r   r   r9   r9   r9   r:   r   h  s    

r   c                   @   sF   e Zd Zdd Zdd Zdd Zejjde	e
d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 indicesr>   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	   )rA   rB   rC   r   )r,   rH   r9   r9   r:   r     s4   "z!TestIntIndex.test_check_integrityc                 C   rb   rc   rh   rj   r9   r9   r:   rl     rm   zTestIntIndex.test_int_internalc                 C   s8   t dg d}||sJ |t dg drJ d S )Nr   r<   rg   )r   r@   r   r9   r9   r:   r     s   zTestIntIndex.test_equalsr   rP   c                 C   s^   t t||}t t||}|  }	|  }
t|	t sJ |	|s&J |
|s-J d S r[   )r   r    r*   rX   r"   r@   )r,   r-   r.   r/   r0   r1   r2   r3   r4   xbindexybindexr9   r9   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*   r   r9   r9   r:   r     s   zTestIntIndex.test_to_int_indexN)rJ   rK   rL   r   rl   r   rA   rM   rN   r_   r`   r   r   r9   r9   r9   r:   r     s    &
r   c                   @   s8   e Zd Zejdg dejjdeeddd ZdS )TestSparseOperatorsopname)addsubmultruedivfloordivr   rP   c                 C   sH  t td| d}t t|}	tt||}
tt||}|
 }| }t|
jd d }t|jd d }d}d}|||
||||\}}}|||||||\}}}| 	|s[J t
|| ||ksgJ t||j}|tt|}t||j}|tt|}|	||}||j}t
||j t
||j d S )Nsparse__float64g      $@r   g      Y@r   r   )getattrspliboperatorr   r    r*   r&   r   ri   r@   r#   r$   r   r+   reindexfillnavalues)r,   r   r-   r.   r/   r0   r1   r2   	sparse_op	python_opr3   r4   xdindexydindexxyxfillyfillresult_block_valsrb_indexbfillresult_int_valsri_indexifillxseriesyseriesseries_resultr9   r9   r:   test_op  s6   



zTestSparseOperators.test_opN)	rJ   rK   rL   rA   rM   rN   r_   r`   r   r9   r9   r9   r:   r      s    r   )%r   numpyr&   rA   pandas._libs.sparse_libssparser   pandas.util._test_decoratorsutil_test_decoratorsr]   pandasr   pandas._testing_testingr#   pandas.core.arrays.sparser   r   r   r    r   r   r   r   r   r   
both_emptyr_   r`   r   rO   ra   r   r   r   r9   r9   r9   r:   <module>   s    			


	
[. IO