3
pd                 @   sf   d dl Zd dlZd dlmZmZ d dlZd dlm	Z	 d dl
jZG dd dZG dd dZdd	 ZdS )
    N)libwriters)Indexc               @   s$   e Zd Zdd Zdd Zdd ZdS )TestMiscc          
   C   s   t jddt jgdd }}tj|dks,t|jdjt}tj|dksNt|jdjt}tj|dksptd}tj	t
|d	 tj|jd W d Q R X d S )
Nfoobobject)dtype   USzNo matching signature found)match)nparraynan
libwritersZmax_len_string_arrayAssertionErrorZastyper   pytestraises	TypeError)selfarramsg r   7/tmp/pip-build-7vycvbft/pandas/pandas/tests/test_lib.pytest_max_len_string_array   s    z"TestMisc.test_max_len_string_arrayc             C   s   ddgddgddgg}dd |D }t jdddddg}tj|dd	}tjt j|| d
d |D }t jdddddg}tj|dd	}tjt j|| d S )Npr   ndsc             s   s   | ]
}|V  qd S )Nr   ).0keyr   r   r   	<genexpr>!   s    zCTestMisc.test_fast_unique_multiple_list_gen_sort.<locals>.<genexpr>T)sortc             s   s   | ]
}|V  qd S )Nr   )r!   r"   r   r   r   r#   &   s    F)r   r   r   Zfast_unique_multiple_list_gentmassert_numpy_array_equal)r   keysgenexpectedoutr   r   r   'test_fast_unique_multiple_list_gen_sort   s    z0TestMisc.test_fast_unique_multiple_list_gen_sortc             C   s>   t jdtjdgg}tjt tj|d d W d Q R X d S )Nr   2000)r$   )	r   r   pdZ	Timestampr%   Zassert_produces_warningRuntimeWarningr   Zfast_unique_multiple)r   r   r   r   r   3test_fast_unique_multiple_unsortable_runtimewarning+   s    z<TestMisc.test_fast_unique_multiple_unsortable_runtimewarningN)__name__
__module____qualname__r   r+   r/   r   r   r   r   r      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dS )TestIndexingc             C   s  t jd}t jg t jd}tj|t|}t|ts8t	t
j|| ||  xd
D ]}xdD ]}t jd	||t jd}tj|t|}t|tst	t
j|| ||  |d d d }tj|t|}t|tst	t
j|| ||  q\W qRW xdddd	gdddd	gd	dddgdd	dgdd	dggD ]X}t j|t jd}tj|t|}t|t sXt	t
j|| t
j|| ||  q"W d S )Nd   )r	               c      r   )r5   r6   r7   r8   r9   )r5   r6   r:   r<   )r   aranger   intpr   maybe_indices_to_slicelen
isinstanceslicer   r%   r&   )r   targetindicesmaybe_sliceendstepcaser   r   r   %test_maybe_indices_to_slice_left_edge2   s*    


8z2TestIndexing.test_maybe_indices_to_slice_left_edgec          "   C   sF  t jd}xdD ]}xdD ]}t j|d
|t jd}tj|t|}t|tsPtt	j
|| ||  |d d d }tj|t|}t|tstt	j
|| ||  qW qW t jddd
dgt jd}tj|t|}t|t stt	j
|| d}tjt|d ||  W d Q R X tjt|d ||  W d Q R X t jdd
ddgt jd}tj|t|}t|t srtt	j
|| tjt|d ||  W d Q R X tjt|d ||  W d Q R X x~d
dd
dgd
d
ddgddddggD ]X}t j|t jd}tj|t|}t|t stt	j
|| t	j
|| ||  qW d S )Nr4   r   r6   r7   r8   a   b   r5   r:   r9   )r	   z7index 100 is out of bounds for axis (0|1) with size 100)r   `   )r   r6   r7   r8   rJ   rK   )r5   r6   r:   r;   )r   r=   r>   r   r?   r@   rA   rB   r   r%   r&   r   r   r   
IndexError)r   rC   startrG   rD   rE   r   rH   r   r   r   &test_maybe_indices_to_slice_right_edgeT   sD    


(z3TestIndexing.test_maybe_indices_to_slice_right_edgec             C   s   t jd}xd
D ]}t jdd|t jd	}tj|t|}t|tsFtt	j
|| ||  |d d d }tj|t|}t|tstt	j
|| ||  qW x|ddddgddddgddddggD ]V}t j|t jd	}tj|t|}t|t  stt	j
|| t	j
|| ||  qW d S )N
   r5   r6   r:   r7      	   r   )r	   )r5   r6   r:   r7   rQ   rR   r;   r<   )r   r=   r>   r   r?   r@   rA   rB   r   r%   r&   r   )r   rC   rG   rD   rE   rH   r   r   r   &test_maybe_indices_to_slice_both_edges   s     

(z3TestIndexing.test_maybe_indices_to_slice_both_edgesc             C   s2  t jd}xdD ]\}}xdD ]}t j|||t jd}tj|t|}t|tsTtt	j
|| ||  |d d d }tj|t|}t|tstt	j
|| ||  qW qW x|ddddgddddgddddggD ]V}t j|t jd}tj|t|}t|t s
tt	j
|| t	j
|| ||  qW d S )Nr4   r6   rP   r7      A   rJ   r5   r:   r8   )r	            r6   rP   r7   rT   rU   rJ   )rY   rZ   r[   )r5   r6   r:   r8   r;   )r   r=   r>   r   r?   r@   rA   rB   r   r%   r&   r   )r   rC   rN   rF   rG   rD   rE   rH   r   r   r   "test_maybe_indices_to_slice_middle   s"    

(z/TestIndexing.test_maybe_indices_to_slice_middlec             C   s`   t jdddddddgt jd}tj|}|jt jks8ttj|d d }|tddks\td S )Nr   r5   )r	   )	r   r   Zuint8r   Zmaybe_booleans_to_slicer	   Zbool_r   rB   )r   r   resultr   r   r   test_maybe_booleans_to_slice   s
    
z)TestIndexing.test_maybe_booleans_to_slicec          	   C   sV   t jd
dddddddgt jd}tj|d}t jddddd	gt jd}tj|| d S )Nr5   r6   r   r
   r:   )r	   r7         r;   r;   r;   )r   r   Zint64r   Zget_reverse_indexerr%   r&   )r   Zindexerr]   r)   r   r   r   test_get_reverse_indexer   s     z%TestIndexing.test_get_reverse_indexerN)	r0   r1   r2   rI   rO   rS   r\   r^   ra   r   r   r   r   r3   1   s   "4r3   c               C   s   t jjd k	std S )N)r   Zhasnans__doc__r   r   r   r   r   'test_cache_readonly_preserve_docstrings   s    rc   )numpyr   r   Zpandas._libsr   r   r   Zpandasr-   r   Zpandas._testingZ_testingr%   r   r3   rc   r   r   r   r   <module>   s   
& 