
x\c           @   sQ
  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 Z d  d l 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 d  d l j Z d  d	 l m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* m+ Z+ d  d
 l, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 m: Z: d  d l; m< Z< d  d l= Z> d  d l= m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI d  d lJ mK ZK d  d lL mM ZM mN ZN mO ZO mP ZP mQ ZQ mR ZR d  d lS jT jU ZV d  d lW mX ZX d  d lY mZ ZZ d Z[ d Z\ e] Z^ e_ e j` f Za d   Zb d   Zc eb   d   Zd d d  Zf d d  Zg d d  Zh e d    Zi d d  Zj d e] d  Zk d   Zl em d  Zn d d  d!  Zo e jp eq e jr e js  d" e jt d# f Zu e jp eq e) d$  jv e% e* e# d% d    e js  d" e jw d# f Zx d' d(  Zy d' d)  Zz d*   Z{ d+   Z| d d,  Z} d-   Z~ d.   Z d em e d/  Z e e j d0   Z e j d1  Z d2   Z e d3    Z d4   Z d5   Z d6   Z e d e] d7   Z e d8    Z e d9    Z d:   Z d em e] em em d; d<  Z em d= d>  Z d? d@  Z dA   Z dB   Z dC   Z em em dD dE  Z d dF dG  Z dH dI  Z dJ dK  Z dL dM  Z d dN  Z e] em d d dO dP  Z em e] e] dQ  Z em d em e] em e] e] em dR dS 	 Z em d d em e] em e] e] e] em e] dT dU  Z em e] e] e] e] dV dW  Z dX   Z em dY  Z dZ   Z em em em e] d[  Z em em em em em em e] d\ d]  Z em em em em em e] d^ d_  Z d`   Z da   Z db   Z dc d dd  Z dc d de  Z dc df d dg  Z dc d dh  Z dc d di  Z dc d dj  Z dc d dk  Z dc d dl  Z dc d dm  Z dc dn d do  Z dc dp d dq  Z dc d dr  Z dc d ds  Z dc dt  Z du   Z dc dv  Z d dw  Z d dx  Z d dy  Z dz   Z d dn d d{  Z d d d|  Z d dn d}  Z d d~  Z d dn d  Z d   Z d   Z d   Z d d  Z d d  Z d d  Z d e] d d d  Z em em d# d# d d d d d d d 
 Z d d  Z d d em em d# d# d d d d d d d  Z d d d  Z d   Z d e f d     YZ d   Z d Z d Z e e! j f Z e re e f 7Z n  e d  Z e d e^ e] e e e d   Z e Z d d  Z d e f d     YZ e e d d em d   Z d e f d     YZ e d    Z e d d   Z d d d  Z d eH f d     YZ d eA f d     YZ d e> j f d     YZ d e> j f d     YZ d e? f d     YZ e d    Z d d  Z d   Z d S(   i(   t   division(   t   contextmanager(   t   datetime(   t   wrapsN(   t   rmtree(   t   randt   randn(   t   testing(   t   PY2t   PY3t   Countert   callablet   filtert   httplibt   lmapt   lranget   lzipt   mapt   raise_with_tracebackt   ranget   string_typest   ut   unichrt   zip(   t   is_boolt   is_categorical_dtypet   is_datetime64_dtypet   is_datetime64tz_dtypet   is_datetimelike_v_numerict   is_datetimelike_v_objectt   is_extension_array_dtypet   is_interval_dtypet   is_list_liket	   is_numbert   is_period_dtypet   is_sequencet   is_timedelta64_dtypet   needs_i8_conversion(   t   array_equivalent(   t   Categoricalt   CategoricalIndext	   DataFramet   DatetimeIndext   Indext   IntervalIndext
   MultiIndext   Panelt
   RangeIndext   Seriest   bdate_range(   t   take_1d(   t   DatetimeArrayt   ExtensionArrayt   IntervalArrayt   PeriodArrayt   TimedeltaArrayt   period_array(   t   urlopen(   t   pprint_thingi   i   c          C   s8   t  j j d d  }  d |  k r4 t j d t  n  d  S(   Nt   PANDAS_TESTING_MODEt   Nonet	   deprecatet   always(   t   ost   environt   gett   warningst   simplefiltert   _testing_mode_warnings(   t   testing_mode(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   set_testing_mode6   s    c          C   s8   t  j j d d  }  d |  k r4 t j d t  n  d  S(   NR;   R<   R=   t   ignore(   R?   R@   RA   RB   RC   RD   (   RE   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   reset_testing_mode=   s    c           C   s   t  j d d t d S(   sJ   
    Reset the display options for printing and representing objects.
    s	   ^display.t   silentN(   t   pdt   reset_optiont   True(    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   reset_display_optionsG   s    c         C   sc   | d k r- t d j d t d    } n  t |  $ } t j |  |  t j |  SWd QXd S(   s  
    Pickle an object and then read it again.

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

    Returns
    -------
    round_trip_pickled_object : pandas object
        The original object that was pickled and then re-read.
    s   __{random_bytes}__.picklet   random_bytesi
   N(   R<   R   t   formatt   randst   ensure_cleanRJ   t	   to_picklet   read_pickle(   t   objt   path(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   round_trip_pickleO   s
    !c         C   sn   d d l  } | j d  j } | d k r3 d } n  t |  ) } |  | |   | | |   } Wd QX| S(   s  
    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
    -------
    round_trip_object : pandas object
        The original object that was serialized and then re-read.
    iNt   pathlibt   ___pathlib___(   t   pytestt   importorskipt   PathR<   RQ   (   t   writert   readerRU   RY   R[   RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   round_trip_pathlibg   s    	c         C   sn   d d l  } | j d  j } | d k r3 d } n  t |  ) } |  | |   | | |   } Wd QX| S(   s  
    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
    -------
    round_trip_object : pandas object
        The original object that was serialized and then re-read.
    iNs   py.patht   ___localpath___(   RY   RZ   t   localR<   RQ   (   R\   R]   RU   RY   t	   LocalPathRT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   round_trip_localpath   s    	c   
      c   si  | d k r t |  d  } n| d k rK d d l } | j |  d  } n | d k rx d d l } | j |  d  } n | d k r t j   } | j |  d  } n | d k rd d l } | j	 |   } | j
   } t |  d k r| j | j    } q5t d	 j |     n d
 j |  }	 t |	   z	 | VWd | j   | d k rd| j   n  Xd S(   s   
    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
    -------
    f : file object
    t   rbt   gzipiNt   bz2t   xzR   i   s)   ZIP file {} error. Only one file per ZIP.s!   Unrecognized compression type: {}(   R<   t   openRd   Re   t   BZ2Filet   compatt   import_lzmat   LZMAFilet   zipfilet   ZipFilet   namelistt   lent   popt
   ValueErrorRO   t   close(
   RU   t   compressiont   fRd   Re   t   lzmaRl   t   zip_filet	   zip_namest   msg(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   decompress_file   s4    		
t   testc         C   s  |  d k r$ d d l  } | j } n |  d k rH d d l } | j } nc |  d k rl d d l } | j } n? |  d k r t j   } | j } n d j	 |   }	 t
 |	   |  d k r d }
 | | f } d	 } n d
 }
 | f } d } | | d |
  } t | |  |   Wd QXd S(   s  
    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   iNRd   Re   Rf   s!   Unrecognized compression type: {}t   wt   writestrt   wbt   writet   mode(   Rl   Rm   Rd   t   GzipFileRe   Rh   Ri   Rj   Rk   RO   Rq   t   getattr(   Rs   RU   t   datat   destRl   t   compress_methodRd   Re   Ru   Rx   R   t   argst   methodRt   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   write_to_compressed   s.    		t   equivc      
   K   sD  t  |  t j  r4 t |  | d t d | d | | St  |  t j  rh t |  | d t d | d | | St  |  t j  r t |  | d t d | d | | S| r!t	 |   r t	 |  r q!t
 |   r t
 |  r q!t  |  t j  s t  | t j  rd } n d } t |  | d | n  t j |  | d | d | | Sd S(	   sw  
    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 / string {'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.
    t   check_exactt   exactt   check_less_preciset   check_dtypes   numpy arrayt   InputRT   N(   t
   isinstanceRJ   R+   t   assert_index_equalt   FalseR0   t   assert_series_equalR)   t   assert_frame_equalR!   R   t   npt   ndarrayt   assert_class_equalt   _testingt   assert_almost_equal(   t   leftt   rightR   R   t   kwargsRT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR     sB    		c      	   C   s   d } | j  } t |  |  sK t | j d | d | d t |      n  t | |  s t | j d | d | d t |     n  d S(   s  
    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`.
    s9   {name} Expected type {exp_type}, found {act_type} insteadt   namet   exp_typet   act_typeN(   t   __name__R   t   AssertionErrorRO   t   type(   R   R   t   clst   err_msgt   cls_name(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _check_isinstanceK  s    	c         C   s&   t  |  | t  t j |  | d | S(   Nt   compare_keys(   R   t   dictR   t   assert_dict_equal(   R   R   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   g  s    g      ?c         C   s   t  |    | k S(   N(   R   (   t   sizet   p(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   randboolm  s    t   dtypei   t    i  i   t   Oc         C   sa   t  j j t d |  t  j |  j t  j |  f  j |  } | d k rP | S| j	 |  Sd S(   s"   Generate an array of byte strings.R   N(
   R   t   randomt   choicet   RANDS_CHARSt   prodt   viewt   str_t   reshapeR<   t   astype(   t   ncharsR   R   t   retval(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   rands_arrayw  s
    %c         C   sa   t  j j t d |  t  j |  j t  j |  f  j |  } | d k rP | S| j	 |  Sd S(   s%   Generate an array of unicode strings.R   N(
   R   R   R   t   RANDU_CHARSR   R   t   unicode_R   R<   R   (   R   R   R   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   randu_array  s
    %c         C   s   d j  t j j t |    S(   st   
    Generate one random byte string.

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

    R   (   t   joinR   R   R   R   (   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRP     s    c         C   s   d j  t j j t |    S(   s   
    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   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   randu  s    c         C   sQ   d d l  m } m } |  d  k rC x( |   D] }  | |   q, Wn
 | |   d  S(   Ni(   t   get_fignumsRr   (   t   matplotlib.pyplotR   Rr   R<   (   t   fignumR   t   _close(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRr     s
    c          O   s   d | k r t  d   n  t j d t j d t j |  |  } | j   \ } } | j   } | r | j d  } | d k r |  d } n  t j | | d |  n  | S(   s  Run command with arguments and return its output as a byte string.

    If the exit code was non-zero it raises a CalledProcessError.  The
    CalledProcessError object will have the return code in the returncode
    attribute and output in the output attribute.

    The arguments are the same as for the Popen constructor.  Example:

    >>> check_output(["ls", "-l", "/dev/null"])
    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

    The stdout argument is not allowed as it is used internally.
    To capture standard error in the result, use stderr=STDOUT.

    >>> check_output(["/bin/sh", "-c",
    ...               "ls -l non_existent_file ; exit 0"],
    ...              stderr=STDOUT)
    'ls: non_existent_file: No such file or directory\n'
    t   stdouts3   stdout argument not allowed, it will be overridden.t   stderrR   i    t   outputN(	   Rq   t
   subprocesst   Popent   PIPEt   communicatet   pollRA   R<   t   CalledProcessError(   t	   popenargsR   t   processR   t
   unused_errt   retcodet   cmd(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   check_output  s    c          C   sT   y t  d g d t }  Wn4 t j k
 rO } t |  d j d |    n X|  S(   Ns	   locale -at   shellsC   {exception}, the 'locale -a' command cannot be found on your systemt	   exception(   R   RL   R   R   R   RO   (   t   raw_localest   e(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _default_locale_getter  s    c         C   s   y |   } Wn t  k
 r! d SXyh | j d  } g  } xL | D]D } t rr | j t | d t j j j	  qA | j t |   qA WWn t
 k
 r n X|  d k r t | |  St j d j d |    } | j d j |   } t | |  S(   s  Get all the locales that are available on the system.

    Parameters
    ----------
    prefix : str
        If not ``None`` then return only those locales with the prefix
        provided. For example to get all English language locales (those that
        start with ``"en"``), pass ``prefix="en"``.
    normalize : bool
        Call ``locale.normalize`` on the resulting list of available locales.
        If ``True``, only locales that can be set without throwing an
        ``Exception`` are returned.
    locale_getter : callable
        The function to use to retrieve the current locales. This should return
        a string with each locale separated by a newline character.

    Returns
    -------
    locales : list of strings
        A list of locale strings that can be set with ``locale.setlocale()``.
        For example::

            locale.setlocale(locale.LC_ALL, locale_string)

    On error will return None (no locale available, e.g. Windows)

    s   
t   encodings
   {prefix}.*t   prefixN(   t	   ExceptionR<   t   splitR	   t   appendt   strRJ   t   optionst   displayR   t	   TypeErrort   _valid_localest   ret   compileRO   t   findallR   (   R   t	   normalizet   locale_getterR   t   out_localest   xt   patternt   found(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   get_locales  s&    	c         c   si   t  j   } zE t  j | |   t  j   } t j |   rK d j |  Vn |  VWd t  j | |  Xd S(   s@  Context manager for temporarily setting a locale.

    Parameters
    ----------
    new_locale : str or tuple
        A string of the form <language_country>.<encoding>. For example to set
        the current locale to US English with a UTF8 encoding, you would pass
        "en_US.UTF-8".
    lc_var : int, default `locale.LC_ALL`
        The category of the locale being set.

    Notes
    -----
    This is useful when you want to run a particular block of code under a
    particular locale, without globally setting the locale. This probably isn't
    thread-safe.
    t   .N(   t   localet	   getlocalet	   setlocalet   comt   _all_not_noneR   (   t
   new_localet   lc_vart   current_localet   normalized_locale(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt
   set_locale  s    	c         C   sC   y t  |  d |  Wd QXWn t t j f k
 r: t SXt Sd S(   su  
    Check to see if we can set a locale, and subsequently get the locale,
    without raising an Exception.

    Parameters
    ----------
    lc : str
        The locale to attempt to set.
    lc_var : int, default `locale.LC_ALL`
        The category of the locale being set.

    Returns
    -------
    is_valid : bool
        Whether the passed locale can be set
    R   N(   R   Rq   R   t   ErrorR   RL   (   t   lcR   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   can_set_locale3  s    
c         C   s7   | r d   } n	 d   } t  t t t | |     S(   sm  Return a list of normalized locales that do not throw an ``Exception``
    when set.

    Parameters
    ----------
    locales : str
        A string where each locale is separated by a newline.
    normalize : bool
        Whether to call ``locale.normalize`` on each locale.

    Returns
    -------
    valid_locales : list
        A list of valid locales.
    c         S   s   t  j |  j    S(   N(   R   R   t   strip(   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   <lambda>`  s    c         S   s
   |  j    S(   N(   R   (   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   b  s    (   t   listR   R   R   (   t   localesR   t
   normalizer(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   O  s    	c         c   sV   t  s t d   n  t j   } t t  t j |   z	 d VWd t j |  Xd S(   s   
    Set default encoding (as given by sys.getdefaultencoding()) to the given
    encoding; restore on exit.

    Parameters
    ----------
    encoding : str
    s:   set_defaultencoding context is only available in Python 2.N(   R   Rq   t   syst   getdefaultencodingt   reloadt   setdefaultencoding(   R   t   orig(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   set_defaultencodingj  s    

	c         O   sr   d d l  m } y# d d l m } t d d  } Wn t k
 rR | } i  } n X| |   } | j |  | |  S(   Ni(   t   Pdbt   color_schemet   Linux(   t   pdbR  t   IPython.core.debuggerR   t   ImportErrort   runcall(   Rt   R   R   t   OldPdbR  t   kwR  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   debug  s    
c         O   s   d d  l  } | j |  | |  S(   Ni(   t   pudbR	  (   Rt   R   R   R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   pudebug  s    c          C   st   d d l  m }  y# |  d d  j t j   j  Wn: t k
 ro d d l m } |   j t j   j  n Xd  S(   Ni(   R  R  R  (   R  R  t	   set_traceR   t	   _getframet   f_backR   R  (   R  R
  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    #c         c   sN  |  p	 d }  d } | rD t j d |   } z	 | VWd | j   Xnt t j j |    rk t d   n  y t j	 d |   \ } }  Wn* t
 k
 r d d l } | j d  n Xz	 |  VWd y t j |  Wn( t k
 r d j d | d	 |   GHn Xy& t j j |   r!t j |   n  Wn$ t k
 rH} d
 j d |  GHn XXd S(   s  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   t   suffixNs-   Can't pass a qualified name to ensure_clean()is$   no unicode file names on this systems7   Couldn't close file descriptor: {fdesc} (file: {fname})t   fdesct   fnames#   Exception on removing file: {error}t   error(   R<   t   tempfilet   TemporaryFileRr   Ro   R?   RU   t   dirnameRq   t   mkstempt   UnicodeEncodeErrorRY   t   skipR   RO   t   existst   remove(   t   filenamet   return_fileliket   fdRt   RY   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRQ     s4    			c          c   sE   t  j d d  }  z	 |  VWd y t |   Wn t k
 r? n XXd S(   s{   
    Get a temporary directory path and agrees to remove on close.

    Yields
    ------
    Temporary directory path
    R  R   N(   R  t   mkdtempR   R   (   t   directory_name(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   ensure_clean_dir  s    		c          c   s=   t  t j  }  z	 d VWd t j j   t j j |   Xd S(   s   
    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@   t   cleart   update(   t   saved_environ(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt!   ensure_safe_environment_variables  s
    	c         C   s   t  |   t  |  k S(   sJ   Checks if the set of unique elements of arr1 and arr2 are equivalent.
    (   t	   frozenset(   t   arr1t   arr2(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   equalContents  s    R+   c            s|  t  } d    f d  }	 d   }
 t |  | t  |	 |  | d | |  j | j k r d j d |  } d j d |  j d |   } d	 j d | j d
 |  } t | | | |  n  t |   t |  k r3d j d |  } d j d t |   d |   } d j d t |  d
 |  } t | | | |  n  |  j d k rx t |  j  D] } |
 |  |  } |
 | |  } d j d |  } t | | d  d | d | d | d | |	 |  j	 | | j	 | d | qRWn  | re  re|  j
 |  st j |  j | j k j t   d t |   } d j d | d t j | d   } t | | |  |  qn4 t j |  j | j d | d  d | d |  d | | rt d |  | d | n  t |  t j  st | t j  rt d |  | d | n  t |  t j  st | t j  r/t |  j | j  n    rxt |   sMt |  rxt |  j | j d d j d |  qxn  d  S(!   s  Check that left and right Index are equal.

    Parameters
    ----------
    left : Index
    right : Index
    exact : bool / string {'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
    R+   c            s    r~ t  |  | d  d |   r> t d |  | d | n  |  j d k re | j d k s{ t  q~ t d |  | d | n  d  S(	   NR   RT   R   t   stringt   unicodet   inferred_type(   R,  R-  (   R,  R-  (   R   t   assert_attr_equalR.  R   (   t   lt   rRT   (   t   check_categoricalR   (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _check_types  s    c         S   sU   |  j  | } |  j | } t | j | d | j } | j | d |  j | } | S(   Nt
   fill_valueR   (   t   levelst   codesR2   t   valuest	   _na_valuet   _shallow_copyt   names(   t   indext   levelt   uniquet   labelst   filledR7  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _get_ilevel_values)  s
    RT   s   {obj} levels are differents   {nlevels}, {left}t   nlevelsR   s   {nlevels}, {right}R   s   {obj} length are differents   {length}, {left}t   lengths   {length}, {right}i   s   MultiIndex level [{level}]R<  R   t   check_namesR   R   g      Y@s$   {obj} values are different ({pct} %)t   pcti   R   t   lobjt   robjR:  t   freqs   {obj} categoryN(   RL   R   R+   RA  RO   t   raise_assert_detailRo   R   R   R5  t   equalsR   t   sumR7  R   t   intt   roundR   R   R/  R   RJ   t   PeriodIndexR,   t   assert_interval_array_equalR   t   assert_categorical_equal(   R   R   R   RC  R   R   R2  RT   t   __tracebackhide__R3  R@  t   msg1t   msg2t   msg3R<  t   llevelt   rlevelRE  t   diffRx   (    (   R2  R   s2   lib/python2.7/site-packages/pandas/util/testing.pyR     s\    		(2	$R   c         C   s   t  } d   } | d k r t |   t |  k r t |   j t |  j h } t | d d h  r d j d |  } t | | | |   | |   q q nU | r t |   t |  k r d j d |  } t | | | |   | |   q n  d S(	   s   checks classes are equal.c         S   sF   t  |  t  r |  Sy |  j j SWn t k
 rA t t |    SXd  S(   N(   R   R+   t	   __class__R   t   AttributeErrort   reprR   (   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt
   repr_classu  s    R   t
   Int64IndexR/   s    {obj} classes are not equivalentRT   s   {obj} classes are differentN(   RL   R   R   Ro   RO   RH  (   R   R   R   RT   RP  RZ  t   typesRx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   q  s    	
t
   Attributesc   	      C   s   t  } t | |   } t | |   } | | k r4 t  St |  rn t j |  rn t |  rn t j |  rn t  Sy | | k } Wn t k
 r t } n Xt | t  s | j	   } n  | r t  Sd j
 d |   } t | | | |  d S(   sK  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
    s    Attribute "{attr}" are differentt   attrN(   RL   R   R!   R   t   isnanR   R   R   t   boolt   allRO   RH  (	   R^  R   R   RT   RP  t	   left_attrt
   right_attrt   resultRx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR/    s$    
c         C   s   d d  l  j } t |  t j t j f  r x |  j   D]B } d j d | j	 j
  } t | | j t f  s7 t |   q7 Wn9 t |  | j t t f  s t d j d |  j	 j
    d  S(   NisJ   one of 'objs' is not a matplotlib Axes instance, type encountered {name!r}R   sq   objs is neither an ndarray of Artist instances nor a single Artist instance, tuple, or dict, "objs" is a {name!r}(   R   t   pyplotR   RJ   R0   R   R   t   ravelRO   RW  R   t   AxesR   R   t   Artistt   tuple(   t   objst   pltt   elRx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt"   assert_is_valid_plot_return_object  s    	+	c         C   s   t  |  d  S(   Nt   __iter__(   t   hasattr(   RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt
   isiterable  s    c         C   s@   t  |  t t f  r! |  j }  n  t |  t j t j |     S(   N(   R   R+   R0   R7  t   assert_numpy_array_equalR   t   sortt   array(   t   seq(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt	   is_sorted  s    R'   c      	   C   s   t  |  | t  | ri t |  j | j d d j d |  t |  j | j d | d d j d |  nn t |  j j   | j j   d d j d |  t |  j j |  j  | j j | j  d d j d |  t	 d |  | d | d S(   sv  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
    RT   s   {obj}.categoriesR   s   {obj}.codess   {obj}.valuest   orderedN(
   R   R'   R   t
   categoriesRO   Rq  R6  t   sort_valuest   takeR/  (   R   R   R   t   check_category_orderRT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRO    s    R5   c      	   C   s   t  |  | t  t |  j | j d | d d j d |  t |  j | j d | d d j d |  t d |  | d | d S(   s  Test that two IntervalArrays are equivalent.

    Parameters
    ----------
    left, right : IntervalArray
        The IntervalArrays to compare.
    exact : bool / string {'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
    R   RT   s
   {obj}.leftt   closedN(   R   R5   R   R   RO   R   R/  (   R   R   R   RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRN    s    R6   c         C   sO   t  |  | t  t |  j | j d d j d |  t d |  | d | d  S(   NRT   s   {obj}.valuesRG  (   R   R6   Rq  t   _dataRO   R/  (   R   R   RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_period_array_equal  s    R3   c         C   sk   t  } t |  | t  t |  j | j d d j d |  t d |  | d | t d |  | d | d  S(   NRT   s   {obj}._dataRG  t   tz(   RL   R   R3   Rq  R|  RO   R/  (   R   R   RT   RP  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_datetime_array_equal  s    R7   c         C   sU   t  } t |  | t  t |  j | j d d j d |  t d |  | d | d  S(   NRT   s   {obj}._dataRG  (   RL   R   R7   Rq  R|  RO   R/  (   R   R   RT   RP  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_timedelta_array_equal   s
    c      	   C   s%  t  } t | t j  r' t |  } n t |  rB t |  } n  t ri t | t  ri | j	 d  } n  t | t j  r t |  } n t |  r t |  } n  t r t | t  r | j	 d  } n  d j
 d |  d | d | d |  } | d  k	 r| d j
 d |  7} n  t |   d  S(	   Ns   utf-8s?   {obj} are different

{message}
[left]:  {left}
[right]: {right}RT   t   messageR   R   s   
[diff]: {diff}RV  (   RL   R   R   R   R:   R   RY  R   R   t   encodeRO   R<   R   (   RT   R  R   R   RV  RP  Rx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRH  (  s"    $s   numpy arrayc            sU  t  } t |  | d   t |  | t j  d   } | |   }	 | |  }
 | d k r |	 |
 k	 r d j d |	 d |
  } t |   q nB | d k r |	 |
 k r d j d |	 d |
  } t |   q n     f d	   } t |  | d
  s| |  | |  n  | rQt |  t j  rQt | t j  rQt	 d |  | d   qQn  t  S(   s   Checks that 'np.ndarray' is equivalent

    Parameters
    ----------
    left : np.ndarray or iterable
    right : np.ndarray or iterable
    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
    RT   c         S   s#   t  |  d d   d  k	 r |  j S|  S(   Nt   base(   R   R<   R  (   RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt	   _get_basef  s    t   sames   {left!r} is not {right!r}R   R   t   copys   {left!r} is {right!r}c            s   | d  k r |  j | j k rF t   d j d    |  j | j  n  d } x? t |  |  D]. \ } } t | | d  s\ | d 7} q\ q\ W| d |  j } d j d   d t j | d	   } t   | |  |  n  t	 |   d  S(
   Ns   {obj} shapes are differentRT   i    t
   strict_nani   g      Y@s$   {obj} values are different ({pct} %)RD  i   (
   R<   t   shapeRH  RO   R   R&   R   R   RL  R   (   R   R   R   RV  R0  R1  Rx   (   RT   R  (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _raisew  s    	R  R   (
   RL   R   R   R   R   RO   R   R&   R   R/  (   R   R   R  R   R   t
   check_sameRT   RP  R  t	   left_baset
   right_baseRx   R  (    (   RT   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyRq  I  s.    			$c   	   	   C   sL  t  |  t  s t d   t  | t  s6 t d   | rU t d |  | d d n  t |  d  r t |  t |   k r t |  j | j  d St 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 d d S(   s;  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.
    s   left is not an ExtensionArrays   right is not an ExtensionArrayR   RT   R4   t   asi8Ns   ExtensionArray NA maskR   R   (   R   R4   R   R/  Ro  R   Rq  R  R   t   asarrayt   isnaR   t   objectR   R   (	   R   R   R   R   R   t   left_nat   right_nat
   left_validt   right_valid(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_extension_array_equal  s$    'R0   c         C   sp  t  } t |  | t  | r: t |  t |   s: t  n  t |   t |  k r d j d t |   d |  j  } d j d t |  d | j  } t	 |
 d | |  n  t
 |  j | j d | d | d	 | d
 | d |	 d d j d |
  | r(t |   rt |  r|	 rq(t d |  |  n  | rbt |  j   | j   d | d d j d |
  n| rt |  |  st |  |  st |   st |  rt |  j  j t | j   sd j d |  j d | j  } t |   qqt |  j   | j   d | n t |   s)t |  r?t |  j | j  n t |  j  rt |  j  rt | j  srt  t |  j | j  St |   rt |   rt |  rt |  rt |  j | j  St j |  j   | j   d	 | d | d d j d |
  | r#t d |  | d |
 n  |	 rlt |   sAt |  rlt |  j | j d d j d |
  qln  d S(   s  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 / string {'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.
    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.
    obj : str, default 'Series'
        Specify object name being compared, internally used to show appropriate
        assertion message.
    s   {len}, {left}Ro   R   s   {len}, {right}R   s   Series length are differentR   RC  R   R   R2  RT   s   {obj}.indexR   R   s   {obj}s:   [datetimelike_compat=True] {left} is not equal to {right}.R   s   {obj} categoryN(    RL   R   R0   R   R   R   Ro   RO   R;  RH  R   R   R/  Rq  t
   get_valuesR   R   R%   R+   R7  RI  R   RN  Rs  R   R   R   R  t   _valuesR   R   RO  (   R   R   R   t   check_index_typet   check_series_typeR   RC  R   t   check_datetimelike_compatR2  RT   RP  RQ  RR  Rx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR     sj    &!!!	
R)   c         C   su  t  } t |  | t  | r: t |  t |   s: t  n  |  j | j k r t | d d j d |  j  d j d | j   n  | r |  j	 |  | }  } n  t
 |  j | j d | d | d | d |	 d | d	 d
 j d	 |  t
 |  j | j d | d | d | d |	 d | d	 d j d	 |  | r| j   } |  j   } x+t t t | j    t | j      D]K } | | k st  | | k st  t | | | | d | d	 d qrWn x t |  j  D] \ } } | | k st  |  j d d  | f } | j d d  | f } t | | d | d | d | d |	 d | d |
 d | d	 d j d |  qWd S(   s  
    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 / string {'equiv'}, default 'equiv'
        Whether to check the Index class, dtype and inferred_type
        are identical.
    check_column_type : bool / string {'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.
    check_names : bool, default True
        Whether to check that the `names` attribute for both the `index`
        and `column` attributes of the DataFrame is identical, i.e.

        * left.index.names == right.index.names
        * left.columns.names == right.columns.names
    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.util.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 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)
    s   DataFrame shape mismatchs	   {shape!r}R  R   RC  R   R   R2  RT   s   {obj}.indexs   {obj}.columnsR   s   DataFrame.blocksNR  R  s   DataFrame.iloc[:, {idx}]t   idx(   RL   R   R)   R   R   R   R  RH  RO   t   reindex_likeR   R;  t   columnst   _to_dict_of_blocksR   t   sett   keysR   t	   enumeratet   ilocR   (   R   R   R   R  t   check_column_typet   check_frame_typeR   RC  t	   by_blocksR   R  R2  t
   check_likeRT   RP  t   rblockst   lblocksR   t   it   colt   lcolt   rcol(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   E  sV    ]5R.   c         C   s  | r t  |  | d | n  xB |  j D]7 } t |  |  }	 t | |  }
 t |	 |
 d | q& W| r | j   } |  j   } xKt t t | j    t | j      D]E } | | k s t  | | k s t  t	 | | j
 | | j
  q Wn x t |  j d   D]i \ } } d j d |  } | | k sFt |   |  j | } | j | } t | | d | d | qWxM t | j d   D]6 \ } } d j d |  } | |  k st |   qWd S(	   s  Check that left and right Panels are equal.

    Parameters
    ----------
    left : Panel (or nd)
    right : Panel (or nd)
    check_dtype : bool, default True
        Whether to check the Panel dtype is identical.
    check_panel_type : bool, default False
        Whether to check the Panel 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
    check_names : bool, default True
        Whether to check the Index names attribute.
    by_blocks : bool, default False
        Specify how to compare internal data. If False, compare by columns.
        If True, compare by blocks.
    obj : str, default 'Panel'
        Specify the object name being compared, internally used to show
        the appropriate assertion message.
    RT   RC  i    s"   non-matching item (right) '{item}'t   itemR   s!   non-matching item (left) '{item}'N(   R   t   _AXIS_ORDERSR   R   R  R   R  R  R   R&   R7  R  t	   _get_axisRO   R  R   (   R   R   R   t   check_panel_typeR   RC  R  RT   t   axist   left_indt	   right_indR  R  R   R  R  Rx   t   litemt   ritem(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_panel_equal  s0    5"""c         K   sZ  t  } t |  t j  r+ t |  | |  n+t |  t j  rP t |  | |  nt |  t j  ru t |  | |  n t |  t	  r t
 |  | |  n t |  t  r t |  | |  n t |  t  r t |  | |  n{ t |  t  r t |  | |  nY t |  t  rt |  | |  n7 t |  t j  rDt |  | |  n t t |     d S(   s  
    Wrapper for tm.assert_*_equal to dispatch to the appropriate test function.

    Parameters
    ----------
    left : Index, Series, DataFrame, ExtensionArray, or np.ndarray
    right : Index, Series, DataFrame, ExtensionArray, or np.ndarray
    **kwargs
    N(   RL   R   RJ   R+   R   R0   R   R)   R   R5   RN  R6   R}  R3   R  R7   R  R4   R  R   R   Rq  t   NotImplementedErrorR   (   R   R   R   RP  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_equal   s(    
c         C   s  | t  j k r! t  j |   }  n | t  j k rB t  j |   }  n | t  j k r{ t  j |   j   }  | r|  j }  qn | t k r t |   }  n~ | t k r t |   }  nc | t	 k r t	 |   }  nH | t
 j k r t
 j |   }  n' | t k rt |   }  n t |   |  S(   s   
    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
    (   RJ   R+   R0   R)   t   to_framet   TR6   R8   R3   R7   R   R   Rs  t   to_arrayR  (   t   expectedt   box_clst	   transpose(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   box_expectedB  s(    c         C   se   t  |   r t |   St |   s. t |   r; t j |   St |   rT t j |   St j	 |   Sd  S(   N(
   R"   R8   R   R   R3   t   _from_sequenceR$   R7   R   Rs  (   RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  j  s    
c         C   sW  t  |  | t j  t |  j | j d | t |  j t j j j	  sM t
  t | j t j j j	  sn t
  | s |  j j   } | j j   } n |  j } | j } | r |  j d k r | j   j   } | j   j   } n  | j |  st d d | |  n  | r!t d |  |  n  | r:t d |  |  n  t |  j | j d | d S(   s#  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   t   blocks   SparseArray.indexs   index are not equalR4  R   N(   R   RJ   t   SparseArrayRq  t	   sp_valuesR   t   sp_indext   _libst   sparset   SparseIndexR   t   to_block_indext   kindt   to_int_indexRI  RH  R/  R7  (   R   R   R   t
   check_kindt   check_fill_valuet   consolidate_block_indicest
   left_indext   right_index(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_sp_array_equalz  s,    !!			t   SparseSeriesc
   
   	   C   s   t  |  | t j  | r/ t |  | d |	 n  t |  j | j d d j d |	  t |  j | j d | d | d | | r t	 d |  |  n  | r t	 d |  |  n  t
 t j |  j  t j | j   d S(	   s  Check that the left and right SparseSeries are equal.

    Parameters
    ----------
    left : SparseSeries
    right : SparseSeries
    check_dtype : bool, default True
        Whether to check the Series dtype is identical.
    exact_indices : bool, default True
    check_series_type : bool, default True
        Whether to check the SparseSeries class is identical.
    check_names : bool, default True
        Whether to check the SparseSeries name attribute.
    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.
    obj : str, default 'SparseSeries'
        Specify the object name being compared, internally used to show
        the appropriate assertion message.
    RT   s   {obj}.indexR  R  R  R   R   N(   R   RJ   R  R   R   R;  RO   R  R7  R/  Rq  R   R  (
   R   R   R   t   exact_indicesR  RC  R  R  R  RT   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_sp_series_equal  s    !t   SparseDataFramec	         C   sF  t  |  | t j  | r/ t |  | d | n  t |  j | j d d j d |  t |  j | j d d j d |  | r t d |  | d | n  x t	 j
 |   D]s \ }	 }
 |	 | k s t  | r t |
 | |	 d | d | d | d | q t |
 j   | |	 j   d | q Wx  | D] }	 |	 |  k s&t  q&Wd	 S(
   s  Check that the left and right SparseDataFrame are equal.

    Parameters
    ----------
    left : SparseDataFrame
    right : SparseDataFrame
    check_dtype : bool, default True
        Whether to check the Series dtype is identical.
    exact_indices : bool, default True
        SparseSeries SparseIndex objects must be exactly the same,
        otherwise just compare dense representations.
    check_frame_type : bool, default True
        Whether to check the SparseDataFrame class 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.
    obj : str, default 'SparseDataFrame'
        Specify the object name being compared, internally used to show
        the appropriate assertion message.
    RT   s   {obj}.indexs   {obj}.columnst   default_fill_valueR   R  R  R  N(   R   RJ   R  R   R   R;  RO   R  R/  Ri   t	   iteritemsR   R  R   t   to_dense(   R   R   R   R  R  R  R  R  RT   R  t   series(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_sp_frame_equal  s,     
c         C   s9   x2 |  D]* } | | k s t  d j d |    q Wd  S(   Ns   Did not contain item: '{key!r}'t   key(   R   RO   (   t   iterablet   dict   k(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_contains_all3  s    c         K   sp   xi t  |  |  D]X \ } } t | | |  d j d t |  d t |   } | | k	 s t |   q Wd S(   s   
    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)
    sd   Expected object {obj1!r} and object {obj2!r} to be different objects, but they were the same object.t   obj1t   obj2N(   R   R   RO   R   R   (   t   iter1t   iter2t
   eql_kwargst   elem1t   elem2Rx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_copy8  s
    		c         C   s   t  j |   S(   N(   R,  t   ascii_uppercase(   R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   getColsI  s    i
   c         C   s   t  t d d d |   d | S(   NR   i
   R   R   (   R+   R   (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeStringIndexN  s    c         C   s   t  t d d d |   d | S(   NR   i
   R   R   (   R+   R   (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeUnicodeIndexR  s    i   c         K   s7   t  d d d |  } t t j j | |   d | | S(   s'    make a length k index or n categories R   i   R   R   (   R   R(   R   R   R   (   R  t   nR   R   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeCategoricalIndexV  s    c         K   s2   t  j d d d |  d } t j | d | | S(   s    make a length k IntervalIndex i    id   t   numi   R   (   R   t   linspaceR,   t   from_breaks(   R  R   R   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeIntervalIndex\  s    c         C   sf   |  d k r t  t g d | S|  d k rA t  t t g d | St  t t g t g |  d d | S(   Ni   R   i   (   R+   RL   R   (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeBoolIndexb  s
    c         C   s   t  t |   d | S(   NR   (   R+   R   (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeIntIndexj  s    c         C   s-   t  g  t |   D] } d | ^ q d | S(   Ni   i?   R   l            (   R+   R   (   R  R   R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeUIntIndexn  s    c         K   s   t  d |  d d | | S(   Ni    i   R   (   R/   (   R  R   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeRangeIndexr  s    c         C   sO   t  t j j |    t j j d  } t | d t j j d d  d | S(   Ni   i
   i    i	   R   (   t   sortedR   R   t   random_sampleR+   t   randint(   R  R   R7  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeFloatIndexv  s    (t   Bc         K   sC   t  d d d  } t | d |  d | d | } t | d | | S(   Ni  i   t   periodsRG  R   (   R   R1   R*   (   R  RG  R   R   t   dtt   dr(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeDateIndex{  s    t   Dc      
   K   s%   t  j d d d |  d | d | |  S(   Nt   starts   1 dayR  RG  R   (   RJ   t   timedelta_range(   R  RG  R   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeTimedeltaIndex  s    c      
   K   s=   t  d d d  } t j d | d |  d d d | |  } | S(   Ni  i   R  R  RG  R  R   (   R   RJ   t   period_range(   R  R   R   R  R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makePeriodIndex  s    'c         K   s   t  j d d f d | | S(   Nt   foot   bari   i   R:  (   R  R  (   i   i   (   R-   t   from_product(   R  R:  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeMultiIndex  s    c         c   sJ   t  t t t t t t t t t	 t
 g } x | D] } | d |   Vq. Wd S(   s   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  R  R  R  R  R  R  R  R  R  R  (   R  t   all_make_index_funcst   make_index_func(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   all_index_generator  s    				c          c   s5   t  t t t t t t g }  x |  D] } | Vq" Wd  S(   N(   R  R  R  R  R  R  R  (   t   make_index_funcsR	  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   index_subclass_makers_generator  s    	c         c   s2   t  t t g } x | D] } | d |   Vq Wd S(   s   Generator which can be iterated over to get instances of all the classes
    which represent time-seires.

    Parameters
    ----------
    k: length of each of the index instances
    R  N(   R  R  R  (   R  R  R	  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   all_timeseries_index_generator  s    c         C   s(   t  t  } t t t  d | d |  S(   NR;  R   (   R  t   NR0   R   (   R   R;  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeFloatSeries  s    c         C   s(   t  t  } t t t  d | d |  S(   NR;  R   (   R  R  R0   R   (   R   R;  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeStringSeries  s    c         C   s@   t  t  } t | d t } t t  } t | d | d |  S(   NR   R;  R   (   R  R  R+   R  R  R0   (   R   t	   dateIndexR;  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeObjectSeries  s    c              s&   t  t      f d   t t  D S(   Nc            s+   i  |  ]! } t  t t  d    |  q S(   R;  (   R0   R   R  (   t   .0t   c(   R;  (    s2   lib/python2.7/site-packages/pandas/util/testing.pys
   <dictcomp>  s   	 (   R  R  R  t   K(    (    (   R;  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   getSeriesData  s    c         C   s=   |  d  k r t }  n  t t |   d t |  d | d | S(   NR;  RG  R   (   R<   R  R0   R   R  (   t   nperRG  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeTimeSeries  s    	c         C   s7   |  d  k r t }  n  t t |   d t |   d | S(   NR;  R   (   R<   R  R0   R   R  (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makePeriodSeries  s    	c            s      f d   t  t  D S(   Nc            s"   i  |  ] } t      |  q S(    (   R  (   R  R  (   RG  R  (    s2   lib/python2.7/site-packages/pandas/util/testing.pys
   <dictcomp>  s   	 (   R  R  (   R  RG  (    (   RG  R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   getTimeSeriesData  s    c            s     f d   t  t  D S(   Nc            s   i  |  ] } t     |  q S(    (   R  (   R  R  (   R  (    s2   lib/python2.7/site-packages/pandas/util/testing.pys
   <dictcomp>  s   	 (   R  R  (   R  (    (   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   getPeriodData  s    c         C   s   t  |  |  } t |  S(   N(   R  R)   (   R  RG  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeTimeDataFrame  s    c          C   s   t    }  t |   S(   N(   R  R)   (   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeDataFrame  s    	c          C   s   t  d d d d d g  }  i d d d d	 d
 g d 6d d d d d g d 6d d d d d g d 6t d d d d 6} |  | f S(   Nt   at   bR  t   dR   g        g      ?g       @g      @g      @t   AR  t   foo1t   foo2t   foo3t   foo4t   foo5t   Cs   1/1/2009R  i   R  (   R+   R1   (   R;  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   getMixedTypeDict  s    c           C   s   t  t   d  S(   Ni   (   R)   R(  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeMixedDataFrame  s    c         C   s   t  |   } t |  S(   N(   R  R)   (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makePeriodFrame  s    c            s{   t  j d t  c t  j d d t  g  t j t d  D] } d | ^ q8 }   f d   | D } t j	 |  SWd  QXd  S(   Nt   recordRG   s   \nPaneli   t   Itemc            s   i  |  ] } t     |  q S(    (   R  (   R  R  (   R  (    s2   lib/python2.7/site-packages/pandas/util/testing.pys
   <dictcomp>
  s   	 (
   RB   t   catch_warningsRL   t   filterwarningst   FutureWarningR,  R  R  R.   t   fromDict(   R  R  t   colsR   (    (   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt	   makePanel  s
    (c            s{   t  j d t  c t  j d d t  g  t j t d  D] } d | ^ q8 }   f d   | D } t j	 |  SWd  QXd  S(   NR+  RG   s   \nPaneli   R,  c            s   i  |  ] } t     |  q S(    (   R*  (   R  R  (   R  (    s2   lib/python2.7/site-packages/pandas/util/testing.pys
   <dictcomp>  s   	 (
   RB   R-  RL   R.  R/  R,  R  R  R.   R0  (   R  R  R1  R   (    (   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makePeriodPanel  s
    (t   #c         C   s[  | d k r d g | } n  t |  r: t |  | k s@ t  | d k s| | t k s| | t k s| t |  | k s| t  | d k s | d k r | d k s t  | t k r g  t |  D] } | t |  ^ q } n  | t k r d } n  t | t	 j
  r| d k r| g } n  t d t d t d t d t d t d t d t  j |  } | r| |   } | r| d	 | _ n  | S| d k	 rt d
 j d |    n  t |  | k  r| j d g | t |   n  t |  | k st  t d   | D  st  g  }	 x t |  D] } d   }
 |  | | d } t   } x@ t |  D]2 } d j d | d | d |  } | | | | <q]Wt t | j   d |
  |   } |	 j |  q&Wt |	   }	 |  d k rt |	 d	 d | d	 } n\ | d k rB| d k rd n | d	 } t d   |	 D d | } n t  j! |	 d | } | S(   s  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.
    i   R  Rt   t   sR   R  R   t   tdi    sT   "{idx_type}" is not a legal value for `idx_type`, use  "i"/"f"/"s"/"u"/"dt/"p"/"td".t   idx_typec         s   s   |  ] } | d  k Vq d S(   i    N(    (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pys	   <genexpr>V  s    c         S   s7   d d  l  } | j d d |   j d  } t t |  S(   Nis   [^\d_]_?R   t   _(   R   t   subR   R   RK  (   R   R   t   numeric_tuple(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   keyfuncZ  s    s   {prefix}_l{i}_g{j}R   t   jR  R   c         s   s   |  ] } | d  Vq d S(   i    N(    (   R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pys	   <genexpr>q  s    R:  N(   R  Rt   R5  R   R  R   R6  ("   R<   R#   Ro   R   R   RL   R   R   R   Ri   R   R   R  R  R  R  R  R  R  RA   R   Rq   RO   t   extendRa  R
   R   R  t   elementsR   R   R+   R-   t   from_tuples(   t   nentriesRA  R   R:  t   ndupe_lR7  R  t   idx_funcR  t   tuplesR;  t
   div_factort   cntR<  t   labelRd  R;  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeCustomIndex  s`    $$	,	!		"c         C   s;  | d k s t   | d k s$ t   | d k sN | d k rH | d	 k sN t   |
 d k sx |
 d k rr | d	 k sx t   t | d
 | d d d | d | d |
 } t |  d
 | d d d | d | d | } | d k r d   } n  g  t |   D]. } g  t |  D] } | | |  ^ q^ q } t | | | d |	 S(   s	  
   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 conjuncion 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)
    i    R  Rt   R5  R   R  R   R6  i   RA  R   R'  R:  RA  R7  t   Rc         S   s   d j  d |  d |  S(   Ns   R{rows}C{cols}t   rowsR1  (   RO   (   R1  R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR     s    R   N(   R  Rt   R5  R   R  R   R6  (   R  Rt   R5  R   R  R   R6  (   R   R<   RG  R   R)   (   t   nrowst   ncolst   c_idx_namest   r_idx_namest   c_idx_nlevelst   r_idx_nlevelst
   data_gen_ft	   c_ndupe_lt	   r_ndupe_lR   t
   c_idx_typet
   r_idx_typeR  R;  R1  R  R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeCustomDataframew  s$    ;				Ac            s  | d  k r t j } n t j j |  } t t j d |       d } d } t  | |   }     f d   } | | |  } x, | j  k  r | d 9} | | |  } q Wt j | d   j	 t  }	 | |	  j	 t  }
 |
 j
   |	 j
   f S(   Ni   i   gRQ?c            s7   |  j  t |   } t j t j |        S(   N(   R   RK  R   R=  t   floor(   t   rngt   _extra_sizet   ind(   RK  RJ  R   (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _gen_unique_rand  s    g?g      ?(   R<   R   R   t   RandomStateRK  RL  t   minR   RV  R   t   tolist(   RJ  RK  t   densityt   random_statet   min_rowst   fact
   extra_sizeRZ  RY  R<  R  (    (   RK  RJ  R   s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _create_missing_idx  s    !
 g?c         C   s   t  |  | d | d | d | d | d | d |	 d |
 d | d	 | d
 | 
} t |  | | |  \ } } t j | j | | f <| S(   s[  
    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.
    RL  RM  RN  RO  RP  RQ  RR  R   RS  RT  (   RU  Rc  R   t   nanR7  (   RJ  RK  R^  R_  RL  RM  RN  RO  RP  RQ  RR  R   RS  RT  t   dfR  R<  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeMissingCustomDataframe  s    	c         C   sD   t    } t d |  d | | j  \ } } t j | j | | f <| S(   NR^  R_  (   R  Rc  R  R   Rd  R7  (   R^  R_  Re  R  R<  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   makeMissingDataframe	  s
    	c   	      C   su   |  j  \ } } } x\ t |  j  D]K \ } } |  | } x2 t | j  D]! \ } } t j | | | | *qH Wq" W|  S(   N(   R  R  t   itemsR  R   t   NaN(	   t   panelt   It   JR  R  R  t   dmR<  R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   add_nans	  s    
t   TestSubDictc           B   s   e  Z d    Z RS(   c         O   s   t  j |  | |  d  S(   N(   R   t   __init__(   t   selfR   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRp  	  s    (   R   t
   __module__Rp  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRo  	  s   c            s   t       f d    } | S(   s8  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             sf       f d   }  o; t     d k o; t   d  } | r^   d } g    | |  S| Sd  S(   Nc            s    |      S(   N(    (   Rt   (   R   t	   decoratorR   (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   dec(	  s    i   i    (   Ro   R   (   R   R   Rt  t   is_decoratingRt   (   Rs  (   R   R   s2   lib/python2.7/site-packages/pandas/util/testing.pyt   wrapper&	  s    )

(   R   (   Rs  Rv  (    (   Rs  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   optional_args	  s    
s	   timed outs   Server Hangups#   HTTP Error 503: Service Unavailables   502: Proxy Errors   HTTP Error 502: internal errors   HTTP Error 502s   HTTP Error 503s   HTTP Error 403s   HTTP Error 400s$   Temporary failure in name resolutions   Name or service not knowns   Connection refuseds   certificate verifyie   io   in   ih   i6   i<   c         C   s4   y t  |    Wd QXWn | k
 r+ t SXt Sd S(   s;  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
    N(   R9   R   RL   (   t   urlt   error_classes(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   can_connect`	  s    
s   http://www.google.comc      	      sP   d d l  m  t  _ t j            f d    } | S(   s^  
    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.util.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.
    i(   R  c             sg   r)  r) t     s)    q) n  y  |  |   SWn&t k
 rb} t | d d   } | r t | d  r t | j d d   } n  |  k r  d j d |   n  y t j |    Wn t k
 r t	 |    n Xt
   f d    D  r d j d |   n  t |   s.  n   sCt     rI  qc d j d |   n Xd  S(   Nt   errnot   reasons2   Skipping test due to known errno and error {error}R  c         3   s'   |  ] } | j      j    k Vq d  S(   N(   t   lower(   R  t   m(   t   e_str(    s2   lib/python2.7/site-packages/pandas/util/testing.pys	   <genexpr>	  s    sB   Skipping test because exception message is known and error {error}s;   Skipping test due to lack of connectivity and error {error}(   Rz  R   R   R<   Ro  R|  RO   t	   tracebackt
   format_excR   t   anyR   (   R   R   R   R{  (   t   _skip_on_messagest   check_before_testRy  t   raise_on_errorR  t   skip_errnost   tRx  (   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyRv  	  s2    (   RY   R  RL   t   networkRi   R   (   R  Rx  R  R  Ry  R  R  Rv  (    (   R  R  Ry  R  R  R  R  Rx  s2   lib/python2.7/site-packages/pandas/util/testing.pyR  x	  s    Z	3"c         O   s\   t  j d t d d t d |  d |  } | d k	 rT |  | | |   Wd QXn | Sd S(   s  
    Check that the specified Exception is raised and that the error message
    matches a given regular expression pattern. This may be a regular
    expression object or a string containing a regular expression suitable
    for use by `re.search()`. This is a port of the `assertRaisesRegexp`
    function from unittest in Python 2.7.

    .. deprecated:: 0.24.0
        Use `pytest.raises` instead.

    Examples
    --------
    >>> assert_raises_regex(ValueError, 'invalid literal for.*XYZ', int, 'XYZ')
    >>> import re
    >>> assert_raises_regex(ValueError, re.compile('literal'), int, 'XYZ')

    If an exception of a different type is raised, it bubbles up.

    >>> assert_raises_regex(TypeError, 'literal', int, 'XYZ')
    Traceback (most recent call last):
        ...
    ValueError: invalid literal for int() with base 10: 'XYZ'
    >>> dct = dict()
    >>> assert_raises_regex(KeyError, 'pear', dct.__getitem__, 'apple')
    Traceback (most recent call last):
        ...
    AssertionError: "pear" does not match "'apple'"

    You can also use this in a with statement.

    >>> with assert_raises_regex(TypeError, r'unsupported operand type\(s\)'):
    ...     1 + {}
    >>> with assert_raises_regex(TypeError, 'banana'):
    ...     'apple'[0] = 'b'
    Traceback (most recent call last):
        ...
    AssertionError: "banana" does not match "'str' object does not support \
item assignment"
    st   assert_raises_regex has been deprecated and will be removed in the next release. Please use `pytest.raises` instead.t
   stackleveli   R   t   regexpN(   RB   t   warnR/  t   _AssertRaisesContextmanagerR<   (   t
   _exceptiont   _regexpt	   _callableR   R   t   manager(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_raises_regex	  s    )	R  c           B   s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   s7   
    Context manager behind `assert_raises_regex`.
    c         C   sJ   | |  _  | d k	 r= t | d  r= t j | t j  } n  | |  _ d S(   s  
        Initialize an _AssertRaisesContextManager instance.

        Parameters
        ----------
        exception : class
            The expected Exception class.
        regexp : str, default None
            The regex to compare against the Exception message.
        t   searchN(   R   R<   Ro  R   R   t   DOTALLR  (   Rq  R   R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRp  7
  s    	c         C   s   |  S(   N(    (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt	   __enter__J
  s    c         C   sU   |  j  } | sB t | d t |   } t d j d |    n  |  j | | |  S(   NR   s   {name} not raised.R   (   R   R   R   R   RO   t   exception_matches(   Rq  t   exc_typet	   exc_valuet
   trace_backR  t   exp_name(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   __exit__M
  s
    	c         C   s   t  | |  j  r |  j d k	 r| t |  } |  j j |  s| d j d |  j j d |  } t |  } t	 | |  q| n  t
 St Sd S(   s  
        Check that the Exception raised matches the expected Exception
        and expected error message regular expression.

        Parameters
        ----------
        exc_type : class
            The type of Exception raised.
        exc_value : Exception
            The instance of `exc_type` raised.
        trace_back : stack trace object
            The traceback object associated with `exc_value`.

        Returns
        -------
        is_matched : bool
            Whether or not the Exception raised matches the expected
            Exception class and expected error message regular expression.

        Raises
        ------
        AssertionError : The error message provided does not match
                         the expected error message regular expression.
        s   "{pat}" does not match "{val}"t   patt   valN(   t
   issubclassR   R  R<   R   R  RO   R   R   R   RL   R   (   Rq  R  R  R  R  Rx   R   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  V
  s    	N(   R   Rr  t   __doc__R<   Rp  R  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  2
  s
   			R>   c         c   s  t  } t j d t   } | d k	 rx t |  s? | g } n  x6 | D]+ } y | j j   WqF t k
 rp qF XqF Wn  t } t j	 |  | Vg  } x | D] }	 |  rWt
 |	 j |   rWt  } | rt
 |	 j t t f  rd d l m }
 m } |
 |   d d  } d j d |	 j d | j d	 |	 j  } |	 j | j k sTt |   qq | j |	 j j |	 j |	 j |	 j f  q W|  rd
 j d |  j  } | st |   n  | st d j d |    Wd QXd S(   sB	  
    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, 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.

    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.
    R+  i(   t   getframeinfot   stacki   i    sw   Warning not set with correct stacklevel. File where warning is raised: {actual} != {caller}. Warning message: {message}t   actualt   callerR  s/   Did not see expected warning of class {name!r}.R   s(   Caused unexpected warning(s): {extra!r}.t   extraN(   RL   RB   R-  R<   R    t   __warningregistry__R$  R   R   RC   R  t   categoryR/  t   DeprecationWarningt   inspectR  R  RO   R  R  R   R   R   t   lineno(   t   expected_warningt   filter_levelR$  t   check_stacklevelRP  R{   R~  t   saw_warningt   extra_warningst   actual_warningR  R  R  Rx   (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   assert_produces_warning
  sL    <				$	t
   RNGContextc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s-  
    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(   t   seed(   Rq  R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyRp     s    c         C   s)   t  j j   |  _ t  j j |  j  d  S(   N(   R   R   t	   get_statet   start_stateR  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    c         C   s   t  j j |  j  d  S(   N(   R   R   t	   set_stateR  (   Rq  R  R  R  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    (   R   Rr  R  Rp  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  
  s   		c         k   s\   d d l  } d d d h } |  | k r6 t d   n  | j |  |  d V| j |   d S(   su  
    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.
    iNt   excels	   excel-tabt   unixs    Cannot override builtin dialect.(   t   csvRq   t   register_dialectt   unregister_dialect(   R   R   R  t   _BUILTIN_DIALECTS(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   with_csv_dialect  s    c         c   so   d d l  m } | d  k r( | j } n  | j } | j } | j |   | | _ d  V| | _ | j |  d  S(   Ni(   t   expressions(   t   pandas.core.computationR  R<   t   _MIN_ELEMENTSt   _USE_NUMEXPRt   set_use_numexpr(   t   uset   min_elementst   exprt   olduset   oldmin(    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   use_numexpr,  s    				i   c            sg    d k s t    d k	     r? t    k s? t   n  d d l       f d   } | S(   s  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

    i    iNc            s+   t           f d    } | S(   Nc             s    r    f d   } n   f d   } g  } xK t    D]= } | |  }  j d  d |  d |  } | j |  q= Wx | D] } | j   q Wx | D] } | j   q Wd  S(   Nc            s   t     |   S(   N(   R   (   R  (   R   t   kwargs_list(    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   Y  s    c            s     S(   N(    (   R  (   R   (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR   [  s    t   targetR   R   (   R   t   ThreadR   R  R   (   R   R   t   update_kwargst   threadsR  t   updated_kwargst   thread(   t   funct   has_kwargs_listR  t   num_threadst	   threading(   R   s2   lib/python2.7/site-packages/pandas/util/testing.pyt   innerV  s    	(   R   (   R  R  (   R  R  R  R  (   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyRv  U  s    '(   R   R<   Ro   R  (   R  R  Rv  (    (   R  R  R  R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   test_parallel;  s    t   SubclassedSeriesc           B   s2   e  Z d  d g Z e d    Z e d    Z RS(   t   testattrR   c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _constructorm  s    c         C   s   t  S(   N(   t   SubclassedDataFrame(   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _constructor_expanddimq  s    (   R   Rr  t	   _metadatat   propertyR  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  j  s   R  c           B   s/   e  Z d  g Z e d    Z e d    Z RS(   R  c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  y  s    c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _constructor_sliced}  s    (   R   Rr  R  R  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR  v  s   	t   SubclassedSparseSeriesc           B   s/   e  Z d  g Z e d    Z e d    Z RS(   R  c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    c         C   s   t  S(   N(   t   SubclassedSparseDataFrame(   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    (   R   Rr  R  R  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s   	R  c           B   s/   e  Z d  g Z e d    Z e d    Z RS(   R  c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    (   R   Rr  R  R  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s   	t   SubclassedCategoricalc           B   s   e  Z e d     Z RS(   c         C   s   t  S(   N(   R  (   Rq  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    (   R   Rr  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s   c         #   sa   d d l    d d l     f d   }   j j d  } | |   z	 d VWd | |  Xd S(   s  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'
    iNc            sL   |  d  k r1 y   j d =WqH t k
 r- qH Xn |    j d < j   d  S(   Nt   TZ(   R<   R@   t   KeyErrort   tzset(   R~  (   R?   t   time(    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   setTZ  s    R  (   R?   R  R@   RA   (   R~  R  t   orig_tz(    (   R?   R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   set_timezone  s    

	c            s+    r  f d   } n   f d   } | S(   sl  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
    -------
    skipna_wrapper : function
    c            s     |  j   S(   N(   R7  (   R   (   t   skipna_alternative(    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   skipna_wrapper  s    c            s/   |  j    } t |  d k r% t j S  |  S(   Ni    (   t   dropnaRo   R   Rd  (   R   t   nona(   t   alternative(    s2   lib/python2.7/site-packages/pandas/util/testing.pyR    s    (    (   R  R  R  (    (   R  R  s2   lib/python2.7/site-packages/pandas/util/testing.pyt   _make_skipna_wrapper  s    c         C   s    t  j } | j |   | } | S(   ss  
    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
        The list of string. Each element represents the row of csv.

    Returns
    -------
    expected : string
        Expected output of to_csv() in current OS
    (   R?   t   linesepR   (   t	   rows_listt   sepR  (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   convert_rows_list_to_csv_str  s    	(    i  (   s	   timed outs   Server Hangups#   HTTP Error 503: Service Unavailables   502: Proxy Errors   HTTP Error 502: internal errors   HTTP Error 502s   HTTP Error 503s   HTTP Error 403s   HTTP Error 400s$   Temporary failure in name resolutions   Name or service not knowns   Connection refuseds   certificate verify(   ie   io   in   ih   i6   i<   (   t
   __future__R    t
   contextlibR   R   t	   functoolsR   R   R?   R   t   shutilR   R,  R   R   R  R  RB   t   numpyR   t   numpy.randomR   R   t   pandas._libsR   R   t   pandas.compatRi   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   t   pandas.core.dtypes.commonR   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   t   pandas.core.dtypes.missingR&   t   pandasRJ   R'   R(   R)   R*   R+   R,   R-   R.   R/   R0   R1   t   pandas.core.algorithmsR2   t   pandas.core.arraysR3   R4   R5   R6   R7   R8   t   pandas.core.commont   coret   commonR   t   pandas.io.commonR9   t   pandas.io.formats.printingR:   R  R  R   t   _RAISE_NETWORK_ERROR_DEFAULTR  t   ResourceWarningRD   RF   RH   RM   R<   RV   R^   Rb   Ry   R   R   R   RL   R   R   Rs  R   t   ascii_letterst   digitsR   R   R   R   R   R   R   RP   R   Rr   R   R   R   t   LC_ALLR   R   R   R  R  R  R  RQ   R#  R'  R+  R   R   R/  Rm  Rp  Ru  RO  RN  R}  R  R  RH  Rq  R  R   R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R
  R  R  R  R  R  R  R  R  R  R  R  R  R(  R)  R*  R2  R3  RG  RU  Rc  Rf  Rg  Rn  R   Ro  Rw  t   _network_error_messagest   _network_errno_valst   IOErrort   HTTPExceptiont   _network_error_classest   TimeoutErrorRz  R  t   with_connectivity_checkR  R  R  t   WarningR  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s2   lib/python2.7/site-packages/pandas/util/testing.pyt   <module>   s  j^L.			21G	-

	
	
	#		9				/	q(			%
!J0v9	"(	92C									`		Q				                 	|5Nm/,