
    -i@                       S SK r S SKrS SK Jr  S SK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JrJrJr  SSKJr  SS	KJr  SS
KJrJrJr  SSKJr  SSKJrJ r J!r!J"r"  SS/r# " S S\
\5      r$ " S S\$5      r% " S S\	\$5      r&g)    N)Integral)sparse   )BaseEstimatorOneToOneFeatureMixinTransformerMixin_fit_context)_safe_indexingcheck_array)_check_unknown_encode_get_counts_unique)	_get_mask)is_scalar_nan)Interval
RealNotInt
StrOptions)_get_output_config)_check_feature_names_check_feature_names_in_check_n_featurescheck_is_fittedOneHotEncoderOrdinalEncoderc                      ^  \ rS rSrSrSS jr    SS jr    SS jr\S 5       r	S r
S rS	 rS
 rU 4S jrSrU =r$ )_BaseEncoder   za
Base class for encoders that includes the code to categorize and
transform the input features.

c                    [        US5      (       a  [        USS5      S:X  de  [        USUS9n[        US5      (       dD  [        R                  " UR
                  [        R                  5      (       a  [        U[        US9nOUnSnOUnUR                  u  pV/ n[        U5       H*  n[        XS	S
9n	[        U	SSUS9n	UR                  U	5        M,     XuU4$ )a  
Perform custom check_array:
- convert list of strings to object dtype
- check for missing values for object dtype data (check_array does
  not do that)
- return list of features (arrays): this list of features is
  constructed feature by feature to preserve the data types
  of pandas DataFrame columns, as otherwise information is lost
  and cannot be used, e.g. for the `categories_` attribute.

ilocndimr   r   N)dtypeensure_all_finiter"   F   )indicesaxis)	ensure_2dr"   r#   )hasattrgetattrr   np
issubdtyper"   str_objectshaperanger
   append)
selfXr#   X_tempneeds_validation	n_samples
n_features	X_columnsiXis
             R/var/www/html/venv/lib/python3.13/site-packages/sklearn/preprocessing/_encoders.py_check_X_BaseEncoder._check_X#   s     6""wq&!'<'A $BSTF1g&&2==rww+O+OCTU$  1 !		z"A15Be4CSB R  # Z//    c                 2   U R                  5         [        XSS9  [        XSS9  U R                  XS9u  pgnXl        U R
                  S:w  a$  [        U R
                  5      U:w  a  [        S5      e/ U l        / n	U=(       d    U R                  n
[        U5       GHp  nXk   nU R
                  S:X  a+  [        XS9nU
(       a  Uu  pU	R                  U5        GOUnGO[        R                  " UR                  [        R                   5      (       a  ["        nOUR                  n[        R$                  " U R
                  U   US9nUR                  ["        :X  a\  ['        US   [(        5      (       aD  UR                  R*                  S	:w  a*  S
U S[-        US   5      R.                   S3n[        U5      eUS S  H$  n[1        U5      (       d  M  [        SU SU 35      e   UR2                  [        [        U5      5      :w  a  S
U S3n[        U5      eUR                  R*                  S;  ai  [        R4                  " U5      nSn[        R6                  " US   5      (       a  SOS n[        R8                  " US U US U :g  5      (       a  [        U5      eUS:X  a/  [;        X5      nU(       a  SR=                  UU5      n[        U5      eU
(       a  U	R                  [?        X5      5        U R                  R                  U5        GMs     SU0nU(       a  U	US'   0 nU(       aK  [A        U R                  5       H-  u  nn[1        US   5      (       d  M  UR2                  S-
  UU'   M/     UUS'   U R                  (       a  U RC                  UU	U5        U$ )NTresetr#   autozOShape mismatch: if categories is an array, it has to be of shape (n_features,).)return_countsr"   r   Sz
In column zY, the predefined categories have type 'bytes' which is incompatible with values of type 'z'.zKNan should be the last element in user provided categories, see categories z in column #z7, the predefined categories contain duplicate elements.OUSz>Unsorted categories are not supported for numerical categorieserrorz5Found unknown categories {0} in column {1} during fitr5   category_countsr$   missing_indices)"_check_infrequent_enabledr   r   r;   n_features_in_
categorieslen
ValueErrorcategories__infrequent_enabledr/   r   r0   r*   r+   r"   r,   r-   array
isinstancebyteskindtype__name__r   sizesortisnananyr   formatr   	enumerate _fit_infrequent_category_mapping)r1   r2   handle_unknownr#   rC   (return_and_ignore_missing_for_infrequentX_listr5   r6   rI   compute_countsr8   r9   resultcatscountsXi_dtypemsgcategorysorted_cats	error_msgstop_idxdiffoutputrJ   feature_idxcategories_for_idxs                              r:   _fit_BaseEncoder._fitH   sg    	&&($.TD1(, )6 )
%: )??f$4??#z1 < 
 &B$*B*Bz"AB&( B!#)LD#**62!D==27733  &H!xxHxx 2(CJJ&("47E22, %QC (!"Q%[112"6 
 %S/) !%Sb	H$X..(DDH6*1#/  !* 99GDM 22$QC (7 7  %S/)88==-"$''$-KX  &(XXk"o%>%>rDHvvk)84YhGHH(33!W,)"3D**0&q/  )o-!#**;r+@A##D)K #N y)(7F$%33<T=M=M3N// !3B!7883E3J3JQ3NOK0 4O )8F$%##11
 r=   c                 h   U R                  XS9u  pgn[        XSS9  [        XSS9  [        R                  " Xx4[
        S9n	[        R                  " Xx4[        S9n
/ n[        U5       GH  nXl   n[        XR                  U   SS9u  p[        R                  " U5      (       Gd1  US:X  a  SR                  X5      n[        U5      eU(       a  UR                  U5        XS S 2U4'   U R                  U   R                  R                   S	;   aP  U R                  U   R"                  UR"                  :  a)  UR%                  U R                  U   R                  5      nOcU R                  U   R                  R                   S
:X  a,  UR                  R                   S:X  a  UR%                  S
5      nOUR'                  5       nU R                  U   S   X) '   [)        XR                  U   SS9U	S S 2U4'   GM     U(       a  [*        R,                  " SU S3[.        5        U R1                  XU5        X4$ )NrA   Fr?   rD   T)return_maskrH   z;Found unknown categories {0} in column {1} during transform)UrE   Ort   r   )uniquescheck_unknownz$Found unknown categories in columns zH during transform. These unknown categories will be encoded as all zeros)r;   r   r   r*   zerosintonesboolr/   r   rP   allr\   rO   r0   r"   rU   itemsizeastypecopyr   warningswarnUserWarning_map_infrequent_categories)r1   r2   r_   r#   warn_on_unknownignore_category_indicesra   r5   r6   X_intX_maskcolumns_with_unknownr8   r9   rl   
valid_maskrg   s                    r:   
_transform_BaseEncoder._transform   s    )- )6 )
%: 	TE2$/)0<)0=!z"AB-b2B2B12ESWXD66*%%!W,,,2F4O  %S/)&,33A6 $.1a4L ((+1166*D ,,Q/882;;FYYt'7'7':'@'@A))!,22773>288==TWCW  YYs^WWY&*&6&6q&9!&<B{O "".>.>q.AQVWE!Q$KI #J  MM:+, -FF  	''7NO}r=   c                     U R                   n[        U R                  U5       VVs/ s H  u  p#Uc  SOX#   PM     snn$ s  snnf )z'Infrequent categories for each feature.N)_infrequent_indicesziprP   )r1   infrequent_indicesrh   r%   s       r:   infrequent_categories_#_BaseEncoder.infrequent_categories_  sT     "55 &))9)9;M%N
%N! OD)::%N
 	
 
s   ?c                 x    [        U SS5      n[        U SS5      nUSL=(       a    US:  =(       d    USLU l        g)z
This functions checks whether _infrequent_enabled is True or False.
This has to be called after parameter validation in the fit function.
max_categoriesNmin_frequencyr$   )r)   rQ   )r1   r   r   s      r:   rK   &_BaseEncoder._check_infrequent_enabled  sH    
 !'7>ot<$&>>Q+>$'$& 	 r=   c                 t   [        U R                  [        R                  5      (       a  XR                  :  nOb[        U R                  [        R                  5      (       a  X R                  -  nX:  nO&[
        R                  " UR                  S   [        S9nUR                  UR                  5       -
  S-   nU R                  bH  U R                  U:  a8  U R                  S-
  nUS:X  a  SUSS& O[
        R                  " USS9SU*  nSXH'   [
        R                  " U5      n	U	R                  S:  a  U	$ S$ )a  Compute the infrequent indices.

Parameters
----------
category_count : ndarray of shape (n_cardinality,)
    Category counts.

n_samples : int
    Number of samples.

col_idx : int
    Index of the current category. Only used for the error message.

Returns
-------
output : ndarray of shape (n_infrequent_categories,) or None
    If there are infrequent categories, indices of infrequent
    categories. Otherwise None.
r   rD   r$   NT	mergesort)rU   )rS   r   numbersr   Realr*   rx   r.   r{   rX   sumr   argsortflatnonzero)
r1   category_countr5   col_idxinfrequent_maskmin_frequency_absn_current_featuresfrequent_category_countsmallest_levelsrm   s
             r:   _identify_infrequent!_BaseEncoder._identify_infrequent  s   ( d(('*:*:;;,/A/AAO**GLL99 ),>,> >,@O hh~';';A'>dKO+00?3F3F3HH1L*t/B/BEW/W&*&9&9A&=#&!+%)" #%**^+"N---# 4800qv2d2r=   c           	      6   U(       aW  / n[        U5       HE  u  pVXS;   a*  UR                  [        R                  " XcU   5      5        M4  UR                  U5        MG     OUn[        U5       VVs/ s H  u  pxU R	                  XU5      PM     snnU l        / U l        [        U R
                  5       H  u  pYU R                  U   n
U	c  U R                  R                  S5        M4  [        U
5      nXS;   a  US-  n[        R                  " U[        R                  S9nU	R                  nX-
  nXU	'   [        R                  " [        R                  " U5      U	5      n[        R                  " U5      X'   U R                  R                  U5        M     gs  snnf )a  Fit infrequent categories.

Defines the private attribute: `_default_to_infrequent_mappings`. For
feature `i`, `_default_to_infrequent_mappings[i]` defines the mapping
from the integer encoding returned by `super().transform()` into
infrequent categories. If `_default_to_infrequent_mappings[i]` is None,
there were no infrequent categories in the training set.

For example if categories 0, 2 and 4 were frequent, while categories
1, 3, 5 were infrequent for feature 7, then these categories are mapped
to a single output:
`_default_to_infrequent_mappings[7] = array([0, 3, 1, 3, 2, 3])`

Defines private attribute: `_infrequent_indices`. `_infrequent_indices[i]`
is an array of indices such that
`categories_[i][_infrequent_indices[i]]` are all the infrequent category
labels. If the feature `i` has no infrequent categories
`_infrequent_indices[i]` is None.

.. versionadded:: 1.1

Parameters
----------
n_samples : int
    Number of samples in training set.
category_counts: list of ndarray
    `category_counts[i]` is the category counts corresponding to
    `self.categories_[i]`.
missing_indices : dict
    Dict mapping from feature_idx to category index with a missing value.
Nr$   rD   )r]   r0   r*   deleter   r   _default_to_infrequent_mappingsrP   rN   emptyint64rX   	setdiff1darange)r1   r5   rI   rJ   category_counts_rn   countr   r   
infreq_idxrd   n_catsmappingn_infrequent_catsn_frequent_catsfrequent_indicess                   r:   r^   -_BaseEncoder._fit_infrequent_category_mappingD  sv   F !&/&@"1$++		%)EF %++E2 'A  / ,55E+F$
+F' %%nI+F$
  02,'01I1I'J#K##K0D!44;;DAYF- ! hhvRXX6G * %8O"1J!||BIIf,=zJ(*		/(BG%0077@3 (K$
s   /Fc                    U R                   (       d  gU=(       d    0 n[        UR                  S   5       HC  nU R                  U   nUc  M  US   XSS2U4   ) U4'   U R                  S:X  d  M:  SUSS2U4'   ME     [        U R                  5       HG  u  pgUc  M
  Xc;   a  USS2U4   X6   :g  nO[        S5      n[        R                  " XqX4   5      XU4'   MI     g)au  Map infrequent categories to integer representing the infrequent category.

This modifies X_int in-place. Values that were invalid based on `X_mask`
are mapped to the infrequent category if there was an infrequent
category for that feature.

Parameters
----------
X_int: ndarray of shape (n_samples, n_features)
    Integer encoded categories.

X_mask: ndarray of shape (n_samples, n_features)
    Bool mask for valid values in `X_int`.

ignore_category_indices : dict
    Dictionary mapping from feature_idx to category index to ignore.
    Ignored indexes will not be grouped and the original ordinal encoding
    will remain.
Nr$   r   infrequent_if_existT)
rQ   r/   r.   r   r_   r]   r   slicer*   take)	r1   r   r   r   r   infrequent_idxr8   r   rows_to_updates	            r:   r   '_BaseEncoder._map_infrequent_categories  s    ( ''"9"?RU[[^,G!55g>N%2@2CE!W*%%w./""&;;
 &*q'z" - $D$H$HIJA+!&q!t0G0J!J!&t')wwwn>O8P'QE!#$ Jr=   c                 h   > [         TU ]  5       nSUR                  l        SUR                  l        U$ )NT)super__sklearn_tags__
input_tagscategorical	allow_nan)r1   tags	__class__s     r:   r   _BaseEncoder.__sklearn_tags__  s-    w')&*#$(!r=   )r   rQ   r   rP   rL   T)rH   TFF)rH   TFN)rW   
__module____qualname____firstlineno____doc__r;   rp   r   propertyr   rK   r   r^   r   r   __static_attributes____classcell__)r   s   @r:   r   r      sp    #0P 16tr  $BH 
 
	'+3ZPAd2Rh r=   r   c                   F   \ rS rSr% Sr\" S15      \/\" SS15      SS/S\" 1 S	k5      /\" \S
SSS9S/\" \S
SSS9\" \	SS
SS9S/S/\" S15      \
/S.r\\S'   SSS\R                  SSSSS.S jrS rS rS#S jrS rS r\" SS9S$S j5       rS rS rS$S  jrS! rS"rg)%r   i  ar+  
Encode categorical features as a one-hot numeric array.

The input to this transformer should be an array-like of integers or
strings, denoting the values taken on by categorical (discrete) features.
The features are encoded using a one-hot (aka 'one-of-K' or 'dummy')
encoding scheme. This creates a binary column for each category and
returns a sparse matrix or dense array (depending on the ``sparse_output``
parameter).

By default, the encoder derives the categories based on the unique values
in each feature. Alternatively, you can also specify the `categories`
manually.

This encoding is needed for feeding categorical data to many scikit-learn
estimators, notably linear models and SVMs with the standard kernels.

Note: a one-hot encoding of y labels should use a LabelBinarizer
instead.

Read more in the :ref:`User Guide <preprocessing_categorical_features>`.
For a comparison of different encoders, refer to:
:ref:`sphx_glr_auto_examples_preprocessing_plot_target_encoder.py`.

Parameters
----------
categories : 'auto' or a list of array-like, default='auto'
    Categories (unique values) per feature:

    - 'auto' : Determine categories automatically from the training data.
    - list : ``categories[i]`` holds the categories expected in the ith
      column. The passed categories should not mix strings and numeric
      values within a single feature, and should be sorted in case of
      numeric values.

    The used categories can be found in the ``categories_`` attribute.

    .. versionadded:: 0.20

drop : {'first', 'if_binary'} or an array-like of shape (n_features,),             default=None
    Specifies a methodology to use to drop one of the categories per
    feature. This is useful in situations where perfectly collinear
    features cause problems, such as when feeding the resulting data
    into an unregularized linear regression model.

    However, dropping one category breaks the symmetry of the original
    representation and can therefore induce a bias in downstream models,
    for instance for penalized linear classification or regression models.

    - None : retain all features (the default).
    - 'first' : drop the first category in each feature. If only one
      category is present, the feature will be dropped entirely.
    - 'if_binary' : drop the first category in each feature with two
      categories. Features with 1 or more than 2 categories are
      left intact.
    - array : ``drop[i]`` is the category in feature ``X[:, i]`` that
      should be dropped.

    When `max_categories` or `min_frequency` is configured to group
    infrequent categories, the dropping behavior is handled after the
    grouping.

    .. versionadded:: 0.21
       The parameter `drop` was added in 0.21.

    .. versionchanged:: 0.23
       The option `drop='if_binary'` was added in 0.23.

    .. versionchanged:: 1.1
        Support for dropping infrequent categories.

sparse_output : bool, default=True
    When ``True``, it returns a :class:`scipy.sparse.csr_matrix`,
    i.e. a sparse matrix in "Compressed Sparse Row" (CSR) format.

    .. versionadded:: 1.2
       `sparse` was renamed to `sparse_output`

dtype : number type, default=np.float64
    Desired dtype of output.

handle_unknown : {'error', 'ignore', 'infrequent_if_exist', 'warn'},                      default='error'
    Specifies the way unknown categories are handled during :meth:`transform`.

    - 'error' : Raise an error if an unknown category is present during transform.
    - 'ignore' : When an unknown category is encountered during
      transform, the resulting one-hot encoded columns for this feature
      will be all zeros. In the inverse transform, an unknown category
      will be denoted as None.
    - 'infrequent_if_exist' : When an unknown category is encountered
      during transform, the resulting one-hot encoded columns for this
      feature will map to the infrequent category if it exists. The
      infrequent category will be mapped to the last position in the
      encoding. During inverse transform, an unknown category will be
      mapped to the category denoted `'infrequent'` if it exists. If the
      `'infrequent'` category does not exist, then :meth:`transform` and
      :meth:`inverse_transform` will handle an unknown category as with
      `handle_unknown='ignore'`. Infrequent categories exist based on
      `min_frequency` and `max_categories`. Read more in the
      :ref:`User Guide <encoder_infrequent_categories>`.
    - 'warn' : When an unknown category is encountered during transform
      a warning is issued, and the encoding then proceeds as described for
      `handle_unknown="infrequent_if_exist"`.

    .. versionchanged:: 1.1
        `'infrequent_if_exist'` was added to automatically handle unknown
        categories and infrequent categories.

    .. versionadded:: 1.6
       The option `"warn"` was added in 1.6.

min_frequency : int or float, default=None
    Specifies the minimum frequency below which a category will be
    considered infrequent.

    - If `int`, categories with a smaller cardinality will be considered
      infrequent.

    - If `float`, categories with a smaller cardinality than
      `min_frequency * n_samples`  will be considered infrequent.

    .. versionadded:: 1.1
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

max_categories : int, default=None
    Specifies an upper limit to the number of output features for each input
    feature when considering infrequent categories. If there are infrequent
    categories, `max_categories` includes the category representing the
    infrequent categories along with the frequent categories. If `None`,
    there is no limit to the number of output features.

    .. versionadded:: 1.1
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

feature_name_combiner : "concat" or callable, default="concat"
    Callable with signature `def callable(input_feature, category)` that returns a
    string. This is used to create feature names to be returned by
    :meth:`get_feature_names_out`.

    `"concat"` concatenates encoded feature name and category with
    `feature + "_" + str(category)`.E.g. feature X with values 1, 6, 7 create
    feature names `X_1, X_6, X_7`.

    .. versionadded:: 1.3

Attributes
----------
categories_ : list of arrays
    The categories of each feature determined during fitting
    (in order of the features in X and corresponding with the output
    of ``transform``). This includes the category specified in ``drop``
    (if any).

drop_idx_ : array of shape (n_features,)
    - ``drop_idx_[i]`` is the index in ``categories_[i]`` of the category
      to be dropped for each feature.
    - ``drop_idx_[i] = None`` if no category is to be dropped from the
      feature with index ``i``, e.g. when `drop='if_binary'` and the
      feature isn't binary.
    - ``drop_idx_ = None`` if all the transformed features will be
      retained.

    If infrequent categories are enabled by setting `min_frequency` or
    `max_categories` to a non-default value and `drop_idx[i]` corresponds
    to a infrequent category, then the entire infrequent category is
    dropped.

    .. versionchanged:: 0.23
       Added the possibility to contain `None` values.

infrequent_categories_ : list of ndarray
    Defined only if infrequent categories are enabled by setting
    `min_frequency` or `max_categories` to a non-default value.
    `infrequent_categories_[i]` are the infrequent categories for feature
    `i`. If the feature `i` has no infrequent categories
    `infrequent_categories_[i]` is None.

    .. versionadded:: 1.1

n_features_in_ : int
    Number of features seen during :term:`fit`.

    .. versionadded:: 1.0

feature_names_in_ : ndarray of shape (`n_features_in_`,)
    Names of features seen during :term:`fit`. Defined only when `X`
    has feature names that are all strings.

    .. versionadded:: 1.0

feature_name_combiner : callable or None
    Callable with signature `def callable(input_feature, category)` that returns a
    string. This is used to create feature names to be returned by
    :meth:`get_feature_names_out`.

    .. versionadded:: 1.3

See Also
--------
OrdinalEncoder : Performs an ordinal (integer)
  encoding of the categorical features.
TargetEncoder : Encodes categorical features using the target.
sklearn.feature_extraction.DictVectorizer : Performs a one-hot encoding of
  dictionary items (also handles string-valued features).
sklearn.feature_extraction.FeatureHasher : Performs an approximate one-hot
  encoding of dictionary items or strings.
LabelBinarizer : Binarizes labels in a one-vs-all
  fashion.
MultiLabelBinarizer : Transforms between iterable of
  iterables and a multilabel format, e.g. a (samples x classes) binary
  matrix indicating the presence of a class label.

Examples
--------
Given a dataset with two features, we let the encoder find the unique
values per feature and transform the data to a binary one-hot encoding.

>>> from sklearn.preprocessing import OneHotEncoder

One can discard categories not seen during `fit`:

>>> enc = OneHotEncoder(handle_unknown='ignore')
>>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
>>> enc.fit(X)
OneHotEncoder(handle_unknown='ignore')
>>> enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> enc.transform([['Female', 1], ['Male', 4]]).toarray()
array([[1., 0., 1., 0., 0.],
       [0., 1., 0., 0., 0.]])
>>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])
array([['Male', 1],
       [None, 2]], dtype=object)
>>> enc.get_feature_names_out(['gender', 'group'])
array(['gender_Female', 'gender_Male', 'group_1', 'group_2', 'group_3'], ...)

One can always drop the first column for each feature:

>>> drop_enc = OneHotEncoder(drop='first').fit(X)
>>> drop_enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> drop_enc.transform([['Female', 1], ['Male', 2]]).toarray()
array([[0., 0., 0.],
       [1., 1., 0.]])

Or drop a column for feature only having 2 categories:

>>> drop_binary_enc = OneHotEncoder(drop='if_binary').fit(X)
>>> drop_binary_enc.transform([['Female', 1], ['Male', 2]]).toarray()
array([[0., 1., 0., 0.],
       [1., 0., 1., 0.]])

One can change the way feature names are created.

>>> def custom_combiner(feature, category):
...     return str(feature) + "_" + type(category).__name__ + "_" + str(category)
>>> custom_fnames_enc = OneHotEncoder(feature_name_combiner=custom_combiner).fit(X)
>>> custom_fnames_enc.get_feature_names_out()
array(['x0_str_Female', 'x0_str_Male', 'x1_int_1', 'x1_int_2', 'x1_int_3'],
      dtype=object)

Infrequent categories are enabled by setting `max_categories` or `min_frequency`.

>>> import numpy as np
>>> X = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3], dtype=object).T
>>> ohe = OneHotEncoder(max_categories=3, sparse_output=False).fit(X)
>>> ohe.infrequent_categories_
[array(['a', 'd'], dtype=object)]
>>> ohe.transform([["a"], ["b"]])
array([[0., 0., 1.],
       [1., 0., 0.]])
rB   first	if_binaryz
array-likeNno_validation>   r   rH   ignorer   r$   leftclosedr   neitherbooleanconcat)rM   dropr"   r_   r   r   sparse_outputfeature_name_combiner_parameter_constraintsTrH   )rM   r   r   r"   r_   r   r   r   c                d    Xl         X0l        X@l        XPl        X l        X`l        Xpl        Xl        g N)rM   r   r"   r_   r   r   r   r   )	r1   rM   r   r   r"   r_   r   r   r   s	            r:   __init__OneHotEncoder.__init__  s1     %*
,	*,%:"r=   c                     U R                   (       d  U$ U R                  U   nUc  U$ U R                  U   nUb7  X$;   a2  U R                  U   n[	        SXR   R                  5       < SU S35      eX2   $ )zConvert `drop_idx` into the index for infrequent categories.

If there are no infrequent categories, then `drop_idx` is
returned. This method is called in `_set_drop_idx` when the `drop`
parameter is an array-like.
zUnable to drop category z from feature z because it is infrequent)rQ   r   r   rP   rO   item)r1   rn   drop_idxdefault_to_infrequentr   rM   s         r:   _map_drop_idx_to_infrequent)OneHotEncoder._map_drop_idx_to_infrequent  s     ''O $ D D[ Q (O "55kB)h.L))+6J*:+?+D+D+F*I J'=(AC  %..r=   c                    U R                   c  SnGO[        U R                   [        5      (       a  U R                   S:X  a.  [        R                  " [        U R                  5      [        S9nGOU R                   S:X  a  U R                   Vs/ s H  n[        U5      PM     nnU R                  (       a<  [        U R                  5       H#  u  pEUc  M
  X4==   UR                  S-
  -  ss'   M%     [        R                  " U Vs/ s H  nUS:X  a  SOSPM     sn[        S9nGO[        R                  " U R                   [        S9n[        U5      nU[        U R                  5      :w  a0  Sn	[        U	R                  [        U R                  5      U5      5      e/ n
/ n[        [!        XpR                  5      5       H  u  nu  p[#        U5      (       dd  [        R$                  " X:H  5      S   nUR                  (       a$  UR'                  U R)                  XS   5      5        OU
R'                  X45        M|  [#        US	   5      (       a/  UR'                  U R)                  XR                  S-
  5      5        M  U
R'                  X45        M     [+        U
5      (       aQ  S
R                  SR-                  U
 VVs/ s H  u  nnSR                  UU5      PM     snn5      5      n	[        U	5      e[        R                  " U[        S9nWU l        U R                  (       a  Uc  U R.                  U l        g/ n[        U5       HJ  u  pU R2                  U   nUb  Uc  UnO[        R4                  " UU:H  5      S   nUR'                  U5        ML     [        R                  " U[        S9U l        gs  snf s  snf s  snnf )a  Compute the drop indices associated with `self.categories_`.

If `self.drop` is:
- `None`, No categories have been dropped.
- `'first'`, All zeros to drop the first category.
- `'if_binary'`, All zeros if the category is binary and `None`
  otherwise.
- array-like, The indices of the categories that match the
  categories in `self.drop`. If the dropped category is an infrequent
  category, then the index for the infrequent category is used. This
  means that the entire infrequent category is dropped.

This methods defines a public `drop_idx_` and a private
`_drop_idx_after_grouping`.

- `drop_idx_`: Public facing API that references the drop category in
  `self.categories_`.
- `_drop_idx_after_grouping`: Used internally to drop categories *after* the
  infrequent categories are grouped together.

If there are no infrequent categories or drop is `None`, then
`drop_idx_=_drop_idx_after_grouping`.
Nr   rD   r   r$   r   r   zF`drop` should have length equal to the number of features ({}), got {}rF   zaThe following categories were supposed to be dropped, but were not found in the training data.
{}
zCategory: {}, Feature: {})r   rS   strr*   rx   rN   rP   r-   rQ   r]   r   rX   rR   asarrayrO   r\   r   r   wherer0   r   r[   join_drop_idx_after_grouping	drop_idx_r   r   )r1   drop_idx_after_groupingcatn_features_out_no_dropr8   r   n_features_out
drop_arraydroplenrg   missing_dropsdrop_indicesrn   drop_valcat_listr   cvr   r   orig_drop_idxs                        r:   _set_drop_idxOneHotEncoder._set_drop_idx#  sc   0 99&*#		3''yyG#*,((3t7G7G3HPV*W'k)>B>N>N)O>Ns#c(>N&)O++)243K3K)L%-$.1Z__q5HH1 *M
 +-(( /E.DN ,q0d:.D !+' DIIV<J*oG#d..///  !C0@0@,A7!KLLML5>J 0 01611h %X..!xx(<=a@H}}$++ <<[ST+V &,,k-DE !".. ''88mmVWFWX "((+)@A'6* =!!  &		 -:,9DAq !< B B1a H,9!  !o%&(hh|6&J#
 )@%''+B+J!::DNI)23J)K%(,(L(L)% #'<'D$,M$&NN3HH3T$UVW$XM  / *L  ZZ	@DNi *P\s   N3N8=N=c                 &   U R                   U   nU R                  (       aX  U R                  U   nUbF  XDR                  5       :  nSn[        R
                  " X5   [        R                  " U/[        S945      nU(       a  U R                  X15      nU$ )zCompute the transformed categories used for column `i`.

1. If there are infrequent categories, the category is named
'infrequent_sklearn'.
2. Dropped columns are removed when remove_dropped=True.
infrequent_sklearnrD   )	rP   rQ   r   maxr*   concatenaterR   r-   _remove_dropped_categories)r1   r8   remove_droppedrd   
infreq_mapfrequent_maskinfrequent_cats          r:   _compute_transformed_categories-OneHotEncoder._compute_transformed_categories  s     "##==a@J% *^^-= =!5~~("((N3C6*RS 224;Dr=   c                     U R                   b3  U R                   U   b#  [        R                  " XR                   U   5      $ U$ )zRemove dropped categories.)r   r*   r   )r1   rM   r8   s      r:   r  (OneHotEncoder._remove_dropped_categories  sA     ))5--a0<99Z)F)Fq)IJJr=   c                 p   U R                    Vs/ s H  n[        U5      PM     nnU R                  b/  [        U R                  5       H  u  p4Uc  M
  X#==   S-  ss'   M     U R                  (       d  U$ [        U R
                  5       H#  u  p5Uc  M
  X#==   UR                  S-
  -  ss'   M%     U$ s  snf )z2Compute the n_features_out for each input feature.r$   )rP   rN   r   r]   rQ   r   rX   )r1   rd   rm   r8   r   r   s         r:   _compute_n_features_outs&OneHotEncoder._compute_n_features_outs  s    (,(8(89(8#d)(89((4()F)FG'INI  H ''M 't'?'?@MA!I1,,I A
 # :s   B3prefer_skip_nested_validationc                     U R                  UU R                  SS9  U R                  5         U R                  5       U l        U $ )a6  
Fit OneHotEncoder to X.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to determine the categories of each feature.

y : None
    Ignored. This parameter exists only for compatibility with
    :class:`~sklearn.pipeline.Pipeline`.

Returns
-------
self
    Fitted encoder.
	allow-nan)r_   r#   )rp   r_   r   r  _n_features_outs)r1   r2   ys      r:   fitOneHotEncoder.fit  sH    & 			..) 	 	

 	 $ = = ?r=   c                    [        U 5        [        SU S9S   nUS:w  a5  U R                  (       a$  UR                  5       n[	        U SU SU S35      eU R
                  S:X  a  S	u  pEO0U R                  S
L=(       a    U R
                  S;   nU R
                  nU R                  UUSUS9u  pgUR                  u  pU R                  bu  U R                  R                  5       n
Xj:g  n[        U R                  5       H  u  pX   b  M  [        U5      X'   M     U
R                  SS5      n
XfU
:  ==   S-  ss'   X{-  nUR                  5       n[         R"                  " S/U R$                  -   5      nXoS
S -   R                  5       U   n[         R&                  " US-   [(        S9nSUS'   [         R*                  " USUSS
 UR,                  S9  [         R"                  " USS
 USS
 S9  [         R.                  " US   5      n[0        R2                  " UUU4XS   4U R,                  S9nU R                  (       d  UR5                  5       $ U$ )a_  
Transform X using one-hot encoding.

If `sparse_output=True` (default), it returns an instance of
:class:`scipy.sparse._csr.csr_matrix` (CSR format).

If there are infrequent categories for a feature, set by specifying
`max_categories` or `min_frequency`, the infrequent categories are
grouped into a single category.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to encode.

Returns
-------
X_out : {ndarray, sparse matrix} of shape                 (n_samples, n_encoded_features)
    Transformed input. If `sparse_output=True`, a sparse matrix will be
    returned.
	transform)	estimatordensedefaultzH output does not support sparse data. Set sparse_output=False to output z dataframes or disable z1 output via` ohe.set_output(transform="default").r   )Tr   N>   r   r   r  )r_   r#   r   r$   rF   r   rD   )r&   outr"   )r  )r.   r"   )r   r   r   
capitalizerO   r_   r   r   r.   r   r   r]   rP   rN   reshaperavelr*   cumsumr  r   ry   r   r"   rz   r   
csr_matrixtoarray)r1   r2   transform_outputcapitalize_transform_outputr   r_   r   r   r5   r6   to_drop
keep_cellsr8   rd   maskfeature_indicesr%   indptrdatar  s                       r:   r  OneHotEncoder.transform  s]   . 	-kTJ7Sy(T-?-?*:*E*E*G'./ 066F5G H78 999  &(.I+O^"iit3 8K8K P 9O "00N))+	 ( 
 !&	((43388:G )J$T%5%56:%!$TGJ	 7 ooa,G'/"a'" F||~))QC$*?*?$?@3B//668>)a-s3q	
vA6!":V\\B
		&*&*-wwvbz"7F#b12**

 !!;;= Jr=   c           	      2   [        U 5        [        USS9nUR                  u  p#[        U R                  5      n[
        R                  " U R                  5      nSnUR                  S   U:w  a'  [        UR                  XQR                  S   5      5      e[        U R                  5       VVs/ s H  u  psU R                  USS9PM     nnn[
        R                  " U V	s/ s H  oR                  PM     sn	6 n
[
        R                  " X$4U
S9nSn0 nU R                  (       a  U R                   nOS	/U-  n[#        U5       GH  nU R%                  X   U5      nUR                  S   nUS:X  a-  U R                  U   U R&                  U      US	S	2U4'   UU-  nMZ  US	S	2XU-   24   n[
        R(                  " UR+                  SS
95      R-                  5       nUU   US	S	2U4'   U R.                  S:X  d  U R.                  S;   a  X   c  [
        R(                  " UR                  SS
9S:H  5      R-                  5       nUR1                  5       (       aF  U R&                  b  U R&                  U   c  UX'   OU R                  U   U R&                  U      UUU4'   O[
        R(                  " UR                  SS
9S:H  5      R-                  5       nUR1                  5       (       aM  U R&                  c%  [
        R2                  " U5      n[        SU S35      eU R&                  U   nX   U   UUU4'   UU-  nGM     U(       aJ  UR                  [4        :w  a  UR7                  [4        5      nUR9                  5        H  u  nnS	UUU4'   M     U$ s  snnf s  sn	f )a  
Convert the data back to the original representation.

When unknown categories are encountered (all zeros in the
one-hot encoding), ``None`` is used to represent this category. If the
feature with the unknown category has a dropped category, the dropped
category will be its inverse.

For a given input feature, if there is an infrequent category,
'infrequent_sklearn' will be used to represent the infrequent category.

Parameters
----------
X : {array-like, sparse matrix} of shape                 (n_samples, n_encoded_features)
    The transformed data.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    Inverse transformed array.
csr)accept_sparseIShape of the passed X data is not correct. Expected {0} columns, got {1}.r$   F)r  rD   r   N)r&   r   )r   r   zSamples z] can not be inverted when drop=None and handle_unknown='error' because they contain all zeros)r   r   r.   rN   rP   r*   r   r  rO   r\   r]   r  result_typer"   r   rQ   r   r/   r  r   r   argmaxflattenr_   r[   r   r-   r~   items)r1   r2   r5   _r6   r   rg   r8   transformed_featuresr   dtX_trjfound_unknownr   cats_wo_droppedn_categoriessublabelsunknowndroppedall_zero_samplesr   idxr&  s                            r:   inverse_transformOneHotEncoder.inverse_transform?  s   . 	/ww	))*
 5 56 X 	 771:'SZZ
CDD "$"2"23 
3 0050I3 	  
 ^^3GH3GCii3GHIxx/r:##!%!9!9"&*!4z"A"==$'O +003L
 q !--a01N1Nq1QRQT
\!Aq|+++,CZZ


 23;;=F(0DAJ""h.##'FF&)1**SWW!W_%9:BBD;;== 55=88;C+2(+/+;+;A+> 99!<,WaZ( **SWW!W_%9:BBD;;==44<+->>'+B((&'7&8 9= =   $<<Q?H';'>x'HD!$Ag #n zzV#{{6**002	T"&T3Y 3 _ 
 Is   -N Nc                    [        U 5        [        X5      n[        U R                  5       VVs/ s H  u  p#U R	                  U5      PM     nnnU R                  5       n/ n[        [        U5      5       H0  nXB    Vs/ s H  ou" X   U5      PM     nnUR                  U5        M2     [        R                  " U[        S9$ s  snnf s  snf )ao  Get output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
    Input features.

    - If `input_features` is `None`, then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.

Returns
-------
feature_names_out : ndarray of str objects
    Transformed feature names.
rD   )r   r   r]   rP   r   _check_get_feature_name_combinerr/   rN   extendr*   rR   r-   )	r1   input_featuresr8   r3  rd   name_combinerfeature_namestnamess	            r:   get_feature_names_out#OneHotEncoder.get_feature_names_out  s    ( 	0F "$"2"23
3 0033 	 

 ==?s4y!ABF'J'Q]>#4a8'EJ  ' " xxV44
 Ks   C>Cc                     U R                   S:X  a  S $ U R                  SS5      n[        U[        5      (       d  [        S[	        U5       S35      eU R                   $ )Nr   c                 $    U S-   [        U5      -   $ )Nr3  )r   )featurerh   s     r:   <lambda>@OneHotEncoder._check_get_feature_name_combiner.<locals>.<lambda>  s    Ws]S]-Jr=   rO  rh   zRWhen `feature_name_combiner` is a callable, it should return a Python string. Got z	 instead.)r   rS   r   	TypeErrorrV   )r1   dry_run_combiners     r:   rD  .OneHotEncoder._check_get_feature_name_combiner  sk    %%1JJ#99)ZP.44**./?*@)AL  ---r=   )r   r  rM   r   r   r"   r   r_   r   r   r   r   r   )rW   r   r   r   r   r   listr   r   r   callabler   dict__annotations__r*   float64r   r   r   r  r  r  r	   r  r  rA  rK  rD  r    r=   r:   r   r     s   Qh "6(+T2Wk23\4H IJ
 $HafEtLXq$v6ZAi8

 $",hZ"8(!C$D ( jj&;*/0rAh.* 5 66Unun!5F
.r=   c                   D   \ rS rSr% Sr\" S15      \/S\\" \	R                  5      /\" SS15      /\\" \	R                  5      S/\" \SSS	S
9S/\" \SSS	S
9\" \SSSS
9S/S.r\\S'   S\	R                   SS\	R                  SSS.S jr\" SS9SS j5       rS rS rSrg)r   i  a  
Encode categorical features as an integer array.

The input to this transformer should be an array-like of integers or
strings, denoting the values taken on by categorical (discrete) features.
The features are converted to ordinal integers. This results in
a single column of integers (0 to n_categories - 1) per feature.

Read more in the :ref:`User Guide <preprocessing_categorical_features>`.
For a comparison of different encoders, refer to:
:ref:`sphx_glr_auto_examples_preprocessing_plot_target_encoder.py`.

.. versionadded:: 0.20

Parameters
----------
categories : 'auto' or a list of array-like, default='auto'
    Categories (unique values) per feature:

    - 'auto' : Determine categories automatically from the training data.
    - list : ``categories[i]`` holds the categories expected in the ith
      column. The passed categories should not mix strings and numeric
      values, and should be sorted in case of numeric values.

    The used categories can be found in the ``categories_`` attribute.

dtype : number type, default=np.float64
    Desired dtype of output.

handle_unknown : {'error', 'use_encoded_value'}, default='error'
    When set to 'error' an error will be raised in case an unknown
    categorical feature is present during transform. When set to
    'use_encoded_value', the encoded value of unknown categories will be
    set to the value given for the parameter `unknown_value`. In
    :meth:`inverse_transform`, an unknown category will be denoted as None.

    .. versionadded:: 0.24

unknown_value : int or np.nan, default=None
    When the parameter handle_unknown is set to 'use_encoded_value', this
    parameter is required and will set the encoded value of unknown
    categories. It has to be distinct from the values used to encode any of
    the categories in `fit`. If set to np.nan, the `dtype` parameter must
    be a float dtype.

    .. versionadded:: 0.24

encoded_missing_value : int or np.nan, default=np.nan
    Encoded value of missing categories. If set to `np.nan`, then the `dtype`
    parameter must be a float dtype.

    .. versionadded:: 1.1

min_frequency : int or float, default=None
    Specifies the minimum frequency below which a category will be
    considered infrequent.

    - If `int`, categories with a smaller cardinality will be considered
      infrequent.

    - If `float`, categories with a smaller cardinality than
      `min_frequency * n_samples`  will be considered infrequent.

    .. versionadded:: 1.3
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

max_categories : int, default=None
    Specifies an upper limit to the number of output categories for each input
    feature when considering infrequent categories. If there are infrequent
    categories, `max_categories` includes the category representing the
    infrequent categories along with the frequent categories. If `None`,
    there is no limit to the number of output features.

    `max_categories` do **not** take into account missing or unknown
    categories. Setting `unknown_value` or `encoded_missing_value` to an
    integer will increase the number of unique integer codes by one each.
    This can result in up to `max_categories + 2` integer codes.

    .. versionadded:: 1.3
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

Attributes
----------
categories_ : list of arrays
    The categories of each feature determined during ``fit`` (in order of
    the features in X and corresponding with the output of ``transform``).
    This does not include categories that weren't seen during ``fit``.

n_features_in_ : int
    Number of features seen during :term:`fit`.

    .. versionadded:: 1.0

feature_names_in_ : ndarray of shape (`n_features_in_`,)
    Names of features seen during :term:`fit`. Defined only when `X`
    has feature names that are all strings.

    .. versionadded:: 1.0

infrequent_categories_ : list of ndarray
    Defined only if infrequent categories are enabled by setting
    `min_frequency` or `max_categories` to a non-default value.
    `infrequent_categories_[i]` are the infrequent categories for feature
    `i`. If the feature `i` has no infrequent categories
    `infrequent_categories_[i]` is None.

    .. versionadded:: 1.3

See Also
--------
OneHotEncoder : Performs a one-hot encoding of categorical features. This encoding
    is suitable for low to medium cardinality categorical variables, both in
    supervised and unsupervised settings.
TargetEncoder : Encodes categorical features using supervised signal
    in a classification or regression pipeline. This encoding is typically
    suitable for high cardinality categorical variables.
LabelEncoder : Encodes target labels with values between 0 and
    ``n_classes-1``.

Notes
-----
With a high proportion of `nan` values, inferring categories becomes slow with
Python versions before 3.10. The handling of `nan` values was improved
from Python 3.10 onwards, (c.f.
`bpo-43475 <https://github.com/python/cpython/issues/87641>`_).

Examples
--------
Given a dataset with two features, we let the encoder find the unique
values per feature and transform the data to an ordinal encoding.

>>> from sklearn.preprocessing import OrdinalEncoder
>>> enc = OrdinalEncoder()
>>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
>>> enc.fit(X)
OrdinalEncoder()
>>> enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> enc.transform([['Female', 3], ['Male', 1]])
array([[0., 2.],
       [1., 0.]])

>>> enc.inverse_transform([[1, 0], [0, 1]])
array([['Male', 1],
       ['Female', 2]], dtype=object)

By default, :class:`OrdinalEncoder` is lenient towards missing values by
propagating them.

>>> import numpy as np
>>> X = [['Male', 1], ['Female', 3], ['Female', np.nan]]
>>> enc.fit_transform(X)
array([[ 1.,  0.],
       [ 0.,  1.],
       [ 0., nan]])

You can use the parameter `encoded_missing_value` to encode missing values.

>>> enc.set_params(encoded_missing_value=-1).fit_transform(X)
array([[ 1.,  0.],
       [ 0.,  1.],
       [ 0., -1.]])

Infrequent categories are enabled by setting `max_categories` or `min_frequency`.
In the following example, "a" and "d" are considered infrequent and grouped
together into a single category, "b" and "c" are their own categories, unknown
values are encoded as 3 and missing values are encoded as 4.

>>> X_train = np.array(
...     [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3 + [np.nan]],
...     dtype=object).T
>>> enc = OrdinalEncoder(
...     handle_unknown="use_encoded_value", unknown_value=3,
...     max_categories=3, encoded_missing_value=4)
>>> _ = enc.fit(X_train)
>>> X_test = np.array([["a"], ["b"], ["c"], ["d"], ["e"], [np.nan]], dtype=object)
>>> enc.transform(X_test)
array([[2.],
       [0.],
       [1.],
       [2.],
       [3.],
       [4.]])
rB   r   rH   use_encoded_valueNr$   r   r   r   r   )rM   r"   encoded_missing_valuer_   unknown_valuer   r   r   rM   r"   r_   r^  r]  r   r   c                X    Xl         X l        X0l        X@l        XPl        X`l        Xpl        g r   r_  )r1   rM   r"   r_   r^  r]  r   r   s           r:   r   OrdinalEncoder.__init__  s,     %
,*%:"*,r=   Tr  c                 v   U R                   S:X  a  [        U R                  5      (       aH  [        R                  " U R                  5      R
                  S:w  a  [        SU R                   S35      eOi[        U R                  [        R                  5      (       d  [        SU R                   S35      eO&U R                  b  [        SU R                   S35      eU R                  UU R                   SSS	9nUS
   U l        U R                   Vs/ s H  n[        U5      PM     nnU R                  (       a8  [!        U R"                  5       H  u  pgUc  M
  XV==   [        U5      -  ss'   M!     [!        U R                  5       H&  u  p[        U	S   5      (       d  M  XX==   S-  ss'   M(     U R                   S:X  a=  U H7  n
SU R                  s=::  a  U
:  d  M  O  M   [        SU R                   S35      e   U R                  (       Ga   [        R                  " U R                  5      R
                  S:w  aI  [        U R$                  5      (       a/  [        S['        U R                  5       SU R                   S35      e[        U R$                  5      (       d  [!        U5       VV
s/ s H5  u  pXR                  ;   d  M  SU R$                  s=::  a  U
:  d  M/  O  M3  UPM7     nnn
U(       a;  [)        U S5      (       a  U R*                  U   n[        SU R$                   SU 35      eU $ s  snf s  sn
nf )aD  
Fit the OrdinalEncoder to X.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to determine the categories of each feature.

y : None
    Ignored. This parameter exists only for compatibility with
    :class:`~sklearn.pipeline.Pipeline`.

Returns
-------
self : object
    Fitted encoder.
r\  fzOWhen unknown_value is np.nan, the dtype parameter should be a float dtype. Got .z]unknown_value should be an integer or np.nan when handle_unknown is 'use_encoded_value', got zQunknown_value should only be set when handle_unknown is 'use_encoded_value', got r  T)r_   r#   r`   rJ   rF   r$   r   z!The used value for unknown_value zD is one of the values already used for encoding the seen categories.z%There are missing values in features z:. For OrdinalEncoder to encode missing values with dtype: zG, set encoded_missing_value to a non-nan value, or set dtype to a floatfeature_names_in_zencoded_missing_value (z:) is already used to encode a known category in features: )r_   r   r^  r*   r"   rU   rO   rS   r   r   rR  rp   _missing_indicesrP   rN   rQ   r]   r   r]  rU  r(   re  )r1   r2   r  fit_resultsrM   cardinalitiesrn   
infrequentcat_idxro   cardinalityinvalid_featuress               r:   r  OrdinalEncoder.fit  sS   & "55T//0088DJJ',,3$..2jj\<  4   2 2G4D4DEE  --.a1  F +))*!-  ii..)59	   
 !,,= >;?;K;KL;KZZ;KL## ,5T5P5P+Q')!.#j/A. ,R ,5T5E5E+F'G/344&!+& ,G "55,**8[88$;--. /++   -    xx

#((C/M**5 5 !;D1123 499= E++  !!;!;<< 1:-0H$0H,"7"77  T77E+E  F 0H ! $ $t%899+/+A+ABR+S($1$2L2L1M NS+,.  s MP$s   L0-L5L5L5#L5c                 ^   [        U S5        U R                  UU R                  SU R                  S9u  p#UR	                  U R
                  SS9nU R                  R                  5        H!  u  pVUSS2U4   U:H  nU R                  XGU4'   M#     U R                  S:X  a  U R                  XC) '   U$ )z
Transform X to ordinal codes.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to encode.

Returns
-------
X_out : ndarray of shape (n_samples, n_features)
    Transformed input.
rP   r  )r_   r#   r   Fr   Nr\  )	r   r   r_   rf  r~   r"   r2  r]  r^  )r1   r2   r   r   X_transrj  missing_idxX_missing_masks           r:   r  OrdinalEncoder.transform.  s     	m,..)$($9$9	 ( 
 ,,tzz,6$($9$9$?$?$A G"1g:.+=N/3/I/IGG+, %B
 "55#11GGr=   c                    [        U 5        [        USS9nUR                  u  p#[        U R                  5      nSnUR                  S   U:w  a'  [        UR                  XAR                  S   5      5      e[        R                  " U R                   Vs/ s H  ofR                  PM     sn6 n[        R                  " X$4US9n0 n	0 n
[        U SS5      n[        U5       GH  nUSS2U4   nXR                  ;   a&  [        XR                  5      nU R                  U   X'   [!        S5      nU R                  U   nUbO  X   bJ  [        U5      [        X   5      -
  nUU:H  X'   X   ) n[        R"                  " U[$        S9nSUX   '   UU   nU R&                  S	:X  aC  [        XR(                  5      nUX'   U) n[+        U[        R,                  5      (       a  UU-  nOUnX   R/                  S
SS9nUU   XU4'   GM     U	(       d  U
(       a  UR/                  [0        SS9nU	(       a!  U	R3                  5        H  u  nnSUUU4'   M     U
(       a!  U
R3                  5        H  u  nnSUUU4'   M     U$ s  snf )a  
Convert the data back to the original representation.

Parameters
----------
X : array-like of shape (n_samples, n_encoded_features)
    The transformed data.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    Inverse transformed array.
r  rA   r.  r$   rD   r   NFr\  r   ro  r   )r   r   r.   rN   rP   rO   r\   r*   r/  r"   r   r)   r/   rf  r   r]  r   	ones_liker{   r_   r^  rS   ndarrayr~   r-   r2  )r1   r2   r5   r3  r6   rg   r   r5  r6  r8  infrequent_masksr   r8   r<  X_i_maskr   rM   infrequent_encoding_valuefrequent_categories_maskunknown_labelsknown_labels
labels_intr@  r&  s                           r:   rA   OrdinalEncoder.inverse_transformN  s    	[9ww	))*
 X 	 771:#SZZ
GGAJ?@@ ^^43C3CD3CCii3CDExx/r:$T+@$Gz"Aq!tWF )))$V-G-GH#'#8#8#; "4[N))!,J!-2D2G2S,/
OcBTBW>X,X)&,0I&I #"2"5!5 ,.<<
$+O(BG();)>?'(@A
""&99!*63E3E!F#1  .nbjj99"l2N%1N/66wU6KJ&0&<D"#E #H ,;;vE;2D *002	T"&T3Y 3 -335	T"6T3Y 6 q Es   I3)rf  rM   r"   r]  r_   r   r   r^  r   )rW   r   r   r   r   r   rU  r   rV   r*   nanr   r   r   rW  rX  rY  r   r	   r  r  rA  r   rZ  r=   r:   r   r     s    wt "6(+T2 "*DL!9%w0C&DEF"DL$7#HafEtLXq$v6ZAi8
$D " jj ff-& 5j 6jX@Tr=   )'r   r   r   numpyr*   scipyr   baser   r   r   r	   utilsr
   r   utils._encoder   r   r   r   utils._maskr   utils._missingr   utils._param_validationr   r   r   utils._set_outputr   utils.validationr   r   r   r   __all__r   r   r   rZ  r=   r:   <module>r     s}         V V / I I # * F F 2  ,
-r#] rjR.L R.j|)< |r=   