3
Êb_$H ã               @   s|  d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlZd dl	Z	d dl
mZ d dlZd dlZd dlmZmZmZmZmZ d dlZd dlZd dlZd dlmZmZ d d	lmZmZmZ d dlj j!Z"d d
l#m$Z$m%Z% d dl&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7 d dl8Z9d dl8m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC d dlDmEZE d dlFmGZGmHZHmIZImJZJmKZKmLZL d dlMmNZN d dlOmPZP e(ƒ ZQdZRdZSdZTeUeVfZWdd„ ZXdd„ ZYeXƒ  dd„ ZZ�d*eee$ e%dœdd„Z[�d+ee\ dœd d!„Z]�d,ee\ dœd"d#„Z^ed$d%„ ƒZ_�d-d'd(„Z`�d.eeae\f eeaebf d*œd+d,„Zcd-d.„ Zd�d/ead0œd1d2„Zef d3fefd4œd5d6„Zgejheiejjejk ƒejld7fd8�Zmejheid9jneoepeqd:�d0ƒƒƒejk ƒejrd7fd8�Zs�d1d=d>„Zt�d2d?d@„ZudAdB„ ZvdCdD„ Zw�d3dEdF„Zxe�d4dGdH„ƒZyedIdJ„ ƒZzedKdL„ ƒZ{eadMœdNdO„Z|�d5e>e>eeae\f eaeeaebf eaeae\ddQœ	dRdS„Z}�d6eeae\f dUœdVdW„Z~�d7dYdZ„Zd[d\„ Z€d]d^„ Z�d_d`„ Z‚�d8dbdc„Zƒ�d9dedf„Z„�d:dhdi„Z…�d;dkdl„Z†�d<dndo„Z‡�d=dpdq„Zˆ�d>dsdt„Z‰�d?dudv„ZŠ�d@dxdy„Z‹�dAd{d|„ZŒd}d~„ Z��dBdd€„ZŽd�d‚„ Z��dCdƒd„„Z�d…d†„ Z‘d‡dˆ„ Z’d‰dŠ„ Z“�dDdŒd�„Z”�dEdŽd�„Z•�dFd‘d’„Z–�dGd“d”„Z—�dHd•d–„Z˜�dId—d˜„Z™�dJd™dš„Zš�dKd›dœ„Z›�dLd�dž„Zœ�dMd d¡„Z��dNd£d¤„Zž�dOd¥d¦„ZŸ�dPd§d¨„Z d©dªd«d¬d­d®d¯d°d±d²d³d´dµd¶d·d¸d¹dºd»d¼d½d¾d¿dÀdÁdÂgZ¡�dQdÆdÇ„Z¢�dRdÈdÉ„Z£dÊdË„ Z¤�dSdÌdÍ„Z¥�dTdÎdÏ„Z¦�dUdÐdÑ„Z§�dVdÒdÓ„Z¨dÔdÕ„ Z©�dWdÖd×„Zª�dXdØdÙ„Z«�dYdÚdÛ„Z¬�dZdÜdÝ„Z­�d[dÞdß„Z®dàdá„ Z¯dâdã„ Z°dädå„ Z±�d\dædç„Z²�d]dédê„Z³�d^dëdì„Z´�d_dídî„Zµ�d`dðdñ„Z¶�dadòdó„Z·dôdõ„ Z¸�dbZ¹�dcZº�d	�d
„ Z»�dd�d�d„Z¼e¸�deTddeºe¹f�d�d„ƒZ½e½Z¾ee¿�ddd/d/f�d�d„ƒZÀG �d�d„ �dƒZÁe�d�d„ ƒZÂe�de�d�d„ƒZÃ�df�d�d„ZÄG �d�d„ �deBƒZÅG �d�d„ �de<ƒZÆG �d �d!„ �d!e:ƒZÇee\�d"œ�d#�d$„ƒZÈ�dg�d%�d&„ZÉee\ �d'œ�d(�d)„ZÊdS (h  é    N)ÚCounter)Úcontextmanager)Údatetime)Úwraps)Úrmtree)ÚAnyÚListÚOptionalÚUnionÚcast)ÚrandÚrandn)Úcan_set_localeÚget_localesÚ
set_locale)ÚFilePathOrBufferÚFrameOrSeries)Ú_get_lzma_fileÚ_import_lzma)Úis_boolÚis_categorical_dtypeÚis_datetime64_dtypeÚis_datetime64tz_dtypeÚis_extension_array_dtypeÚis_interval_dtypeÚis_list_likeÚ	is_numberÚis_period_dtypeÚis_sequenceÚis_timedelta64_dtypeÚneeds_i8_conversion)Úarray_equivalent)
ÚCategoricalÚCategoricalIndexÚ	DataFrameÚDatetimeIndexÚIndexÚIntervalIndexÚ
MultiIndexÚ
RangeIndexÚSeriesÚbdate_range)Útake_1d)ÚDatetimeArrayÚExtensionArrayÚIntervalArrayÚPeriodArrayÚTimedeltaArrayÚperiod_array)Úurlopen)Úpprint_thingé   é   Fc              C   s&   t jjddƒ} d| kr"tjdtƒ d S )NÚPANDAS_TESTING_MODEÚNoneÚ	deprecateÚalways)ÚosÚenvironÚgetÚwarningsÚsimplefilterÚ_testing_mode_warnings)Útesting_mode© rB   ú1/tmp/pip-build-jkwsxyiy/pandas/pandas/_testing.pyÚset_testing_modeP   s    rD   c              C   s&   t jjddƒ} d| kr"tjdtƒ d S )Nr7   r8   r9   Úignore)r;   r<   r=   r>   r?   r@   )rA   rB   rB   rC   Úreset_testing_modeW   s    rF   c               C   s   t jddd� dS )zJ
    Reset the display options for printing and representing objects.
    z	^display.T)ZsilentN)ÚpdZreset_optionrB   rB   rB   rC   Úreset_display_optionsa   s    rH   )ÚobjÚpathÚreturnc          
   C   sF   |}|dkrdt dƒ› d�}t|ƒ�}tj| |ƒ tj|ƒS Q R X dS )a�  
    Pickle an object and then read it again.

    Parameters
    ----------
    obj : any object
        The object to pickle and then re-read.
    path : str, path object or file-like object, default None
        The path where the pickled object is written and then read.

    Returns
    -------
    pandas object
        The original object that was pickled and then re-read.
    NÚ__é
   z	__.pickle)ÚrandsÚensure_cleanrG   Z	to_pickleZread_pickle)rI   rJ   Ú_pathZ	temp_pathrB   rB   rC   Úround_trip_pickleh   s    
rQ   )rJ   c          
   C   sP   ddl }|jdƒj}|dkr d}t|ƒ�}| ||ƒƒ |||ƒƒ}W dQ R X |S )aÛ  
    Write an object to file specified by a pathlib.Path and read it back

    Parameters
    ----------
    writer : callable bound to pandas object
        IO writing function (e.g. DataFrame.to_csv )
    reader : callable
        IO reading function (e.g. pd.read_csv )
    path : str, default None
        The path where the object is written and then read.

    Returns
    -------
    pandas object
        The original object that was serialized and then re-read.
    r   NZpathlibZ___pathlib___)ÚpytestÚimportorskipÚPathrO   )ÚwriterÚreaderrJ   rR   rT   rI   rB   rB   rC   Úround_trip_pathlib‚   s    
rW   c          
   C   sP   ddl }|jdƒj}|dkr d}t|ƒ�}| ||ƒƒ |||ƒƒ}W dQ R X |S )aá  
    Write an object to file specified by a py.path LocalPath and read it back.

    Parameters
    ----------
    writer : callable bound to pandas object
        IO writing function (e.g. DataFrame.to_csv )
    reader : callable
        IO reading function (e.g. pd.read_csv )
    path : str, default None
        The path where the object is written and then read.

    Returns
    -------
    pandas object
        The original object that was serialized and then re-read.
    r   Nzpy.pathZ___localpath___)rR   rS   ÚlocalrO   )rU   rV   rJ   rR   Z	LocalPathrI   rB   rB   rC   Úround_trip_localpathŸ   s    
rY   c             c   sØ   |dkrt | dƒ}nš|dkr*tj | dƒ}n„|dkr@tj| dƒ}nn|dkrXttƒ| dƒ}nV|dkr tj| ƒ}|jƒ }t	|ƒdkrŽ|j |j
ƒ ƒ}q®td| › d	�ƒ‚ntd
|› �ƒ‚z
|V  W d|jƒ  |dkrÒ|jƒ  X dS )a  
    Open a compressed file and return a file object.

    Parameters
    ----------
    path : str
        The path where the file is read from.

    compression : {'gzip', 'bz2', 'zip', 'xz', None}
        Name of the decompression to use

    Returns
    -------
    file object
    NÚrbÚgzipÚbz2ÚxzÚzipé   z	ZIP file z error. Only one file per ZIP.zUnrecognized compression type: )Úopenr[   r\   ÚBZ2Filer   ÚlzmaÚzipfileÚZipFileÚnamelistÚlenÚpopÚ
ValueErrorÚclose)rJ   ÚcompressionÚfZzip_fileZ	zip_namesrB   rB   rC   Údecompress_file¼   s(    

rl   Útestc          
   C   sº   | dkrddl }|j}nP| dkr0ddl}|j}n8| dkrHddl}|j}n | dkrZttƒ}ntd| › �ƒ‚| dkr‚d}||f}	d	}
nd
}|f}	d}
|||d��}t	||
ƒ|	Ž  W dQ R X dS )až  
    Write data to a compressed file.

    Parameters
    ----------
    compression : {'gzip', 'bz2', 'zip', 'xz'}
        The compression type to use.
    path : str
        The file path to write the data.
    data : str
        The data to write.
    dest : str, default "test"
        The destination file (for ZIP only)

    Raises
    ------
    ValueError : An invalid compression value was passed in.
    r^   r   Nr[   r\   r]   zUnrecognized compression type: ÚwÚwritestrÚwbÚwrite)Úmode)
rc   rd   r[   ÚGzipFiler\   ra   r   rb   rh   Úgetattr)rj   rJ   ÚdataÚdestrc   Zcompress_methodr[   r\   rr   ÚargsÚmethodrk   rB   rB   rC   Úwrite_to_compressedç   s*    
ry   Úequiv)Úcheck_dtypeÚcheck_less_precisec             K   sî   t | tjƒr(t| |fd||dœ|—Ž nÂt | tjƒrPt| |fd||dœ|—Ž nšt | tjƒrxt| |fd||dœ|—Ž nr|rÐt| ƒrŽt|ƒrŽnBt	| ƒr t	|ƒr n0t | t
jƒs¸t |t
jƒr¾d}nd}t| ||d� tj| |f||dœ|—Ž dS )	aq  
    Check that the left and right objects are approximately equal.

    By approximately equal, we refer to objects that are numbers or that
    contain numbers which may be equivalent to specific levels of precision.

    Parameters
    ----------
    left : object
    right : object
    check_dtype : bool or {'equiv'}, default 'equiv'
        Check dtype if both a and b are the same type. If 'equiv' is passed in,
        then `RangeIndex` and `Int64Index` are also considered equivalent
        when doing type checking.
    check_less_precise : bool or int, default False
        Specify comparison precision. 5 digits (False) or 3 digits (True)
        after decimal points are compared. If int, then specify the number
        of digits to compare.

        When comparing two numbers, if the first number has magnitude less
        than 1e-5, we compare the two numbers directly and check whether
        they are equivalent within the specified precision. Otherwise, we
        compare the **ratio** of the second number to the first number and
        check whether it is equivalent to 1 within the specified precision.
    F)Úcheck_exactÚexactr|   )r}   r{   r|   znumpy arrayÚInput)rI   )r{   r|   N)Ú
isinstancerG   r&   Úassert_index_equalr*   Úassert_series_equalr$   Úassert_frame_equalr   r   ÚnpÚndarrayÚassert_class_equalÚ_testingÚassert_almost_equal)ÚleftÚrightr{   r|   ÚkwargsrI   rB   rB   rC   rˆ     sN     


rˆ   c             C   sZ   |j }t| |ƒs.t|› d|› dt| ƒ› d�ƒ‚t||ƒsVt|› d|› dt|ƒ› d�ƒ‚dS )aª  
    Helper method for our assert_* methods that ensures that
    the two objects being compared have the right type before
    proceeding with the comparison.

    Parameters
    ----------
    left : The first object being compared.
    right : The second object being compared.
    cls : The class type to check against.

    Raises
    ------
    AssertionError : Either `left` or `right` is not an instance of `cls`.
    z Expected type z, found z insteadN)Ú__name__r€   ÚAssertionErrorÚtype)r‰   rŠ   ÚclsZcls_namerB   rB   rC   Ú_check_isinstancen  s    

r�   T)Úcompare_keysc             C   s    t | |tƒ tj| ||d� d S )N)r‘   )r�   Údictr‡   Úassert_dict_equal)r‰   rŠ   r‘   rB   rB   rC   r“   Š  s    r“   g      à?)Úpc             C   s   t | Ž |kS )N)r   )Úsizer”   rB   rB   rC   Úrandbool�  s    r–   r_   )ÚdtypeÚ iÐ  é   ÚOc             C   sF   t jjt| t j|ƒ d�jt j| fƒj|ƒ}|dkr8|S |j|ƒS dS )z,
    Generate an array of byte strings.
    )r•   N)	r„   ÚrandomÚchoiceÚRANDS_CHARSÚprodÚviewÚstr_ÚreshapeÚastype)Úncharsr•   r—   ÚretvalrB   rB   rC   Úrands_array›  s    r¥   c             C   sF   t jjt| t j|ƒ d�jt j| fƒj|ƒ}|dkr8|S |j|ƒS dS )z/
    Generate an array of unicode strings.
    )r•   N)	r„   r›   rœ   ÚRANDU_CHARSrž   rŸ   Úunicode_r¡   r¢   )r£   r•   r—   r¤   rB   rB   rC   Úrandu_arrayª  s    r¨   c             C   s   dj tjjt| ƒƒS )zt
    Generate one random byte string.

    See `rands_array` if you want to create an array of random strings.

    r˜   )Újoinr„   r›   rœ   r�   )r£   rB   rB   rC   rN   ¹  s    rN   c             C   s   dj tjjt| ƒƒS )z
    Generate one random unicode string.

    See `randu_array` if you want to create an array of random unicode strings.

    r˜   )r©   r„   r›   rœ   r¦   )r£   rB   rB   rC   ÚranduÃ  s    rª   c             C   s>   ddl m}m} | d kr2x |ƒ D ]} || ƒ q W n|| ƒ d S )Nr   )Úget_fignumsri   )Úmatplotlib.pyplotr«   ri   )Zfignumr«   Ú_closerB   rB   rC   ri   Í  s
    ri   c          )   c   s"  | pd} d}|r4t j| d�}z
|V  W d|jƒ  X nêttjj| ƒƒrLtdƒ‚yt j| d�\}} W n& t	k
r†   ddl
}|jdƒ Y nX z
| V  W dytj|ƒ W n* tk
rÌ   td|› d| › d	�ƒ Y nX ytjj| ƒrætj| ƒ W n2 tk
�r } ztd
|› �ƒ W Y dd}~X nX X dS )aÏ  
    Gets a temporary path and agrees to remove on close.

    Parameters
    ----------
    filename : str (optional)
        if None, creates a temporary file which is then removed when out of
        scope. if passed, creates temporary file with filename as ending.
    return_filelike : bool (default False)
        if True, returns a file-like which is *always* cleaned. Necessary for
        savefig and other functions which want to append extensions.
    r˜   N)Úsuffixz-Can't pass a qualified name to ensure_clean()r   z$no unicode file names on this systemz Couldn't close file descriptor: z (file: ú)zException on removing file: )ÚtempfileÚTemporaryFileri   rf   r;   rJ   Údirnamerh   ÚmkstempÚUnicodeEncodeErrorrR   ÚskipÚOSErrorÚprintÚexistsÚremove)ÚfilenameZreturn_filelikeÚfdrk   rR   ÚerB   rB   rC   rO   Û  s2    

rO   c              c   s@   t jdd�} z
| V  W dyt| ƒ W n tk
r8   Y nX X dS )z{
    Get a temporary directory path and agrees to remove on close.

    Yields
    ------
    Temporary directory path
    r˜   )r®   N)r°   Úmkdtempr   r¶   )Zdirectory_namerB   rB   rC   Úensure_clean_dir  s    	
r¾   c              c   s2   t tjƒ} z
dV  W dtjjƒ  tjj| ƒ X dS )zÚ
    Get a context manager to safely set environment variables

    All changes will be undone on close, hence environment variables set
    within this contextmanager will neither persist nor change global state.
    N)r’   r;   r<   ÚclearÚupdate)Zsaved_environrB   rB   rC   Ú!ensure_safe_environment_variables  s
    


rÁ   )rK   c             C   s   t | ƒt |ƒkS )zO
    Checks if the set of unique elements of arr1 and arr2 are equivalent.
    )Ú	frozenset)Zarr1Zarr2rB   rB   rC   ÚequalContents3  s    rÃ   r&   )	r‰   rŠ   r~   Úcheck_namesr|   r}   Úcheck_categoricalrI   rK   c          
      sl  d}d‡ ‡fdd„	}	dd„ }
t | |tƒ |	| ||d� | j|jkrz|› d�}| j› d	| › �}|j› d	|› �}t||||ƒ t| ƒt|ƒkrÆ|› d
�}t| ƒ› d	| › �}t|ƒ› d	|› �}t||||ƒ | jdk�rJtt| ƒ} tt|ƒ}xbt| jƒD ]T}|
| |ƒ}|
||ƒ}d|› d�}t||ˆ||||d� |	| j	| |j	| |d� qòW |�r®ˆ �r®| j
|ƒ�sÊtj| j|jkjtƒƒd t| ƒ }|› dtj|dƒ› d�}t||| |ƒ ntj| j|j|ˆ|| |d� |�ràtd| ||d� t| tjƒ�süt|tjƒ�rtd| ||d� t| tjƒ�s(t|tjƒ�r6t| j|jƒ ˆ �rht| ƒ�sPt|ƒ�rht| j|j|› d�d� dS )aà  
    Check that left and right Index are equal.

    Parameters
    ----------
    left : Index
    right : Index
    exact : bool or {'equiv'}, default 'equiv'
        Whether to check the Index class, dtype and inferred_type
        are identical. If 'equiv', then RangeIndex can be substituted for
        Int64Index as well.
    check_names : bool, default True
        Whether to check the names attribute.
    check_less_precise : bool or int, default False
        Specify comparison precision. Only used when check_exact is False.
        5 digits (False) or 3 digits (True) after decimal points are compared.
        If int, then specify the digits to compare.
    check_exact : bool, default True
        Whether to compare number exactly.
    check_categorical : bool, default True
        Whether to compare internal Categorical exactly.
    obj : str, default 'Index'
        Specify object name being compared, internally used to show appropriate
        assertion message.
    Tr&   c                sV   ˆrRt | |ˆ|d� ˆ r(td| ||d� | jdkrB|jdksRt‚ntd| ||d� d S )	N)r~   rI   r—   )rI   ÚstringÚunicodeÚinferred_type)rÆ   rÇ   )rÆ   rÇ   )r†   Úassert_attr_equalrÈ   r�   )ÚlÚrrI   )rÅ   r~   rB   rC   Ú_check_types_  s    
z(assert_index_equal.<locals>._check_typesc             S   s>   | j | }| j| }t|j||jd�}|j|| j| d�}|S )N)Ú
fill_value)Úname)ÚlevelsÚcodesr,   Ú_valuesZ	_na_valueZ_shallow_copyÚnames)ÚindexÚlevelÚuniqueZlevel_codesZfilledÚvaluesrB   rB   rC   Ú_get_ilevel_valuesm  s
    

z.assert_index_equal.<locals>._get_ilevel_values)rI   z levels are differentz, z length are differentr_   zMultiIndex level [ú])r~   rÄ   r|   r}   rI   g      Y@z values are different (é   z %))r|   r{   rI   ÚlobjZrobjrÒ   Úfreqz	 categoryN)r&   )r�   r&   ÚnlevelsÚraise_assert_detailrf   r   r(   Úranger�   rÏ   Úequalsr„   ÚsumrÖ   r¢   ÚintÚroundr‡   rˆ   rÉ   r€   rG   ZPeriodIndexr'   Úassert_interval_array_equalr   Úassert_categorical_equal)r‰   rŠ   r~   rÄ   r|   r}   rÅ   rI   Ú__tracebackhide__rÌ   r×   Úmsg1Úmsg2Zmsg3rÔ   ZllevelZrlevelrÚ   ÚdiffÚmsgrB   )rÅ   r~   rC   r�   :  sj    #	





$r�   r   )r~   c             C   s¢   d}dd„ }|dkrjt | ƒt |ƒkržt | ƒjt |ƒjh}t|ddh ƒrž|› d�}t|||| ƒ||ƒƒ n4|ržt | ƒt |ƒkrž|› d�}t|||| ƒ||ƒƒ d	S )
z#
    Checks classes are equal.
    Tc             S   s:   t | tƒr| S y
t| ƒjS  tk
r4   tt| ƒƒS X d S )N)r€   r&   rŽ   rŒ   ÚAttributeErrorÚrepr)ÚxrB   rB   rC   Ú
repr_classÄ  s    

z&assert_class_equal.<locals>.repr_classrz   Z
Int64Indexr)   z classes are not equivalentz classes are differentN)rŽ   rŒ   rf   rÝ   )r‰   rŠ   r~   rI   rå   rí   Útypesré   rB   rB   rC   r†   ¾  s    


r†   Ú
Attributesc       	      C   sª   d}t || ƒ}t || ƒ}||kr$dS t|ƒrLtj|ƒrLt|ƒrLtj|ƒrLdS y||k}W n tk
rp   d}Y nX t|tƒs„|jƒ }|rŒdS d| › d�}t||||ƒ dS )aK  checks attributes are equal. Both objects must have attribute.

    Parameters
    ----------
    attr : str
        Attribute name being compared.
    left : object
    right : object
    obj : str, default 'Attributes'
        Specify object name being compared, internally used to show appropriate
        assertion message
    TFzAttribute "z" are differentN)	rt   r   r„   ÚisnanÚ	TypeErrorr€   ÚboolÚallrÝ   )	Úattrr‰   rŠ   rI   rå   Z	left_attrZ
right_attrÚresultré   rB   rB   rC   rÉ   Û  s(    





rÉ   c             C   sŽ   dd l j}t| tjtjfƒr\xl| jƒ D ]0}dtt	|ƒj
ƒ› �}t||jtfƒs&t|ƒ‚q&W n.dtt	| ƒj
ƒ› �}t| |jttfƒsŠt|ƒ‚d S )Nr   zBone of 'objs' is not a matplotlib Axes instance, type encountered zoobjs is neither an ndarray of Artist instances nor a single ArtistArtist instance, tuple, or dict, 'objs' is a )r¬   Zpyplotr€   rG   r*   r„   r…   Zravelrë   rŽ   rŒ   ZAxesr’   r�   ZArtistÚtuple)ÚobjsZpltÚelré   rB   rB   rC   Ú"assert_is_valid_plot_return_object  s    
rù   c             C   s
   t | dƒS )NÚ__iter__)Úhasattr)rI   rB   rB   rC   Ú
isiterable  s    rü   c             C   s.   t | ttfƒr| j} t| tjtj| ƒƒƒ dS )z#Assert that the sequence is sorted.N)r€   r&   r*   rÖ   Úassert_numpy_array_equalr„   ÚsortÚarray)ÚseqrB   rB   rC   Úassert_is_sorted  s    r  r"   c             C   s    t | |tƒ |rDt| j|j|› d�d� t| j|j||› d�d� nHt| jjƒ |jjƒ |› d�d� t| jj| jƒ|jj|jƒ|› d�d� td| ||d� dS )av  Test that Categoricals are equivalent.

    Parameters
    ----------
    left : Categorical
    right : Categorical
    check_dtype : bool, default True
        Check that integer dtype of the codes are the same
    check_category_order : bool, default True
        Whether the order of the categories should be compared, which
        implies identical integer codes.  If False, only the resulting
        values are compared.  The ordered attribute is
        checked regardless.
    obj : str, default 'Categorical'
        Specify object name being compared, internally used to show appropriate
        assertion message
    z.categories)rI   z.codes)r{   rI   z.valuesÚorderedN)	r�   r"   r�   Ú
categoriesrý   rÐ   Zsort_valuesZtakerÉ   )r‰   rŠ   r{   Úcheck_category_orderrI   rB   rB   rC   rä   &  s    rä   r/   c             C   sT   t | |tƒ t| j|j||› d�d� t| j|j||› d�d� td| ||d� dS )aÿ  Test that two IntervalArrays are equivalent.

    Parameters
    ----------
    left, right : IntervalArray
        The IntervalArrays to compare.
    exact : bool or {'equiv'}, default 'equiv'
        Whether to check the Index class, dtype and inferred_type
        are identical. If 'equiv', then RangeIndex can be substituted for
        Int64Index as well.
    obj : str, default 'IntervalArray'
        Specify object name being compared, internally used to show appropriate
        assertion message
    z.left)r~   rI   Úclosed)rI   N)r�   r/   r�   r‰   rŠ   rÉ   )r‰   rŠ   r~   rI   rB   rB   rC   rã   P  s    rã   r0   c             C   s8   t | |tƒ t| j|j|› d�d� td| ||d� d S )Nz.values)rI   rÛ   )r�   r0   rý   Ú_datarÉ   )r‰   rŠ   rI   rB   rB   rC   Úassert_period_array_equalf  s    r  r-   c             C   sL   d}t | |tƒ t| j|j|› d�d� td| ||d� td| ||d� d S )NTz._data)rI   rÛ   Útz)r�   r-   rý   r  rÉ   )r‰   rŠ   rI   rå   rB   rB   rC   Úassert_datetime_array_equalm  s
    r	  r1   c             C   s<   d}t | |tƒ t| j|j|› d�d� td| ||d� d S )NTz._data)rI   rÛ   )r�   r1   rý   r  rÉ   )r‰   rŠ   rI   rå   rB   rB   rC   Úassert_timedelta_array_equalv  s    r
  c             C   sŒ   d}t |tjƒrt|ƒ}nt|ƒr*t|ƒ}t |tjƒr@t|ƒ}nt|ƒrPt|ƒ}| › d|› d|› d|› �}|d k	r€|d|› �7 }t|ƒ‚d S )NTz are different

z

[left]:  z

[right]: z	
[diff]: )r€   r„   r…   r4   r   rë   r�   )rI   Úmessager‰   rŠ   rè   rå   ré   rB   rB   rC   rÝ   }  s    

rÝ   únumpy arrayc                sæ   d}t | |ˆ d� t| |tjƒ dd„ }|| ƒ}	||ƒ}
|dkrd|	|
k	rŽtt|	ƒ› dt|
ƒ› �ƒ‚n*|dkrŽ|	|
krŽtt|	ƒ› dt|
ƒ› �ƒ‚‡ ‡fd	d
„}t| |ˆd�s¶|| ||ƒ |rât| tjƒrât|tjƒrâtd| |ˆ d� dS )a´  
    Check that 'np.ndarray' is equivalent.

    Parameters
    ----------
    left, right : numpy.ndarray or iterable
        The two arrays to be compared.
    strict_nan : bool, default False
        If True, consider NaN and None to be different.
    check_dtype : bool, default True
        Check dtype if both a and b are np.ndarray.
    err_msg : str, default None
        If provided, used as assertion message.
    check_same : None|'copy'|'same', default None
        Ensure left and right refer/do not refer to the same memory area.
    obj : str, default 'numpy array'
        Specify object name being compared, internally used to show appropriate
        assertion message.
    T)rI   c             S   s   t | dd ƒd k	r| jS | S )NÚbase)rt   r  )rI   rB   rB   rC   Ú	_get_baseº  s    z+assert_numpy_array_equal.<locals>._get_baseZsamez is not Úcopyz is c                sž   |d kr’| j |j kr,tˆ ˆ › d�| j |j ƒ d}x,t| |ƒD ]\}}t||ˆd�s<|d7 }q<W |d | j }ˆ › dtj|dƒ› d�}tˆ || |ƒ t|ƒ‚d S )	Nz shapes are differentr   )Ú
strict_nanr_   g      Y@z values are different (rÙ   z %))ÚshaperÝ   r^   r!   r•   r„   râ   r�   )r‰   rŠ   Úerr_msgrè   rÊ   rË   ré   )rI   r  rB   rC   Ú_raiseÇ  s    z(assert_numpy_array_equal.<locals>._raise)r  r—   N)	r†   r�   r„   r…   r�   rë   r!   r€   rÉ   )r‰   rŠ   r  r{   r  Z
check_samerI   rå   r  Z	left_baseZ
right_baser  rB   )rI   r  rC   rý   –  s$    rý   c       	      C   sæ   t | tƒstdƒ‚t |tƒs$tdƒ‚|r8td| |dd� t| dƒrdt|ƒt| ƒkrdt| j|jƒ dS tj	| j
ƒ ƒ}tj	|j
ƒ ƒ}t||dd� tj	| |  jtƒƒ}tj	||  jtƒƒ}|rÎt||dd� ntj||||dd	� dS )
a;  Check that left and right ExtensionArrays are equal.

    Parameters
    ----------
    left, right : ExtensionArray
        The two arrays to compare
    check_dtype : bool, default True
        Whether to check if the ExtensionArray dtypes are identical.
    check_less_precise : bool or int, default False
        Specify comparison precision. Only used when check_exact is False.
        5 digits (False) or 3 digits (True) after decimal points are compared.
        If int, then specify the digits to compare.
    check_exact : bool, default False
        Whether to compare number exactly.

    Notes
    -----
    Missing values are checked separately from valid values.
    A mask of missing values is computed for each and checked to match.
    The remaining all-valid values are cast to object dtype and checked.
    zleft is not an ExtensionArrayzright is not an ExtensionArrayr—   r.   )rI   Úasi8NzExtensionArray NA mask)r{   r|   rI   )r€   r.   r�   rÉ   rû   rŽ   rý   r  r„   ZasarrayZisnar¢   Úobjectr‡   rˆ   )	r‰   rŠ   r{   r|   r}   Zleft_naZright_naZ
left_validZright_validrB   rB   rC   Úassert_extension_array_equalã  s(    r  r*   c          
   C   sR  d}t | |tƒ |r&t| t|ƒƒs&t‚t| ƒt|ƒkrlt| ƒ› d| j› �}t|ƒ› d|j› �}t|d||ƒ t| j|j|||||	|› d�d� |rÀt	| ƒrªt	|ƒrª|	 rªnt
d| |d|› �d� |rät| jƒ |jƒ |t|ƒd	� �n |�rLt| ƒsüt|ƒ�r4t| jƒjt|jƒƒ�sJd
| j› d|j› d�}t|ƒ‚nt| jƒ |jƒ |d� n¸t| ƒ�s`t|ƒ�rpt| j|jƒ n”t| jƒ�r¨t| jƒ�r¨t|jƒ�s˜t‚t| j|jƒ n\t| ƒ�rät	| ƒ �rät|ƒ�rät	|ƒ �rät| j|jƒ n tj| jƒ |jƒ ||t|ƒd� |�rt
d| ||d� |	�rNt	| ƒ�s4t	|ƒ�rNt| j|j|› d�|
d� dS )að  
    Check that left and right Series are equal.

    Parameters
    ----------
    left : Series
    right : Series
    check_dtype : bool, default True
        Whether to check the Series dtype is identical.
    check_index_type : bool or {'equiv'}, default 'equiv'
        Whether to check the Index class, dtype and inferred_type
        are identical.
    check_series_type : bool, default True
        Whether to check the Series class is identical.
    check_less_precise : bool or int, default False
        Specify comparison precision. Only used when check_exact is False.
        5 digits (False) or 3 digits (True) after decimal points are compared.
        If int, then specify the digits to compare.

        When comparing two numbers, if the first number has magnitude less
        than 1e-5, we compare the two numbers directly and check whether
        they are equivalent within the specified precision. Otherwise, we
        compare the **ratio** of the second number to the first number and
        check whether it is equivalent to 1 within the specified precision.
    check_names : bool, default True
        Whether to check the Series and Index names attribute.
    check_exact : bool, default False
        Whether to compare number exactly.
    check_datetimelike_compat : bool, default False
        Compare datetime-like which is comparable ignoring dtype.
    check_categorical : bool, default True
        Whether to compare internal Categorical exactly.
    check_category_order : bool, default True
        Whether to compare category order of internal Categoricals

        .. versionadded:: 1.0.2
    obj : str, default 'Series'
        Specify object name being compared, internally used to show appropriate
        assertion message.
    Tz, zSeries length are differentz.index)r~   rÄ   r|   r}   rÅ   rI   r—   zAttributes of )rI   )r{   rI   z[datetimelike_compat=True] z is not equal to Ú.)r{   )r|   r{   rI   rÎ   z	 category)rI   r  N)r�   r*   r€   rŽ   r�   rf   rÓ   rÝ   r�   r   rÉ   rý   Z_internal_get_valuesÚstrr    r&   rÖ   rß   r   rã   rÿ   r   r—   r   r  rÑ   r‡   rˆ   rä   )r‰   rŠ   r{   Úcheck_index_typeZcheck_series_typer|   rÄ   r}   Úcheck_datetimelike_compatrÅ   r  rI   rå   ræ   rç   ré   rB   rB   rC   r‚     s~    6



r‚   r$   c             C   s   d}t | |tƒ |r&t| t|ƒƒs&t‚| j|jkrVt||› d�t| jƒ› t|jƒ› ƒ |rj| j|ƒ| } }t	| j
|j
||||	||› d�d� t	| j|j||||	||› d�d� |�r"|jƒ }| jƒ }xÖttt|jƒ ƒt|jƒ ƒ ƒƒD ]6}||ksöt‚||k�st‚t|| || ||d� qæW nzxxt| jƒD ]j\}}||k�sDt‚| jdd…|f }|jdd…|f }t||||||	||
||› d|› d	|› d
�d�
 �q.W dS )aæ  
    Check that left and right DataFrame are equal.

    This function is intended to compare two DataFrames and output any
    differences. Is is mostly intended for use in unit tests.
    Additional parameters allow varying the strictness of the
    equality checks performed.

    Parameters
    ----------
    left : DataFrame
        First DataFrame to compare.
    right : DataFrame
        Second DataFrame to compare.
    check_dtype : bool, default True
        Whether to check the DataFrame dtype is identical.
    check_index_type : bool or {'equiv'}, default 'equiv'
        Whether to check the Index class, dtype and inferred_type
        are identical.
    check_column_type : bool or {'equiv'}, default 'equiv'
        Whether to check the columns class, dtype and inferred_type
        are identical. Is passed as the ``exact`` argument of
        :func:`assert_index_equal`.
    check_frame_type : bool, default True
        Whether to check the DataFrame class is identical.
    check_less_precise : bool or int, default False
        Specify comparison precision. Only used when check_exact is False.
        5 digits (False) or 3 digits (True) after decimal points are compared.
        If int, then specify the digits to compare.

        When comparing two numbers, if the first number has magnitude less
        than 1e-5, we compare the two numbers directly and check whether
        they are equivalent within the specified precision. Otherwise, we
        compare the **ratio** of the second number to the first number and
        check whether it is equivalent to 1 within the specified precision.
    check_names : bool, default True
        Whether to check that the `names` attribute for both the `index`
        and `column` attributes of the DataFrame is identical.
    by_blocks : bool, default False
        Specify how to compare internal data. If False, compare by columns.
        If True, compare by blocks.
    check_exact : bool, default False
        Whether to compare number exactly.
    check_datetimelike_compat : bool, default False
        Compare datetime-like which is comparable ignoring dtype.
    check_categorical : bool, default True
        Whether to compare internal Categorical exactly.
    check_like : bool, default False
        If True, ignore the order of index & columns.
        Note: index labels must match their respective rows
        (same as in columns) - same labels must be with the same data.
    obj : str, default 'DataFrame'
        Specify object name being compared, internally used to show appropriate
        assertion message.

    See Also
    --------
    assert_series_equal : Equivalent method for asserting Series equality.
    DataFrame.equals : Check DataFrame equality.

    Examples
    --------
    This example shows comparing two DataFrames that are equal
    but with columns of differing dtypes.

    >>> from pandas._testing import assert_frame_equal
    >>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
    >>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})

    df1 equals itself.

    >>> assert_frame_equal(df1, df1)

    df1 differs from df2 as column 'b' is of a different type.

    >>> assert_frame_equal(df1, df2)
    Traceback (most recent call last):
    ...
    AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="b") are different

    Attribute "dtype" are different
    [left]:  int64
    [right]: float64

    Ignore differing dtypes in columns with check_dtype.

    >>> assert_frame_equal(df1, df2, check_dtype=False)
    Tz shape mismatchz.index)r~   rÄ   r|   r}   rÅ   rI   z.columns)r{   rI   Nz	.iloc[:, z] (column name="z"))r{   r  r|   r}   rÄ   r  rÅ   rI   )r�   r$   r€   rŽ   r�   r  rÝ   rë   Zreindex_liker�   rÓ   ÚcolumnsZ_to_dict_of_blocksÚlistÚsetÚkeysrƒ   Ú	enumerateÚilocr‚   )r‰   rŠ   r{   r  Zcheck_column_typeZcheck_frame_typer|   rÄ   Z	by_blocksr}   r  rÅ   Z
check_likerI   rå   ZrblocksZlblocksr—   ÚiÚcolZlcolZrcolrB   rB   rC   rƒ   ¹  sd    h"&rƒ   c             K   s2  d}t | tjƒr"t| |f|Ž �nt | tjƒr>t| |f|Ž nðt | tjƒrZt| |f|Ž nÔt | tƒrtt	| |f|Ž nºt | t
ƒrŽt| |f|Ž n t | tƒr¨t| |f|Ž n†t | tƒrÂt| |f|Ž nlt | tƒrÜt| |f|Ž nRt | tjƒrøt| |f|Ž n6t | tƒ�r"|i k�st‚| |k�s.t‚ntt| ƒƒ‚dS )aC  
    Wrapper for tm.assert_*_equal to dispatch to the appropriate test function.

    Parameters
    ----------
    left, right : Index, Series, DataFrame, ExtensionArray, or np.ndarray
        The two items to be compared.
    **kwargs
        All keyword arguments are passed through to the underlying assert method.
    TN)r€   rG   r&   r�   r*   r‚   r$   rƒ   r/   rã   r0   r  r-   r	  r1   r
  r.   r  r„   r…   rý   r  r�   ÚNotImplementedErrorrŽ   )r‰   rŠ   r‹   rå   rB   rB   rC   Úassert_equalj  s.    




r$  c             C   sº   |t jkrt j| ƒ} n |t jkr,t j| ƒ} nŠ|t jkrPt j| ƒjƒ } |r¶| j} nf|tkrbt| ƒ} nT|tkrtt| ƒ} nB|t	kr†t	| ƒ} n0|t
jkrœt
j| ƒ} n|tkr®t| ƒ} nt|ƒ‚| S )z÷
    Helper function to wrap the expected output of a test in a given box_class.

    Parameters
    ----------
    expected : np.ndarray, Index, Series
    box_cls : {Index, Series, DataFrame}

    Returns
    -------
    subclass of box_cls
    )rG   r&   r*   r$   Zto_frameÚTr0   r2   r-   r1   r„   r…   rÿ   Úto_arrayr#  )ÚexpectedZbox_clsZ	transposerB   rB   rC   Úbox_expected�  s(    







r(  c             C   sJ   t | ƒrt| ƒS t| ƒs t| ƒr*tj| ƒS t| ƒr<tj| ƒS tj	| ƒS d S )N)
r   r2   r   r   r-   Z_from_sequencer   r1   r„   rÿ   )rI   rB   rB   rC   r&  ¸  s    

r&  c             C   sî   t | |tjjƒ t| j|j|d� t| jtjj	j
ƒs8t‚t|jtjj	j
ƒsNt‚|sh| jjƒ }|jjƒ }n| j}|j}|rš| jdkrš|jƒ jƒ }|jƒ jƒ }|j|ƒs´tdd||ƒ n |rÄtd| |ƒ |rÔtd| |ƒ t| jƒ |jƒ |d� dS )a#  Check that the left and right SparseArray are equal.

    Parameters
    ----------
    left : SparseArray
    right : SparseArray
    check_dtype : bool, default True
        Whether to check the data dtype is identical.
    check_kind : bool, default True
        Whether to just the kind of the sparse index for each column.
    check_fill_value : bool, default True
        Whether to check that left.fill_value matches right.fill_value
    consolidate_block_indices : bool, default False
        Whether to consolidate contiguous blocks for sparse arrays with
        a BlockIndex. Some operations, e.g. concat, will end up with
        block indices that could be consolidated. Setting this to true will
        create a new BlockIndex for that array, with consolidated
        block indices.
    )r{   ÚblockzSparseArray.indexzindex are not equalrÍ   r—   N)r�   rG   ZarraysZSparseArrayrý   Z	sp_valuesr€   Zsp_indexÚ_libsÚsparseZSparseIndexr�   Zto_block_indexÚkindZto_int_indexrß   rÝ   rÉ   Zto_dense)r‰   rŠ   r{   Z
check_kindZcheck_fill_valueZconsolidate_block_indicesZ
left_indexZright_indexrB   rB   rC   Úassert_sp_array_equalÈ  s(    

r-  c             C   s,   x&| D ]}||kst dt|ƒ› �ƒ‚qW d S )NzDid not contain item: )r�   rë   )ÚiterableZdicÚkrB   rB   rC   Úassert_contains_all  s    
r0  c             K   s\   xVt | |ƒD ]H\}}t||f|Ž dtt|ƒƒ› dtt|ƒƒ› d�}||k	st|ƒ‚qW dS )zï
    iter1, iter2: iterables that produce elements
    comparable with assert_almost_equal

    Checks that the elements are equal, but not
    the same object. (Does not check that items
    in sequences are also not the same object)
    zExpected object z and object z8 to be different objects, but they were the same object.N)r^   rˆ   rë   rŽ   r�   )Ziter1Ziter2Z
eql_kwargsZelem1Zelem2ré   rB   rB   rC   Úassert_copy  s    	"r1  c             C   s   t jd | … S )N)rÆ   Úascii_uppercase)r/  rB   rB   rC   ÚgetCols"  s    r3  rM   c             C   s   t td| d�|d�S )NrM   )r£   r•   )rÎ   )r&   r¥   )r/  rÎ   rB   rB   rC   ÚmakeStringIndex'  s    r4  c             C   s   t td| d�|d�S )NrM   )r£   r•   )rÎ   )r&   r¨   )r/  rÎ   rB   rB   rC   ÚmakeUnicodeIndex+  s    r5  é   c             K   s4   t d|d�}ttjtj| ƒ| |d�fd|i|—ŽS )z' make a length k index or n categories r6   )r£   r•   )r  rÎ   )r¥   r#   r"   Z
from_codesr„   Zarange)r/  ÚnrÎ   r‹   rì   rB   rB   rC   ÚmakeCategoricalIndex/  s    r8  c             K   s*   t jdd| d d�}tj|fd|i|—ŽS )z make a length k IntervalIndex r   éd   r_   )ÚnumrÎ   )r„   Zlinspacer'   Zfrom_breaks)r/  rÎ   r‹   rì   rB   rB   rC   ÚmakeIntervalIndex7  s    r;  c             C   sL   | dkrt dg|d�S | dkr.t ddg|d�S t ddgdg| d   |d�S )Nr_   T)rÎ   é   F)r&   )r/  rÎ   rB   rB   rC   ÚmakeBoolIndex=  s
    r=  c             C   s   t tt| ƒƒ|d�S )N)rÎ   )r&   r  rÞ   )r/  rÎ   rB   rB   rC   ÚmakeIntIndexE  s    r>  c             C   s   t dd„ t| ƒD ƒ|d�S )Nc             S   s   g | ]}d| ‘qS )r<  é?   l            rB   )Ú.0r!  rB   rB   rC   ú
<listcomp>J  s    z!makeUIntIndex.<locals>.<listcomp>)rÎ   )r&   rÞ   )r/  rÎ   rB   rB   rC   ÚmakeUIntIndexI  s    rB  c             K   s   t d| dfd|i|—ŽS )Nr   r_   rÎ   )r)   )r/  rÎ   r‹   rB   rB   rC   ÚmakeRangeIndexM  s    rC  c             C   s:   t tjj| ƒƒtjjdƒ }t|dtjjddƒ  |d�S )Nr_   rM   r   é	   )rÎ   )Úsortedr„   r›   Zrandom_sampler&   Úrandint)r/  rÎ   rÖ   rB   rB   rC   ÚmakeFloatIndexQ  s    rG  ÚBc             K   s0   t dddƒ}t|| ||d�}t|fd|i|—ŽS )NiÐ  r_   )ÚperiodsrÛ   rÎ   rÎ   )r   r+   r%   )r/  rÛ   rÎ   r‹   ÚdtÚdrrB   rB   rC   ÚmakeDateIndexV  s    rL  ÚDc             K   s   t jf d| ||dœ|—ŽS )Nz1 day)ÚstartrI  rÛ   rÎ   )rG   Ztimedelta_range)r/  rÛ   rÎ   r‹   rB   rB   rC   ÚmakeTimedeltaIndex\  s    rO  c             K   s*   t dddƒ}tjf || d|dœ|—Ž}|S )NiÐ  r_   rH  )rN  rI  rÛ   rÎ   )r   rG   Zperiod_range)r/  rÎ   r‹   rJ  rK  rB   rB   rC   ÚmakePeriodIndex`  s    rP  c             K   s   t jd	d|i|—ŽS )
NÚfooÚbarr_   r<  rÒ   ©rQ  rR  ©r_   r<  ©rS  rT  )rU  )r(   Zfrom_product)r/  rÒ   r‹   rB   rB   rC   ÚmakeMultiIndexf  s    rV  ZAliceZBobZCharlieZDanZEdithZFrankZGeorgeZHannahZIngridZJerryZKevinZLauraZMichaelZNorbertZOliverZPatriciaZQuinnZRayZSarahZTimZUrsulaZVictorZWendyZXavierZYvonneZZeldaú
2000-01-01ú
2000-12-31Ú1Dc       	      C   s˜   t j| ||dd�}t|ƒ}tjj|ƒ}|jt|d�|jd|d�|j	|ƒd d |j	|ƒd d dœ}t j
||t|ƒd�}|jd
 |kr”|jd	d… }|S )a²  
    Make a DataFrame with a DatetimeIndex

    Parameters
    ----------
    start : str or Timestamp, default "2000-01-01"
        The start of the index. Passed to date_range with `freq`.
    end : str or Timestamp, default "2000-12-31"
        The end of the index. Passed to date_range with `freq`.
    freq : str or Freq
        The frequency to use for the DatetimeIndex
    seed : int, optional
        The random state seed.

        * name : object dtype with string names
        * id : int dtype with
        * x, y : float dtype

    Examples
    --------
    >>> _make_timeseries()
                  id    name         x         y
    timestamp
    2000-01-01   982   Frank  0.031261  0.986727
    2000-01-02  1025   Edith -0.086358 -0.032920
    2000-01-03   982   Edith  0.473177  0.298654
    2000-01-04  1009   Sarah  0.534344 -0.750377
    2000-01-05   963   Zelda -0.271573  0.054424
    ...          ...     ...       ...       ...
    2000-12-27   980  Ingrid -0.132333 -0.422195
    2000-12-28   972   Frank -0.376007 -0.298687
    2000-12-29  1009  Ursula -0.865047 -0.503133
    2000-12-30  1000  Hannah -0.063757 -0.507336
    2000-12-31   972     Tim -0.869120  0.531685
    Ú	timestamp)rN  ÚendrÛ   rÎ   )r•   iè  r<  r_   )rÎ   Úidrì   Úy)rÓ   r  Néÿÿÿÿr^  )rG   Z
date_rangerf   r„   r›   ÚRandomStaterœ   Ú_namesZpoissonr   r$   rE  rÓ   r   )	rN  r[  rÛ   ÚseedrÓ   r7  Ústater  ÚdfrB   rB   rC   Ú_make_timeseriesˆ  s    $rd  c             c   s8   t ttttttttt	t
g}x|D ]}|| d�V  q W dS )z¬Generator which can be iterated over to get instances of all the various
    index classes.

    Parameters
    ----------
    k: length of each of the index instances
    )r/  N)r>  rG  r4  r5  rL  rP  rO  r=  rC  r;  r8  )r/  Zall_make_index_funcsÚmake_index_funcrB   rB   rC   Úall_index_generator»  s    	
rf  c              c   s*   t ttttttg} x| D ]
}|V  qW d S )N)rL  rP  rO  rC  r;  r8  rV  )Úmake_index_funcsre  rB   rB   rC   Úindex_subclass_makers_generatorÔ  s    
rh  c             c   s(   t ttg}x|D ]}|| d�V  qW dS )zºGenerator which can be iterated over to get instances of all the classes
    which represent time-series.

    Parameters
    ----------
    k: length of each of the index instances
    )r/  N)rL  rP  rO  )r/  rg  re  rB   rB   rC   Úall_timeseries_index_generatorâ  s    

ri  c             C   s   t tƒ}tttƒ|| d�S )N)rÓ   rÎ   )r4  ÚNr*   r   )rÎ   rÓ   rB   rB   rC   ÚmakeFloatSeriesð  s    rk  c             C   s   t tƒ}tttƒ|| d�S )N)rÓ   rÎ   )r4  rj  r*   r   )rÎ   rÓ   rB   rB   rC   ÚmakeStringSeriesõ  s    rl  c             C   s*   t tƒ}t|td�}t tƒ}t||| d�S )N)r—   )rÓ   rÎ   )r4  rj  r&   r  r*   )rÎ   ru   rÓ   rB   rB   rC   ÚmakeObjectSeriesú  s    rm  c                  s   t tƒ‰ ‡ fdd„ttƒD ƒS )Nc                s   i | ]}t ttƒˆ d �|“qS ))rÓ   )r*   r   rj  )r@  Úc)rÓ   rB   rC   ú
<dictcomp>  s    z!getSeriesData.<locals>.<dictcomp>)r4  rj  r3  ÚKrB   rB   )rÓ   rC   ÚgetSeriesData  s    rq  c             C   s&   | d krt } tt| ƒt| |d�|d�S )N)rÛ   )rÓ   rÎ   )rj  r*   r   rL  )ÚnperrÛ   rÎ   rB   rB   rC   ÚmakeTimeSeries  s    rs  c             C   s"   | d krt } tt| ƒt| ƒ|d�S )N)rÓ   rÎ   )rj  r*   r   rP  )rr  rÎ   rB   rB   rC   ÚmakePeriodSeries  s    rt  c                s   ‡ ‡fdd„t tƒD ƒS )Nc                s   i | ]}t ˆˆ ƒ|“qS rB   )rs  )r@  rn  )rÛ   rr  rB   rC   ro    s    z%getTimeSeriesData.<locals>.<dictcomp>)r3  rp  )rr  rÛ   rB   )rÛ   rr  rC   ÚgetTimeSeriesData  s    ru  c                s   ‡ fdd„t tƒD ƒS )Nc                s   i | ]}t ˆ ƒ|“qS rB   )rt  )r@  rn  )rr  rB   rC   ro    s    z!getPeriodData.<locals>.<dictcomp>)r3  rp  )rr  rB   )rr  rC   ÚgetPeriodData  s    rv  c             C   s   t | |ƒ}t|ƒS )N)ru  r$   )rr  rÛ   ru   rB   rB   rC   ÚmakeTimeDataFrame  s    
rw  c              C   s   t ƒ } t| ƒS )N)rq  r$   )ru   rB   rB   rC   ÚmakeDataFrame   s    rx  c              C   sN   t dddddgƒ} dddd	d
gdddddgdddddgtddd�dœ}| |fS )NÚaÚbrn  Údr¼   g        g      ð?g       @g      @g      @Zfoo1Zfoo2Zfoo3Zfoo4Zfoo5z1/1/2009rÙ   )rI  )ÚArH  ÚCrM  )r&   r+   )rÓ   ru   rB   rB   rC   ÚgetMixedTypeDict%  s    r~  c               C   s   t tƒ d ƒS )Nr_   )r$   r~  rB   rB   rB   rC   ÚmakeMixedDataFrame2  s    r  c             C   s   t | ƒ}t|ƒS )N)rv  r$   )rr  ru   rB   rB   rC   ÚmakePeriodFrame6  s    r€  ú#c          	      sX  |dkrdg| }t |ƒr&t|ƒ|ks*t‚|dksR|dksR|dksRt|ƒ|ksRt‚|dksn|dkrj|dksnt‚|dkrŒ‡ fdd„t|ƒD ƒ}|dkr˜d}t|tƒr°|dkr°|g}tttt	t
tttd�j|ƒ}|rê|| ƒ}|ræ|d |_|S |dk	�rtt|ƒ› d�ƒ‚t|ƒ|k �r,|jdg|t|ƒ  ƒ t|ƒ|k�s>t‚tdd„ |D ƒƒ�sVt‚g }x†t|ƒD ]z}	dd„ }
| ||	  d }tƒ }x2t|ƒD ]&}ˆ › d|	› d|› �}||	 ||< �q�W t|jƒ |
d�d| … }|j|ƒ �qdW tt|Ž ƒ}| dk�rt|d |d d�}nF|dk�rF|dk�r&dn|d }tdd„ |D ƒ|d�}ntj||d�}|S )aã  Create an index/multindex with given dimensions, levels, names, etc'

    nentries - number of entries in index
    nlevels - number of levels (> 1 produces multindex)
    prefix - a string prefix for labels
    names - (Optional), bool or list of strings. if True will use default
       names, if false will use no names, if a list is given, the name of
       each level in the index will be taken from the list.
    ndupe_l - (Optional), list of ints, the number of rows for which the
       label will repeated at the corresponding level, you can specify just
       the first few, the rest will use the default ndupe_l of 1.
       len(ndupe_l) <= nlevels.
    idx_type - "i"/"f"/"s"/"u"/"dt"/"p"/"td".
       If idx_type is not None, `idx_nlevels` must be 1.
       "i"/"f" creates an integer/float index,
       "s"/"u" creates a string/unicode index
       "dt" create a datetime index.
       "td" create a datetime index.

        if unspecified, string labels will be generated.
    Nr_   FTr!  rk   ÚsÚurJ  r”   Útdc                s   g | ]}ˆ t |ƒ ‘qS rB   )r  )r@  r!  )ÚprefixrB   rC   rA  ^  s    z#makeCustomIndex.<locals>.<listcomp>)r!  rk   r‚  rƒ  rJ  r„  r”   r   zI is not a legal value for `idx_type`, use  'i'/'f'/'s'/'u'/'dt'/'p'/'td'.c             s   s   | ]}|d kV  qdS )r   NrB   )r@  rì   rB   rB   rC   ú	<genexpr>�  s    z"makeCustomIndex.<locals>.<genexpr>c             S   s*   dd l }|jdd| ƒjdƒ}dd„ |D ƒS )Nr   z[^\d_]_?r˜   Ú_c             S   s   g | ]}t |ƒ‘qS rB   )rá   )r@  r:  rB   rB   rC   rA  Š  s    z4makeCustomIndex.<locals>.keyfunc.<locals>.<listcomp>)ÚreÚsubÚsplit)rì   rˆ  Znumeric_tuplerB   rB   rC   Úkeyfunc†  s    z makeCustomIndex.<locals>.keyfuncZ_lZ_g)Úkey)rÎ   c             s   s   | ]}|d  V  qdS )r   NrB   )r@  rì   rB   rB   rC   r†  ž  s    )rÒ   )r!  rk   r‚  rƒ  rJ  r”   r„  )r   rf   r�   rÞ   r€   r  r’   r>  rG  r4  r5  rL  rO  rP  r=   rÎ   rh   rë   Úextendró   r   rE  ÚelementsÚappendr  r^   r&   r(   Úfrom_tuples)ZnentriesrÜ   r…  rÒ   Úndupe_lÚidx_typeZidx_funcÚidxZtuplesr!  r‹  Z
div_factorZcntÚjÚlabelrõ   rÓ   rÎ   rB   )r…  rC   ÚmakeCustomIndex;  sf    
(



r–  c                s°   |dkst ‚|dkst ‚|dks4|dkr0|d
ks4t ‚|
dksP|
dkrL|d
ksPt ‚tˆ|d|||
d�}t| |d|||d�}ˆ dkrˆdd„ ‰ ‡ ‡fdd„t| ƒD ƒ}t||||	d�S )aú	  
   nrows,  ncols - number of data rows/cols
   c_idx_names, idx_names  - False/True/list of strings,  yields No names ,
        default names or uses the provided names for the levels of the
        corresponding index. You can provide a single string when
        c_idx_nlevels ==1.
   c_idx_nlevels - number of levels in columns index. > 1 will yield MultiIndex
   r_idx_nlevels - number of levels in rows index. > 1 will yield MultiIndex
   data_gen_f - a function f(row,col) which return the data value
        at that position, the default generator used yields values of the form
        "RxCy" based on position.
   c_ndupe_l, r_ndupe_l - list of integers, determines the number
        of duplicates for each label at a given level of the corresponding
        index. The default `None` value produces a multiplicity of 1 across
        all levels, i.e. a unique index. Will accept a partial list of length
        N < idx_nlevels, for just the first N levels. If ndupe doesn't divide
        nrows/ncol, the last label might have lower multiplicity.
   dtype - passed to the DataFrame constructor as is, in case you wish to
        have more control in conjunction with a custom `data_gen_f`
   r_idx_type, c_idx_type -  "i"/"f"/"s"/"u"/"dt"/"td".
       If idx_type is not None, `idx_nlevels` must be 1.
       "i"/"f" creates an integer/float index,
       "s"/"u" creates a string/unicode index
       "dt" create a datetime index.
       "td" create a timedelta index.

        if unspecified, string labels will be generated.

    Examples:

    # 5 row, 3 columns, default names on both, single index on both axis
    >> makeCustomDataframe(5,3)

    # make the data a random int between 1 and 100
    >> mkdf(5,3,data_gen_f=lambda r,c:randint(1,100))

    # 2-level multiindex on rows with each label duplicated
    # twice on first level, default names on both axis, single
    # index on both axis
    >> a=makeCustomDataframe(5,3,r_idx_nlevels=2,r_ndupe_l=[2])

    # DatetimeIndex on row, index with unicode labels on columns
    # no names on either axis
    >> a=makeCustomDataframe(5,3,c_idx_names=False,r_idx_names=False,
                             r_idx_type="dt",c_idx_type="u")

    # 4-level multindex on rows with names provided, 2-level multindex
    # on columns with default labels and default names.
    >> a=makeCustomDataframe(5,3,r_idx_nlevels=4,
                             r_idx_names=["FEE","FI","FO","FAM"],
                             c_idx_nlevels=2)

    >> a=mkdf(5,3,r_idx_nlevels=2,c_idx_nlevels=4)
    r   Nr!  rk   r‚  rƒ  rJ  r”   r„  r_   r}  )rÜ   r…  rÒ   r‘  r’  ÚRc             S   s   d| › d|› �S )Nr—  r}  rB   )rË   rn  rB   rB   rC   Ú<lambda>  s    z%makeCustomDataframe.<locals>.<lambda>c                s$   g | ]‰ ‡‡ fd d„t ˆƒD ƒ‘qS )c                s   g | ]}ˆ ˆ|ƒ‘qS rB   rB   )r@  rn  )Ú
data_gen_frË   rB   rC   rA    s    z2makeCustomDataframe.<locals>.<listcomp>.<listcomp>)rÞ   )r@  )r™  Úncols)rË   rC   rA    s    z'makeCustomDataframe.<locals>.<listcomp>)r—   )r!  rk   r‚  rƒ  rJ  r”   r„  )r!  rk   r‚  rƒ  rJ  r”   r„  )r�   r–  rÞ   r$   )Únrowsrš  Úc_idx_namesÚr_idx_namesÚc_idx_nlevelsÚr_idx_nlevelsr™  Ú	c_ndupe_lÚ	r_ndupe_lr—   Ú
c_idx_typeÚ
r_idx_typer  rÓ   ru   rB   )r™  rš  rC   ÚmakeCustomDataframe¤  s0    Er¤  c                sÆ   |d krt j}nt jj|ƒ}tt jd| ˆ ˆ  ƒƒ‰d}d}tˆ| |ˆ ƒ}‡ ‡‡fdd„}|||ƒ}x |jˆk rŠ|d9 }|||ƒ}qlW t j|d ˆ ƒjtƒ}	||	ˆ  jtƒ}
|
j	ƒ |	j	ƒ fS )Nr_   rÙ   gR¸…ëQð?c                s.   | j t|ƒƒ}tjtj|ˆ ˆ  ƒƒd ˆ… S )N)r   rá   r„   rÕ   Úfloor)ÚrngZ_extra_sizeÚind)rš  r›  r•   rB   rC   Ú_gen_unique_rand  s    z-_create_missing_idx.<locals>._gen_unique_randgÍÌÌÌÌÌð?g      ð?)
r„   r›   r_  rá   râ   Úminr•   r¥  r¢   Útolist)r›  rš  ÚdensityÚrandom_stateZmin_rowsZfacZ
extra_sizer¨  r§  r”  r!  rB   )rš  r›  r•   rC   Ú_create_missing_idx  s    
r­  çÍÌÌÌÌÌì?c             C   sF   t | |||||||	|
|||d�}t| |||ƒ\}}tj|j||f< |S )a[  
    Parameters
    ----------
    Density : float, optional
        Float in (0, 1) that gives the percentage of non-missing numbers in
        the DataFrame.
    random_state : {np.random.RandomState, int}, optional
        Random number generator or random seed.

    See makeCustomDataframe for descriptions of the rest of the parameters.
    )
rœ  r�  rž  rŸ  r™  r   r¡  r—   r¢  r£  )r¤  r­  r„   ÚnanrÖ   )r›  rš  r«  r¬  rœ  r�  rž  rŸ  r™  r   r¡  r—   r¢  r£  rc  r!  r”  rB   rB   rC   ÚmakeMissingCustomDataframe'  s     r°  c             C   s0   t ƒ }t|j| |dœŽ\}}tj|j||f< |S )N)r«  r¬  )rx  r­  r  r„   r¯  rÖ   )r«  r¬  rc  r!  r”  rB   rB   rC   ÚmakeMissingDataframeV  s    r±  c                s   t ˆ ƒ‡ fdd„ƒ}|S )a8  allows a decorator to take optional positional and keyword arguments.
    Assumes that taking a single, callable, positional argument means that
    it is decorating a function, i.e. something like this::

        @my_decorator
        def function(): pass

    Calls decorator with decorator(f, *args, **kwargs)c                 sN   ‡ ‡‡fdd„}ˆ o,t ˆ ƒdko,tˆ d ƒ}|rFˆ d }g ‰ ||ƒS |S d S )Nc                s   ˆ| fˆ žˆŽS )NrB   )rk   )rw   Ú	decoratorr‹   rB   rC   Údeci  s    z+optional_args.<locals>.wrapper.<locals>.decr_   r   )rf   Úcallable)rw   r‹   r³  Zis_decoratingrk   )r²  )rw   r‹   rC   Úwrapperg  s    zoptional_args.<locals>.wrapper)r   )r²  rµ  rB   )r²  rC   Úoptional_args]  s    
r¶  ú	timed outúServer Hangupú#HTTP Error 503: Service Unavailableú502: Proxy ErrorúHTTP Error 502: internal errorúHTTP Error 502úHTTP Error 503úHTTP Error 403úHTTP Error 400ú$Temporary failure in name resolutionúName or service not knownúConnection refusedúcertificate verifyée   éo   én   éh   é6   é<   c              C   s   dd l } t| jjtfS )Nr   )Úhttp.clientÚIOErrorÚclientÚHTTPExceptionÚTimeoutError)ÚhttprB   rB   rC   Ú_get_default_network_errors�  s    rÐ  c             C   sD   |dkrt ƒ }yt| ƒ� W dQ R X W n |k
r:   dS X dS dS )a;  Try to connect to the given url. True if succeeds, False if IOError
    raised

    Parameters
    ----------
    url : basestring
        The URL to try to connect to

    Returns
    -------
    connectable : bool
        Return True if no IOError (unable to connect) or URLError (bad url) was
        raised
    NFT)rÐ  r3   )ÚurlÚerror_classesrB   rB   rC   Úcan_connect¤  s    
rÓ  zhttp://www.google.comc          	      sF   ddl m‰ ˆdkrtƒ ‰dˆ_tˆƒ‡ ‡‡‡‡‡‡‡fdd„ƒ}|S )aZ  
    Label a test as requiring network connection and, if an error is
    encountered, only raise if it does not find a network connection.

    In comparison to ``network``, this assumes an added contract to your test:
    you must assert that, under normal conditions, your test will ONLY fail if
    it does not have network connectivity.

    You can call this in 3 ways: as a standard decorator, with keyword
    arguments, or with a positional argument that is the url to check.

    Parameters
    ----------
    t : callable
        The test requiring network connectivity.
    url : path
        The url to test via ``pandas.io.common.urlopen`` to check
        for connectivity. Defaults to 'http://www.google.com'.
    raise_on_error : bool
        If True, never catches errors.
    check_before_test : bool
        If True, checks connectivity before running the test case.
    error_classes : tuple or Exception
        error classes to ignore. If not in ``error_classes``, raises the error.
        defaults to IOError. Be careful about changing the error classes here.
    skip_errnos : iterable of int
        Any exception that has .errno or .reason.erno set to one
        of these values will be skipped with an appropriate
        message.
    _skip_on_messages: iterable of string
        any exception e for which one of the strings is
        a substring of str(e) will be skipped with an appropriate
        message. Intended to suppress errors where an errno isn't available.

    Notes
    -----
    * ``raise_on_error`` supercedes ``check_before_test``

    Returns
    -------
    t : callable
        The decorated test ``t``, with checks for connectivity errors.

    Example
    -------

    Tests decorated with @network will fail if it's possible to make a network
    connection to another URL (defaults to google.com)::

      >>> from pandas._testing import network
      >>> from pandas.io.common import urlopen
      >>> @network
      ... def test_network():
      ...     with urlopen("rabbit://bonanza.com"):
      ...         pass
      Traceback
         ...
      URLError: <urlopen error unknown url type: rabit>

      You can specify alternative URLs::

        >>> @network("http://www.yahoo.com")
        ... def test_something_with_yahoo():
        ...    raise IOError("Failure Message")
        >>> test_something_with_yahoo()
        Traceback (most recent call last):
            ...
        IOError: Failure Message

    If you set check_before_test, it will check the url first and not run the
    test on failure::

        >>> @network("failing://url.blaher", check_before_test=True)
        ... def test_something():
        ...     print("I ran!")
        ...     raise ValueError("Failure")
        >>> test_something()
        Traceback (most recent call last):
            ...

    Errors not related to networking will always be raised.
    r   )rµ   NTc                 sä   ˆrˆ rt ˆˆƒsˆƒ  y
ˆ| |ŽS  tk
rÞ } zžt|dd ƒ}| r`t|dƒr`t|jdd ƒ}|ˆkrvˆd|› �ƒ t|ƒ‰ t‡ fdd„ˆD ƒƒr¢ˆd|› �ƒ t|ˆƒs®‚ ˆs¼t ˆˆƒrÀ‚ nˆd|› �ƒ W Y d d }~X nX d S )NÚerrnoÚreasonz+Skipping test due to known errno and error c             3   s   | ]}|j ƒ ˆ j ƒ kV  qd S )N)Úlower)r@  Úm)Úe_strrB   rC   r†  4	  s    z+network.<locals>.wrapper.<locals>.<genexpr>z;Skipping test because exception message is known and error z4Skipping test due to lack of connectivity and error )rÓ  Ú	Exceptionrt   rû   rÕ  r  Úanyr€   )rw   r‹   ÚerrrÔ  )Ú_skip_on_messagesÚcheck_before_testrÒ  Úraise_on_errorrµ   Úskip_errnosÚtrÑ  )rØ  rC   rµ  #	  s(    



znetwork.<locals>.wrapper)rR   rµ   rÐ  Únetworkr   )rà  rÑ  rÞ  rÝ  rÒ  rß  rÜ  rµ  rB   )rÜ  rÝ  rÒ  rÞ  rµ   rß  rà  rÑ  rC   rá  À  s    \"rá  r:   c             c   sj  d}t jdd���N}|dk	r\t|ƒs*|g}x0|D ](}y|jjƒ  W q0 tk
rV   Y q0X q0W d}t j|ƒ |V  g }	x¤|D ]œ}
| rút|
j| ƒrúd}|røt|
jt	t
fƒrøddlm}m} ||ƒ d d ƒ}d|
j› d	|j› d
|
j› �}|
j|jksøt|ƒ‚qz|	j|
jj|
j|
j|
jfƒ qzW | �r>dt| jƒ› �}|�s>t|ƒ‚|�r\|	�r\tdt|	ƒ› �ƒ‚W dQ R X dS )aä	  
    Context manager for running code expected to either raise a specific
    warning, or not raise any warnings. Verifies that the code raises the
    expected warning, and that it does not raise any other unexpected
    warnings. It is basically a wrapper around ``warnings.catch_warnings``.

    Parameters
    ----------
    expected_warning : {Warning, False, None}, default Warning
        The type of Exception raised. ``exception.Warning`` is the base
        class for all warnings. To check that no warning is returned,
        specify ``False`` or ``None``.
    filter_level : str or None, default "always"
        Specifies whether warnings are ignored, displayed, or turned
        into errors.
        Valid values are:

        * "error" - turns matching warnings into exceptions
        * "ignore" - discard the warning
        * "always" - always emit a warning
        * "default" - print the warning the first time it is generated
          from each location
        * "module" - print the warning the first time it is generated
          from each module
        * "once" - print the warning the first time it is generated

    clear : str, default None
        If not ``None`` then remove any previously raised warnings from
        the ``__warningsregistry__`` to ensure that no warning messages are
        suppressed by this context manager. If ``None`` is specified,
        the ``__warningsregistry__`` keeps track of which warnings have been
        shown, and does not show them again.
    check_stacklevel : bool, default True
        If True, displays the line that called the function containing
        the warning to show were the function is called. Otherwise, the
        line that implements the function is displayed.
    raise_on_extra_warnings : bool, default True
        Whether extra warnings not of the type `expected_warning` should
        cause the test to fail.

    Examples
    --------
    >>> import warnings
    >>> with assert_produces_warning():
    ...     warnings.warn(UserWarning())
    ...
    >>> with assert_produces_warning(False):
    ...     warnings.warn(RuntimeWarning())
    ...
    Traceback (most recent call last):
        ...
    AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
    >>> with assert_produces_warning(UserWarning):
    ...     warnings.warn(RuntimeWarning())
    Traceback (most recent call last):
        ...
    AssertionError: Did not see expected warning of class 'UserWarning'.

    ..warn:: This is *not* thread-safe.
    T)ÚrecordNFr   )ÚgetframeinfoÚstackr<  zGWarning not set with correct stacklevel. File where warning is raised: z != z. Warning message: z&Did not see expected warning of class zCaused unexpected warning(s): )r>   Úcatch_warningsr   Ú__warningregistry__r¿   rê   r?   Ú
issubclassÚcategoryÚFutureWarningÚDeprecationWarningÚinspectrã  rä  rº   r  r�   r�  rŒ   Úlinenorë   )Zexpected_warningZfilter_levelr¿   Zcheck_stacklevelZraise_on_extra_warningsrå   rn   r×  Zsaw_warningZextra_warningsZactual_warningrã  rä  Zcallerré   rB   rB   rC   Úassert_produces_warningG	  sF    D




rí  c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú
RNGContexta-  
    Context manager to set the numpy random number generator speed. Returns
    to the original value upon exiting the context manager.

    Parameters
    ----------
    seed : int
        Seed for numpy.random.seed

    Examples
    --------

    with RNGContext(42):
        np.random.randn()
    c             C   s
   || _ d S )N)ra  )Úselfra  rB   rB   rC   Ú__init__Ù	  s    zRNGContext.__init__c             C   s   t jjƒ | _t jj| jƒ d S )N)r„   r›   Z	get_stateÚstart_statera  )rï  rB   rB   rC   Ú	__enter__Ü	  s    zRNGContext.__enter__c             C   s   t jj| jƒ d S )N)r„   r›   Z	set_staterñ  )rï  Úexc_typeÚ	exc_valueÚ	tracebackrB   rB   rC   Ú__exit__á	  s    zRNGContext.__exit__N)rŒ   Ú
__module__Ú__qualname__Ú__doc__rð  rò  rö  rB   rB   rB   rC   rî  È	  s   rî  c             k   sD   ddl }dddh}| |kr"tdƒ‚|j| f|Ž dV  |j| ƒ dS )au  
    Context manager to temporarily register a CSV dialect for parsing CSV.

    Parameters
    ----------
    name : str
        The name of the dialect.
    kwargs : mapping
        The parameters for the dialect.

    Raises
    ------
    ValueError : the name of the dialect conflicts with a builtin one.

    See Also
    --------
    csv : Python's CSV library.
    r   NÚexcelz	excel-tabÚunixz Cannot override builtin dialect.)Úcsvrh   Úregister_dialectÚunregister_dialect)rÎ   r‹   rü  Z_BUILTIN_DIALECTSrB   rB   rC   Úwith_csv_dialectæ	  s    
rÿ  c             c   sP   ddl m} |d kr|j}|j}|j}|j| ƒ ||_d V  ||_|j|ƒ d S )Nr   )Úexpressions)Zpandas.core.computationr   Z_MIN_ELEMENTSZ_USE_NUMEXPRZset_use_numexpr)ZuseZmin_elementsÚexprZolduseZoldminrB   rB   rC   Úuse_numexpr
  s    
r  r<  c                sF   ˆdkst ‚ˆdk	‰ ˆ r(tˆƒˆks(t ‚ddl‰‡ ‡‡‡fdd„}|S )a  Decorator to run the same function multiple times in parallel.

    Parameters
    ----------
    num_threads : int, optional
        The number of times the function is run in parallel.
    kwargs_list : list of dicts, optional
        The list of kwargs to update original
        function kwargs on different threads.
    Notes
    -----
    This decorator does not pass the return value of the decorated function.

    Original from scikit-image:

    https://github.com/scikit-image/scikit-image/pull/1519

    r   Nc                s    t ˆ ƒ‡ ‡‡‡‡fdd„ƒ}|S )Nc                 sˆ   ˆr‡ ‡fdd„}n‡ fdd„}g }x2t ˆƒD ]&}||ƒ}ˆjˆ| |d�}|j|ƒ q.W x|D ]}|jƒ  q^W x|D ]}|jƒ  qtW d S )Nc                s   t ˆ fˆ|  ŽS )N)r’   )r!  )r‹   Úkwargs_listrB   rC   r˜  4
  s    z?test_parallel.<locals>.wrapper.<locals>.inner.<locals>.<lambda>c                s   ˆ S )NrB   )r!  )r‹   rB   rC   r˜  6
  s    )Útargetrw   r‹   )rÞ   ÚThreadr�  rN  r©   )rw   r‹   Zupdate_kwargsÚthreadsr!  Zupdated_kwargsÚthread)ÚfuncÚhas_kwargs_listr  Únum_threadsÚ	threading)r‹   rC   Úinner1
  s    

z-test_parallel.<locals>.wrapper.<locals>.inner)r   )r  r  )r	  r  r
  r  )r  rC   rµ  0
  s    ztest_parallel.<locals>.wrapper)r�   rf   r  )r
  r  rµ  rB   )r	  r  r
  r  rC   Útest_parallel
  s    r  c               @   s,   e Zd ZddgZedd„ ƒZedd„ ƒZdS )ÚSubclassedSeriesÚtestattrrÎ   c             C   s   t S )N)r  )rï  rB   rB   rC   Ú_constructorI
  s    zSubclassedSeries._constructorc             C   s   t S )N)ÚSubclassedDataFrame)rï  rB   rB   rC   Ú_constructor_expanddimM
  s    z'SubclassedSeries._constructor_expanddimN)rŒ   r÷  rø  Ú	_metadataÚpropertyr  r  rB   rB   rB   rC   r  F
  s   r  c               @   s*   e Zd ZdgZedd„ ƒZedd„ ƒZdS )r  r  c             C   s   t S )N)r  )rï  rB   rB   rC   r  U
  s    z SubclassedDataFrame._constructorc             C   s   t S )N)r  )rï  rB   rB   rC   Ú_constructor_slicedY
  s    z'SubclassedDataFrame._constructor_slicedN)rŒ   r÷  rø  r  r  r  r  rB   rB   rB   rC   r  R
  s   r  c               @   s   e Zd Zedd„ ƒZdS )ÚSubclassedCategoricalc             C   s   t S )N)r  )rï  rB   rB   rC   r  _
  s    z"SubclassedCategorical._constructorN)rŒ   r÷  rø  r  r  rB   rB   rB   rC   r  ^
  s   r  )r  c             #   sL   ddl ‰ ddl‰‡ ‡fdd„}ˆ jjdƒ}|| ƒ z
dV  W d||ƒ X dS )aŸ  
    Context manager for temporarily setting a timezone.

    Parameters
    ----------
    tz : str
        A string representing a valid timezone.

    Examples
    --------

    >>> from datetime import datetime
    >>> from dateutil.tz import tzlocal
    >>> tzlocal().tzname(datetime.now())
    'IST'

    >>> with set_timezone('US/Eastern'):
    ...     tzlocal().tzname(datetime.now())
    ...
    'EDT'
    r   Nc                sB   | d kr,yˆ j d= W q> tk
r(   Y q>X n| ˆ j d< ˆjƒ  d S )NÚTZ)r<   ÚKeyErrorÚtzset)r  )r;   ÚtimerB   rC   ÚsetTZ
  s    
zset_timezone.<locals>.setTZr  )r;   r  r<   r=   )r  r  Zorig_tzrB   )r;   r  rC   Úset_timezoned
  s    

r  c                s"   ˆr‡fdd„}n‡ fdd„}|S )a`  
    Create a function for calling on an array.

    Parameters
    ----------
    alternative : function
        The function to be called on the array with no NaNs.
        Only used when 'skipna_alternative' is None.
    skipna_alternative : function
        The function to be called on the original array

    Returns
    -------
    function
    c                s
   ˆ | j ƒS )N)rÖ   )rì   )Úskipna_alternativerB   rC   Úskipna_wrapper£
  s    z,_make_skipna_wrapper.<locals>.skipna_wrapperc                s"   | j ƒ }t|ƒdkrtjS ˆ |ƒS )Nr   )Zdropnarf   r„   r¯  )rì   Znona)ÚalternativerB   rC   r  ¨
  s    rB   )r  r  r  rB   )r  r  rC   Ú_make_skipna_wrapper‘
  s    r   )Ú	rows_listc             C   s   t j}|j| ƒ| }|S )aW  
    Convert list of CSV rows to single CSV-formatted string for current OS.

    This method is used for creating expected value of to_csv() method.

    Parameters
    ----------
    rows_list : List[str]
        Each element represents the row of csv.

    Returns
    -------
    str
        Expected output of to_csv() in current OS.
    )r;   Úlinesepr©   )r!  Úsepr'  rB   rB   rC   Úconvert_rows_list_to_csv_str±
  s    r$  )N)N)N)rm   )rz   F)Tiê  )rš   )rš   )N)NF)rz   TFTTr&   )Tr   )rï   )TTr"   )rz   r/   )r0   )r-   )r1   )N)FTNNr  )TFF)
Trz   TFTFFTTr*   )Trz   rz   TFTFFFTFr$   )T)TTTF)rM   N)rM   N)rM   r6  N)rM   N)rM   N)rM   N)rM   N)rM   N)rM   N)rM   rH  N)rM   rM  N)rM   N)rM   N)rW  rX  rY  N)rM   )rM   )N)N)N)NrH  N)NN)NrH  )N)NrH  )N)r�  FNN)
TTr_   r_   NNNNNN)N)r®  NTTr_   r_   NNNNNN)r®  N)r·  r¸  r¹  rº  r»  r¼  r½  r¾  r¿  rÀ  rÁ  rÂ  rÃ  )rÄ  rÅ  rÆ  rÇ  rÈ  rÉ  )N)N)r<  N)N)Ër\   Úcollectionsr   Ú
contextlibr   r   Ú	functoolsr   r[   r;   Úshutilr   rÆ   r°   Útypingr   r   r	   r
   r   r>   rc   Znumpyr„   Znumpy.randomr   r   Zpandas._config.localizationr   r   r   Zpandas._libs.testingr*  Ztestingr‡   Zpandas._typingr   r   Zpandas.compatr   r   Zpandas.core.dtypes.commonr   r   r   r   r   r   r   r   r   r   r   r    Zpandas.core.dtypes.missingr!   ZpandasrG   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   Zpandas.core.algorithmsr,   Zpandas.core.arraysr-   r.   r/   r0   r1   r2   Zpandas.io.commonr3   Zpandas.io.formats.printingr4   rb   rj  rp  Z_RAISE_NETWORK_ERROR_DEFAULTrê  ÚResourceWarningr@   rD   rF   rH   rQ   r  rW   rY   rl   ry   rò   rá   rˆ   r�   r“   Úfloatr–   rÿ   r  Úascii_lettersÚdigitsr    r�   r©   ÚmapÚchrrÞ   r§   r¦   r¥   r¨   rN   rª   ri   rO   r¾   rÁ   rÃ   r�   r†   rÉ   rù   rü   r  rä   rã   r  r	  r
  rÝ   rý   r  r‚   rƒ   r$  r(  r&  r-  r0  r1  r3  r4  r5  r8  r;  r=  r>  rB  rC  rG  rL  rO  rP  rV  r`  rd  rf  rh  ri  rk  rl  rm  rq  rs  rt  ru  rv  rw  rx  r~  r  r€  r–  r¤  r­  r°  r±  r¶  Z_network_error_messagesZ_network_errno_valsrÐ  rÓ  rá  Zwith_connectivity_checkÚWarningrí  rî  rÿ  r  r  r  r  r  r  r   r$  rB   rB   rB   rC   Ú<module>   sî  80 	+4 $R  

0
     ${,	)	    G7                      $&(   =3k         \           !                 |{ 0, 