
\c           @` s  d  d l  m Z m Z m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z m Z m Z d  d l m Z d	 d
 l m Z m Z m Z m Z m Z m Z m Z m  Z  d	 d l! m" Z" d	 d l# m$ Z$ m% Z% m& Z' d	 d l( m) Z) d	 d l* m+ Z+ m, Z, d	 d l- m. Z. m/ Z/ m0 Z0 d= Z1 d   Z2 d e3 f d     YZ4 d d d  Z6 d   Z7 d   Z8 e9 d  Z: d   Z; d   Z< d    Z= d!   Z> d"   Z? d#   Z@ d$   ZA e+   ZB eB jC eD e eE eF e eG eH d  eH eI eJ eH eK  f e  eB jC eL  d%    ZM eB jC e  d&    ZN eB jC eO  d'    ZP eB jC eQ eR f  d(    ZS eB jC e3  d)    ZT i  ZU e jV   ZW d*   ZX d+   ZY eB jZ d,  d-    Z[ eB jZ d.  d/    Z\ eB jZ d0  d1    Z] d2   Z^ i e/ j_ d3 6e/ j_ d4 6e/ j_ d5 6e0 j& d6 6e0 j& d7 6Z` y d  d8 la mb Zc Wn ed k
 rn" Xe` je i ec j& d9 6ec j& d: 6 d; jf   Zg d d d d d<  Zh d S(>   i    (   t   absolute_importt   divisiont   print_function(   t   OrderedDict(   t   partial(   t   md5(   t   getitemN(   t   merget   groupbyt   curryt   identity(   t   Composei   (   t   applyt   longt   unicodet   Iteratort   is_dataclasst   dataclass_fieldst   Mappingt   cPickle(   t   thread_state(   t   flattent   quotet   get(   t   hash_buffer_hex(   t   Dispatcht   ensure_dict(   t   configt   localt   threadedt   DaskMethodsMixint   is_dask_collectiont   computet   persistt   optimizet	   visualizet   tokenizet   normalize_tokenc         C` s3   y |  j    d k	 SWn t t f k
 r. t SXd S(   s.   Returns ``True`` if ``x`` is a dask collectionN(   t   __dask_graph__t   Nonet   AttributeErrort	   TypeErrort   False(   t   x(    (    s(   lib/python2.7/site-packages/dask/base.pyR      s    c           B` s8   e  Z d  Z d Z d d e d  Z d   Z d   Z RS(   s/   A mixin adding standard dask collection methodst   mydaskc      	   K` s   t  |  d | d | d | | S(   s  Render the computation of this object's task graph using graphviz.

        Requires ``graphviz`` to be installed.

        Parameters
        ----------
        filename : str or None, optional
            The name (without an extension) of the file to write to disk.  If
            `filename` is None, no file will be written, and we communicate
            with dot using only pipes.
        format : {'png', 'pdf', 'dot', 'svg', 'jpeg', 'jpg'}, optional
            Format in which to write output file.  Default is 'png'.
        optimize_graph : bool, optional
            If True, the graph is optimized before rendering.  Otherwise,
            the graph is displayed as is. Default is False.
        color: {None, 'order'}, optional
            Options to color nodes.  Provide ``cmap=`` keyword for additional
            colormap
        **kwargs
           Additional keyword arguments to forward to ``to_graphviz``.

        Examples
        --------
        >>> x.visualize(filename='dask.pdf')  # doctest: +SKIP
        >>> x.visualize(filename='dask.pdf', color='order')  # doctest: +SKIP

        Returns
        -------
        result : IPython.diplay.Image, IPython.display.SVG, or None
            See dask.dot.dot_graph for more information.

        See Also
        --------
        dask.base.visualize
        dask.dot.dot_graph

        Notes
        -----
        For more information on optimization see here:

        https://docs.dask.org/en/latest/optimize.html
        t   filenamet   formatt   optimize_graph(   R#   (   t   selfR-   R.   R/   t   kwargs(    (    s(   lib/python2.7/site-packages/dask/base.pyR#   +   s    ,c         K` s   t  |  d t | \ } | S(   s  Persist this dask collection into memory

        This turns a lazy Dask collection into a Dask collection with the same
        metadata, but now with the results fully computed or actively computing
        in the background.

        The action of function differs significantly depending on the active
        task scheduler.  If the task scheduler supports asynchronous computing,
        such as is the case of the dask.distributed scheduler, then persist
        will return *immediately* and the return value's task graph will
        contain Dask Future objects.  However if the task scheduler only
        supports blocking computation then the call to persist will *block*
        and the return value's task graph will contain concrete Python results.

        This function is particularly useful when using distributed systems,
        because the results will be kept in distributed memory, rather than
        returned to the local process as with compute.

        Parameters
        ----------
        scheduler : string, optional
            Which scheduler to use like "threads", "synchronous" or "processes".
            If not provided, the default is to check the global settings first,
            and then fall back to the collection defaults.
        optimize_graph : bool, optional
            If True [default], the graph is optimized before computation.
            Otherwise the graph is run as is. This can be useful for debugging.
        **kwargs
            Extra keywords to forward to the scheduler function.

        Returns
        -------
        New dask collections backed by in-memory data

        See Also
        --------
        dask.base.persist
        t   traverse(   R!   R*   (   R0   R1   t   result(    (    s(   lib/python2.7/site-packages/dask/base.pyR!   Z   s    'c         K` s   t  |  d t | \ } | S(   s  Compute this dask collection

        This turns a lazy Dask collection into its in-memory equivalent.
        For example a Dask.array turns into a  :func:`numpy.array` and a Dask.dataframe
        turns into a Pandas dataframe.  The entire dataset must fit into memory
        before calling this operation.

        Parameters
        ----------
        scheduler : string, optional
            Which scheduler to use like "threads", "synchronous" or "processes".
            If not provided, the default is to check the global settings first,
            and then fall back to the collection defaults.
        optimize_graph : bool, optional
            If True [default], the graph is optimized before computation.
            Otherwise the graph is run as is. This can be useful for debugging.
        kwargs
            Extra keywords to forward to the scheduler function.

        See Also
        --------
        dask.base.compute
        R2   (   R    R*   (   R0   R1   R3   (    (    s(   lib/python2.7/site-packages/dask/base.pyR       s    (    N(	   t   __name__t
   __module__t   __doc__t	   __slots__R'   R*   R#   R!   R    (    (    (    s(   lib/python2.7/site-packages/dask/base.pyR   '   s
   /	*c         K` sI   t  d | d |  d |  } t |   t |  | |  } | | | |  S(   sq   Compute a graph as if it were of type cls.

    Allows for applying the same optimizations and default scheduler.t	   schedulert   clsR   (   t   get_schedulert   optimization_functionR   (   R9   t   dskt   keysR8   R   R1   t   schedulet   dsk2(    (    s(   lib/python2.7/site-packages/dask/base.pyt   compute_as_if_collection   s    c         K` s   |  S(   N(    (   R<   R=   R1   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   dont_optimize   s    c         C` s   t  |  d t  S(   Nt   __dask_optimize__(   t   getattrRA   (   R+   (    (    s(   lib/python2.7/site-packages/dask/base.pyR;      s    c      	   ` s   | j  d d  p! t j d g   } | r t t |   } d   | j   D } x* | D]"     f d   | j   D } qV Wt t t	 g  | j   D]$ \   \ } }   | | |  ^ q    } n t
 |   \ } } | S(   sO   
    Convert many collections into a single dask graph, after optimization
    t   optimizationsc         S` s%   i  |  ] \ } } t  |  |  q S(    (   t   _extract_graph_and_keys(   t   .0t   optt   val(    (    s(   lib/python2.7/site-packages/dask/base.pys
   <dictcomp>   s   	c         ` s4   i  |  ]* \ } \ } }   | |  | f |  q S(    (    (   RF   t   kR<   R=   (   RG   (    s(   lib/python2.7/site-packages/dask/base.pys
   <dictcomp>   s   	N(   t   popR'   R   R   R   R;   t   itemsR   t   mapR   RE   (   t   collectionsR/   R1   RD   t   groupsR<   R=   t   _(    (   RG   s(   lib/python2.7/site-packages/dask/base.pyt   collections_to_dsk   s    =c         ` s   d d l  m   g  |  D] } | j   ^ q } g  |  D] } | j   ^ q6 } t   f d   | D  r|   j |   } n t |   } | | f S(   s   Given a list of dask vals, return a single graph and a list of keys such
    that ``get(dsk, keys)`` is equivalent to ``[v.compute() for v in vals]``.i   (   t   HighLevelGraphc         3` s   |  ] } t  |    Vq d  S(   N(   t
   isinstance(   RF   t   graph(   RQ   (    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>   s    (   t   highlevelgraphRQ   R&   t   __dask_keys__t   anyR   (   t   valst   vt   graphsR=   RS   (    (   RQ   s(   lib/python2.7/site-packages/dask/base.pyRE      s    c          ` s   | j  d t   g   i   t j   j        f d     t j   j  t g  |  D] }   |  ^ qa f   <   f d   }  | f S(   s  Extract collections in preparation for compute/persist/etc...

    Intended use is to find all collections in a set of (possibly nested)
    python objects, do something to them (compute, etc...), then repackage them
    in equivalent python objects.

    Parameters
    ----------
    *args
        Any number of objects. If it is a dask collection, it's extracted and
        added to the list of collections returned. By default, python builtin
        collections are also traversed to look for dask collections (for more
        information see the ``traverse`` keyword).
    traverse : bool, optional
        If True (default), builtin python collections are traversed looking for
        any dask collections they might contain.

    Returns
    -------
    collections : list
        A list of all dask collections contained in ``args``
    repack : callable
        A function to call on the transformed collections to repackage them as
        they were in the original ``args``.
    R2   c         ` s  t  |   rQ t |   } |  k rM t  t   f  | < j |   n  | St j   j }  su t |   } nt	 |  t
  r t n	 t |   } | t t t f k r | g  |  D] }   |  ^ q f } n | t t f k r%| g  |  j   D]$ \ } }   |    |  g ^ q f } n_ t |   rt | d t g  t |   D]' } | j   t |  | j   g ^ qJf f } n |  S|  | <| S(   N(    (   R   R$   R   t   lent   appendt   uuidt   uuid4t   hexR   RR   R   t   listt   typet   tuplet   sett   dictR   RK   R   R   R   t   nameRC   (   t   exprt   tokt   tskt   typt   iRI   RX   t   f(   t   _unpackRM   t   collections_tokent
   repack_dskR2   (    s(   lib/python2.7/site-packages/dask/base.pyRk      s,    !(:@
c         ` s)    j    } t |   |   <t |   S(   N(   t   copyR   t
   simple_get(   t   resultsR<   (   Rl   t   outRm   (    s(   lib/python2.7/site-packages/dask/base.pyt   repack  s    (   RJ   t   TrueR\   R]   R^   Ra   (   t   argsR1   Ri   Rr   (    (   Rk   RM   Rl   Rq   Rm   R2   s(   lib/python2.7/site-packages/dask/base.pyt   unpack_collections   s    )c    
      O` s   t  |  |   \ } } | s |  St | |  } g  |  D]* } t |  rS | j   n	 d | f ^ q5 } g  g  } } x: | D]2 } | j t | j     | j | j    qy W| g  | D] \ } }	 | | |	  ^ q  S(   s  Optimize several dask collections at once.

    Returns equivalent dask collections that all share the same merged and
    optimized underlying graph. This can be useful if converting multiple
    collections to delayed objects, or to manually apply the optimizations at
    strategic points.

    Note that in most cases you shouldn't need to call this method directly.

    Parameters
    ----------
    *args : objects
        Any number of objects. If a dask object, its graph is optimized and
        merged with all those of all other dask objects before returning an
        equivalent dask collection. Non-dask arguments are passed through
        unchanged.
    traverse : bool, optional
        By default dask traverses builtin python collections looking for dask
        objects passed to ``optimize``. For large collections this can be
        expensive. If none of the arguments contain any dask objects, set
        ``traverse=False`` to avoid doing this traversal.
    optimizations : list of callables, optional
        Additional optimization passes to perform.
    **kwargs
        Extra keyword arguments to forward to the optimization passes.

    Examples
    --------
    >>> import dask.array as da
    >>> a = da.arange(10, chunks=2).sum()
    >>> b = da.arange(10, chunks=2).mean()
    >>> a2, b2 = optimize(a, b)

    >>> a2.compute() == a.compute()
    True
    >>> b2.compute() == b.compute()
    True
    N(	   Ru   RP   R   t   __dask_postpersist__R'   t   extendR   RU   R[   (
   Rt   R1   RM   Rr   R<   t   at   postpersistsR=   t   rt   s(    (    s(   lib/python2.7/site-packages/dask/base.pyR"   "  s    '4c       	   O` s  | j  d t  } | j  d t  } t d | |   \ } } | sF |  St d | j  d d  d | d | j  d d   } t | | |  } g  | D] } | j   ^ q }	 g  | D] } | j   ^ q }
 | | |	 |  } | g  t | |
  D]! \ } \ } } | | |  ^ q  S(   s?  Compute several dask collections at once.

    Parameters
    ----------
    args : object
        Any number of objects. If it is a dask object, it's computed and the
        result is returned. By default, python builtin collections are also
        traversed to look for dask objects (for more information see the
        ``traverse`` keyword). Non-dask arguments are passed through unchanged.
    traverse : bool, optional
        By default dask traverses builtin python collections looking for dask
        objects passed to ``compute``. For large collections this can be
        expensive. If none of the arguments contain any dask objects, set
        ``traverse=False`` to avoid doing this traversal.
    scheduler : string, optional
        Which scheduler to use like "threads", "synchronous" or "processes".
        If not provided, the default is to check the global settings first,
        and then fall back to the collection defaults.
    optimize_graph : bool, optional
        If True [default], the optimizations for each collection are applied
        before computation. Otherwise the graph is run as is. This can be
        useful for debugging.
    kwargs
        Extra keywords to forward to the scheduler function.

    Examples
    --------
    >>> import dask.array as da
    >>> a = da.arange(10, chunks=2).sum()
    >>> b = da.arange(10, chunks=2).mean()
    >>> compute(a, b)
    (45, 4.5)

    By default, dask objects inside python collections will also be computed:

    >>> compute({'a': a, 'b': b, 'c': 1})  # doctest: +SKIP
    ({'a': 45, 'b': 4.5, 'c': 1},)
    R2   R/   R8   RM   R   N(	   RJ   Rs   Ru   R:   R'   RP   RU   t   __dask_postcompute__t   zip(   Rt   R1   R2   R/   RM   Rr   R>   R<   R+   R=   t   postcomputesRp   Rz   Rj   Rx   (    (    s(   lib/python2.7/site-packages/dask/base.pyR    Y  s    'c          ` sM  d d l  m } | j d d  } | j d t  } g  } xC |  D]; } t | t t t f  ro | j |  qA | j	 |  qA Wg  | D] } t | t
  r | ^ q } g  | D] } t |  r | ^ q } t t | d |  }	 x | D] }
 |	 j |
  q W| j d  } | d k r!d d	 l m } d d
 l j } | |	   y | j d    Wn t k
 r{| j j   n Xt   t  rd d
 l j } t | j      n  t  j    d     f d    j   D }  f d   | j   D | d <d   | j   D | d <n | r:t d |   n  | |	 d | | S(   s  
    Visualize several dask graphs at once.

    Requires ``graphviz`` to be installed. All options that are not the dask
    graph(s) should be passed as keyword arguments.

    Parameters
    ----------
    dsk : dict(s) or collection(s)
        The dask graph(s) to visualize.
    filename : str or None, optional
        The name (without an extension) of the file to write to disk.  If
        `filename` is None, no file will be written, and we communicate
        with dot using only pipes.
    format : {'png', 'pdf', 'dot', 'svg', 'jpeg', 'jpg'}, optional
        Format in which to write output file.  Default is 'png'.
    optimize_graph : bool, optional
        If True, the graph is optimized before rendering.  Otherwise,
        the graph is displayed as is. Default is False.
    color: {None, 'order'}, optional
        Options to color nodes.  Provide ``cmap=`` keyword for additional
        colormap
    **kwargs
       Additional keyword arguments to forward to ``to_graphviz``.

    Examples
    --------
    >>> x.visualize(filename='dask.pdf')  # doctest: +SKIP
    >>> x.visualize(filename='dask.pdf', color='order')  # doctest: +SKIP

    Returns
    -------
    result : IPython.diplay.Image, IPython.display.SVG, or None
        See dask.dot.dot_graph for more information.

    See Also
    --------
    dask.dot.dot_graph

    Notes
    -----
    For more information on optimization see here:

    https://docs.dask.org/en/latest/optimize.html
    i    (   t	   dot_graphR-   R,   R/   t   colort   orderi   (   R   Nt   cmapc         ` s5   i  |  ]+ \ } } t    |  d  t  |  q S(   t   bytes(   t	   _colorizeRs   (   RF   RI   RX   (   R   t   mx(    s(   lib/python2.7/site-packages/dask/base.pys
   <dictcomp>  s   	 c         ` s7   i  |  ]- \ } } i | d  6t    |  d 6|  q S(   R   t   label(   t   str(   RF   RI   RX   (   t   o(    s(   lib/python2.7/site-packages/dask/base.pys
   <dictcomp>  s   	t   function_attributesc         S` s&   i  |  ] \ } } i | d  6|  q S(   R   (    (   RF   RI   RX   (    (    s(   lib/python2.7/site-packages/dask/base.pys
   <dictcomp>  s   	 t   data_attributess   Unknown value color=%s(   t   dask.dotR   RJ   R*   RR   R_   Ra   Rb   Rw   R[   R   R   Rc   RP   t   updateR   R   t   matplotlib.pyplott   pyplott   KeyErrort   cmt   RdBuR   RC   t   maxt   valuesRK   t   NotImplementedError(   Rt   R1   R   R-   R/   t   args2t   argt   dskst   args3R<   t   dR   R   t   pltt   colors(    (   R   R   R   s(   lib/python2.7/site-packages/dask/base.pyR#     sB    .(%c          ` s  | j  d t  } | j  d t  } t d | |   \ } } | sF |  St d | j  d d  d |  } t j |  r y d d l m } Wn t	 k
 r q Xy |   } Wn t
 k
 r q X| j | k r | j | d | | }	 | |	  Sn  t | | |  }
 g  g  } } x[ | D]S } t t | j     } | j   \ } } | j |  | j | | | f  qW| |
 | |  }	 t t | |	     g  | D]. \ } } } |   f d   | D |  ^ q} | |  S(	   sR
   Persist multiple Dask collections into memory

    This turns lazy Dask collections into Dask collections with the same
    metadata, but now with their results fully computed or actively computing
    in the background.

    For example a lazy dask.array built up from many lazy calls will now be a
    dask.array of the same shape, dtype, chunks, etc., but now with all of
    those previously lazy tasks either computed in memory as many small :class:`numpy.array`
    (in the single-machine case) or asynchronously running in the
    background on a cluster (in the distributed case).

    This function operates differently if a ``dask.distributed.Client`` exists
    and is connected to a distributed scheduler.  In this case this function
    will return as soon as the task graph has been submitted to the cluster,
    but before the computations have completed.  Computations will continue
    asynchronously in the background.  When using this function with the single
    machine scheduler it blocks until the computations have finished.

    When using Dask on a single machine you should ensure that the dataset fits
    entirely within memory.

    Examples
    --------
    >>> df = dd.read_csv('/path/to/*.csv')  # doctest: +SKIP
    >>> df = df[df.name == 'Alice']  # doctest: +SKIP
    >>> df['in-debt'] = df.balance < 0  # doctest: +SKIP
    >>> df = df.persist()  # triggers computation  # doctest: +SKIP

    >>> df.value().min()  # future computations are now fast  # doctest: +SKIP
    -10
    >>> df.value().max()  # doctest: +SKIP
    100

    >>> from dask import persist  # use persist function on multiple collections
    >>> a, b = persist(a, b)  # doctest: +SKIP

    Parameters
    ----------
    *args: Dask collections
    scheduler : string, optional
        Which scheduler to use like "threads", "synchronous" or "processes".
        If not provided, the default is to check the global settings first,
        and then fall back to the collection defaults.
    traverse : bool, optional
        By default dask traverses builtin python collections looking for dask
        objects passed to ``persist``. For large collections this can be
        expensive. If none of the arguments contain any dask objects, set
        ``traverse=False`` to avoid doing this traversal.
    optimize_graph : bool, optional
        If True [default], the graph is optimized before computation.
        Otherwise the graph is run as is. This can be useful for debugging.
    **kwargs
        Extra keywords to forward to the scheduler function.

    Returns
    -------
    New dask collections backed by in-memory data
    R2   R/   R8   RM   i    (   t   default_clientc         ` s   i  |  ] }   | |  q S(    (    (   RF   RI   (   R   (    s(   lib/python2.7/site-packages/dask/base.pys
   <dictcomp>M  s   	 N(   RJ   Rs   Ru   R:   R'   t   inspectt   ismethodt   distributed.clientR   t   ImportErrort
   ValueErrorR   R!   RP   R_   R   RU   Rv   Rw   R[   Rc   R}   (   Rt   R1   R2   R/   RM   Rr   R>   R   t   clientRp   R<   R=   Ry   Rx   t   a_keyst   rebuildt   stateRz   t   ksR{   t   results2(    (   R   s(   lib/python2.7/site-packages/dask/base.pyR!     s@    <		;c          O` sA   | r |  | f }  n  t  t t t t |     j    j   S(   s    Deterministic token

    >>> tokenize([1, 2, '3'])
    '7d6a880cd9ec03506eee6973ff551339'

    >>> tokenize('Hello') == tokenize('Hello')
    True
    (   R   R   Ra   RL   R%   t   encodet	   hexdigest(   Rt   R1   (    (    s(   lib/python2.7/site-packages/dask/base.pyR$   U  s    	c         C` s   t  t |  j   d t  S(   Nt   key(   R%   t   sortedRK   R   (   R   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_dicti  s    c         C` s%   t  |   j t t |  j     f S(   N(   R`   R4   R%   R_   RK   (   R   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_ordered_dictn  s    c         C` s   t  t |  d t  S(   NR   (   R%   R   R   (   R{   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_sets  s    c         C` s"   t  |   j t t t |    f S(   N(   R`   R4   R_   RL   R%   (   t   seq(    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_seqx  s    c         C` sH   t  |  d d   } | d  k	 r% |   St |   r; t |   St j   j S(   Nt   __dask_tokenize__(   RC   R'   t   callablet   normalize_functionR\   R]   R^   (   R   t   method(    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_object}  s    c         C` s   y t  |  SWn t k
 r t |   } t t   d k r t E t t   d k r x+ t t   d  d  d  D] } t  | =qm Wn  Wd  QXn  | t  |  <| St k
 r t |   SXd  S(   Ni  i   (   t   function_cacheR   t   _normalize_functionRZ   t   function_cache_lockR_   R)   (   t   funcR3   RI   (    (    s(   lib/python2.7/site-packages/dask/base.pyR     s     
c         C` si  t  |  t  r |  j }  n  t  |  t  ru t |  d d   } | rX t | f |  j  n |  j } t d   | D  St  |  t	  r t d   |  j
 D  } |  j r t d   t |  j j    D  } n d  } t |  j  | | f Sy) t j |  d d } d | k r| SWn t k
 r&n Xy# d d  l } | j |  d d SWn t k
 rdt |   SXd  S(   Nt   firstc         s` s   |  ] } t  |  Vq d  S(   N(   R   (   RF   Rj   (    (    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>  s    c         s` s   |  ] } t  |  Vq d  S(   N(   R%   (   RF   Ri   (    (    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>  s    c         s` s'   |  ] \ } } | t  |  f Vq d  S(   N(   R%   (   RF   RI   RX   (    (    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>  s   t   protocoli    t   __main__(   RR   R	   t   _partialR   RC   R'   t   reversedt   funcsRa   R   Rt   t   keywordsR   RK   R   R   t   picklet   dumpst	   Exceptiont   cloudpickleR   (   R   R   R   Rt   t   kwsR3   R   (    (    s(   lib/python2.7/site-packages/dask/base.pyR     s0    %		t   pandasc          C` s|   d d  l  }  t j |  j  d    } t j |  j  d    } t j |  j  d    } t j |  j  d    } d  S(   Ni    c         S` s   |  j  t |  j  g S(   N(   Rd   R%   R   (   t   ind(    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_index  s    c         S` s"   t  |  j  t  |  j  |  j g S(   N(   R%   t   codest
   categoriest   ordered(   t   cat(    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_categorical  s    c         S` s2   |  j  |  j t |  j j d j  t |  j  g S(   Ni    (   Rd   t   dtypeR%   t   _datat   blocksR   t   index(   R{   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_series  s    c         S` sK   g  |  j  j D] } | j ^ q } | |  j |  j g 7} t t t |   S(   N(   R   R   R   t   columnsR   R_   RL   R%   (   t   dft   blockt   data(    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_dataframe  s    "(   R   R%   t   registert   Indext   Categoricalt   Seriest	   DataFrame(   t   pdR   R   R   R   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   register_pandas  s
    t   numpyc          ` s   d d  l   t j  j  d      t j  j     f d    }  t j  j t  t j  j t  t j  j   f d    } d  S(   Ni    c         S` s  |  j  s t |   |  j f St |  d  r t |  d d   r t |  j d  rw |  j j   j	 |  j j j   j	 } n d } |  j
 t j j |  j
  |  j |  j  |  j | f S|  j j rwy^ y. t d j |  j  j d d d d	   } Wn) t k
 rt d j |  j   } n XWqt t f k
 rsy t t j |  t j   } Wqtt k
 rot j   j } qtXqXni y% t |  j d
 d  j d   } WnA t t  t! f k
 rt |  j"   j d
 d  j d   } n X| |  j |  j  |  j f S(   Nt   modeR-   t   ctypesi    t   -t   encodings   utf-8t   errorst   surrogatepassR   t   Kt   i1(#   t   shapeR   R   t   hasattrRC   R'   t   baseR   t   get_as_parametert   valueR-   t   ost   patht   getmtimet   stridest	   hasobjectR   t   joint   flatR   t   UnicodeDecodeErrorR)   R   R   t   HIGHEST_PROTOCOLR   R\   R]   R^   t   ravelt   viewt   BufferErrorR(   R   Rn   (   R+   t   offsetR   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_array  s2    	!. %+c         ` s(   t  |   j   |  j d  j   f S(   NR`   (   R`   R4   R   t   ndarray(   R+   (   R   t   np(    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_matrix  s    c         ` sI   y* |  j  } t   |  |  k r) d | SWn t k
 rD t |   SXd  S(   Ns   np.(   R4   RC   R(   R   (   R+   Rd   (   R   (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_ufunc  s    	(	   R   R%   R   R   t   matrixR   t   reprt   generict   ufunc(   R   R   (    (   R   R   s(   lib/python2.7/site-packages/dask/base.pyt   register_numpy  s    "$t   scipyc       	   C` s   d d  l  j }  d   } xx |  j d f |  j d f |  j d f |  j d f |  j d f |  j d f g D]( \ } } t j	 | t
 | d |  qg Wt j	 |  j  d    } d  S(   Ni    c         ` s)   t     j t   f d   | D  f S(   Nc         3` s$   |  ] } t  t   |   Vq d  S(   N(   R%   RC   (   RF   R   (   R+   (    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>  s   (   R`   R4   R   (   R+   t   attrs(    (   R+   s(   lib/python2.7/site-packages/dask/base.pyt   normalize_sparse_matrix  s    R   t   offsetsR   t   indicest   indptrt	   blocksizet   rowt   colt   rowsR  c         S` s%   t  |   j t t |  j     f S(   N(   R`   R4   R%   R   RK   (   R+   (    (    s(   lib/python2.7/site-packages/dask/base.pyt   normalize_dok_matrix  s    (   R   R  R   (   R   R  R	  R
  R   (   R   R  R  R   (   R   R  R	  R   (   R   R  R	  R   (   R   R  R   (   t   scipy.sparset   sparset
   dia_matrixt
   bsr_matrixt
   coo_matrixt
   csr_matrixt
   csc_matrixt
   lil_matrixR%   R   R   t
   dok_matrix(   t   spR  R9   R  R  (    (    s(   lib/python2.7/site-packages/dask/base.pyt   register_scipy  s    		c         ` sh     d    t    f d   t    D  } t t |   d j   } d d t |  | } d | S(   s    Convert (r, g, b) triple to "#RRGGBB" string

    For use with ``visualize(color=...)``

    Examples
    --------
    >>> _colorize((255, 255, 255))
    '#FFFFFF'
    >>> _colorize((0, 32, 128))
    '#002080'
    i   c         3` s1   |  ]' \ } } | d  t     | d Vq d S(   i   i   N(   RZ   (   RF   Ri   RX   (   t   t(    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>,  s    i   t   0i   t   #(   t   sumt	   enumerateR^   t   intt   upperRZ   (   R  Ri   t   h(    (   R  s(   lib/python2.7/site-packages/dask/base.pyR     s
    
"t   synct   synchronouss   single-threadedt   threadst	   threading(   t   multiprocessingt	   processesR&  s  
The get= keyword has been removed.

Please use the scheduler= keyword instead with the name of
the desired scheduler like 'threads' or 'processes'

    x.compute(scheduler='single-threaded')
    x.compute(scheduler='threads')
    x.compute(scheduler='processes')

or with a function that takes the graph and keys

    x.compute(scheduler=my_scheduler_function)

or with a Dask client

    x.compute(scheduler=client)
c         ` s    r t  t   n  | d k	 r t |  r1 | Sd t |  j k r\ t | d  r\ | j S| j   t	 k r| t	 | j   S| j   d k r d d l
 m } |   j S| j   d k r t d	 |   q t d
 d j t t	     n  t j d d  rt d t j d d   St j d d  r;t t   n  t t d t  rjd d l
 m } |   j j S| d k	 r}| j S| rg  | D] } | d k	 r| ^ q} n  | r| d j   t   f d   | D  st d   n    Sd S(   sK   Get scheduler function

    There are various ways to specify the scheduler to use:

    1.  Passing in scheduler= parameters
    2.  Passing these into global confiuration
    3.  Using defaults of a dask collection

    This function centralizes the logic to determine the right scheduler to use
    from those many options
    t   ClientR   s   dask.distributedt   distributedi    (   t
   get_clientR'  R&  s5   Please install cloudpickle to use the '%s' scheduler.s!   Expected one of [distributed, %s]s   , R8   R   (   t
   get_workerc         3` s   |  ] } | j    k Vq d  S(   N(   t   __dask_scheduler__(   RF   t   c(   R   (    s(   lib/python2.7/site-packages/dask/base.pys	   <genexpr>  s    s   Compute called on multiple collections with differing default schedulers. Please specify a scheduler=` parameter explicitly in compute or globally with `dask.config.set`.N(   s   dask.distributedR)  (   R'  R&  (   R)   t   get_err_msgR'   R   R`   R4   R   R   t   lowert   named_schedulerst   distributed.workerR*  R   R   R   R   R:   RC   R   R*   R+  R   R,  t   all(   R   R8   RM   R9   R*  R+  R-  (    (   R   s(   lib/python2.7/site-packages/dask/base.pyR:   Y  s@    $
"((   R   R   R    R!   R"   R#   R$   R%   (i   t
   __future__R    R   R   RM   R   t	   functoolsR   t   hashlibR   t   operatorR   R   R   R   R%  R\   t   toolzR   R   R	   R
   t   toolz.functoolzR   t   compatibilityR   R   R   R   R   R   R   R   t   contextR   t   coreR   R   R   Ro   t   hashingR   t   utilsR   R   t    R   R   R   t   __all__R   t   objectR   R'   R@   RA   R;   Rs   RP   RE   Ru   R"   R    R#   R!   R$   R%   R   R  t   floatR   R   R`   t   slicet   complext   EllipsisRc   R   R   Rb   R   Ra   R_   R   R   R   t   LockR   R   R   t   register_lazyR   R  R  R   t   get_syncR0  t   daskR&  t   dask_multiprocessingR   R   t   stripR.  R:   (    (    (    s(   lib/python2.7/site-packages/dask/base.pyt   <module>   s   ":   	y					I	7	9	Z	i		!		7	



	
