U
    /e!                     @   s   d Z ddlZddlmZ ddlmZ ddl	m
Z
 e
dZe
dZe
dZe
dZe
dZe
d	Ze
d
Ze
dZe
dZe
dZe
dZe
dZe
dZe
dZdddZdd ZdddZdd ZdddZd ddZdS )!z4
Dispatch in dask.dataframe.

Also see extension.py
    N)Dispatchmake_meta_dispatchmake_meta_objmeta_nonemptymeta_lib_from_arrayhash_object_dispatchgroup_split_dispatchget_parallel_typeZCategoricalDtypeconcattolistis_categorical_dtypeunion_categoricalsZgrouperpyarrow_schema_dispatchouterFTc                 K   sF   t | dkr| d S tt| d }|| f|||||d|S dS )a  Concatenate, handling some edge cases:

    - Unions categoricals between partitions
    - Ignores empty partitions

    Parameters
    ----------
    dfs : list of DataFrame, Series, or Index
    axis : int or str, optional
    join : str, optional
    uniform : bool, optional
        Whether to treat ``dfs[0]`` as representative of ``dfs[1:]``. Set to
        True if all arguments have the same columns and dtypes (but not
        necessarily categories). Default is False.
    ignore_index : bool, optional
        Whether to allow index values to be ignored/dropped during
        concatenation. Default is False.
    ignore_order : bool, optional
        Whether to ignore the order when doing the union of categoricals.
        Default is False.
       r   )axisjoinuniformfilter_warningignore_indexN)lenconcat_dispatchdispatchtype)dfsr   r   r   r   r   kwargsfunc r   ;/tmp/pip-unpacked-wheel-dbjnr7gq/dask/dataframe/dispatch.pyr
      s    c                 C   s"   t | d| } tt| }|| S )NZdtype)getattris_categorical_dtype_dispatchr   r   objr   r   r   r   r   J   s    c                 C   s   t t| }|||dS )N)
categoriesordered)categorical_dtype_dispatchr   r   )metar#   r$   r   r   r   r   categorical_dtypeP   s    r'   c                 C   s   t t| }|| S )N)tolist_dispatchr   r   r!   r   r   r   r   U   s    c                 C   s   t | tjtjjtjjtjjt	j
fr*| jS zt| |dW S  tk
r   |dk	rntt|}|| |d Y S ttj}|| |d Y S Y nX dS )a  
    This method creates meta-data based on the type of ``x``,
    and ``parent_meta`` if supplied.

    Parameters
    ----------
    x : Object of any type.
        Object to construct meta-data from.
    index :  Index, optional
        Any index to use in the metadata. This is a pass-through
        parameter to dispatches registered.
    parent_meta : Object, default None
        If ``x`` is of arbitrary types and thus Dask cannot determine
        which back-end to be used to generate the meta-data for this
        object type, in which case ``parent_meta`` will be used to
        determine which back-end to select and dispatch to. To use
        utilize this parameter ``make_meta_obj`` has be dispatched.
        If ``parent_meta`` is ``None``, a pandas DataFrame is used for
        ``parent_meta`` thats chooses pandas as the backend.

    Returns
    -------
    A valid meta-data
    )indexN)
isinstanceddZ_FramecoreZScalargroupbyZ_GroupByaccessorZAccessordaArrayZ_metar   	TypeErrorr   r   r   pdZ	DataFrame)xr)   Zparent_metar   r   r   r   	make_metaZ   s$    
r4   c                 C   s    t t| d }|| ||dS )Nr   )sort_categoriesignore_order)union_categoricals_dispatchr   r   )Zto_unionr5   r6   r   r   r   r   r      s    )r   r   FTF)NF)NN)FF)__doc__Zpandasr2   Z
dask.arrayarrayr/   Zdask.dataframeZ	dataframer+   Z
dask.utilsr   r   r   r   r   r   r   r	   r%   r   r(   r    r7   Zgrouper_dispatchr   r
   r   r'   r   r4   r   r   r   r   r   <module>   s:        
-

3