B
    ˜íY²  ã               @   sl   d Z ddlZddlZddlmZmZmZ ddlZ	ddl
mZmZ dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ ZdS )zTest replace().é    N)Úassert_equalÚassert_array_equalÚassert_raisesé   )ÚarraysÚarray_orderc              c   s"   xt  d¡D ]} t| fV  qW dS )ztest nonreduce functionsZ	nonreduceN)ÚbnZget_functionsÚ
unit_maker)Úfunc© r   ú>lib/python3.7/site-packages/bottleneck/tests/nonreduce_test.pyÚtest_nonreduce   s    r   c             C   sÄ  d}|d7 }| j }td| ƒ}tj dddg¡}ddtjtj g}xztt|ƒƒD ]h\}}x\t	dƒD ]N}|j
dkr~d}	n| t|j
dƒ¡}|j| }	x|D ]}
t|jjtjƒsÐt |	¡sÄq¢t |
¡sÐq¢| ¡ }t ¡  t d¡ | ||	|
ƒ W d	Q R X | ¡ }t ¡  t d¡ |||	|
ƒ W d	Q R X |d
t|ƒ t|jƒt|jƒ|	|
t|ƒ|f}|| }t|||d |d7 }t|dƒs”t|dƒr¢|j}|j}t|||||f ƒ q¢W qhW qRW d	S )z1Test that bn.xxx gives the same output as np.xxx.zA
func %s | input %s (%s) | shape %s | old %f | new %f | order %s
z
Input array:
%s
z
bn.slow.%sr   é   é   r   ÚignoreNÚa)Úerr_msgz
 dtype mismatch %s %sÚdtype)Ú__name__ÚevalÚnpZrandomZRandomStateÚnanÚinfÚ	enumerater   ÚrangeÚsizeZrandintÚmaxZflatÚ
issubclassr   ÚtypeZinexactZisfiniteÚcopyÚwarningsÚcatch_warningsÚsimplefilterÚstrÚshaper   r   Úhasattrr   )r
   ÚmsgÚnameZfunc0ZrsZnewsÚiZarrÚidxÚoldÚnewÚactualÚdesiredÚtupr   ZdaZddr   r   r   r	      sF    







r	   c              C   s„   ddg} xv| D ]n}t jd|d}tttj| ¡ ddƒ tttj| ¡ ddƒ tttjj| ¡ ddƒ tttjj| ¡ ddƒ qW dS )zTest replace for unsafe castsZint32Zint64r   )r   gš™™™™™¹?r   N)r   Zzerosr   Ú
ValueErrorr   Úreplacer   Úslow)Zdtypesr   r   r   r   r   Útest_replace_unsafe_cast>   s    
r2   c              C   s6   dddg} t ttj| ddƒ d} t ttj| ddƒ dS )z Test that non-array input raisesr   r   r   r   )r   r   r   N)r   Ú	TypeErrorr   r0   )r   r   r   r   Útest_non_arrayI   s    
r4   c              C   sv   t  d¡ ddd¡} |  ¡ }t |t jd¡ |  ¡ }d}t|||d |  ¡ }tj |t jd¡ d}t|||d d	S )
z'Test replace, int array, old=nan, new=0é   r   r   é   r   z,replace failed on int input looking for nans)r   z1slow.replace failed on int input looking for nansN)	r   ZarangeZreshaper   r   r0   r   r   r1   )r   r,   r-   r&   r   r   r   Útest_replace_nan_intU   s    r7   )Ú__doc__r    Znumpyr   Znumpy.testingr   r   r   Z
bottleneckr   Úutilr   r   r   r	   r2   r4   r7   r   r   r   r   Ú<module>   s   -