Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/core/reshape/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/core/reshape/__pycache__/encoding.cpython-312.pyc

�

MٜgJ��P�ddlmZddlmZddlmZmZddlZddlm	Z	m
Z
ddlZddl
mZddlmZmZmZmZddlmZmZdd	lmZdd
lmZddlmZddlmZdd
lm Z m!Z!ddl"m#Z#e	rddl$m%Z%							d											dd�Z&					d											dd�Z'		d							dd�Z(y)�)�annotations)�defaultdict)�Hashable�IterableN)�
TYPE_CHECKING�cast)�IntIndex)�is_integer_dtype�is_list_like�is_object_dtype�pandas_dtype)�
ArrowDtype�CategoricalDtype)�SparseArray)�factorize_from_iterable)�StringDtype)�	DataFrame)�Index�
default_index)�Series)�NpDtypec
���ddlm}gd�}	t|t��r�|�|j	|	���nt|�st
d��||�d�fd�}
|
|d�|
|d�t|t�rtj|g�}t|t�r�jD�cgc]}||��	}}|��j}t|t�rtj|g�}n,t|t�r�jD�cgc]}||��	}}�j|jk(rg}n*|�|j|d	�
�g}n|j	|	��g}t�j�||�D],\}}
}t!|d	|
|||||��}|j#|��.||d	�
�}|St!|||||||�
�}|Scc}wcc}w)a�

    Convert categorical variable into dummy/indicator variables.

    Each variable is converted in as many 0/1 variables as there are different
    values. Columns in the output are each named after a value; if the input is
    a DataFrame, the name of the original variable is prepended to the value.

    Parameters
    ----------
    data : array-like, Series, or DataFrame
        Data of which to get dummy indicators.
    prefix : str, list of str, or dict of str, 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 : str, 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
        `object`, `string`, or `category` dtype will be converted.
    sparse : bool, default False
        Whether the dummy-encoded columns should be backed by
        a :class:`SparseArray` (True) or a regular NumPy array (False).
    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.

    Returns
    -------
    DataFrame
        Dummy-coded data. If `data` contains other columns than the
        dummy-coded one(s), these will be prepended, unaltered, to the result.

    See Also
    --------
    Series.str.get_dummies : Convert Series of strings to dummy codes.
    :func:`~pandas.from_dummies` : Convert dummy codes to categorical ``DataFrame``.

    Notes
    -----
    Reference :ref:`the user guide <reshaping.dummies>` for more examples.

    Examples
    --------
    >>> s = pd.Series(list('abca'))

    >>> pd.get_dummies(s)
           a      b      c
    0   True  False  False
    1  False   True  False
    2  False  False   True
    3   True  False  False

    >>> s1 = ['a', 'b', np.nan]

    >>> pd.get_dummies(s1)
           a      b
    0   True  False
    1  False   True
    2  False  False

    >>> pd.get_dummies(s1, dummy_na=True)
           a      b    NaN
    0   True  False  False
    1  False   True  False
    2  False  False   True

    >>> df = pd.DataFrame({'A': ['a', 'b', 'a'], 'B': ['b', 'a', 'c'],
    ...                    'C': [1, 2, 3]})

    >>> pd.get_dummies(df, prefix=['col1', 'col2'])
       C  col1_a  col1_b  col2_a  col2_b  col2_c
    0  1    True   False   False    True   False
    1  2   False    True    True   False   False
    2  3    True   False   False   False    True

    >>> pd.get_dummies(pd.Series(list('abcaa')))
           a      b      c
    0   True  False  False
    1  False   True  False
    2  False  False   True
    3   True  False  False
    4   True  False  False

    >>> pd.get_dummies(pd.Series(list('abcaa')), drop_first=True)
           b      c
    0  False  False
    1   True  False
    2  False   True
    3  False  False
    4  False  False

    >>> pd.get_dummies(pd.Series(list('abc')), dtype=float)
         a    b    c
    0  1.0  0.0  0.0
    1  0.0  1.0  0.0
    2  0.0  0.0  1.0
    r��concat)�object�string�category)�includez1Input must be a list-like for parameter `columns`c���t|�rIt|��jdk(s-d|�dt|��d�jd�d�}t|��yy)N�zLength of 'z' (�9) did not match the length of the columns being encoded (z).)r�len�shape�
ValueError)�item�name�len_msg�data_to_encodes   ��G/usr/local/lib/python3.12/site-packages/pandas/core/reshape/encoding.py�	check_lenzget_dummies.<locals>.check_len�sl����D�!��4�y�N�$8�$8��$;�;�%�d�V�3�s�4�y�k�:�*�0�0��3�4�B�8��
%�W�-�-�
<�"��prefix�
prefix_sepr ��axis)�exclude)r,r-�dummy_na�sparse�
drop_first�dtype)r2r3r4)r&�str)�pandas.core.reshape.concatr�
isinstancer�
select_dtypesr�	TypeErrorr5�	itertools�cycle�dict�columnsr#�drop�zip�items�_get_dummies_1d�append)�datar,r-r1r=r2r3r4r�dtypes_to_encoder*�col�with_dummies�pre�sep�dummy�resultr(s                 @r)�get_dummiesrK+s����f2�7���$�	�"��?�!�/�/�8H�/�I�N��g�&��O�P�P�!�'�]�N�	.�	�&�(�#��*�l�+��f�c�"��_�_�f�X�.�F��f�d�#�-;�-C�-C�D�-C�c�f�S�k�-C�F�D��>�#�+�+�F��j�#�&�"���*��6�J�
�
�D�
)�5C�5K�5K�L�5K�c�*�S�/�5K�J�L����4�:�:�-��L�
�
 �!�I�I�g�A�I�6�7�L�!�.�.�7G�.�H�I�L� ��!5�!5�!7���L�M�C��c�#��A����!��%���E�
����&�M���1�-���M�!������!��
���M��_E��Ms�)G�
G
c	�b�ddlm}tt|d���\}}	|��t	|d�r�|j
}
t
|
t�r|
jj
}
t
|
t�rddl
}t|j��}n`t
|
t�r|
jdk7rtd�}n5tj
t �}n|�tj
t �}t|�}t#|�rt%d��dd	�}
|st'|	�dk(r|
|�S|j)�}|r:t'|	�||d
k(<|	j+t'|	�tj,�}	|rt'|	�dk(r|
|�St'|	�}|�|	}nt/|	D�cgc]
}|�|�|����c}�}t
|t�r
|j0}nd}|�r't3|�rd}n!|tj
t �k(rd}nd}g}t'|�}t5t'|��D�cgc]}g��}}|d
k7}||}tj6|�|}t9||�D]\}}||j;|��|r
|dd}|dd}t9||�D]Z\}}t=tj>t'|�|�
�tA||�||��}|j;t|||d����\||dd��St'|�|f}t
|tj
�r|}ntj}tjB||d��} d| tj6t'|��|f<|sd| |d
k(<|r| dd�dd�f} |dd}tE| |||��Scc}wcc}w)NrrF��copyr4�
pyarrow_numpy�booleanz1dtype=object is not a valid dtype for get_dummiesc�|�t|t�r
|j}ntt	|��}t|��S)N)�index)r7rrRrr"r)rCrRs  r)�get_empty_framez(_get_dummies_1d.<locals>.get_empty_frames.���d�F�#��J�J�E�!�#�d�)�,�E��u�%�%r+���r g�r4)�sparse_index�
fill_valuer4)rCrRr&rN)r/rN�F)r#r4�order)rRr=r4)�returnr)#r6rrr�hasattrr4r7r�
categoriesr�pyarrow�bool_r�storager
�np�boolrr$r"rN�insert�nanrrRr
�range�aranger?rBr�onesr	�zerosr)!rCr,r-r1r2r3r4r�codes�levels�input_dtype�pa�_dtyperS�number_of_cols�
dummy_cols�levelrRrW�
sparse_series�N�_�
sp_indices�mask�n_idx�ndx�coderE�ixs�sarrr#�dummy_dtype�	dummy_mats!                                 r)rArA�sg��2�,�F�4�e�,D�E�M�E�6��}���w�/��j�j���k�#3�4�%�0�0�6�6�K��k�:�.� ��r�x�x�z�*�E��{�K�0��#�#��6� ��+�E��H�H�T�N�E�	��������
�%�
 �F��v���L�M�M�&���F��q�(��t�$�$��J�J�L�E�� ��[��e�r�k�����s�6�{�B�F�F�3���c�&�k�Q�&��t�$�$���[�N�
�~��
���O��u�v�h�z�l�5�'�:��O�P�
��$����
�
����
��E�"��J�
�b�h�h�t�n�
$��J��J��
���I��.3�C�
�O�.D�!E�.D��"�.D�
�!E���{���d����	�	�!��T�"���U�E�*�I�C���t��#�#�C�(�+��$�A�B��J�#�A�B��J��J�
�3�H�C�������C���.�%�a��-�%��	�D�
� � ��T��S�u�!U�V�4��m�!�%�8�8��E�
�N�*���f�b�h�h�'� �K��(�(�K��H�H�5��3�G�	�23�	�"�)�)�C��J�'��.�/��%&�I�e�r�k�"��!�!�Q�R�%�(�I�#�A�B��J���%��6�R�R��}P��&"Fs�(N'�2	N,c	��ddlm}t|t�s!t	dt|�j����tt|j�j��}|j�rtd|j��d���	|jdd��}tt�}|�t|j �|d<n�t|t"�r_|j D]O}|j%|�d}t'|�t'|�k(rtd|����||j)|��Qn!t	d
t|�j����|��t|t*�r=t'|�t'|�k(szdt'|��dt'|��d�}	t|	��t|t,�r#t+t/||gt'|�z��}n!t	dt|�j����i}
|j1�D�]�\}}|�|j3�}n|D�cgc]}|t'||z�d
��}}|j4d
d
�|fj7d��}
t|
dkD�rtd|
j�����t|
dk(�rbt|t*�r|j)||�ntd|
j9�����||j4d
d
�|f|
dk(fd��}n|j4d
d
�|f}|j;||j j<��}|jd��}|j j?|�}|jA|�jC|jD�|
|<���t|
�}|�4|j j|j j<�|_|S#t$rt	d	��wxYwcc}w)a>
    Create a categorical ``DataFrame`` from a ``DataFrame`` of dummy variables.

    Inverts the operation performed by :func:`~pandas.get_dummies`.

    .. versionadded:: 1.5.0

    Parameters
    ----------
    data : DataFrame
        Data which contains dummy-coded variables in form of integer columns of
        1's and 0's.
    sep : str, default None
        Separator used in the column names of the dummy categories they are
        character indicating the separation of the categorical names from the prefixes.
        For example, if your column names are 'prefix_A' and 'prefix_B',
        you can strip the underscore by specifying sep='_'.
    default_category : None, Hashable or dict of Hashables, default None
        The default category is the implied category when a value has none of the
        listed categories specified with a one, i.e. if all dummies in a row are
        zero. Can be a single value for all variables or a dict directly mapping
        the default categories to a prefix of a variable.

    Returns
    -------
    DataFrame
        Categorical data decoded from the dummy input-data.

    Raises
    ------
    ValueError
        * When the input ``DataFrame`` ``data`` contains NA values.
        * When the input ``DataFrame`` ``data`` contains column names with separators
          that do not match the separator specified with ``sep``.
        * When a ``dict`` passed to ``default_category`` does not include an implied
          category for each prefix.
        * When a value in ``data`` has more than one category assigned to it.
        * When ``default_category=None`` and a value in ``data`` has no category
          assigned to it.
    TypeError
        * When the input ``data`` is not of type ``DataFrame``.
        * When the input ``DataFrame`` ``data`` contains non-dummy data.
        * When the passed ``sep`` is of a wrong data type.
        * When the passed ``default_category`` is of a wrong data type.

    See Also
    --------
    :func:`~pandas.get_dummies` : Convert ``Series`` or ``DataFrame`` to dummy codes.
    :class:`~pandas.Categorical` : Represent a categorical variable in classic.

    Notes
    -----
    The columns of the passed dummy data should only include 1's and 0's,
    or boolean values.

    Examples
    --------
    >>> df = pd.DataFrame({"a": [1, 0, 0, 1], "b": [0, 1, 0, 0],
    ...                    "c": [0, 0, 1, 0]})

    >>> df
       a  b  c
    0  1  0  0
    1  0  1  0
    2  0  0  1
    3  1  0  0

    >>> pd.from_dummies(df)
    0     a
    1     b
    2     c
    3     a

    >>> df = pd.DataFrame({"col1_a": [1, 0, 1], "col1_b": [0, 1, 0],
    ...                    "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
    ...                    "col2_c": [0, 0, 1]})

    >>> df
          col1_a  col1_b  col2_a  col2_b  col2_c
    0       1       0       0       1       0
    1       0       1       1       0       0
    2       1       0       0       0       1

    >>> pd.from_dummies(df, sep="_")
        col1    col2
    0    a       b
    1    b       a
    2    a       c

    >>> df = pd.DataFrame({"col1_a": [1, 0, 0], "col1_b": [0, 1, 0],
    ...                    "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
    ...                    "col2_c": [0, 0, 0]})

    >>> df
          col1_a  col1_b  col2_a  col2_b  col2_c
    0       1       0       0       1       0
    1       0       1       1       0       0
    2       0       0       0       0       0

    >>> pd.from_dummies(df, sep="_", default_category={"col1": "d", "col2": "e"})
        col1    col2
    0    a       b
    1    b       a
    2    d       e
    rrz>Expected 'data' to be a 'DataFrame'; Received 'data' of type: z.Dummy DataFrame contains NA value in column: '�'rPFrMz(Passed DataFrame contains non-dummy dataN�z$Separator not specified for column: zFExpected 'sep' to be of type 'str' or 'None'; Received 'sep' of type: zLength of 'default_category' (r!�)znExpected 'default_category' to be of type 'None', 'Hashable', or 'dict'; Received 'default_category' of type: r r.zEDummy DataFrame contains multi-assignment(s); First instance in row: zEDummy DataFrame contains unassigned value(s); First instance in row: rU)#r6rr7rr9�type�__name__rr�isna�anyr$�idxmax�astyper�listr=r5�splitr"rBr<rr?r@rN�loc�sum�idxmin�_constructor_slicedr4�get_indexer_for�take�set_axisrR)rCrH�default_categoryr�
col_isna_mask�data_to_decode�variables_slicerEr,r'�cat_data�prefix_slice�cats�assigned�
data_slice�
cats_array�true_values�indexerrJs                   r)�from_dummiesr�os��\2��d�I�&��
(�(,�T�
�(;�(;�'<�
>�
�	
�
��������!2�3�M������
��$�$�&�'�q�
*�
�	
�D����Y�U��;��
"�$�'�O�
�{�"�4�<�<�0����	�C��	�!�)�)�C��Y�Y�s�^�A�&�F��6�{�c�#�h�&� �#G��u�!M�N�N��F�#�*�*�3�/�	*��
'�'+�C�y�'9�'9�&:�
<�
�	
�
�#��&��-��'�(�C��,@�@�4�S�9I�5J�4K�L��O�,�-�Q�0��
!��)�)�
�(�(�
3�#��O�&6�%7�#�o�:N�%N�O� ���8��(�)�2�2�3�5��
��H� /� 5� 5� 7�����;��$�$�&�D�8D�E���C��F�S�L�)�+�,��D�E�!�%�%�a��o�6�:�:��:�B���x�!�|���*�*2�/�/�*;�)<�>��
��x�1�}���*�D�1����,�V�4�5� �.�.6�o�o�.?�-@�B��� ��#�#�A�|�O�4�h�!�m�D�1��J�(�+�+�A�|�O�<�J��-�-�d�$�,�,�:L�:L�-�M�
� �'�'�Q�'�/���$�$�4�4�[�A��%�?�?�7�3�<�<�T�Z�Z�H����9!8�<�x�
 �F�
�����.�.�t�|�|�/A�/A�B����M��U�D��B�C�C�D��ZFs�O#�2O;�#O8)NrrFNFFN)r-z$str | Iterable[str] | dict[str, str]r1rar2rar3rar4zNpDtype | NonerZr)rrFFFN)NN)rCrrHz
None | strr�z%None | Hashable | dict[str, Hashable]rZr))�
__future__r�collectionsr�collections.abcrrr:�typingrr�numpyr`�pandas._libs.sparser	�pandas.core.dtypes.commonr
rrr
�pandas.core.dtypes.dtypesrr�pandas.core.arraysr�pandas.core.arrays.categoricalr�pandas.core.arrays.string_r�pandas.core.framer�pandas.core.indexes.apirr�pandas.core.seriesr�pandas._typingrrKrAr��r+r)�<module>r�sF��"�#����
�(����
+�B�2�'��&��&�
�7:����� �@�5�@��	@�
�
@��@��@��@�L8;���� �~S�5�~S��	~S�

�~S��
~S��~S��~S�F�>B�K�
�K�	�K�<�K��	Kr+

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists