U
    W7b                     @   sj   d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlm	Z	m
Z
mZmZ d dlmZ G dd dZdS )    N)
skip_if_no)	DataFrameIndexSeries
date_rangec                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
dededededddgd ededededededededdgedd edD ejeddejeddddgdgdd Zej	
deededggdd  Zd!d" Zd#d$ Z d%d& Z!d'd( Z"d)d* Z#d+d, Z$d-d. Z%ej	
d/d0egd1d2 Z&ej	
d/d3d4gd5d6 Z'd7d8 Z(e)d9d:d; Z*d<d= Z+ej	
d>d?d@dAdBgdCdD Z,dEdF Z-dGdH Z.d3S )ITestSeriesMiscc                 C   s@   t td}dt|kstdt|ks,tdt|ks<td S )NZabcdstrdtcatr   listdirAssertionErrorselfs r   @/tmp/pip-unpacked-wheel-rhjceu4d/pandas/tests/series/test_api.pytest_tab_completion   s    z"TestSeriesMisc.test_tab_completionc                 C   sD   t tddd}dt|ks tdt|ks0tdt|ks@td S )N1/1/2015   periodsr	   r   r
   )r   r   r   r   r   r   r   r   test_tab_completion_dt   s    z%TestSeriesMisc.test_tab_completion_dtc                 C   sD   t tddd}dt|ks tdt|ks0tdt|ks@td S )NZabbcdcategorydtyper
   r   r	   r   r   r   r   r   test_tab_completion_cat#   s    z&TestSeriesMisc.test_tab_completion_catc                 C   sJ   t tdddd}dt|ks&tdt|ks6tdt|ksFtd S )Nr   r   r   r   r
   r   r	   )r   r   astyper   r   r   r   r   r   test_tab_completion_cat_str+   s    z*TestSeriesMisc.test_tab_completion_cat_strc                 C   s\   ddddddddd	d
dg}t tdd}tdd |j D }t|tt| d S )N
categoriescodesZorderedZset_categoriesZadd_categoriesZremove_categoriesZrename_categoriesZreorder_categoriesZremove_unused_categoriesZ
as_orderedZas_unorderedZaabbcder   c                 S   s   h | ]}| d s|qS )_)
startswith).0rr   r   r   	<setcomp>C   s     
 zFTestSeriesMisc.test_tab_completion_with_categorical.<locals>.<setcomp>)	r   r   r   sortedr
   __dir__tmassert_almost_equalset)r   Z
ok_for_catr   resultsr   r   r   $test_tab_completion_with_categorical2   s    z3TestSeriesMisc.test_tab_completion_with_categoricalindex
   foobarZbaz   TFc                 C   s   g | ]}d | qS )ar   )r$   ir   r   r   
<listcomp>U   s     zTestSeriesMisc.<listcomp>e   ABCDZEFGHr         c                 C   sh   t |td}t|}t|jjddD ]<\}}|dk rVt|trb| rb||ksbt	q&||ks&t	q&d S )Nr.   r   r   )leveld   )
r   objectr   	enumerater.   unique
isinstancer   isidentifierr   )r   r.   r   Zdir_sr4   xr   r   r   test_index_tab_completionF   s     z(TestSeriesMisc.test_index_tab_completionserr   c              	   C   s*   d}t jt|d t| W 5 Q R X d S )Nzunhashable type: 'Series'match)pytestraises	TypeErrorhashr   rD   msgr   r   r   test_not_hashabled   s    z TestSeriesMisc.test_not_hashablec                 C   s   t |j| d S N)r)   Zassert_contains_allr.   )r   datetime_seriesr   r   r   test_containsj   s    zTestSeriesMisc.test_containsc                 C   sj   t ddtjg}t|jdd|jdd | ddksBt|ddksTt|	ddksftd S )Nr8   r2   Zrows)Zaxisr.   r9   r   )
r   npnanr)   assert_series_equalZdropnasumr   Z_get_axis_numberZ_get_axis_namer   r   r   r   test_axis_aliasm   s
    zTestSeriesMisc.test_axis_aliasc                 C   s   t tjstd S rN   )pydocgetdocr   r.   r   )r   r   r   r   test_class_axist   s    zTestSeriesMisc.test_class_axisc                 C   sP   t tjdddddgtdddd}d	d
 }||}| }t|| d S )Ni  r9   ABCz1/1/2000r   )columnsr.   c                 S   s   | |    S rN   )Zidxmax)rB   r   r   r   f   s    z-TestSeriesMisc.test_ndarray_compat.<locals>.f)	r   rQ   randomrandnr   applymaxr)   rS   )r   Ztsdfr]   resultexpectedr   r   r   test_ndarray_compaty   s    

z"TestSeriesMisc.test_ndarray_compatc                 C   s@   t tjd}t t|}t dtddd}t|| d S )Nr/   r8   Zfloat64r:   )r   rQ   r^   r_   Z	ones_likeranger)   rS   )r   r   rb   rc   r   r   r   test_ndarray_compat_like_func   s    z,TestSeriesMisc.test_ndarray_compat_like_funcc                 C   s2   t tjd}t|jdd|jjdd d S )Nr/   F)order)r   rQ   r^   r_   r)   r*   Zravelvaluesr   r   r   r   test_ndarray_compat_ravel   s    z(TestSeriesMisc.test_ndarray_compat_ravelc                 C   s   t td}|jstd S Nr   )r   r=   emptyr   )r   Zs_emptyr   r   r   test_empty_method   s    
z TestSeriesMisc.test_empty_methodr   Zint64c                 C   s   t dg|d}|jrtd S )Nr8   r:   )r   rl   r   )r   r   Zfull_seriesr   r   r   test_empty_method_full_series   s    z,TestSeriesMisc.test_empty_method_full_seriesNZInt64c                 C   s"   t td|d}|jdkstd S )N	   r   )r   re   sizer   )r   r   r   r   r   r   test_integer_series_size   s    z'TestSeriesMisc.test_integer_series_sizec                 C   sF   t ddgdd}|ji kstd|jd< |d }|jddiksBtd S )Nr   r8   abc)nameversion)r   attrsr   )r   r   rb   r   r   r   
test_attrs   s
    
zTestSeriesMisc.test_attrsZjinja2c              	   C   s.   t td}td  t| W 5 Q R X d S rk   )r   r=   r)   Zassert_produces_warninginspect
getmembersr   rD   r   r   r   test_inspect_getmembers   s    
z&TestSeriesMisc.test_inspect_getmembersc              	   C   s`   t jdddd}ttjjdd|d}d|j ks8td}t	j
t|d	 |j W 5 Q R X d S )
Nr   r/   Z1s)startr   freq)rp   )r.   r0   z&'Series' object has no attribute 'foo'rE   )pdZtimedelta_ranger   rQ   r^   normal__dict__keysr   rG   rH   AttributeErrorr0   )r   ZtdirD   rL   r   r   r   test_unknown_attribute   s    z%TestSeriesMisc.test_unknown_attributeopyeardaysecondweekdayc              	   C   s4   d| d}t jt|d t|| W 5 Q R X d S )Nz"'Series' object has no attribute ''rE   )rG   rH   r   getattr)r   r   rO   rL   r   r   r   &test_datetime_series_no_datelike_attrs   s    z5TestSeriesMisc.test_datetime_series_no_datelike_attrsc                 C   s>   t dddd}|jdkst|jdks,t|jdks:td S )N  r8   r/   r   monthr   )r   r   r   r   r   ry   r   r   r   )test_series_datetimelike_attribute_access   s    z8TestSeriesMisc.test_series_datetimelike_attribute_accessc              	   C   s8   t dddd}d}tjt|d |j W 5 Q R X d S )Nr   r8   r/   r   z*'Series' object has no attribute 'weekday'rE   )r   rG   rH   r   r   rK   r   r   r   1test_series_datetimelike_attribute_access_invalid   s    z@TestSeriesMisc.test_series_datetimelike_attribute_access_invalid)/__name__
__module____qualname__r   r   r   r   r-   rG   markZparametrizer)   ZmakeUnicodeIndexZmakeStringIndexZmakeCategoricalIndexr   ZmakeDateIndexZmakePeriodIndexZmakeTimedeltaIndexZmakeIntIndexZmakeUIntIndexZmakeFloatIndexre   r}   Z
MultiIndexfrom_tuplesziprC   r   r=   rM   rP   rU   rX   rd   rf   rj   rm   rn   rq   rv   r   rz   r   r   r   r   r   r   r   r   r      s\   






	
r   )rw   rV   ZnumpyrQ   rG   Zpandas.util._test_decoratorsr   Zpandasr}   r   r   r   r   Zpandas._testingZ_testingr)   r   r   r   r   r   <module>   s   