3
®yb91  ã            &   @   sB  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Z	d dl
jZd dlmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZmZ d dlmZmZm Z  ej!j"dd	d
gdej#d	d
gƒfd	d
ge$eej%d	d
ge$d�ƒfd	d
gej&dƒeej%ddgej&dƒd�ƒfej%d	d
gdd�dej#d	d
gƒfd	d
gdeej%d	d
gdd�ƒfe	j'ddƒe	j'ddƒgdeddgdd�fe	j'ddƒge	j(dƒedgdd�fd	d
gej&dƒej#ej%d	d
gdd�ƒfej%d	d
gdd�dej#ej%d	d
gdd�ƒfe	j)ddgƒej&dƒej#ddgƒfe	j)ddgƒdej#ddgƒfddgej&dƒej#ddgƒfddge	j*dd�ej#ddge	j*dd�d�fddgej&dƒej#ddgƒfe	j+ddgƒej&dƒej#ddgƒfe	j+ddgƒdej#ddgƒfddgde	j,ddgƒfddge	j-ddd�e	j,ddgdd�fe	j.d	d
ƒe	j.d d!ƒgd"ej/dRdSgƒfd d	gd#ed d	gdd�fd	dgd$ed	dgd$d�fe	j0d	d
gƒdeej%d	d
gej1d�ƒfddgd%ej#ddgƒfddge	j2ƒ ej#ddgƒfddgd&ej#ddgƒfddge	j3ƒ ej#ddgƒfe	j4d	d
gƒdeej%d	d
gej1d�ƒfe	j0e	j,ddgddd'gd(�ƒde	j,ddgddd'gd(�fej5d ƒej5d	ƒgd)e d d	gƒfeddgdd�de	j,e	j'ddƒe	j'ddƒgƒfgƒd*d+„ ƒZ6d,d-„ Z7ej8dƒZ9ej!j"d.e	j'ddƒe	j'ddƒgeddgdd�fe	j.d d	ƒe	j.d	d
ƒgej:d d	d
gƒfe	j;dƒe	j;dƒgej#ddgƒfe j d/d	d	ƒe j d0d	d	ƒgej#ddgƒfej%d	d
gd1d�eej%d	d
gd1d�ƒfej%d	d
gd2d�eej%d3d/gd1d�ƒfe	j;ddd�e	j;ddd�gej#ddge	j*dd�d�fe j d/d	d	e9d4�e j d0d	d	e9d4�gej#ddge9d�fe	j<dƒe	j<dƒgej#ddgƒfej%d	d
gd5d�eej%d	d
gd5d�ƒfej%d	d
gd6d�eej%d3d/gd5d�ƒfd	d
gej#d	d
gƒfd	dgej#d	dgƒfd	e	j=gej#d	e	j=gƒfd	ej>gej#d	ej>gƒfddgej#ddgƒfddgej#ddgƒfdd7gej#dd7gƒfddgej#ddgƒfgƒd8d9„ ƒZ?ej!j"d:e	j'ddƒe	j'dd;ƒge	j.d d	d<d=�e	j.d	d
d>d=�ge	j;ddd�e	j;dd?d�ge	j;ddd�e	j;dƒgej%e	j;dƒe	j;ddd�gƒgƒd@dA„ ƒZ@ej!j"d:ej%d	d
gd d!ggƒd	d
gd d!gggƒdBdC„ ƒZAdDdE„ ZBeG dFdG„ dGeƒƒZCG dHdI„ dIeƒZDdJdK„ ZEejFdLdM„ ƒZGdNdO„ ZHG dPdQ„ dQƒZIdS )Té    N)Úregistry)Úregister_extension_dtype)Ú	is_scalar)ÚBooleanArrayÚDatetimeArrayÚIntegerArrayÚIntervalArrayÚSparseArrayÚStringArrayÚTimedeltaArray)ÚPandasArrayÚinteger_arrayÚperiod_array)ÚDecimalArrayÚDecimalDtypeÚ
to_decimalzdata, dtype, expectedé   é   )ÚdtypeZfloat32g      ð?g       @Úint64Ú2000ÚDZ2001z	Period[D])Úfreqzdatetime64[ns]ZCET)ÚtzZ1HZ2Hztimedelta64[ns]ÚaÚbÚcategoryT)Úorderedé   é   ÚintervalzSparse[int64]ZInt16ÚstringÚbooleanÚc)Ú
categoriesÚdecimalc             C   s   t j| |d�}tj||ƒ d S )N)r   )ÚpdÚarrayÚtmÚassert_equal)Údatar   ÚexpectedÚresult© r-   úB/tmp/pip-install-4cy230dp/pandas/pandas/tests/arrays/test_array.pyÚ
test_array   s    wr/   c              C   sˆ   t jddgƒ} tj| | jd�}t j| |jƒdks4t‚tj| | jdd�}t j| |jƒdks\t‚tj| | jdd�}t j| |jƒdks„t‚d S )Nr   r   )r   FT)r   Úcopy)Únpr'   r&   r   Zshares_memoryZ_ndarrayÚAssertionError)r   r   r-   r-   r.   Útest_array_copy–   s    r3   zdata, expectediÐ  iÑ  zM8[ns]zM8[us]iè  )Útzinfozm8[ns]zm8[us]Fc             C   s   t j| ƒ}tj||ƒ d S )N)r&   r'   r(   r)   )r*   r+   r,   r-   r-   r.   Útest_array_inference¨   s    D
r5   r*   ÚAÚleft)ÚclosedÚrightÚUTCc             C   s,   t j| ƒ}ttj| td�ƒ}tj||ƒ d S )N)r   )r&   r'   r   r1   Úobjectr(   Zassert_extension_array_equal)r*   r,   r+   r-   r-   r.   Útest_array_inference_failsð   s    
r<   c             C   s,   t jtdd�� tj| dd� W d Q R X d S )Nz!PandasArray must be 1-dimensional)Úmatchr   )r   )ÚpytestÚraisesÚ
ValueErrorr&   r'   )r*   r-   r-   r.   Útest_nd_raises  s    rA   c            	   C   s(   t jtdd�� tjdƒ W d Q R X d S )NzCannot pass scalar '1')r=   r   )r>   r?   r@   r&   r'   r-   r-   r-   r.   Útest_scalar_raises
  s    rB   c               @   s   e Zd ZdZedd„ ƒZdS )ÚDecimalDtype2Údecimal2c             C   s   t S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )ÚDecimalArray2)Úclsr-   r-   r.   Úconstruct_array_type  s    	z"DecimalDtype2.construct_array_typeN)Ú__name__Ú
__module__Ú__qualname__ÚnameÚclassmethodrG   r-   r-   r-   r.   rC     s   rC   c                   s"   e Zd Zed‡ fdd„	ƒZ‡  ZS )rE   NFc                s,   t |tjtjfƒrtdƒ‚tƒ j|||d�S )Nz3scalars should not be of type pd.Series or pd.Index)r   r0   )Ú
isinstancer&   ÚSeriesÚIndexÚ	TypeErrorÚsuperÚ_from_sequence)rF   Zscalarsr   r0   )Ú	__class__r-   r.   rR   %  s    zDecimalArray2._from_sequence)NF)rH   rI   rJ   rL   rR   Ú__classcell__r-   r-   )rS   r.   rE   $  s   rE   c             C   sj   | }|t jdƒt jdƒgƒ}tjtdd�� tj|ƒ W d Q R X tj|dd�}tj|j	ƒ}t
j||ƒ d S )NÚ1Ú2z3scalars should not be of type pd.Series or pd.Index)r=   rD   )r   )r%   ÚDecimalr>   r?   rP   rE   rR   r&   r'   Úvaluesr(   r)   )Zindex_or_seriesZboxr*   r,   r+   r-   r-   r.   Útest_array_unboxes-  s    rY   c              c   s.   t jjtƒ} t jj| ƒ d V  t jjtƒ d S )N)r   ZdtypesÚindexr   ÚpopÚappend)Úidxr-   r-   r.   Úregistry_without_decimal<  s    r^   c             C   sN   t jdƒd kst‚tjdƒtjdƒg}tj|td�}tj	|ƒ}t
j||ƒ d S )Nr%   rU   rV   )r   )r   Úfindr2   r%   rW   r&   r'   r   r   rR   r(   r)   )r^   r*   r,   r+   r-   r-   r.   Útest_array_not_registeredD  s
    
r`   c            	   @   s�   e Zd Zdd„ Zdd„ Zdd„ Zejjde	j
dd	d
d�e	jdƒge	j
dd	d
dd�e	jddd�ge	jddd	d�e	jdƒggƒdd„ ƒZdd„ ZdS )ÚTestArrayAnalyticsc             C   sd   t jdddg|d�}|jddd�}t|ƒs.t‚|dks:t‚|jddd�}t|ƒsTt‚|d	ks`t‚d S )
Nr   r   r#   )r   r7   )Zsider   r9   r   )r&   r'   Úsearchsortedr   r2   )ÚselfZstring_dtypeÚarrr,   r-   r-   r.   Útest_searchsortedO  s    z$TestArrayAnalytics.test_searchsortedc             C   sd   t jdddg|d�}|jdƒ}t|ƒs*t‚|dks6t‚|jdgƒ}tjdgtjd�}tj||ƒ d S )Nr   r   éZ   )r   é   r   )	r&   r'   rb   r   r2   r1   Úintpr(   Úassert_numpy_array_equal)rc   Úany_real_dtyperd   r,   r+   r-   r-   r.   Ú'test_searchsorted_numeric_dtypes_scalarZ  s    
z:TestArrayAnalytics.test_searchsorted_numeric_dtypes_scalarc             C   sF   t jdddg|d�}|jddgƒ}tjddgtjd�}tj||ƒ d S )Nr   r   rf   )r   r   rg   )r&   r'   rb   r1   rh   r(   ri   )rc   rj   rd   r,   r+   r-   r-   r.   Ú'test_searchsorted_numeric_dtypes_vectord  s    z:TestArrayAnalytics.test_searchsorted_numeric_dtypes_vectorzarr, valZ20120101é
   Z2D)Úperiodsr   Z20120102zAsia/Hong_Kong)rn   r   r   )r   z1 dayz10 days)ÚstartÚendrn   z2 daysc             C   s0   t j|ƒ}|j|ƒ}t|ƒs t‚|dks,t‚d S )Nr   )r&   r'   rb   r   r2   )rc   rd   Úvalr,   r-   r-   r.   Ú$test_search_sorted_datetime64_scalarj  s    

z7TestArrayAnalytics.test_search_sorted_datetime64_scalarc             C   sP   t jdddg|d�}|jddgtj|ƒd�}tjddgtjd�}tj||ƒ d S )Nr   r   r   )r   r   )Zsorter)r&   r'   rb   r1   Zargsortrh   r(   ri   )rc   rj   rd   r,   r+   r-   r-   r.   Útest_searchsorted_sorter�  s    z+TestArrayAnalytics.test_searchsorted_sorterN)rH   rI   rJ   re   rk   rl   r>   ÚmarkÚparametrizer&   Z
date_rangeÚ	TimestampZtimedelta_rangeÚ	Timedeltarr   rs   r-   r-   r-   r.   ra   N  s   


ra   )r   r   )r   r   )JÚdatetimer%   Znumpyr1   r>   ZpytzZpandas.core.dtypes.baser   Zpandasr&   Zpandas._testingZ_testingr(   Zpandas.api.extensionsr   Zpandas.api.typesr   Zpandas.arraysr   r   r   r   r	   r
   r   Zpandas.core.arraysr   r   r   Zpandas.tests.extension.decimalr   r   r   rt   ru   rR   r;   r'   r   ZPeriodZPeriodDtypeZDatetimeIndexZDatetimeTZDtypeZTimedeltaIndexZCategoricalZCategoricalDtypeZIntervalÚfrom_tuplesrN   r   ZStringDtypeZBooleanDtyperO   rW   r/   r3   ÚtimezoneZcetZfrom_breaksrv   rw   ZNAÚnanr5   r<   rA   rB   rC   rE   rY   Zfixturer^   r`   ra   r-   r-   r-   r.   Ú<module>   s   
$	 
&& ,	
&"*	8
	
