B
    `                 @   s  d dl Z d dl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 d dlmZ d dlmZmZ ejddgddd	 ZG d
d dZG dd dZG dd dZdd Zdd Zejddddgd fd ddgdfd ddgdfd ddddgdfddddgdfg dfgdd Zejdddejejgdejdejgddejggejdejd dgdd Z dd  Z!d!d" Z"d#d$ Z#ejdejdgd%d& Z$dS )'    N)IntIndex)isna)SparseArraySparseDtypeintegerblock)paramsc             C   s   | j S )N)param)request r   T/home/dcms/DCMS/lib/python3.7/site-packages/pandas/tests/arrays/sparse/test_array.pykind   s    r   c               @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	j
deedegdd Zdd Zdd Ze	j
ddeddggdd Zdd Ze	j
deddgdfeddgejfd d!gd!fed"gejfgd#d$ Ze	j
d%d&d'd(ge	j
d)e	jdejd*d+d,d-d.gejd/d0 Ze	j
d%d&d'd(gejd1d2 Z ejd3d4 Z!e	j
d5d!ee"d!fd6ed7dfded8dfd9ed:d9fgd;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'dEdF Z(dGdH Z)e	j
dIddejgdJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dTdU Z/dVdW Z0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d`da Z5dbdc Z6ddde Z7dfdg Z8e	j
dhe9ddgdie9d6dgee:d6djfe9ddge"e9d!d gfe9ddgddke"e9d!d gee"d djfe	je9ddgdle9ejddgdldjedledmdje	j
j;dnd,gd-e9ddd.ge<e9dodpdqgee<dodjfe9dqdrge:e9dsdtgfe9dddge=e9dddgee=ddjfgdudv Z>dwdx Z?dydz Z@e	j
d{ddd|geddgd}gd~d ZAdd ZBdd ZCe	j
ddddddgddfg ddfdgddfddejdgde=fgdd ZDe	j
dejejejejejgdejejd|ejgdejdd|dgge	j
dIddgdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJe	j
dddddddgdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdS )TestSparseArrayc             C   sZ   t t jt jdddt jddt jdg
| _t| j| _tddddddddddg
dd| _d S )	N                  r   )
fill_value)nparraynanarr_datar   arrzarr)selfmethodr   r   r   setup_method   s    (zTestSparseArray.setup_methodc             C   s  t tjddtjg}|jttjtjks,t|jjtjks>tt|j	sNtt tjddtjgdd}|jttjdks|t|j	dkstt ddddgtjd}|jttjtjkstt|j	stt ddddgtj
d}|jttj
dkst|j	dkstt ddddgdtj
d}|jttj
dks4t|j	dksDtt ddddgd d}|jttj
dkspt|j	dkstt ddddgdd d}|jttj
dkst|j	dkstd S )Nr   r   r   )r   r   )dtype)r   r   )r   r   r   r   r   float64AssertionErrorsubtypeisnanr   int64)r   r   r   r   r   test_constructor_dtype   s,    z&TestSparseArray.test_constructor_dtypec             C   s4   t dddgdd}t dddgtd}t|| d S )Nr   r   r   int)r   )r   r&   tmassert_sp_array_equal)r   resultexpectedr   r   r   test_constructor_dtype_str:   s    z*TestSparseArray.test_constructor_dtype_strc             C   sX   t ddddgtddd}t ddddgdtjd}t|| |jjtdksTtd S )Nr   r   r$   )r   )r   r   )	r   r   r   r$   r'   r(   	sp_valuesr   r!   )r   r)   r*   r   r   r   test_constructor_sparse_dtype?   s    z-TestSparseArray.test_constructor_sparse_dtypec             C   sP   t ddddgdd}t ddddgtjd}t|| |jjtdksLtd S )Nr   r   zSparse[int32])r   int32)r   r   r/   r'   r(   r-   r   r!   )r   r)   r*   r   r   r   !test_constructor_sparse_dtype_strE   s    z1TestSparseArray.test_constructor_sparse_dtype_strc             C   s   t ddtjdgtd}|jttks(tt|js8tt ddtjdgtdd}|jttdksdt|jdksrtddddg}t |tdd}|jttdkst|jdksttj	|td}d	d
 t
||D }tj|tjd std S )NAB)r   )r   r   Fr   g      Y@g        c             s   s*   | ]"\}}t |t |ko ||kV  qd S )N)type).0xyr   r   r   	<genexpr>[   s    z@TestSparseArray.test_constructor_object_dtype.<locals>.<genexpr>)r   r   r   objectr   r   r!   r#   r   r   zipZfromiterbool_all)r   r   dataZarr_expecteditr   r   r   test_constructor_object_dtypeK   s    z-TestSparseArray.test_constructor_object_dtyper   r   c          	   C   s2   t jtdd tddtjg|d W d Q R X d S )NzCannot convert)matchr   r   )r   )pytestraises
ValueErrorr   r   r   )r   r   r   r   r   test_constructor_na_dtype^   s    z)TestSparseArray.test_constructor_na_dtypec          	   C   s   t jdddd}ttj|dd}tt t|}W d Q R X t|| tt tt 	|}W d Q R X t|| d S )Nz
2016-01-01r   z
US/Pacific)Zperiodstzzdatetime64[ns])r   )
pdZ
date_ranger   r   asarrayr'   Zassert_produces_warningUserWarningr(   Series)r   Zdtir*   r)   r   r   r   +test_constructor_warns_when_losing_timezonec   s    z;TestSparseArray.test_constructor_warns_when_losing_timezonec             C   s  t ddgtdddgd}t ddddgdd}t|| |jttjksNt|j	dks\tt dddgtddddgtjdd	}t ddddgtjdd
}t|| |jttjkst|j	dkstt ddgtdddgdtjd}t ddddgdtjd}t|| |jttjks t|j	dks0tt dddgtddddgd dd	}t ddddgd d}t|| |jttjkst|j	dkstd S )Nr   r   r   )r<   sparse_indexr   r   )r   r   )r<   rJ   r   r   )r   r   )r<   rJ   r   r   )r   r   )r   )
r   r   r'   r(   r   r   r   r$   r!   r   )r   r   r*   expr   r   r   test_constructor_spindex_dtypes   s:    z.TestSparseArray.test_constructor_spindex_dtyperJ   Nr   c             C   s   t d|d d}t dgd d}t|| |jttjks<t|jdksJtt dt	ddgd d}t dgd d}t|| |jttjkst|jdkstd S )Nr   )r<   rJ   r   )r   r   )
r   r'   r(   r   r   r   r$   r!   r   r   )r   rJ   r   rK   r   r   r   %test_constructor_spindex_dtype_scalar   s    z5TestSparseArray.test_constructor_spindex_dtype_scalarc             C   sf   t ddgtdddgdd d}t ddddgdd d}t|| |jttjksTt|j	dksbtd S )Nr   r   r   r   )r<   rJ   r   r   )r   r   )
r   r   r'   r(   r   r   r   r$   r!   r   )r   r   rK   r   r   r   0test_constructor_spindex_dtype_scalar_broadcasts   s    z@TestSparseArray.test_constructor_spindex_dtype_scalar_broadcastszdata, fill_valuer   g      ?g       @TFz
2017-01-01c             C   s4   t |j}t|r$t|s0tn||ks0td S )N)r   r   rE   r   r!   )r   r<   r   r)   r   r   r   $test_constructor_inferred_fill_value   s    


z4TestSparseArray.test_constructor_inferred_fill_valueformatcoocscZcsrsizez1.16zNumPy-11383)reason)Zmarks
   c             C   sL   dd l }|jj|dd|d}t|}t|}|  }t	
|| d S )Nr   r   g      ?)densityrP   )scipy.sparsesparserandomr   from_spmatrixr   rF   toarrayravelr'   assert_numpy_array_equal)r   rS   rP   scipymatr)   r*   r   r   r   test_from_spmatrix   s    

z"TestSparseArray.test_from_spmatrixc             C   sV   dd l }|jjddd|d}d|jd< t|}t|}| 	 }t
|| d S )Nr   rU   r   g      ?)rV   rP   )rW   rX   rY   r<   r   rZ   r   rF   r[   r\   r'   r]   )r   rP   r^   r_   r)   r*   r   r   r   *test_from_spmatrix_including_explicit_zero   s    


z:TestSparseArray.test_from_spmatrix_including_explicit_zeroc          	   C   sB   dd l }|jjdddd}tjtdd t| W d Q R X d S )Nr   r   r   rR   )rP   znot '4')r?   )rW   rX   Zeyer@   rA   rB   r   rZ   )r   r^   r_   r   r   r   test_from_spmatrix_raises   s    z)TestSparseArray.test_from_spmatrix_raiseszscalar,dtypeg        r    r$   zr8   c             C   sR   t |dddg|d}t |||g|d}t|| |j|ks@t|j|ksNtd S )Nr   r   r   )indexr   )r   )r   r'   r(   r   r!   )r   Zscalarr   r   rK   r   r   r   "test_scalar_with_index_infer_dtype   s
    z2TestSparseArray.test_scalar_with_index_infer_dtypec          	   C   s   t | jd st| jd dks&t| jd dks8t| jd dksJt| jd dks\t| jd dksnttd}tjt	|d | jd  W d Q R X tjt	|d | jd	  W d Q R X | jd
 | jt
| jd  kstd S )Nr   r      r   r   bounds)r?      ir,   )r   r#   r   r!   r   recompiler@   rA   
IndexErrorlen)r   errmsgr   r   r   test_get_item   s    
zTestSparseArray.test_get_itemc          	   C   s.   d}t jt|d | jd W d Q R X d S )Nz-'indices' must be an array, not a scalar '2'.)r?   r   )r@   rA   rB   r   take)r   msgr   r   r   test_take_scalar_raises  s    z'TestSparseArray.test_take_scalar_raisesc             C   sd   t t| jddg}t| jddg| t t| jdddg}t| jdddg| d S )Nr   r   r   r   )r   r   ro   r   r'   r(   r   )r   rK   r   r   r   	test_take  s    zTestSparseArray.test_takec             C   s>   t jddgt dd}|jddgdtjd}t|| d S )Nr   r$   )r   r   T)
allow_fillr   )rE   r   r   ro   r   r   r'   r(   )r   ar)   r   r   r   test_take_all_empty  s    z#TestSparseArray.test_take_all_emptyc             C   s   t dt jdddg}t|dd}tt |dgdd}t|dg| tt |dddgdd}t|dddg| d S )Nr   r   r   )r   r   )r   r   r   r   ro   r'   r(   )r   r<   rX   rK   r   r   r   test_take_fill_value!  s    z$TestSparseArray.test_take_fill_valuec             C   s`   t t| jdg}t| jdg| t t| jdddg}t| jdddg| d S )Nr,   )r   r   ro   r   r'   r(   r   )r   rK   r   r   r   test_take_negative+  s    z"TestSparseArray.test_take_negativer   c             C   sf   t tdddddgdd}|jd|d}t|r:|jj}t t|ddddgdd}t|| d S )Nr   r   r   g       @)r   )	r   r   r   shiftr   r   Zna_valuer'   r(   )r   r   rX   resrK   r   r   r   test_shift_fill_value2  s    z%TestSparseArray.test_shift_fill_valuec          	   C   s,   t jtdd | jdg W d Q R X d S )Nrg   )r?   rh   )r@   rA   rk   r   ro   )r   r   r   r   test_bad_take<  s    zTestSparseArray.test_bad_takec          	   C   s  t tjtjdtjdg}|tdddg}t tjtjdg}t|| |jtdddgdd}t tjtjtjg}t|| |jtdddgddd}t tjtjdg}t|| d	}tjt	|d
  |jtdddgdd W d Q R X tjt	|d
  |jtdddgdd W d Q R X d}tjt
|d
 |tddg W d Q R X tjt
|d
 |tddg W d Q R X tjt
|d
 |jtddgdd W d Q R X d S )Nr   r   r   r,   T)rs   F)rs   r   zInvalid value in 'indices')r?   ry   z out of bounds value in 'indices'ir   )r   r   r   ro   r   r'   r(   r@   rA   rB   rk   )r   rX   r)   r*   rp   r   r   r   test_take_filling@  s,    $$z!TestSparseArray.test_take_fillingc          	   C   s  t tjddddgdd}|tdddg}t dtjdgdd}t|| |jtdddgdd}t dtjtjgdd}t|| |jtdddgddd	}t dtjdgdd}t|| d
}tjt	|d  |jtdddgdd W d Q R X tjt	|d  |jtdddgdd W d Q R X d}tjt
|d |tddg W d Q R X tjt
|d |tddg W d Q R X tjt
|d |jtddgdd W d Q R X d S )Nr   r   r   )r   r,   T)rs   F)rs   r   zInvalid value in 'indices'.)r?   ry   r   z out of bounds value in 'indices'ir   )r   r   r   ro   r   r'   r(   r@   rA   rB   rk   )r   rX   r)   r*   rp   r   r   r   test_take_filling_fill_value`  s,    $$z,TestSparseArray.test_take_filling_fill_valuec          	   C   s*  t tjtjtjtjtjg}|tdddg}t tjtjtjgdd}t|| |jtdddgdd}t tjtjtjgdd}t|| d}tjt	|d	 |tdd
g W d Q R X tjt	|d	 |tddg W d Q R X tjt	|d	 |jtddgdd W d Q R X d S )Nr   r   r,   r   )r   T)r   z out of bounds value in 'indices')r?   ir   )
r   r   r   ro   r   r'   r(   r@   rA   rk   )r   rX   r)   r*   rp   r   r   r   test_take_filling_all_nan  s    z)TestSparseArray.test_take_filling_all_nanc          	      s\    fdd} fdd}t jtdd |  W d Q R X t jtdd |  W d Q R X d S )Nc                  s   d j d< d S )Nr   r   )r   r   )r   r   r   setitem  s    z.TestSparseArray.test_set_item.<locals>.setitemc                  s   d j dd< d S )Nr   r   r   )r   r   )r   r   r   setslice  s    z/TestSparseArray.test_set_item.<locals>.setslicezassignment via setitem)r?   )r@   rA   	TypeError)r   r   r   r   )r   r   test_set_item  s    zTestSparseArray.test_set_itemc          	   C   s2   t jtdd ttdd W d Q R X d S )Nzexpected dimension <= 1 data)r?   rU   )r   r   )r@   rA   r   r   r   arangeZreshape)r   r   r   r   %test_constructor_from_too_large_array  s    z5TestSparseArray.test_constructor_from_too_large_arrayc             C   s.   t | j}|jdkstt|j| jj d S )Nr   )r   r   r   r!   r'   assert_almost_equalr-   )r   r|   r   r   r   test_constructor_from_sparse  s    
z,TestSparseArray.test_constructor_from_sparsec             C   sp   t | jdd}d|jd d< | jjd d dk r8tt | j}d|jd d< | jjd d dk sltd S )NT)copyr   r   )r   r   r-   anyr!   r;   )r   cpZnot_copyr   r   r   test_constructor_copy  s    
z%TestSparseArray.test_constructor_copyc             C   s   t ddddddg}t|dtd}|jttks6tt|j	t ddg t|j
jt ddgt j | }|jtkstt|| d S )NFT)r   r   r   r   )r   r   r   boolr   r   r!   r'   r]   r-   sp_indexindicesr/   to_dense)r   r<   r   denser   r   r   test_constructor_bool  s    z%TestSparseArray.test_constructor_boolc             C   s   t dddgd d}|jttjks&t|jr0tt dddgtjd}|jttjksXt|jrbtt dddgtjdd}|jttjdkst|jstd S )NTF)r   )r   r   )r   r   r   r   r:   r!   r   )r   r   r   r   r    test_constructor_bool_fill_value  s    

z0TestSparseArray.test_constructor_bool_fill_valuec             C   s   t jdt jdgt jd}t|t jd}|jtt jks:tt	|j
t jddgt jd t	|jjt jddgt jd | }|jt jkstt	|| d S )Ng      ?r   )r   r   r   r   )r   r   r   float32r   r   r   r!   r'   r]   r-   r   r   r/   r   )r   r<   r   r   r   r   r   test_constructor_float32  s    z(TestSparseArray.test_constructor_float32c          	   C   s  t d d ddg}|d}t d d ddgtdd}t|| tddd}||}t tjdd	g|j	dt
d
ddg|}t|| tdd}||}t tjddgtjdt
d
ddg|}t|| t dtjddgdd}tjtdd |d W d Q R X d S )Nr   r   zSparse[float32]r   )r   r    )r   g        g       @r   r   r$   r   ZNA)r?   z
Sparse[i8])r   astyper   r   r'   r(   r   _simple_newr   r"   r   r$   r   r@   rA   rB   )r   r   r)   r*   r   r   r   r   test_astype  s"    

$

$zTestSparseArray.test_astypec             C   s   t ddddgttdd}|t}t ddddgttdd}t|| |ttd}t ddddgttdd}t|| d S )Nr   r   )r   TF)r   r   r&   r   r   r'   r(   )r   rt   r)   r*   r   r   r   test_astype_bool  s    
z TestSparseArray.test_astype_boolc             C   st   t dddg}t|dd}t |}||}|jt|dksDt|jj|ksTtt	t 
| || d S )Nr   r   r   )r   )r   r   r   r   r   r   r!   r-   r'   r]   rF   r   )r   Zany_real_dtypevalsr   typr|   r   r   r   test_astype_all  s    

zTestSparseArray.test_astype_allzarray, dtype, expectedfloat)r   )r   zdatetime64[ns]Z1970z
NumPy-76190110Z20g      $@g      4@c             C   s   | |}t|| d S )N)r   r'   r(   )r   r   r   r*   r)   r   r   r   test_astype_more  s    %
z TestSparseArray.test_astype_morec          	   C   s6   t dtjg}tjtdd |t W d Q R X d S )Ng      ?zCannot convert non-finite)r?   )r   r   r   r@   rA   rB   r   r&   )r   r   r   r   r   test_astype_nan_raises9  s    z&TestSparseArray.test_astype_nan_raisesc             C   s   t dtjdgtjd}d|_|jdks*tt dddgdtjd}d|_|jdksTtd|_|jdkshttj|_t|jstt d	d
d	gd
tjd}d	|_|jstd|_|jdksttj|_t|jstd S )Ng      ?g       @)r   r   r   r   )r   r   g@TF)r   r   r   r   r!   r$   r#   r:   )r   r   r   r   r   test_set_fill_value>  s"    
z#TestSparseArray.test_set_fill_valuevalr   )r   r   r   c          	   C   s>   t dddgdtjd}d}tjt|d ||_W d Q R X d S )NTF)r   r   zfill_value must be a scalar)r?   )r   r   r:   r@   rA   rB   r   )r   r   r   rp   r   r   r    test_set_fill_invalid_non_scalarc  s    z0TestSparseArray.test_set_fill_invalid_non_scalarc             C   s2   | j  }|j| j jk	st|j| j jks.td S )N)r   r   r-   r!   r   )r   arr2r   r   r   	test_copyk  s    
zTestSparseArray.test_copyc             C   s   t | j | j d S )N)r'   r   r   r   r   )r   r   r   r   test_values_asarrayp  s    z#TestSparseArray.test_values_asarrayzdata,shape,dtype)r   )r   )r   r1   r2   )r   c             C   s   t ||d}|j|kstd S )N)r   )r   shaper!   )r   r<   r   r   outr   r   r   
test_shapes  s    zTestSparseArray.test_shaper   c             C   sB   t |}t||d}| }t|| | }t|| d S )N)r   )r   r   r   r   r'   r]   Z_internal_get_values)r   r   r   r   r|   res2r   r   r   test_dense_repr  s    

zTestSparseArray.test_dense_reprc                s:    fdd}x(t t jD ]}|| ||  qW d S )Nc                s    t  j|   j |   d S )N)r'   r   r   r   )i)r   r   r   _checkit  s    z.TestSparseArray.test_getitem.<locals>._checkit)rangerl   r   )r   r   r   r   )r   r   test_getitem  s    zTestSparseArray.test_getitemc             C   s8   t dddg}|dddg }t ddg}t|| d S )Nr   r   r   TF)r   r'   r(   )r   r   r)   r*   r   r   r   test_getitem_arraylike_mask  s    z+TestSparseArray.test_getitem_arraylike_maskc             C   s   | j d d }t| j  d d }t|| | j dd  }t| j  dd  }t|| | j dd  }t| j }t|| | j d d }t| j  d d }t|| d S )Nrx   rw   ir   )r   r   r   r'   r(   )r   r)   rK   r   r   r   test_getslice  s    
zTestSparseArray.test_getslicec             C   s   t t jdddddt jt jdg	}t|}|dd f }t|dd f }t|| t|dd}|dd f }t|dd f dd}t|| d}tjt|d |dd d d f  W d Q R X tjt|d |dd d d f  W d Q R X d S )Nr   r   r   r   )r   ztoo many indices for array)r?   )	r   r   r   r   r'   r(   r@   rA   rk   )r   r   rX   r|   rK   rp   r   r   r   test_getslice_tuple  s     "z#TestSparseArray.test_getslice_tuplec             C   s0   t dddg}|dddg }|j|jks,td S )Nr   r   r   F)r   r   r!   )r   r   r|   r   r   r   test_boolean_slice_empty  s    z(TestSparseArray.test_boolean_slice_emptyopaddsubmultruedivfloordivpowc          	   C   s   t t|}tjd}tjd}tj|d d d< tj|d d d< t|}t|}d|d d d< d|d d d< t|dd}t|dd}dd }tjdd0 x(||f||fgD ]\}	}
|||	|
 qW W d Q R X d S )	N   r   r   )r   c       	      S   s  | ||}t | | | |jd}t|t s4tt| |  | || }t|t sdtt|| | | |}t|t stt|| | |d}t|t sty| | d}| |jd}W n tk
r   Y n X t|j| t| | d S )N)r   r   )	r   r   r   
isinstancer!   r'   r   r(   rB   )	r   firstsecondr|   rK   r   Zres3Zres4Zexp_fvr   r   r   	_check_op  s(    

z8TestSparseArray.test_binary_operators.<locals>._check_opignore)r;   )getattroperatorr   rY   Zrandnr   r   Zerrstate)r   r   Zdata1Zdata2Zarr1r   Zfarr1Zfarr2r   Z	first_arrZ
second_arrr   r   r   test_binary_operators  s    
z%TestSparseArray.test_binary_operatorsc             C   s    dd }|| j  || j d S )Nc             S   s   t | }t ||  d S )N)r'   Zround_trip_pickler(   )objZ	unpickledr   r   r   _check_roundtrip  s    
z5TestSparseArray.test_pickle.<locals>._check_roundtrip)r   r   )r   r   r   r   r   test_pickle  s    
zTestSparseArray.test_picklec          	   C   sd   t dddg}tjdd@}tjdtd tjdtd x|D ]}q>W t|dksVtW d Q R X d S )	Nr   r   r   T)recordalways)actioncategoryr   )r   warningscatch_warningsfilterwarningsDeprecationWarningPendingDeprecationWarningrl   r!   )r   Zsp_arrw_r   r   r   test_generator_warnings  s    
z'TestSparseArray.test_generator_warningsc             C   s  t dtjtjdtjg}|d}t dddddgdtjd}t|| t dtjtjdtjgdd}|d}t dddddgdtjd}t|| t dtjdddg}|d}t dddddgdtjd}t|| t dtjdddgdd}|d}t dddddgdtjd}t|| t tjtjtjtjg}|d}t ddddgdtjd}t|| t tjtjtjtjgdd}|d}t ddddgdtjd}t|| t ddddg}|d}t ddddgdd}t|| t ddddg}|jttj	kst
|jdks t
|d}t|| t ddddgdd}|jttj	ks`t
|jdkspt
|d}t ddddgdd}t|| t ddddgtjd}|jttj	tjdkst
t|jst
|d}t ddddgdd}t|| d S )Nr   r   r,   )r   r   r   )r   g        )r   r   r   fillnar    r'   r(   r   r   r$   r!   r   r#   )r   sr|   rK   r   r   r   test_fillna  sZ    









zTestSparseArray.test_fillnac             C   s   t dtjtjdtjg}|d}tjdddddgtjd}t| | t dtjtjdtjgdd}|d}t dddddgdtjd}t	|| d S )Nr   r   )r   r   )r   )r   r   )
r   r   r   r   r   r    r'   r]   r   r(   )r   r   r|   rK   r   r   r   test_fillna_overlapR  s    

z#TestSparseArray.test_fillna_overlapc             C   s   t tdtdddddddddddg}tjdddgtjd}| \}t|| t ddddddddddddg}| \}t|| d S )	Nr   r   r   r   r   r   	   )r   )r   r   r   r   r/   Znonzeror'   r]   )r   sar*   r)   r   r   r   test_nonzero_  s    (
 
zTestSparseArray.test_nonzero)Q__name__
__module____qualname__r   r%   r+   r.   r0   r>   r@   markparametrizer   r&   rC   rI   rL   r   rM   rN   r   r   r   rE   	TimestampZNaTrO   r	   tdskip_if_np_ltskip_if_no_scipyr`   ra   rb   r   re   rn   rq   rr   ru   rv   rz   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zxfailstrr8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    '"	
	

 "	


&%,
 "2	<r   c               @   s  e Zd Zejddddgddfdddgddfdddgdd	fgd
d Zejddddgddfdddgddfdddgdd	fgeddd Z	ejddddgddfdddgddfd	dd	gdd	fgdd Z
ejddddgddfdddgddfd	dd	gdd	fgeddd Zdd Zejdeddejdgedddgedddggejdddejddgejdddejfgdd Zdd Zejdejddddd ged!eedd"d#d$d%gfejddejdd ged!eedd"ejd&d'gfgejd(ddgd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zejdd	ejgd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?S )@TestSparseArrayAnalyticszdata,pos,negTFr   r   r   g      ?g       @g        c             C   sd   t | }|stt ||d }|s,t||d< t | }|rHtt ||d }|r`td S )N)r   r   )r   r;   r!   )r   r<   posnegr   r   r   r   test_alll  s    
z!TestSparseArrayAnalytics.test_allz1.15c          	   C   s   t t|}|stt t||d}|s0t||d< t t|}|rNtt t||d}|rhtd}tjt|d t jt|t g d W d Q R X d S )N)r   r   z$the 'out' parameter is not supported)r?   )r   )r   r;   r   r!   r@   rA   rB   r   )r   r<   r   r   r   rp   r   r   r   test_numpy_all  s    z'TestSparseArrayAnalytics.test_numpy_allc             C   sd   t | }|stt ||d }|s,t||d< t | }|rHtt ||d }|r`td S )N)r   r   )r   r   r!   )r   r<   r   r   r   r   r   r   test_any  s    
z!TestSparseArrayAnalytics.test_anyc          	   C   s   t t|}|stt t||d}|s0t||d< t t|}|rNtt t||d}|rhtd}tjt|d t jt||d W d Q R X d S )N)r   r   z$the 'out' parameter is not supported)r?   )r   )r   r   r   r!   r@   rA   rB   )r   r<   r   r   r   rp   r   r   r   test_numpy_any  s    z'TestSparseArrayAnalytics.test_numpy_anyc             C   sp   t dt}t| }|dks(tt j|d< t|dd }|dksNtt|t jd }|dksltd S )NrU   g     F@r   r   )r   g      D@)r   r   r   r   r   sumr!   r   )r   r<   r   r   r   r   test_sum  s    
z!TestSparseArrayAnalytics.test_sumr   r   zmin_count, expected)r   r   r   c             C   sB   t ||d}|j|d}t|r2t|s>tn||ks>td S )N)r   )	min_count)r   r   r   r#   r!   )r   r   r   r   r*   Zsparrayr)   r   r   r   test_sum_min_count  s
    
z+TestSparseArrayAnalytics.test_sum_min_countc          	   C   s   t dt}t t|}|dks*tt j|d< t t|dd}|dksRtt t|t jd}|dksrtd}tj	t
|d t jt|t jd	 W d Q R X d
}tj	t
|d t jt||d W d Q R X d S )NrU   g     F@r   r   )r   g      D@z&the 'dtype' parameter is not supported)r?   )r   z$the 'out' parameter is not supported)r   )r   r   r   r   r   r   r!   r   r@   rA   rB   r$   )r   r<   r   rp   r   r   r   test_numpy_sum  s    
z'TestSparseArrayAnalytics.test_numpy_sumzdata,expectedr   r   )r   g      @g      @g      $@g      .@g      @g      (@numpyc          	   C   s  |r
t jndd }|t|}t|| |t|t jd}t|| |t|dd}t|| |rd}tjt|d t jt|t j	d W d Q R X d}tjt|d t jt||d	 W d Q R X n@d
}t
d| d}tjt|d t|j|d W d Q R X d S )Nc             S   s   |   S )N)cumsum)r   r   r   r   <lambda>      z6TestSparseArrayAnalytics.test_cumsum.<locals>.<lambda>)r   r   z&the 'dtype' parameter is not supported)r?   )r   z$the 'out' parameter is not supported)r   r   zaxis(=z) out of bounds)axis)r   r   r   r'   r(   r   r@   rA   rB   r$   ri   escape)r   r<   r*   r   r   r   rp   r   r   r   r   test_cumsum  s$    z$TestSparseArrayAnalytics.test_cumsumc             C   sN   t dt}t| }|dks(tt j|d< t| }|dksJtd S )NrU   g      @r   grq@)r   r   r   r   r   meanr!   r   )r   r<   r   r   r   r   	test_mean.  s    
z"TestSparseArrayAnalytics.test_meanc          	   C   s   t dt}t t|}|dks*tt j|d< t t|}|dksNtd}tj	t
|d t jt|t jd W d Q R X d}tj	t
|d t jt||d	 W d Q R X d S )
NrU   g      @r   grq@z&the 'dtype' parameter is not supported)r?   )r   z$the 'out' parameter is not supported)r   )r   r   r   r   r   r   r!   r   r@   rA   rB   r$   )r   r<   r   rp   r   r   r   test_numpy_mean7  s    
z(TestSparseArrayAnalytics.test_numpy_meanc             C   s  t dtjdtjdg}t dtjdtjdg}tt|| tt|| t ddddgdd}t dddg|jdd}tt|| tt|| t ddddgdd}t dddg|jdd}tt|| tt|| t dtjdtjdg}t tdtjdtjdg}tt|| t ddddgdd}t tddddgtdd}tt|| t ddddgdd}t tddddgtdd}tt|| d S )Nr   r   ry   r,   )r   )rJ   r   r   )r   r   r   r'   r(   absr   sin)r   rX   r)   r   r   r   
test_ufuncH  s*      z#TestSparseArrayAnalytics.test_ufuncc             C   s   t dtjdtjdg}t dtjdtjdg}tt|d| t ddddgdd}t ddddgdd}tt|d| t ddddgdd}t ddddgdd}tt|d| d S )Nr   r   ry   r   r,   )r   r   )r   r   r   r'   r(   r   )r   rX   r)   r   r   r   test_ufunc_argse  s    z(TestSparseArrayAnalytics.test_ufunc_argsc             C   sh   t |gd ddg |d}t|\}}tt|\}}t|t ||d t|t ||d d S )NrU   g?g@)r   )r   r   modfrF   r'   r(   )r   r   rX   Zr1Zr2e1e2r   r   r   	test_modfs  s
    z"TestSparseArrayAnalytics.test_modfc             C   s,   t dddddgdd}|j}|dks(td S )Nr   r   r   r   )r      )r   nbytesr!   )r   r   r)   r   r   r   test_nbytes_integer|  s    z,TestSparseArrayAnalytics.test_nbytes_integerc             C   s,   t dddddgdd}|j}|dks(td S )Nr   r   r   r   )r   r  )r   r  r!   )r   r   r)   r   r   r   test_nbytes_block  s    z*TestSparseArrayAnalytics.test_nbytes_blockc             C   s$   t tdd d dg}t| d S )NZ2012Z2013)r   rE   to_datetimer   rF   )r   r   r   r   r   test_asarray_datetime64  s    z0TestSparseArrayAnalytics.test_asarray_datetime64c             C   s   t ddg}|jdkstd S )Nr   r   g      ?)r   rV   r!   )r   r   r   r   r   test_density  s    z%TestSparseArrayAnalytics.test_densityc             C   s   t ddg}|jdkstd S )Nr   r   )r   npointsr!   )r   r   r   r   r   test_npoints  s    z%TestSparseArrayAnalytics.test_npointsN)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  r   r   r   r   r   k  s`   $
		r   c               @   sN   e Zd Zejdddddgdd Zejdd	 Z	ejd
d Z
dd ZdS )TestAccessorattrr  rV   r   r-   c             C   s<   t ddg}t|}t|j|}t||}||ks8td S )Nr   r   )r   rE   rH   r   rX   r!   )r   r  r   serr)   r*   r   r   r   test_get_attributes  s
    

z TestAccessor.test_get_attributesc       	      C   s   dd l }ddddg}ddddg}ddddg}|j|||ff}tjj|}tjddddgddddgg}tjddddg|d	d
}t	|| d S )Nr   r   r   r   r   r   rf   r   zSparse[int])rd   r   )
rW   rX   
coo_matrixrE   rH   Zfrom_coo
MultiIndexZfrom_arraysr'   Zassert_series_equal)	r   r^   rowcolr<   Zsp_arrayr)   rd   r*   r   r   r   test_from_coo  s     zTestAccessor.test_from_cooc             C   sb   dd l }tjdddgtjjdgdddggddgddd	}|j \}}}t||jjj	s^t
d S )
Nr   r   r   r   rt   b)nameszSparse[int])rd   r   )rW   rE   rH   r  Zfrom_productrX   Zto_coor   rQ   r  r!   )r   r^   r  r1   r   r   r   r   test_to_coo  s    zTestAccessor.test_to_cooc          	   C   s6   t dddg}tjtdd |jj W d Q R X d S )Nr   r   r   z.sparse)r?   )rE   rH   r@   rA   AttributeErrorrX   rV   )r   r  r   r   r   test_non_sparse_raises  s    z#TestAccessor.test_non_sparse_raisesN)r   r   r   r@   r   r   r  r   r   r  r  r  r   r   r   r   r    s   	r  c              C   sN   t dtjdgdd} tj| _|  }t|}tdddg}t|| d S )Ng      ?g        )r   FT)	r   r   r   r   r   rF   r   r'   r]   )r   r)   r*   r   r   r   *test_setting_fill_value_fillna_still_works  s    
r  c              C   sT   t dtjgdd} tj| _t jttjgtddgtttjd}t	
| | d S )Ng        r   )r   r   r   )Zsparse_arrayrJ   r   )r   r   r   r   r   r   r   r   r   r'   r(   )r   r*   r   r   r   test_setting_fill_value_updates  s    
r  zarr, locr   r   r   r,   c             C   s   t |  }||kstd S )N)r   Z_first_fill_value_locr!   )r   locr)   r   r   r   test_first_fill_value_loc  s    r   r   r   c             C   sF   t | |d }t|  }t|t s,tt|}t	|| d S )N)r   )
r   uniquerE   rH   r   r!   r   rF   r'   r]   )r   r   rt   r  r   r   r   test_unique_na_fill  s
    
r"  c              C   s.   t ddg} |  }t dg}t|| d S )Nr   )r   r!  r'   r(   )r   r)   r*   r   r   r   test_unique_all_sparse  s    
r#  c              C   s   t dddg} t dddgdd}| dddd}t|| | tdddd}t|| | tdddd}t dddgdd}t|| d S )	Nr   r   r   rU   rh      )r   )r   r   r   )r   mapr'   r(   rE   rH   )r   r*   r)   r   r   r   test_map  s    r&  c              C   s@   t dddg} t ddd gdd}| ddd}t|| d S )Nr   r   r   rU   rh   )r   )r   r   )r   r%  r'   r(   )r   r*   r)   r   r   r   test_map_missing  s    r'  c             C   sv   t tjdg| d}t dg| d}t| | tddg|d}tjdg|dtdgd}t	| | d S )Nr   )r   g      ?r   )rt   r  )rd   )
r   r   r   r'   r(   ZdropnarE   Z	DataFrameZ
Int64IndexZassert_equal)r   r   rK   ZdfZexpected_dfr   r   r   test_dropna  s    r(  )%r   ri   r   r   r   r@   Zpandas._libs.sparser   Zpandas.util._test_decoratorsutilZ_test_decoratorsr   ZpandasrE   r   Zpandas._testingZ_testingr'   Zpandas.core.arrays.sparser   r   Zfixturer   r   r   r  r  r  r   r   r   r   r"  r#  r&  r'  r(  r   r   r   r   <module>   sN         [  -*, 	