3
pdpb                @   sj	  U 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
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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#m$Z$ d dl%j&j'Z(d dl)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< d dl=m>Z> d dl?Z@d dl?mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJ d dlKmLZL d dlMmNZNmOZOmPZPmQZQmRZRmSZS d dlTmUZU d dlVmWZW d dlXmYZY e/ ZZdZ[dZ\dZ]ddddgZ^ee* ^ddddgZ_ee* _e`d d!d"d#gZaee* ad$d%d&d'gZbee* be^ea Zce_eb Zdeed(d)gZfee* fegd*d+gZhee* heid,d-gZjee* jd.d/gZkee* kd0d1gZlee* lemd2gZneod3gZpeqd4gZrefec Zseseh ej ek el en er ep ZteuevfZwd5d6 Zxd7d8 Zyex  d9d: ZzdPeee+ e,d;d<d=Z{dQeei d>d?d@Z|dReei d>dAdBZ}edCdD Z~dSdFdGZeeme`f eedHdIdJZdKe$dLdMfeemeif eeme`f eeeedNdOdPZdQdR ZdTemdTdUdVZf dWfeedXdYdZZejeejej ejd[fd\Zejed]jeeed^dUej ejd[fd\ZdVdadbZdWdcddZdedf ZdXdgdhZedYdidjZedkdl Zedmdn ZemdodpdqZdKdSe$dSdSdLdMdrfeEeEeemeif emeeme`f ememeeeeeiddsdtduZdZeemeif dwdxdyZd[eieid{d|d}Zd~d Zdd Zd\ddZd]ddZd^ddZd_ddZd`ddZdaddZdbddZdSde$ddLdMfeeeedddZdSdKdSe$dSdddSdSdSdLdMdfddZdSdKdKdSe$dSddddSddSdLdMdfddZdd ZdcddZdd Zdd Zdd Zdd Zdd ZddddZdeddZdfddZdgddZdhddZdiddZdjddZdkddZdlddZdmddÄZdnddƄZdoddȄZdpddʄZddddddddddddddddddddddddddgZdqddZdd ZdrddZdsddZdtddZduddZdd ZÐdvddZĐdwddZŐdxddZƐdyddZǐdzdd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Аdd ZѐdZҐdZӐd'd( ZԐdd)d*Zeѐd+e]ddeefd,d-ZeZeeؐd.dSdSfd/d0ZG d1d2 d2Zed3d4 Zedd5d6Zܐdd8d9ZG d:d; d;eIZG d<d= d=eCZG d>d? d?eAZeeid@dAdBZddCdDZeei dEdFdGZee edHdIdJZe@jjjjj ZdKdL ZeiedMdNdOZdS (      N)Counter)contextmanager)datetime)wraps)rmtree)AnyCallableContextManagerListOptionalTypeUnioncast)randrandn)can_set_localeget_locales
set_locale)
no_default)Dtype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_numberis_numeric_dtype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)DatetimeLikeArrayMixin)urlopen)pprint_thing      FZuint8Zuint16Zuint32Zuint64ZUInt8ZUInt16ZUInt32ZUInt64Zint8Zint16Zint32Zint64ZInt8ZInt16ZInt32ZInt64Zfloat32Zfloat64Z	complex64Z
complex128strUzdatetime64[ns]zM8[ns]ztimedelta64[ns]zm8[ns]boolbytesobjectc              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 rM   1/tmp/pip-build-7vycvbft/pandas/pandas/_testing.pyset_testing_moder   s    rO   c              C   s&   t jjdd} d| kr"tjdt d S )NrB   rC   rD   ignore)rF   rG   rH   rI   rJ   rK   )rL   rM   rM   rN   reset_testing_modey   s    rQ   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_optionrM   rM   rM   rN   reset_display_options   s    rS   )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_cleanrR   Z	to_pickleZread_pickle)rT   rU   _pathZ	temp_pathrM   rM   rN   round_trip_pickle   s    
r\   )rU   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PathrZ   )writerreaderrU   r]   r_   rT   rM   rM   rN   round_trip_pathlib   s    
rb   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___)r]   r^   localrZ   )r`   ra   rU   r]   Z	LocalPathrT   rM   rM   rN   round_trip_localpath   s    
rd   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rtj| }|j }t	|dkr|j |j
 }qt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: )openrf   rg   BZ2Filer   lzmazipfileZipFilenamelistlenpop
ValueErrorclose)rU   compressionfZzip_fileZ	zip_namesrM   rM   rN   decompress_file   s(    

rw   testc       	   
   C   s   | dkrt j}n@| dkr tj}n0| dkr0tj}n | dkrBtt}ntd|  | dkrjd}||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.
    ri   rf   rg   rh   zUnrecognized compression type: wwritestrwbwrite)modeN)
rn   ro   rf   GzipFilerg   rl   r   rm   rs   getattr)	ru   rU   datadestZcompress_methodr}   argsmethodrv   rM   rM   rN   write_to_compressed	  s$    
r   )check_less_preciserV   c             C   s*   t | tr| rdS dS ndd|    S dS )a|  
    Return the tolerance equivalent to the deprecated `check_less_precise`
    parameter.

    Parameters
    ----------
    check_less_precise : bool or int

    Returns
    -------
    float
        Tolerance to be used as relative/absolute tolerance.

    Examples
    --------
    >>> # Using check_less_precise as a bool:
    >>> _get_tol_from_less_precise(False)
    0.5e-5
    >>> _get_tol_from_less_precise(True)
    0.5e-3
    >>> # Using check_less_precise as an int representing the decimal
    >>> # tolerance intended:
    >>> _get_tol_from_less_precise(2)
    0.5e-2
    >>> _get_tol_from_less_precise(8)
    0.5e-8

    gMb@?gh㈵>g      ?rX   N)
isinstancer?   )r   rM   rM   rN   _get_tol_from_less_precise4  s
    
r   equivgh㈵>g:0yE>)check_dtyper   rtolatolc             K   s  |t k	r$tjdtdd t| }}t| tjrNt| |fd|||d| nt| tj	rxt
| |fd|||d| nt| tjrt| |fd|||d| nt|rt| rt|rnBt| rt|rn0t| tjst|tjrd}nd}t| ||d	 tj| |f|||d
| dS )a  
    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.

        .. deprecated:: 1.1.0
           Use `rtol` and `atol` instead to define relative/absolute
           tolerance, respectively. Similar to :func:`math.isclose`.
    rtol : float, default 1e-5
        Relative tolerance.

        .. versionadded:: 1.1.0
    atol : float, default 1e-8
        Absolute tolerance.

        .. versionadded:: 1.1.0
    zThe 'check_less_precise' keyword in testing.assert_*_equal is deprecated and will be removed in a future version. You can stop passing 'check_less_precise' to silence this warning.   )
stacklevelF)check_exactexactr   r   )r   r   r   r   znumpy arrayInput)rT   )r   r   r   N)r   rI   warnFutureWarningr   r   rR   r+   assert_index_equalr/   assert_series_equalr)   assert_frame_equalr    r   npndarrayassert_class_equal_testingassert_almost_equal)leftrightr   r   r   r   kwargsrT   rM   rM   rN   r   ]  sX    .


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_namerM   rM   rN   _check_isinstance  s    

r   T)compare_keysc             C   s    t | |t tj| ||d d S )N)r   )r   dictr   assert_dict_equal)r   r   r   rM   rM   rN   r     s    r   g      ?)pc             C   s   t |  |kS )N)r   )sizer   rM   rM   rN   randbool  s    r   rj   )dtype i     Oc             C   s6   t jjt| t j| djt j| fj|}|j|S )z,
    Generate an array of byte strings.
    )r   )	r   randomchoiceRANDS_CHARSprodviewstr_reshapeastype)ncharsr   r   retvalrM   rM   rN   rands_array  s    r   c             C   s6   t jjt| t j| djt j| fj|}|j|S )z/
    Generate an array of unicode strings.
    )r   )	r   r   r   RANDU_CHARSr   r   unicode_r   r   )r   r   r   r   rM   rM   rN   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   rM   rM   rN   rY     s    rY   c             C   s>   ddl m}m} | d kr2x | D ]} ||  q W n||  d S )Nr   )rt   get_fignums)matplotlib.pyplotrt   r   )Zfignum_closer   rM   rM   rN   rt     s
    rt   c          )   k   s*  | pd} d}| |d< |r<t jf |}z
|V  W d|j  X nttjj| rTtdyt jf |\}} 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| rt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.
    **kwargs
        Additional keywords passed in for creating a temporary file.
        :meth:`tempFile.TemporaryFile` is used when `return_filelike` is ``True``.
        :meth:`tempfile.mkstemp` is used when `return_filelike` is ``False``.
        Note that the `filename` parameter will be passed in as the `suffix`
        argument to either function.

    See Also
    --------
    tempfile.TemporaryFile
    tempfile.mkstemp
    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TemporaryFilert   rq   rF   rU   dirnamers   mkstempUnicodeEncodeErrorr]   skipOSErrorprintexistsremove)filenameZreturn_fileliker   fdrv   r]   erM   rM   rN   rZ   '  s4    

rZ   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_namerM   rM   rN   ensure_clean_dirf  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   rF   rG   clearupdate)Zsaved_environrM   rM   rN   !ensure_safe_environment_variablesy  s
    


r   )rV   c             C   s   t | t |kS )zO
    Checks if the set of unique elements of arr1 and arr2 are equivalent.
    )	frozenset)Zarr1Zarr2rM   rM   rN   equalContents  s    r   r+   )r   r   r   check_namesr   r   check_categoricalr   r   rT   rV   c
                s  d}
d fdd	}dd }|t k	r@tjdtdd	 t| }}t| |t || ||	d
 | j|jkr|	 d}| j d|  }|j d| }t|	||| t	| t	|kr|	 d}t	|  d|  }t	| d| }t|	||| | jdkrrt
t| } t
t|}xft| jD ]X}|| |}|||}d| d}t|||||||d || j| |j| |	d
 qW |rֈ r| j|st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r6td| ||	d
 t| tjsRt|tjr`t| j|j  rt| j s~t|j rt!| 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.

        .. deprecated:: 1.1.0
           Use `rtol` and `atol` instead to define relative/absolute
           tolerance, respectively. Similar to :func:`math.isclose`.
    check_exact : bool, default True
        Whether to compare number exactly.
    check_categorical : bool, default True
        Whether to compare internal Categorical exactly.
    rtol : float, default 1e-5
        Relative tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    atol : float, default 1e-8
        Absolute tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    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   rT   r   )rT   stringinferred_type)r   assert_attr_equalr   r   )lrrT   )r   r   rM   rN   _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codesr1   _valuesZ	_na_valueZ_shallow_copynames)indexleveluniqueZlevel_codesZfilledvaluesrM   rM   rN   _get_ilevel_values  s
    

z.assert_index_equal.<locals>._get_ilevel_valueszThe 'check_less_precise' keyword in testing.assert_*_equal is deprecated and will be removed in a future version. You can stop passing 'check_less_precise' to silence this warning.r   )r   )rT   z levels are differentz, z length are differentrj   zMultiIndex level [])r   r   r   r   r   rT   g      Y@z values are different (   z %))r   r   r   rT   lobjZrobjr   freqz	 categoryN)r+   )"r   rI   r   r   r   r   r+   nlevelsraise_assert_detailrq   r   r-   ranger   r   equalsr   sumr   r   introundr   r   r   r   rR   ZPeriodIndexr,   assert_interval_array_equalr   r   r   assert_categorical_equal)r   r   r   r   r   r   r   r   r   rT   __tracebackhide__r   r   msg1msg2Zmsg3r   ZllevelZrlevelr   diffmsgrM   )r   r   rN   r     sz    1





 $r   r   )r   c             C   s   d}dd }|dkrjt | t |krt | jt |jh}t|ddh r| d}t|||| || n4|rt | t |kr| d}t|||| || d	S )
z#
    Checks classes are equal.
    Tc             S   s   t | tr| S t| jS )N)r   r+   r   r   )xrM   rM   rN   
repr_class8  s    
z&assert_class_equal.<locals>.repr_classr   Z
Int64Indexr.   z classes are not equivalentz classes are differentN)r   r   rq   r   )r   r   r   rT   r   r   typesr   rM   rM   rN   r   2  s    

r   
Attributes)attrrT   c       	      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 }|rdS d|  d}t|||| dS )aO  
    Check 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)	r   r    r   isnan	TypeErrorr   r?   allr   )	r   r   r   rT   r   Z	left_attrZ
right_attrresultr   rM   rM   rN   r   L  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st|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   rR   r/   r   r   Zravelreprr   r   ZAxesr   r   ZArtisttuple)objsZpltelr   rM   rM   rN   "assert_is_valid_plot_return_objecty  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)seqrM   rM   rN   assert_is_sorted  s    r  r'   c             C   s   t | |t |rDt| j|j| dd t| j|j|| dd nxy| jj }|jj }W n" tk
r~   | j|j }}Y nX t||| dd t| jj| j|jj|j| dd t	d| ||d dS )a{  
    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)rT   z.codes)r   rT   z.valuesorderedN)
r   r'   r   
categoriesr  r   Zsort_valuesr   Ztaker   )r   r   r   check_category_orderrT   lcrcrM   rM   rN   r     s"    
r   r4   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   rT   closed)rT   N)r   r4   r   r   r   r   )r   r   r   rT   rM   rM   rN   r     s    r   r5   c             C   s8   t | |t t| j|j| dd td| ||d d S )Nz._data)rT   r   )r   r5   r  _datar   )r   r   rT   rM   rM   rN   assert_period_array_equal  s    r  r2   c             C   sL   d}t | |t t| j|j| dd td| ||d td| ||d d S )NTz._data)rT   r   tz)r   r2   r  r  r   )r   r   rT   r   rM   rM   rN   assert_datetime_array_equal  s
    r  r6   c             C   s<   d}t | |t t| j|j| dd td| ||d d S )NTz._data)rT   r   )r   r6   r  r  r   )r   r   rT   r   rM   rM   rN   assert_timedelta_array_equal  s    r  c             C   s   d}|  d| }t |tjr0|dt| 7 }t |tjrFt|}nt|rVt|}t |tjrlt|}nt|r|t|}|d| d| 7 }|d k	r|d| 7 }t|d S )NTz are different

z

[index]: z

[left]:  z

[right]: z	
[diff]: )r   r   r   r:   r   r  r   )rT   messager   r   r   index_valuesr   r   rM   rM   rN   r     s"    

r   numpy arrayc                s   d}t | |d t| |tj dd }	|	| }
|	|}|dkrd|
|k	rtt|
 dt| n*|dkr|
|krtt|
 dt|  fd	d
}t| |ds|| || |rt| tjrt|tjrt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.
    index_values : numpy.ndarray, default None
        optional index (shared by both left and right), used in output.
    T)rT   c             S   s   t | dd d k	r| jS | S )Nbase)r   r  )rT   rM   rM   rN   	_get_base6  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|| | d	 t|d S )
Nz shapes are differentr   )
strict_nanrj   g      Y@z values are different (r   z %))r  )shaper   ri   r&   r   r   r   r   )r   r   err_msgr   r   r   r   )r  rT   r  rM   rN   _raiseC  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_samerT   r  r   r  Z	left_baseZ
right_baser!  rM   )r  rT   r  rN   r    s$    r  )r   r   c          	   C   s.  |t k	r$tjdtdd t| }}t| ts6tdt|tsHtd|r\td| |dd t| t	rt|t	rt
|t
| krttj| jtj|j|d	 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 )ac  
    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.
    index_values : numpy.ndarray, default None
        Optional index (shared by both left and right), used in output.
    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.

        .. deprecated:: 1.1.0
           Use `rtol` and `atol` instead to define relative/absolute
           tolerance, respectively. Similar to :func:`math.isclose`.
    check_exact : bool, default False
        Whether to compare number exactly.
    rtol : float, default 1e-5
        Relative tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    atol : float, default 1e-8
        Absolute tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0

    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.
    zThe 'check_less_precise' keyword in testing.assert_*_equal is deprecated and will be removed in a future version. You can stop passing 'check_less_precise' to silence this warning.r   )r   zleft is not an ExtensionArrayzright is not an ExtensionArrayr   r3   )rT   )r  NzExtensionArray NA mask)rT   r  )r   r   r   rT   r  )r   rI   r   r   r   r   r3   r   r   r8   r   r  r   asarrayZasi8Zisnar   rA   r   r   )r   r   r   r  r   r   r   r   Zleft_naZright_naZ
left_validZright_validrM   rM   rN   assert_extension_array_equal_  sB    .

r#  r/   c             C   s  d}|t k	r(tjdtdd t| }}t| |t |rFt| ||d t| t|krt|  d| j	 }t| d|j	 }t
|d|| t| j	|j	||||	||| dd		 |rt| j	tjtjfr| j	}|j	}|j|jkst|j|jf|r.t| jrt|jr|	 rntd
| |d| d |rrt| jrrt|jrrt| j|j|t|tj| j	d nT|rt| jst|jrt| jjt|jsd| j d|j d}t|nt| jrt|jrt| j |j  nt| jst|jr2t!j"| j|j|||t|tj| j	d nt#| jrht#|jrht$| j|j|tj| j	d n^t| jst|jrt$| j|j|tj| j	d n(t!j"| j|j|||t|tj| j	d |rtd| ||d |	rt| jst|jrt%| 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.

        .. deprecated:: 1.1.0
           Use `rtol` and `atol` instead to define relative/absolute
           tolerance, respectively. Similar to :func:`math.isclose`.
    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
    check_freq : bool, default True
        Whether to check the `freq` attribute on a DatetimeIndex or TimedeltaIndex.
    rtol : float, default 1e-5
        Relative tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    atol : float, default 1e-8
        Absolute tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    obj : str, default 'Series'
        Specify object name being compared, internally used to show appropriate
        assertion message.
    TzThe 'check_less_precise' keyword in testing.assert_*_equal is deprecated and will be removed in a future version. You can stop passing 'check_less_precise' to silence this warning.r   )r   )rT   z, zSeries length are differentz.index)r   r   r   r   r   r   rT   r   zAttributes of )r   rT   r  z[datetimelike_compat=True] z is not equal to .)r   r   r   rT   r  )r   r  r   z	 category)rT   r  N)&r   rI   r   r   r   r   r/   r   rq   r   r   r   r   rR   r*   TimedeltaIndexr   r   r   r   r   r!   r  r   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  
check_freqr   r   rT   r   r   r   ZlidxZridxr   rM   rM   rN   r     s    G
r   r)   c             C   s  d}|t k	r(tjdtdd t| }}t| |t |rJt| t|sJt	| j
|j
krzt|| dt| j
 t|j
  |r| j|| } }t| j|j|||	|||| dd	 t| j|j|||	|||| dd	 |rN|j }| j }xttt|j t|j  D ]:}||ks t	||ks.t	t|| || ||d	 qW n~x|t| jD ]n\}}||kspt	| jd
d
|f }|jd
d
|f }t|||||	||
||| d| d| d||d qZW 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.

        .. deprecated:: 1.1.0
           Use `rtol` and `atol` instead to define relative/absolute
           tolerance, respectively. Similar to :func:`math.isclose`.
    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.
    check_freq : bool, default True
        Whether to check the `freq` attribute on a DatetimeIndex or TimedeltaIndex.
    rtol : float, default 1e-5
        Relative tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    atol : float, default 1e-8
        Absolute tolerance. Only used when check_exact is False.

        .. versionadded:: 1.1.0
    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)
    TzThe 'check_less_precise' keyword in testing.assert_*_equal is deprecated and will be removed in a future version. You can stop passing 'check_less_precise' to silence this warning.r   )r   z shape mismatchz.index)r   r   r   r   r   r   rT   z.columns)r   rT   Nz	.iloc[:, z] (column name="z"))
r   r&  r   r   r'  r   r(  rT   r   r   )r   rI   r   r   r   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_liker(  r   r   rT   r   ZrblocksZlblocksr   icolZlcolZrcolrM   rM   rN   r     sx    y"&r   c             K   sd  d}t | tjrPt| |f| t | tjtjfrL| j|jksLt| j|jfnt | tjrlt	| |f| nt | tj
rt| |f| nt | trt| |f| nt | trt| |f| nt | trt| |f| nt | trt| |f| npt | trt| |f| nTt | tjr*t| |f| n6t | trT|i ksDt| |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   rR   r+   r   r*   r%  r   r   r/   r   r)   r   r4   r   r5   r  r2   r  r6   r  r3   r#  r   r   r  r=   NotImplementedErrorr   )r   r   r   r   rM   rM   rN   assert_equal[  s2     



r2  c             C   s   |t jkrt j| } n|t jkr,t j| } n|t jkrBt j| } n|t jkrft j| j } |r| j} nf|tkrxt| } nT|t	krt	| } nB|t
krt
| } n0|tjkrtj| } n|tkrt| } 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
    )rR   r
  r+   r/   r)   Zto_frameTr5   r7   r2   r6   r   r   to_arrayr1  )expectedZbox_clsZ	transposerM   rM   rN   box_expected  s,    








r6  c             C   sV   t | dd }t|rt| S t|s,t|r6tj| S t|rHtj| S t	j
| S d S )Nr   )r   r"   r7   r   r   r2   Z_from_sequencer$   r6   r   r
  )rT   r   rM   rM   rN   r4    s    

r4  c             C   s   t | |tjj t| j|j t| jtjj	j
s4tt|jtjj	j
sJt| j}|j}|j|sptdd|| n td| | td| | t| j |j  dS )z
    Check that the left and right SparseArray are equal.

    Parameters
    ----------
    left : SparseArray
    right : SparseArray
    zSparseArray.indexzindex are not equalr   r   N)r   rR   ZarraysZSparseArrayr  Z	sp_valuesr   Zsp_index_libssparseZSparseIndexr   r   r   r   Zto_dense)r   r   Z
left_indexZright_indexrM   rM   rN   assert_sp_array_equal  s    	
r9  c             C   s,   x&| D ]}||kst dt| qW d S )NzDid not contain item: )r   r  )iterableZdickrM   rM   rN   assert_contains_all  s    
r<  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)ri   r   r  r   r   )Ziter1Ziter2Z
eql_kwargsZelem1Zelem2r   rM   rM   rN   assert_copy  s    	"r=  c             C   s   t jd |  S )N)r   ascii_uppercase)r;  rM   rM   rN   getCols  s    r?  rX   c             C   s   t td| d|dS )NrX   )r   r   )r   )r+   r   )r;  r   rM   rM   rN   makeStringIndex   s    r@  c             C   s   t td| d|dS )NrX   )r   r   )r   )r+   r   )r;  r   rM   rM   rN   makeUnicodeIndex  s    rA     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 r<   )r   r   )r  r   )r   r(   r'   Z
from_codesr   Zarange)r;  nr   r   r   rM   rM   rN   makeCategoricalIndex  s    rD  c             K   s*   t jdd| d d}tj|fd|i|S )z make a length k IntervalIndex r   d   rj   )numr   )r   Zlinspacer,   Zfrom_breaks)r;  r   r   r   rM   rM   rN   makeIntervalIndex  s    rG  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 )Nrj   T)r   r   F)r+   )r;  r   rM   rM   rN   makeBoolIndex  s
    rH  c             C   s   t tt| |dS )N)r   )r+   r*  r   )r;  r   rM   rM   rN   makeIntIndex  s    rI  c             C   s   t dd t| D |dS )Nc             S   s   g | ]}d| qS )r   ?   l            rM   ).0r/  rM   rM   rN   
<listcomp>#  s    z!makeUIntIndex.<locals>.<listcomp>)r   )r+   r   )r;  r   rM   rM   rN   makeUIntIndex"  s    rM  c             K   s   t d| dfd|i|S )Nr   rj   r   )r.   )r;  r   r   rM   rM   rN   makeRangeIndex&  s    rN  c             C   s:   t tjj| tjjd }t|dtjjdd  |dS )Nrj   rX   r   	   )r   )sortedr   r   Zrandom_sampler+   randint)r;  r   r   rM   rM   rN   makeFloatIndex*  s    rR  Bc             K   s0   t ddd}t|| ||d}t|fd|i|S )Ni  rj   )periodsr   r   r   )r   r0   r*   )r;  r   r   r   dtdrrM   rM   rN   makeDateIndex/  s    rW  Dc             K   s   t jf d| ||d|S )Nz1 day)startrT  r   r   )rR   Ztimedelta_range)r;  r   r   r   rM   rM   rN   makeTimedeltaIndex5  s    rZ  c             K   s*   t ddd}tjf || d|d|}|S )Ni  rj   rS  )rY  rT  r   r   )r   rR   Zperiod_range)r;  r   r   rU  rV  rM   rM   rN   makePeriodIndex9  s    r[  c             K   s   t jd	d|i|S )
Nfoobarrj   r   r   r\  r]  rj   r   r^  r_  )r`  )r-   Zfrom_product)r;  r   r   rM   rM   rN   makeMultiIndex?  s    ra  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)rY  endr   r   )r   i  r   rj   )r   idr   y)r   r)  Nri  )rR   Z
date_rangerq   r   r   RandomStater   _namesZpoissonr   r)   rP  r   r.  )	rY  rf  r   seedr   rC  stater)  dfrM   rM   rN   _make_timeseriesa  s    $ro  c              c   s*   t ttttttg} x| D ]
}|V  qW d S )N)rW  r[  rZ  rN  rG  rD  ra  )make_index_funcsmake_index_funcrM   rM   rN   index_subclass_makers_generator  s    
rr  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)rW  r[  rZ  )r;  rp  rq  rM   rM   rN   all_timeseries_index_generator  s    	

rs  c             C   s   t t}ttt|| dS )N)r   r   )r@  _Nr/   r   )r   r   rM   rM   rN   makeFloatSeries  s    ru  c             C   s   t t}ttt|| dS )N)r   r   )r@  rt  r/   r   )r   r   rM   rM   rN   makeStringSeries  s    rv  c             C   s*   t t}t|td}t t}t||| dS )N)r   )r   r   )r@  rt  r+   rA   r/   )r   r   r   rM   rM   rN   makeObjectSeries  s    rw  c                  s   t t  fddttD S )Nc                s   i | ]}t tt d |qS ))r   )r/   r   rt  )rK  c)r   rM   rN   
<dictcomp>  s    z!getSeriesData.<locals>.<dictcomp>)r@  rt  r?  _KrM   rM   )r   rN   getSeriesData  s    r{  c             C   s&   | d krt } tt| t| |d|dS )N)r   )r   r   )rt  r/   r   rW  )nperr   r   rM   rM   rN   makeTimeSeries  s    r}  c             C   s"   | d krt } tt| t| |dS )N)r   r   )rt  r/   r   r[  )r|  r   rM   rM   rN   makePeriodSeries  s    r~  c                s    fddt tD S )Nc                s   i | ]}t  |qS rM   )r}  )rK  rx  )r   r|  rM   rN   ry    s    z%getTimeSeriesData.<locals>.<dictcomp>)r?  rz  )r|  r   rM   )r   r|  rN   getTimeSeriesData  s    r  c                s    fddt tD S )Nc                s   i | ]}t  |qS rM   )r~  )rK  rx  )r|  rM   rN   ry    s    z!getPeriodData.<locals>.<dictcomp>)r?  rz  )r|  rM   )r|  rN   getPeriodData  s    r  c             C   s   t | |}t|S )N)r  r)   )r|  r   r   rM   rM   rN   makeTimeDataFrame  s    
r  c              C   s   t  } t| S )N)r{  r)   )r   rM   rM   rN   makeDataFrame  s    r  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brx  dr   g        g      ?g       @g      @g      @Zfoo1Zfoo2Zfoo3Zfoo4Zfoo5z1/1/2009r   )rT  )ArS  CrX  )r+   r0   )r   r   rM   rM   rN   getMixedTypeDict  s    r  c               C   s   t t d S )Nrj   )r)   r  rM   rM   rM   rN   makeMixedDataFrame  s    r  c             C   s   t | }t|S )N)r  r)   )r|  r   rM   rM   rN   makePeriodFrame  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rd}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 }xt|D ]z}	dd }
| ||	  d }t }x2t|D ]&}  d|	 d| }||	 ||< qW 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.
    Nrj   FTr/  rv   surU  r   tdc                s   g | ]} t | qS rM   )r=   )rK  r/  )prefixrM   rN   rL    s    z#makeCustomIndex.<locals>.<listcomp>)r/  rv   r  r  rU  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   NrM   )rK  r   rM   rM   rN   	<genexpr>B  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 rM   )r   )rK  rF  rM   rM   rN   rL  K  s    z4makeCustomIndex.<locals>.keyfunc.<locals>.<listcomp>)resubsplit)r   r  Znumeric_tuplerM   rM   rN   keyfuncG  s    z makeCustomIndex.<locals>.keyfuncZ_lZ_g)key)r   c             s   s   | ]}|d  V  qdS )r   NrM   )rK  r   rM   rM   rN   r  _  s    )r   )r/  rv   r  r  rU  r   r  )r#   rq   r   r   r   r=   r   rI  rR  r@  rA  rW  rZ  r[  rH   r   rs   r  extendr  r   rP  elementsappendr*  ri   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   rM   )r  rN   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rdd   fddt| D }t||||	dS )a
  
    Create a DataFrame using supplied parameters.

    Parameters
    ----------
    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/  rv   r  r  rU  r   r  rj   r  )r   r  r   r  r  Rc             S   s   d|  d| S )Nr  r  rM   )r   rx  rM   rM   rN   <lambda>  s    z%makeCustomDataframe.<locals>.<lambda>c                s$   g | ]  fd dt D qS )c                s   g | ]} |qS rM   rM   )rK  rx  )
data_gen_fr   rM   rN   rL    s    z2makeCustomDataframe.<locals>.<listcomp>.<listcomp>)r   )rK  )r  ncols)r   rN   rL    s    z'makeCustomDataframe.<locals>.<listcomp>)r   )r/  rv   r  r  rU  r   r  )r/  rv   r  r  rU  r   r  )r   r  r   r)   )nrowsr  Zc_idx_namesZr_idx_namesZc_idx_nlevelsZr_idx_nlevelsr  Z	c_ndupe_lZ	r_ndupe_lr   Z
c_idx_typeZ
r_idx_typer)  r   r   rM   )r  r  rN   makeCustomDataframee  s0    H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 )Nrj   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   rM   rN   _gen_unique_rand  s    z-_create_missing_idx.<locals>._gen_unique_randg?g      ?)
r   r   rj  r   r   minr   r  r   tolist)r  r  densityrandom_stateZmin_rowsZfacZ
extra_sizer  r  r  r/  rM   )r  r  r   rN   _create_missing_idx  s    
r  ?c             C   s0   t  }t|j| |d\}}tj|j||f< |S )N)r  r  )r  r  r  r   nanr   )r  r  rn  r/  r  rM   rM   rN   makeMissingDataframe  s    r  c                s   t   fdd}|S )aB  
    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 )NrM   )rv   )r   	decoratorr   rM   rN   dec 	  s    z+optional_args.<locals>.wrapper.<locals>.decrj   r   )rq   callable)r   r   r  Zis_decoratingrv   )r  )r   r   rN   wrapper  s    zoptional_args.<locals>.wrapper)r   )r  r  rM   )r  rN   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 verifye   o   n   h   6   <   c              C   s   dd l } t| jjtfS )Nr   )http.clientIOErrorclientHTTPExceptionTimeoutError)httprM   rM   rN   _get_default_network_errors4	  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  r9   )urlerror_classesrM   rM   rN   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`` supersedes ``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 } zt|dd }| r`t|dr`t|jdd }|krvd|  t| t fddD rd|  t|s st 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)rK  m)e_strrM   rN   r  	  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  	Exceptionr   hasattrr  r=   anyr   )r   r   errr  )_skip_on_messagescheck_before_testr  raise_on_errorr   skip_errnostr  )r  rN   r  	  s(    



znetwork.<locals>.wrapper)r]   r   r  networkr   )r  r  r  r  r  r  r  r  rM   )r  r  r  r  r   r  r  r  rN   r  W	  s    \"r  rE   c             c   s  d}t jdd }d}t j| |V  g }x|D ]}| rt|j| rd}|rt|jttfrddlm}	m	}
 |	|
 d d }d|j
 d|j
 d	|j }|j
|j
kst|q2|j|jj|j|j
|jf q2W | rd
t| j }|st||o|rtdt| W dQ R X dS )ar  
    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

    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)recordFr   )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): N)rI   catch_warningsrJ   
issubclasscategoryr   DeprecationWarninginspectr  r  r   r  r   r  r   linenor  )Zexpected_warningZfilter_levelZcheck_stacklevelZraise_on_extra_warningsr   ry   Zsaw_warningZextra_warningsZactual_warningr  r  callerr   rM   rM   rN   assert_produces_warning	  s6    =



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)rl  )selfrl  rM   rM   rN   __init__[
  s    zRNGContext.__init__c             C   s   t jj | _t jj| j d S )N)r   r   Z	get_statestart_staterl  )r  rM   rM   rN   	__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	tracebackrM   rM   rN   __exit__c
  s    zRNGContext.__exit__N)r   
__module____qualname____doc__r  r  r  rM   rM   rM   rN   r  K
  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.)csvrs   register_dialectunregister_dialect)r   r   r  Z_BUILTIN_DIALECTSrM   rM   rN   with_csv_dialecth
  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oldminrM   rM   rN   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_listrM   rN   r  
  s    z?test_parallel.<locals>.wrapper.<locals>.inner.<locals>.<lambda>c                s    S )NrM   )r/  )r   rM   rN   r  
  s    )targetr   r   )r   Threadr  rY  r   )r   r   Zupdate_kwargsthreadsr/  Zupdated_kwargsthread)funchas_kwargs_listr  num_threads	threading)r   rN   inner
  s    

z-test_parallel.<locals>.wrapper.<locals>.inner)r   )r	  r  )r
  r  r  r  )r	  rN   r  
  s    ztest_parallel.<locals>.wrapper)r   rq   r  )r  r  r  rM   )r
  r  r  r  rN   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  rM   rM   rN   _constructor
  s    zSubclassedSeries._constructorc             C   s   t S )N)SubclassedDataFrame)r  rM   rM   rN   _constructor_expanddim
  s    z'SubclassedSeries._constructor_expanddimN)r   r  r  	_metadatapropertyr  r  rM   rM   rM   rN   r  
  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  rM   rM   rN   r  
  s    z SubclassedDataFrame._constructorc             C   s   t S )N)r  )r  rM   rM   rN   _constructor_sliced
  s    z'SubclassedDataFrame._constructor_slicedN)r   r  r  r  r  r  r  rM   rM   rM   rN   r  
  s   r  c               @   s   e Zd Zedd ZdS )SubclassedCategoricalc             C   s   t S )N)r  )r  rM   rM   rN   r  
  s    z"SubclassedCategorical._constructorN)r   r  r  r  r  rM   rM   rM   rN   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)rG   KeyErrortzset)r  )rF   timerM   rN   setTZ   s    
zset_timezone.<locals>.setTZr  )rF   r  rG   rH   )r  r  Zorig_tzrM   )rF   r  rN   set_timezone
  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_alternativerM   rN   skipna_wrapper$  s    z,_make_skipna_wrapper.<locals>.skipna_wrapperc                s"   | j  }t|dkrtjS  |S )Nr   )Zdropnarq   r   r  )r   Znona)alternativerM   rN   r  )  s    rM   )r   r  r  rM   )r   r  rN   _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.
    )rF   linesepr   )r"  sepr5  rM   rM   rN   convert_rows_list_to_csv_str2  s    r%  )expected_exceptionrV   c             C   s   ddl }|j| ddS )a$  
    Helper function to mark pytest.raises that have an external error message.

    Parameters
    ----------
    expected_exception : Exception
        Expected error to raise.

    Returns
    -------
    Callable
        Regular `pytest.raises` function with `match` equal to `None`.
    r   N)match)r]   Zraises)r&  r]   rM   rM   rN   external_error_raisedG  s    r(  c                sD   g }x:|D ]2\ |j  f | fddtD 7 }q
W |S )a  
    Combine frame, functions from SelectionMixin._cython_table
    keys and expected result.

    Parameters
    ----------
    ndframe : DataFrame or Series
    func_names_and_expected : Sequence of two items
        The first item is a name of a NDFrame method ('sum', 'prod') etc.
        The second item is the expected return value.

    Returns
    -------
    list
        List of three items (DataFrame, function, expected result)
    c                s"   g | ]\}}|kr| fqS rM   rM   )rK  r	  r   )r5  	func_namendframerM   rN   rL  r  s   z+get_cython_table_params.<locals>.<listcomp>)r  cython_table)r*  Zfunc_names_and_expectedresultsrM   )r5  r)  r*  rN   get_cython_table_params]  s    r-  )op_namerV   c                sP   | j d}ytt|}W n2 tk
rJ   tt|dd   fdd}Y nX |S )z
    The operator function for a given op name.

    Parameters
    ----------
    op_name : string
        The op name, in form of "add" or "__add__".

    Returns
    -------
    function
        A function performing the operation.
    r  rj   Nc                s
    || S )NrM   )r   rh  )roprM   rN   r    s    z"get_op_from_name.<locals>.<lambda>)stripr   operatorAttributeError)r.  Zshort_opnameoprM   )r/  rN   get_op_from_namey  s    
r4  )N)N)N)rx   )Ti  )r   )r   )N)NF)Tr   )r   )TTr'   )r   r4   )r5   )r2   )r6   )NN)FTNNr  N)T)rX   N)rX   N)rX   rB  N)rX   N)rX   N)rX   N)rX   N)rX   N)rX   N)rX   rS  N)rX   rX  N)rX   N)rX   N)rb  rc  rd  N)rX   )N)N)N)NrS  N)NN)NrS  )N)NrS  )N)r  FNN)
TTrj   rj   NNNNNN)N)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)rg   collectionsr   
contextlibr   r   	functoolsr   rf   r1  rF   shutilr   r   r   typingr   r   r	   r
   r   r   r   r   rI   rn   numpyr   Znumpy.randomr   r   Zpandas._config.localizationr   r   r   Zpandas._libs.libr   Zpandas._libs.testingr7  Ztestingr   Zpandas._typingr   r   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pandasrR   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   Zpandas.core.algorithmsr1   Zpandas.core.arraysr2   r3   r4   r5   r6   r7   Zpandas.core.arrays.datetimeliker8   Zpandas.io.commonr9   Zpandas.io.formats.printingr:   rm   rt  rz  Z_RAISE_NETWORK_ERROR_DEFAULTZUNSIGNED_INT_DTYPESZUNSIGNED_EA_INT_DTYPESr   ZSIGNED_INT_DTYPESZSIGNED_EA_INT_DTYPESZALL_INT_DTYPESZALL_EA_INT_DTYPESfloatZFLOAT_DTYPEScomplexZCOMPLEX_DTYPESr=   ZSTRING_DTYPESZDATETIME64_DTYPESZTIMEDELTA64_DTYPESr?   ZBOOL_DTYPESr@   ZBYTES_DTYPESrA   ZOBJECT_DTYPESZALL_REAL_DTYPESZALL_NUMPY_DTYPESr  ResourceWarningrK   rO   rQ   rS   r\   rb   rd   rw   r   r   r   r   r   r   r
  r*  ascii_lettersdigitsr   r   r   mapchrr   r   r   r   r   rY   rt   rZ   r   r   r   r   r   r   r  r  r   r   r  r  r  r   r  r#  r   r   r2  r6  r4  r9  r<  r=  r?  r@  rA  rD  rG  rH  rI  rM  rN  rR  rW  rZ  r[  ra  rk  ro  rr  rs  ru  rv  rw  r{  r}  r~  r  r  r  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%  r  r(  corer  ZSelectionMixinZ_cython_tableitemsr+  r-  r4  rM   rM   rM   rN   <module>   s   (80 	 ++,(g  
>
( -	.	!     K] ? @(*%3k         _!                 |h 1* 