
    bi]                        d dl mZ d dlZd dlmc mZ 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ddddefd	Z G d
 de      Zy)    )annotationsN)	DataFrameSeriesnew_collection)	Blockwisehas_known_categories)get_meta_library_Fc                    t         t        j                  t        j                  f      rt        j                   f|||||||d|S d}	d}
t         t              r6t        j                         st        |	      t               st        |
      t         t              r|x j                  dk(  j                         rt        |	       j                  dk(  j                         rt        |	       j                  j                  dg      j                  }nt         fd|D              st        |	      t         fd	|D              st        |
      t        t!         |||||||            S )
a
  
    Convert categorical variable into dummy/indicator variables.

    Data must have category dtype to infer result's ``columns``.

    Parameters
    ----------
    data : Series, or DataFrame
        For Series, the dtype must be categorical.
        For DataFrame, at least one column must be categorical.
    prefix : string, list of strings, or dict of strings, default None
        String to append DataFrame column names.
        Pass a list with length equal to the number of columns
        when calling get_dummies on a DataFrame. Alternatively, `prefix`
        can be a dictionary mapping column names to prefixes.
    prefix_sep : string, default '_'
        If appending prefix, separator/delimiter to use. Or pass a
        list or dictionary as with `prefix.`
    dummy_na : bool, default False
        Add a column to indicate NaNs, if False NaNs are ignored.
    columns : list-like, default None
        Column names in the DataFrame to be encoded.
        If `columns` is None then all the columns with
        `category` dtype will be converted.
    sparse : bool, default False
        Whether the dummy columns should be sparse or not.  Returns
        SparseDataFrame if `data` is a Series or if all columns are included.
        Otherwise returns a DataFrame with some SparseBlocks.

        .. versionadded:: 0.18.2

    drop_first : bool, default False
        Whether to get k-1 dummies out of k categorical levels by removing the
        first level.

    dtype : dtype, default bool
        Data type for new columns. Only a single dtype is allowed.

        .. versionadded:: 0.18.2

    Returns
    -------
    dummies : DataFrame

    Examples
    --------
    Dask's version only works with Categorical data, as this is the only way to
    know the output shape without computing all the data.

    >>> import pandas as pd
    >>> import dask.dataframe as dd
    >>> s = dd.from_pandas(pd.Series(list('abca')), npartitions=2)
    >>> dd.get_dummies(s)
    Traceback (most recent call last):
        ...
    NotImplementedError: `get_dummies` with non-categorical dtypes is not supported...

    With categorical data:

    >>> s = dd.from_pandas(pd.Series(list('abca'), dtype='category'), npartitions=2)
    >>> dd.get_dummies(s)  # doctest: +NORMALIZE_WHITESPACE
    Dask DataFrame Structure:
                      a     b     c
    npartitions=2
    0              bool  bool  bool
    2               ...   ...   ...
    3               ...   ...   ...
    Dask Name: operation, 2 expressions
    Expr=GetDummies(frame=df)
    >>> dd.get_dummies(s).compute()  # doctest: +ELLIPSIS
           a      b      c
    0   True  False  False
    1  False   True  False
    2  False  False   True
    3   True  False  False

    See Also
    --------
    pandas.get_dummies
    prefix
prefix_sepdummy_nacolumnssparse
drop_firstdtypez`get_dummies` with non-categorical dtypes is not supported. Please use `df.categorize()` beforehand to convert to categorical dtype.z`get_dummies` with unknown categories is not supported. Please use `column.cat.as_known()` or `df.categorize()` beforehand to ensure known categoriesobjectstringcategory)includec              3  N   K   | ]  }t        j                  |           y wN)methodsis_categorical_dtype.0cdatas     \/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/dataframe/dask_expr/_dummies.py	<genexpr>zget_dummies.<locals>.<genexpr>   s      Nw33DG<Ns   "%c              3  :   K   | ]  }t        |           y wr   r   r   s     r!   r"   zget_dummies.<locals>.<genexpr>   s     BQ'Q0Bs   )
isinstancepdr   r   get_dummiesr   r   NotImplementedErrorr	   dtypesany_metaselect_dtypesr   allr   
GetDummies)r    r   r   r   r   r   r   r   kwargsnot_cat_msgunknown_cat_msgs   `          r!   r&   r&      sg   v $BLL12~~

!!

 

 
	
	( 	  $++D1%k22#D)%o66	D)	$?x',,.)+66x',,.)+66jj..
|.DLLGNgNN)+66B'BB%o66&*hU	
     c                  @    e Zd Zg dZddddddedZg dZed        Zy)r-   )framer   r   r   r   r   r   r   Nr   Fr   )r   r   r   c                @     t        |       j                  | g|i |S r   )r
   r&   )dfargsr.   s      r!   	operationzGetDummies.operation   s%    /#//DTDVDDr1   )	__name__
__module____qualname___parametersbool	_defaults_keyword_onlystaticmethodr7    r1   r!   r-   r-      sB    	K I 6ME Er1   r-   )
__future__r   pandasr%   dask.dataframe.methods	dataframer   $dask.dataframe.dask_expr._collectionr   r   r   dask.dataframe.dask_expr._exprr   dask.dataframe.utilsr	   
dask.utilsr
   r<   r&   r-   r@   r1   r!   <module>rI      sL    "  ( ( R R 4 5 '
 
L^E Er1   