ó
    Ñ]j&M  ã                  ó¦  • S SK Jr  S SKJr  S SKJrJr  S SKrS SKJ	r	  S SK
rS SKJr  S SKJr  S SKJr  S S	KJrJrJrJr  S S
KJrJr  S SKJr  S SKJr  S SKJ r   S SK!J"r"  S SK#J$r$J%r%  S SK&J'r'  \	(       a  S SK(J)r)  \" S5             S           SS jj5       r*     S           SS jjr+\" S5        S       SS jj5       r,g)é    )Úannotations)Údefaultdict)ÚHashableÚIterableN)ÚTYPE_CHECKING)Úmissing)ÚIntIndex)Ú
set_module)Úis_integer_dtypeÚis_list_likeÚis_object_dtypeÚpandas_dtype)Ú
ArrowDtypeÚCategoricalDtype)ÚSparseArray)Úfactorize_from_iterable)ÚStringDtype)Ú	DataFrame)ÚIndexÚdefault_index)ÚSeries)ÚNpDtypeÚpandasc                ó  ^• SSK Jn  / SQn	[        U [        5      (       GaÑ  Uc  U R	                  U	S9mO[        U5      (       d  [        S5      eX   mSU4S jjn
U
" US5        U
" US5        [        U[        5      (       a*  [        R                  " U[        TR                  5      5      n[        U[        5      (       a  TR                   Vs/ s H  o±U   PM	     nnUc  TR                  n[        U[        5      (       a+  [        R                  " U[        TR                  5      5      nO3[        U[        5      (       a  TR                   Vs/ s H  o²U   PM	     nnTR                  U R                  :X  a  / nO%Ub  U R                  US	S
9/nOU R	                  U	S9/n[        TR!                  5       XSS9 H)  u  p½n[#        US	   UUUUUUS9nUR%                  U5        M+     U" US	S
9nU$ [#        U UUUUUUS9nU$ s  snf s  snf )aE  
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
    A string to be prepended to 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, list of str, or dict of str, default '_'
    Should you choose to prepend DataFrame column names with a prefix, this
    is the separator/delimiter to use between the two. Alternatively,
    `prefix_sep` can be a list with length equal to the number of columns,
    or a dictionary mapping column names to separators.
dummy_na : bool, default False
    If True, a NaN indicator column will be added even if no NaN values are present.
    If False, NA values are encoded as all zero.
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                óº   >• [        U 5      (       aJ  [        U 5      TR                  S   :X  d-  SU S[        U 5       STR                  S    S3n[        U5      eg g )Né   zLength 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      €ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pandas/core/reshape/encoding.pyÚ	check_lenÚget_dummies.<locals>.check_len®   so   ø€ Ü˜D×!Ñ!Ü˜4“y N×$8Ñ$8¸Ñ$;Ó;à% d V¨3¬s°4«y¨kð :à*×0Ñ0°Ñ3Ð4°Bð8ð ô
 % WÓ-Ð-ð <ð "ó    ÚprefixÚ
prefix_sepr"   ©Úaxis)ÚexcludeT©Ústrict)r/   r0   Údummy_naÚsparseÚ
drop_firstÚdtype)r7   r8   r9   )r(   ÚstrÚreturnÚNone)Úpandas.core.reshape.concatr   Ú
isinstancer   Úselect_dtypesr   Ú	TypeErrorr:   Ú	itertoolsÚrepeatr$   ÚcolumnsÚdictr%   ÚdropÚzipÚitemsÚ_get_dummies_1dÚappend)Údatar/   r0   r6   rC   r7   r8   r9   r   Údtypes_to_encoder,   ÚcolÚwith_dummiesÚpreÚsepÚdummyÚresultr*   s                    @r+   Úget_dummiesrR   *   s  ø€ õl 2â7Ðä�$œ	×"Ò"à‰?Ø!×/Ñ/Ð8HÐ/ÐI‰NÜ˜g×&Ñ&ÜÐOÓPÐPà!™]ˆN÷	.ñ 	�&˜(Ô#Ù�*˜lÔ+ä�fœc×"Ñ"Ü×%Ò% f¬c°.×2HÑ2HÓ.IÓJˆFÜ�fœd×#Ñ#Ø-;×-CÒ-CÓDÒ-C c˜S”kÑ-CˆFÐDà‰>Ø#×+Ñ+ˆFô �j¤#×&Ñ&Ü"×)Ò)¨*´c¸.×:PÑ:PÓ6QÓR‰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ä Ø× Ñ Ó" F¸tô
‰MˆC�cô $Ø�A‘ØØØ!ØØ%ØñˆEð ×Ñ Ö&ñ
ñ ˜¨1Ñ-ˆð €Mô !ØØØØØØ!Øñ
ˆð €Mùòc Eùò Ms   ÃHÅH	c           
     ó  • SSK Jn  [        [        U SS95      u  p‰UcÔ  [	        U S5      (       aÃ  U R
                  n
[        U
[        5      (       a  U
R                  R
                  n
[        U
[        5      (       a  SS K
n[        UR                  5       5      nOv[        U
[        5      (       a)  U
R                  [        R                  L a  [!        S5      nO8["        R
                  " [$        5      nOUc  ["        R
                  " [$        5      n[!        U5      n['        U5      (       a  [)        S5      eSS jnU(       d  [+        U	5      S:X  a  U" U 5      $ UR-                  5       nU(       a9  [+        U	5      XˆS	:H  '   U	R/                  [+        U	5      ["        R0                  5      n	U(       a  [+        U	5      S
:X  a  U" U 5      $ [+        U	5      nUc  U	nO"[3        U	 Vs/ s H  nU U U 3PM     sn5      n[        U [        5      (       a  U R4                  nOS nU(       Ga-  [7        U5      (       a  SnO#U["        R
                  " [$        5      :X  a  SnOSn/ n[+        U 5      n[9        [+        U5      5       Vs/ s H  n/ PM     nnUS	:g  nUU   n["        R:                  " U5      U   n[=        UUSS9 H  u  nnUU   R?                  U5        M     U(       a
  US
S  nUS
S  n[=        UUSS9 HS  u  nn[A        ["        RB                  " [+        U5      US9[E        UU5      UUS9nUR?                  [        UUUSS95        MU     U" US
S9$ [+        U5      U4n[        U["        R
                  5      (       a  UnO["        R                  n["        RF                  " UUSS9n S
U ["        R:                  " [+        U5      5      U4'   U(       d  SU US	:H  '   U(       a  U S S 2S
S 24   n US
S  n[I        U UXüS9$ s  snf s  snf )Nr   r   F)Úcopyr9   Úbooleanz1dtype=object is not a valid dtype for get_dummiesc                ó€   • [        U [        5      (       a  U R                  nO[        [	        U 5      5      n[        US9$ )N)Úindex)r>   r   rW   r   r$   r   )rJ   rW   s     r+   Úget_empty_frameÚ(_get_dummies_1d.<locals>.get_empty_frame  s1   € ä�dœF×#Ñ#Ø—J‘J‰Eä!¤# d£)Ó,ˆEÜ˜uÑ%Ð%r.   éÿÿÿÿr"   g        Tr4   ©r9   )Úsparse_indexÚ
fill_valuer9   )rJ   rW   r(   rT   r1   ÚF)r%   r9   Úorder)rW   rC   r9   )r;   r   )%r=   r   r   r   Úhasattrr9   r>   r   Ú
categoriesr   ÚpyarrowÚbool_r   Úna_valueÚ
libmissingÚNAr   ÚnpÚboolr   r&   r$   rT   ÚinsertÚnanr   rW   r   ÚrangeÚarangerF   rI   r   Úonesr	   Úzerosr   )!rJ   r/   r0   r6   r7   r8   r9   r   ÚcodesÚlevelsÚinput_dtypeÚpaÚ_dtyperX   Únumber_of_colsÚ
dummy_colsÚlevelrW   r]   Úsparse_seriesÚNÚ_Ú
sp_indicesÚmaskÚn_idxÚndxÚcoderL   ÚixsÚsarrr%   Údummy_dtypeÚ	dummy_mats!                                    r+   rH   rH   ò   s€  € õ 2ô ,¬F°4¸eÑ,DÓE�M€Eà�}œ  w×/Ñ/Ø—j‘jˆÜ�kÔ#3×4Ñ4Ø%×0Ñ0×6Ñ6ˆKä�k¤:×.Ñ.Û ä˜rŸx™x›zÓ*‰Eä�{¤K×0Ñ0Ø×$Ñ$¬
¯©Ò5ä  Ó+‰Eä—H’HœT“N‰EØ	‰Ü—’œ“ˆä˜%Ó €Fä�v×ÑÜÐLÓMÐMô&ö œ˜F› qÓ(Ù˜tÓ$Ð$à�J‰J‹L€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°$Ô7‰IˆC�Ø�tÑ×#Ñ# CÖ(ñ 8ö ð $ A B˜ˆJØ# A B˜ˆJÜ˜J¨
¸4Ô@‰HˆC�ÜÜ—’œ˜C›¨Ñ.Ü% a¨Ó-Ø%Øñ	ˆDð × Ñ ¤¨T¸ÀSÈuÑ!UÖVñ Añ �m¨!Ñ,Ð,ô �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Ü˜¨%¸ÑRÐRùò} Pùò& "Fs   Ç!O=É?Pc           	     ó0  • SSK Jn  [        U [        5      (       d!  [	        S[        U 5      R                   35      eU R                  5       R                  5       nUR                  5       (       a  [        SUR                  5        S35      e U R                  S5      n[        [        5      nUc  [        U R                  5      US	'   O—[        U[        5      (       aa  UR                   HP  nUR!                  U5      S   n	[#        U	5      [#        U5      :X  a  [        S
U 35      eXy   R%                  U5        MR     O![	        S[        U5      R                   35      eUb¬  [        U[&        5      (       a?  [#        U5      [#        U5      :X  d&  S[#        U5       S[#        U5       S3n
[        U
5      eOX[        U[(        5      (       a"  ['        [+        UU/[#        U5      -  SS95      nO![	        S[        U5      R                   35      e0 nUR-                  5        GHŠ  u  pœUc  UR/                  5       nOU Vs/ s H  oˆ[#        X‘-   5      S PM     nnUR0                  SS2U4   R3                  SS9n[        US:„  5      (       a  [        SUR                  5        35      e[        US:H  5      (       ac  [        U[&        5      (       a  UR%                  X)   5        O[        SUR5                  5        35      eU" UR0                  SS2U4   US:H  4SS9nOUR0                  SS2U4   nU R7                  XÐR                  R8                  S9nUR                  SS9nUR                  R;                  U5      nUR=                  U5      R?                  U R@                  5      X¹'   GM�     [        U5      nUb4  UR                  R                  U R                  R8                  5      Ul        U$ ! [         a  n[	        S5      UeSnAff = fs  snf )a‚  
Create a categorical ``DataFrame`` from a ``DataFrame`` of dummy variables.

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

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. The default category
    will be coerced to the dtype of ``data.columns`` if such coercion is
    lossless, and will raise otherwise.

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
r   r   z>Expected 'data' to be a 'DataFrame'; Received 'data' of type: z.Dummy DataFrame contains NA value in column: 'Ú'rU   z(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: zLength of 'default_category' (r#   Ú)Tr4   znExpected 'default_category' to be of type 'None', 'Hashable', or 'dict'; Received 'default_category' of type: r"   r1   zEDummy DataFrame contains multi-assignment(s); First instance in row: zEDummy DataFrame contains unassigned value(s); First instance in row: r[   )!r=   r   r>   r   r@   ÚtypeÚ__name__ÚisnaÚanyr&   ÚidxmaxÚastyper   ÚlistrC   r:   Úsplitr$   rI   rD   r   rF   rG   rT   ÚlocÚsumÚidxminÚ_constructor_slicedr9   Úget_indexer_forÚtakeÚset_axisrW   )rJ   rO   Údefault_categoryr   Úcol_isna_maskÚdata_to_decodeÚerrÚvariables_slicerL   r/   r)   Úcat_dataÚprefix_sliceÚcatsÚassignedÚ
data_sliceÚ
cats_arrayÚtrue_valuesÚindexerrQ   s                       r+   Úfrom_dummiesr£   s  s  € õt 2ä�dœI×&Ñ&Üð(Ü(,¨T«
×(;Ñ(;Ð'<ð>ó
ð 	
ð
 —I‘I“K—O‘OÓ%€Mà×Ñ×ÑÜØ<¸]×=QÑ=QÓ=SÐ<TÐTUÐVó
ð 	
ð
MØŸ™ YÓ/ˆô
 "¤$Ó'€OØ
�{Ü" 4§<¡<Ó0ˆ˜ÒÜ	�Cœ×	Ñ	Ø!×)Ô)ˆCØ—Y‘Y˜s“^ AÑ&ˆFÜ�6‹{œc #›hÓ&Ü Ð#GÈÀuÐ!MÓNÐNØÑ#×*Ñ*¨3Ö/ò	 *ô ð'Ü'+¨C£y×'9Ñ'9Ð&:ð<ó
ð 	
ð
 Ñ#ÜÐ&¬×-Ñ-ÜÐ'Ó(¬C°Ó,@Ó@à4´SÐ9IÓ5JÐ4Kð Lä˜OÓ,Ð-¨Qð0ð ô
 ! Ó)Ð)ð Aô Ð(¬(×3Ñ3Ü#ÜØ#Ø%Ð&¬¨_Ó)=Ñ=Øñó Ñô ð8ô Ð(Ó)×2Ñ2Ð3ð5óð ð €HØ /× 5Ñ 5× 7ÑˆØ‰;Ø×$Ñ$Ó&‰Dá8DÓEº°œ˜F™LÓ)Ð+Ó,¹ˆDÐEØ!×%Ñ%¢a¨ oÑ6×:Ñ:ÀÐ:ÐBˆÜˆx˜!‰|×ÑÜð*Ø*2¯/©/Ó*;Ð)<ð>óð ô ˆx˜1‰}×ÑÜÐ*¬D×1Ñ1Ø—‘Ð,Ñ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øô] ó MÜÐBÓCÈÐLûðMüòb Fs   ÂO5 É PÏ5
PÏ?PÐP)Nry   FNFFN)r0   z$str | Iterable[str] | dict[str, str]r6   rh   r7   rh   r8   rh   r9   zNpDtype | Noner;   r   )ry   FFFN)NN)rJ   r   rO   z
None | strr–   z%None | Hashable | dict[str, Hashable]r;   r   )-Ú
__future__r   Úcollectionsr   Úcollections.abcr   r   rA   Útypingr   Únumpyrg   Úpandas._libsr   re   Úpandas._libs.sparser	   Úpandas.util._decoratorsr
   Úpandas.core.dtypes.commonr   r   r   r   Úpandas.core.dtypes.dtypesr   r   Úpandas.core.arraysr   Úpandas.core.arrays.categoricalr   Úpandas.core.arrays.string_r   Úpandas.core.framer   Úpandas.core.indexes.apir   r   Úpandas.core.seriesr   Úpandas._typingr   rR   rH   r£   © r.   r+   Ú<module>r¶      sr  ðÝ "å #÷ó Ý  ã å .Ý (Ý .÷ó ÷õ
 +Ý BÝ 2Ý '÷õ &æÝ&ñ ˆHÓð Ø7:ØØØØØ ðDð 5ðDð ð	Dð ðDð ðDð ðDð ôDó ðDðT 8;ØØØØ ð~Sð 5ð~Sð ð	~Sð
 ð~Sð ð~Sð ð~Sð õ~SñB ˆHÓð Ø>BðYØ
ðYà	ðYð <ðYð ô	Yó ñYr.   