ó
    §ñ:i…Ÿ  ã                   ó  • S SK r S SKrS SKJr  S SKJ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JrJr  SSKJr  SS	K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 J!r!J"r"  S r#S r$ " S S\\5      r% " S S\%5      r& " S S\\5      r'g)é    N)ÚCounter)Úpartial)ÚCallable)Úsparseé   )ÚBaseEstimatorÚTransformerMixinÚ_fit_context)Ú	_get_mask)Úis_pandas_naÚis_scalar_nan)ÚMissingValuesÚ
StrOptions)Ú_mode)Ú_get_median)ÚFLOAT_DTYPESÚ_check_feature_names_inÚcheck_is_fittedc                 óö   • [        U5      (       a  g U R                  R                  S;   aN  [        U[        R
                  5      (       d.  [        SR                  U R                  [        U5      5      5      eg g )N)ÚfÚiÚuzn'X' and 'missing_values' types are expected to be both numerical. Got X.dtype={} and  type(missing_values)={}.)	r   ÚdtypeÚkindÚ
isinstanceÚnumbersÚRealÚ
ValueErrorÚformatÚtype)ÚXÚmissing_valuess     ÚW/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/impute/_base.pyÚ_check_inputs_dtyper$      s`   € Ü�N×#Ñ#àØ‡w�w‡|�|�Ó&¬z¸.Ì'Ï,É,×/WÑ/WÜð(ç(.©¨q¯w©w¼¸^Ó8LÓ(Mó
ð 	
ð 0XÐ&ó    c                 ó”  ^• U R                   S:”  av  U R                  [        :X  aF  [        U 5      nUR	                  S5      S   S   m[        U4S jUR                  5        5       5      nO [        U 5      nUS   S   nUS   S   mOSnSmTS:X  a  US:X  a  [        R                  $ TU:  a  U$ TU:”  a  U$ TU:X  a  [        XA5      $ g)z�Compute the most frequent value in a 1d array extended with
[extra_value] * n_repeat, where extra_value is assumed to be not part
of the array.r   é   c              3   ó<   >#   • U  H  u  pUT:X  d  M  Uv •  M     g 7f©N© )Ú.0ÚvalueÚcountÚmost_frequent_counts      €r#   Ú	<genexpr>Ú!_most_frequent.<locals>.<genexpr>0   s%   øé € ð &â$3‘L�EØÐ/Ñ/÷ ‘Ú$3ùs   ƒ“	N)
Úsizer   Úobjectr   Úmost_commonÚminÚitemsr   ÚnpÚnan)ÚarrayÚextra_valueÚn_repeatÚcounterÚmost_frequent_valueÚmoder.   s         @r#   Ú_most_frequentr>   $   sá   ø€ ð
 ‡z�z�Aƒ~Ø�;‰;œ&Ó ô ˜e“nˆGØ")×"5Ñ"5°aÓ"8¸Ñ";¸AÑ">Ðä"%ô &à$+§M¡M¤Oó&ó #Ñô ˜“<ˆDØ"& q¡'¨!¡*ÐØ"& q¡'¨!¡*ÑàÐØÐð ˜aÓ H°£MÜ�v‰vˆØ	˜xÓ	'ØÐØ	˜xÓ	'Ø"Ð"Ø	 Ó	(äÐ&Ó4Ð4ð 
)r%   c                   ó„   • \ rS rSr% Sr\" 5       /S/S/S.r\\S'   \	R                  SSS.S jrS rS	 rS
 rS rS rSrg)Ú_BaseImputeréI   zQBase class for all imputers.

It adds automatically support for `add_indicator`.
Úboolean©r"   Úadd_indicatorÚkeep_empty_featuresÚ_parameter_constraintsFc                ó(   • Xl         X l        X0l        g r)   rC   )Úselfr"   rD   rE   s       r#   Ú__init__Ú_BaseImputer.__init__U   s   € ð -ÔØ*ÔØ#6Õ r%   c                 óœ   • U R                   (       a4  [        U R                  SS9U l        U R                  R	                  USS9  gSU l        g)zFit a MissingIndicator.F)r"   Úerror_on_newT)ÚprecomputedN)rD   ÚMissingIndicatorr"   Ú
indicator_Ú_fit©rH   r!   s     r#   Ú_fit_indicatorÚ_BaseImputer._fit_indicator\   sB   € à××Ü.Ø#×2Ñ2ÀñˆDŒOð �O‰O× Ñ  °Ð Ò5à"ˆD�Or%   c                 ó”   • U R                   (       a7  [        U S5      (       d  [        S5      eU R                  R	                  U5      $ g)z¨Compute the indicator mask.'

Note that X must be the original data as passed to the imputer before
any imputation, since imputation may be done inplace in some cases.
rO   z<Make sure to call _fit_indicator before _transform_indicatorN)rD   Úhasattrr   rO   Ú	transformrQ   s     r#   Ú_transform_indicatorÚ!_BaseImputer._transform_indicatorf   sF   € ð ××Ü˜4 ×.Ñ.Ü ØRóð ð —?‘?×,Ñ,¨QÓ/Ð/ð r%   c                 óò   • U R                   (       d  U$ [        R                  " U5      (       a#  [        [        R                  UR
                  S9nO[        R                  nUc  [        S5      eU" X45      $ )z1Concatenate indicator mask with the imputed data.)r   z}Data from the missing indicator are not provided. Call _fit_indicator and _transform_indicator in the imputer implementation.)rD   ÚspÚissparser   Úhstackr   r6   r   )rH   Ú	X_imputedÚX_indicatorr\   s       r#   Ú_concatenate_indicatorÚ#_BaseImputer._concatenate_indicators   si   € à×!×!ØÐä�;Š;�y×!Ñ!ô œRŸY™Y¨y×/?Ñ/?Ñ@‰Fä—Y‘YˆFàÑÜð"óð ñ �yÐ.Ó/Ð/r%   c                 óŒ   • U R                   (       d  U$ U R                  R                  U5      n[        R                  " X/5      $ r)   )rD   rO   Úget_feature_names_outr6   Úconcatenate)rH   ÚnamesÚinput_featuresÚindicator_namess       r#   Ú(_concatenate_indicator_feature_names_outÚ5_BaseImputer._concatenate_indicator_feature_names_outˆ   s6   € Ø×!×!ØˆLàŸ/™/×?Ñ?ÀÓOˆÜ�~Š~˜uÐ6Ó7Ð7r%   c                 ó0   • S[        U R                  5      0$ ©NÚ	allow_nan)r   r"   ©rH   s    r#   Ú
_more_tagsÚ_BaseImputer._more_tags�   s   € Øœ]¨4×+>Ñ+>Ó?Ð@Ð@r%   )rD   rO   rE   r"   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   rF   ÚdictÚ__annotations__r6   r7   rI   rR   rW   r_   rg   rm   Ú__static_attributes__r*   r%   r#   r@   r@   I   sW   ‡ ññ )›?Ð+Ø#˜Ø )˜{ñ$Ð˜Dó ð !#§¡°eÐQVõ7ò#ò0ò0ò*8õAr%   r@   c                   óø   ^ • \ rS rSr% Sr0 \R                  E\" 1 Sk5      \/SS/S.Er\	\
S'   \R                  SS	S
SSS.U 4S jjrS r\" S
S9SS j5       rU 4S jrU 4S jrU 4S jrS rS rSS jrSrU =r$ )ÚSimpleImputeré“   aÅ  Univariate imputer for completing missing values with simple strategies.

Replace missing values using a descriptive statistic (e.g. mean, median, or
most frequent) along each column, or using a constant value.

Read more in the :ref:`User Guide <impute>`.

.. versionadded:: 0.20
   `SimpleImputer` replaces the previous `sklearn.preprocessing.Imputer`
   estimator which is now removed.

Parameters
----------
missing_values : int, float, str, np.nan, None or pandas.NA, default=np.nan
    The placeholder for the missing values. All occurrences of
    `missing_values` will be imputed. For pandas' dataframes with
    nullable integer dtypes with missing values, `missing_values`
    can be set to either `np.nan` or `pd.NA`.

strategy : str or Callable, default='mean'
    The imputation strategy.

    - If "mean", then replace missing values using the mean along
      each column. Can only be used with numeric data.
    - If "median", then replace missing values using the median along
      each column. Can only be used with numeric data.
    - If "most_frequent", then replace missing using the most frequent
      value along each column. Can be used with strings or numeric data.
      If there is more than one such value, only the smallest is returned.
    - If "constant", then replace missing values with fill_value. Can be
      used with strings or numeric data.
    - If an instance of Callable, then replace missing values using the
      scalar statistic returned by running the callable over a dense 1d
      array containing non-missing values of each column.

    .. versionadded:: 0.20
       strategy="constant" for fixed value imputation.

    .. versionadded:: 1.5
       strategy=callable for custom value imputation.

fill_value : str or numerical value, default=None
    When strategy == "constant", `fill_value` is used to replace all
    occurrences of missing_values. For string or object data types,
    `fill_value` must be a string.
    If `None`, `fill_value` will be 0 when imputing numerical
    data and "missing_value" for strings or object data types.

copy : bool, default=True
    If True, a copy of X will be created. If False, imputation will
    be done in-place whenever possible. Note that, in the following cases,
    a new copy will always be made, even if `copy=False`:

    - If `X` is not an array of floating values;
    - If `X` is encoded as a CSR matrix;
    - If `add_indicator=True`.

add_indicator : bool, default=False
    If True, a :class:`MissingIndicator` transform will stack onto output
    of the imputer's transform. This allows a predictive estimator
    to account for missingness despite imputation. If a feature has no
    missing values at fit/train time, the feature won't appear on
    the missing indicator even if there are missing values at
    transform/test time.

keep_empty_features : bool, default=False
    If True, features that consist exclusively of missing values when
    `fit` is called are returned in results when `transform` is called.
    The imputed value is always `0` except when `strategy="constant"`
    in which case `fill_value` will be used instead.

    .. versionadded:: 1.2

Attributes
----------
statistics_ : array of shape (n_features,)
    The imputation fill value for each feature.
    Computing statistics can result in `np.nan` values.
    During :meth:`transform`, features corresponding to `np.nan`
    statistics will be discarded.

indicator_ : :class:`~sklearn.impute.MissingIndicator`
    Indicator used to add binary indicators for missing values.
    `None` if `add_indicator=False`.

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

    .. versionadded:: 0.24

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

See Also
--------
IterativeImputer : Multivariate imputer that estimates values to impute for
    each feature with missing values from all the others.
KNNImputer : Multivariate imputer that estimates missing features using
    nearest samples.

Notes
-----
Columns which only contained missing values at :meth:`fit` are discarded
upon :meth:`transform` if strategy is not `"constant"`.

In a prediction context, simple imputation usually performs poorly when
associated with a weak learner. However, with a powerful learner, it can
lead to as good or better performance than complex imputation such as
:class:`~sklearn.impute.IterativeImputer` or :class:`~sklearn.impute.KNNImputer`.

Examples
--------
>>> import numpy as np
>>> from sklearn.impute import SimpleImputer
>>> imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')
>>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])
SimpleImputer()
>>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]
>>> print(imp_mean.transform(X))
[[ 7.   2.   3. ]
 [ 4.   3.5  6. ]
 [10.   3.5  9. ]]

For a more detailed example see
:ref:`sphx_glr_auto_examples_impute_plot_missing_values.py`.
>   ÚmeanÚmedianÚconstantÚmost_frequentÚno_validationrB   )ÚstrategyÚ
fill_valueÚcopyrF   rz   NTF)r"   r   r€   r�   rD   rE   c                óH   >• [         TU ]  UUUS9  X l        X0l        X@l        g )NrC   )ÚsuperrI   r   r€   r�   )rH   r"   r   r€   r�   rD   rE   Ú	__class__s          €r#   rI   ÚSimpleImputer.__init__   s1   ø€ ô 	‰ÑØ)Ø'Ø 3ð 	ñ 	
ð
 !ŒØ$ŒØ�	r%   c           
      ó*  • U R                   S;   a6  [        U[        5      (       a  [        S U 5       5      (       a  [        nO	S nO[
        nU(       d&  U R                  R                  S:X  a  U R                  n[        U R                  5      (       d  [        U R                  5      (       a  SnOSn U R                  UUSUU(       d  SOS UU R                  S9nU(       a  UR                   U l        [#        XR                  5        UR                   R                  S
;  a$  [        SR                  UR                   5      5      e[$        R&                  " U5      (       a  U R                  S:X  a  [        S5      eU R                   S:X  a»  U(       aF  U R(                  b9  [+        U R(                  5      nSU R(                  < SU< SUR                   < S3nO?U(       d,  U R,                  R                   nSU< SUR                   < S3nOUR                   n[.        R0                  " XqR                   SS9(       d  [        W5      eU$ ! [         a>  nS[        U5      ;   a(  [        S	R                  U R                   U5      5      nUS eUeS nAff = f)N)r}   r|   c              3   óT   #   • U  H  o  H  n[        U[        5      v •  M     M      g 7fr)   )r   Ústr)r+   ÚrowÚelems      r#   r/   Ú0SimpleImputer._validate_input.<locals>.<genexpr>9  s&   é € ð +Ú12¨#»s°t”
˜4¤×%Ð%¹sÑ%²ùs   ‚&(ÚOú	allow-nanTÚcsc)ÚresetÚaccept_sparser   Úforce_writeableÚforce_all_finiter�   zcould not convertz0Cannot use {} strategy with non-numeric data:
{}©r   r   r   rŒ   zûSimpleImputer does not support data with dtype {0}. Please provide either a numeric array (with a floating point or integer dtype) or categorical data represented either as an array with integer dtype or an array of string values with an object dtype.r   údImputation not possible when missing_values == 0 and input is sparse. Provide a dense array instead.r|   zfill_value=z
 (of type z+) cannot be cast to the input data that is z2. Make sure that both dtypes are of the same kind.z%The dtype of the filling value (i.e. z\. Make sure that the dtypes of the input data is of the same kind between fit and transform.Ú	same_kind)Úcasting)r   r   ÚlistÚanyr2   r   Ú
_fit_dtyper   r   r"   r   Ú_validate_datar�   r   rˆ   r   r   r$   rZ   r[   r€   r    Ústatistics_r6   Úcan_cast)	rH   r!   Úin_fitr   r’   ÚveÚnew_veÚfill_value_dtypeÚerr_msgs	            r#   Ú_validate_inputÚSimpleImputer._validate_input3  sf  € Ø�=‰=Ð9Ó9ô
 ˜!œT×"Ñ"¤sñ +Ù12ó+÷ (ñ (ô ‘à‘ä ˆEæ˜$Ÿ/™/×.Ñ.°#Ó5à—O‘OˆEä˜×+Ñ+×,Ñ,´¸d×>QÑ>Q×0RÑ0RØ*Ñà#Ðð	Ø×#Ñ#ØØØ#ØÞ,2¡¸Ø!1Ø—Y‘Yð $ð ˆAö( àŸg™gˆDŒOä˜A×2Ñ2Ô3Ø�7‰7�<‰<Ð3Ó3Üð(÷
 )/©¨q¯w©w«óð ô �;Š;�q�>‰>˜d×1Ñ1°QÓ6ô ð!óð ð �=‰=˜JÓ&Þ˜$Ÿ/™/Ñ5Ü#'¨¯©Ó#8Ð à! $§/¡/Ñ!4°JÐ?OÑ>Rð S@Ø@AÇÁ¹{ð K=ð=ñ ö
 Ø#'×#3Ñ#3×#9Ñ#9Ð à;Ð<LÑ;Oð P@Ø@AÇÁ¹{ð K)ð)ñ ð $%§7¡7Ð ô —;’;Ð/·±À+×NÜ  Ó)Ð)àˆøôy ó 		Ø"¤c¨"£gÓ-Ü#ØG×NÑNØŸ™ róó�ð
  $Ð&à�ûð		ús   Â4(I
 É

JÉ9JÊJ©Úprefer_skip_nested_validationc                 ó‚  • U R                  USS9nU R                  c   UR                  R                  S;   a  SnOSnOU R                  n[        R
                  " U5      (       a.  U R                  XR                  U R                  U5      U l	        U $ U R                  XR                  U R                  U5      U l	        U $ )aY  Fit the imputer on `X`.

Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
    Input data, where `n_samples` is the number of samples and
    `n_features` is the number of features.

y : Ignored
    Not used, present here for API consistency by convention.

Returns
-------
self : object
    Fitted estimator.
T©r�   )r   r   r   r   Úmissing_value)r¢   r€   r   r   rZ   r[   Ú_sparse_fitr   r"   r›   Ú
_dense_fit)rH   r!   Úyr€   s       r#   ÚfitÚSimpleImputer.fit“  s«   € ð$ × Ñ  ¨4Ð Ð0ˆð �?‰?Ñ"Ø�w‰w�|‰|˜Ó.Ø‘
à,‘
àŸ™ˆJä�;Š;�q�>‰>Ø#×/Ñ/Ø—=‘= $×"5Ñ"5°zó ˆDÔð ˆð	  $Ÿ™Ø—=‘= $×"5Ñ"5°zó ˆDÔð ˆr%   c                 óâ  >• [        X5      nUR                  nUR                  S   [        R                  " UR
                  5      -
  n[        R                  " UR                  S   5      nUS:X  a  UR                  U5        GO[[        UR                  S   5       GH>  n	UR                  UR
                  U	   UR
                  U	S-       n
XaR
                  U	   UR
                  U	S-       nX«)    n
[        U
S5      nX¬)    n
UR                  5       nXy   U-   n[        U
5      S:X  a  U R                  (       a  SX‰'   M¤  US:X  a<  U
R                  U-   nUS:X  a  [        R                  OU
R                  5       U-  X‰'   Mæ  US:X  a  [        X®5      X‰'   Mû  US:X  a  [        U
SU5      X‰'   GM  [!        U["        5      (       d  GM+  U R%                  U
5      X‰'   GMA     [&        TU ]Q  U5        U$ )z#Fit the transformer on sparse data.r   r'   r|   rz   r{   r}   )r   ÚdataÚshaper6   ÚdiffÚindptrÚemptyÚfillÚrangeÚsumÚlenrE   r1   r7   r   r>   r   r   r   rƒ   rR   )rH   r!   r   r"   r€   Úmissing_maskÚ	mask_dataÚn_implicit_zerosÚ
statisticsr   ÚcolumnÚmask_columnÚ
mask_zerosÚn_explicit_zerosÚn_zerosÚsr„   s                   €r#   r©   ÚSimpleImputer._sparse_fit¼  s§  ø€ ä  Ó3ˆØ ×%Ñ%ˆ	ØŸ7™7 1™:¬¯ª°·±Ó(9Ñ9Ðä—X’X˜aŸg™g a™jÓ)ˆ
à�zÓ!ð �O‰O˜JÖ'ä˜1Ÿ7™7 1™:×&�ØŸ™ §¡¨¡¨a¯h©h°q¸1±u©oÐ>�Ø'¯©°©°a·h±h¸qÀ1¹u±oÐF�Ø Ñ-�ô ' v¨qÓ1�
Ø Ñ,�Ø#-§>¡>Ó#3Ð Ø*Ñ-Ð0@Ñ@�ä�v“; !Ó#¨×(@×(@à$%�J“Mà 6Ó)Ø"ŸK™K¨'Ñ1˜Ø23°q³&¬¯ª¸f¿j¹j»lÈQÑ>N˜
›à! XÓ-Ü(3°FÓ(D˜
›à! _Ó4Ü(6°v¸qÀ'Ó(J˜
œä# H¬h×7Ô7Ø(,¯©°fÓ(=˜
œñ5 'ô8 	‰Ñ˜|Ô,àÐr%   c                 ó2  >• [        X5      n[        R                  " XS9n[        TU ]  U5        US:X  a‚  [
        R                  R                  USS9n[
        R                  R                  U5      nU R                  (       a  SO[
        R                  U[
        R                  R                  U5      '   U$ US:X  a‚  [
        R                  R                  USS9n	[
        R                  R                  U	5      n
U R                  (       a  SO[
        R                  U
[
        R                  R                  U	5      '   U
$ US:X  Ga  UR                  5       nUR                  5       nUR                  R                  S:X  a'  [
        R                   " UR"                  S   [$        S9nO#[
        R                   " UR"                  S   5      n['        [)        US	S	 US	S	 5      5       Hx  u  nu  pï[
        R*                  " U5      R-                  [.        5      nXï   n[1        U5      S:X  a  U R                  (       a  SXÍ'   M[  [3        U[
        R                  S5      XÍ'   Mz     U$ US
:X  a,  [
        R4                  " UR"                  S   XAR                  S9$ [7        U[8        5      (       am  [
        R                   " UR"                  S   5      n[;        UR"                  S   5       H,  nU R=                  US	S	2U4   R?                  5       5      UU'   M.     U$ g	)z"Fit the transformer on dense data.)Úmaskrz   r   ©Úaxisr{   r}   rŒ   ©r   Nr|   r'   ) r   ÚmaÚmasked_arrayrƒ   rR   r6   rz   ÚgetdatarE   r7   Úgetmaskr{   ÚgetmaskarrayÚ	transposer   r   r³   r°   r2   Ú	enumerateÚzipÚlogical_notÚastypeÚboolr·   r>   Úfullr   r   rµ   r   Ú
compressed)rH   r!   r   r"   r€   r¸   Úmasked_XÚmean_maskedrz   Úmedian_maskedr{   rÄ   r}   r   r‰   Úrow_maskr»   r„   s                    €r#   rª   ÚSimpleImputer._dense_fité  s`  ø€ ä  Ó3ˆÜ—?’? 1Ñ8ˆä‰Ñ˜|Ô,ð �vÓÜŸ%™%Ÿ*™* X°A˜*Ð6ˆKä—5‘5—=‘= Ó-ˆDØ48×4L×4L©qÔRT×RXÑRXˆD”—‘—‘˜{Ó+Ñ,àˆKð ˜Ó!ÜŸE™EŸL™L¨¸˜LÐ:ˆMä—U‘U—]‘] =Ó1ˆFà×-×-‘´2·6±6ð ”2—5‘5×%Ñ% mÓ4Ñ5ð ˆMð ˜Ô(ð —‘“ˆAØ×)Ñ)Ó+ˆDà�w‰w�|‰|˜sÓ"Ü "§¢¨¯©°©¼6Ñ B‘ä "§¢¨¯©°©Ó 4�ä&/´°A±a°D¸$¹q¸'Ó0BÖ&CÑ"�‘?�CÜŸ>š>¨(Ó3×:Ñ:¼4Ó@�Ø‘m�Ü�s“8˜q“= T×%=×%=Ø'(�MÓ$ä'5°c¼2¿6¹6À1Ó'E�MÓ$ñ 'Dð !Ð ð ˜Ó#ô —7’7˜1Ÿ7™7 1™: z¿¹ÑAÐAô ˜¤(×+Ñ+ÜŸš (§.¡.°Ñ"3Ó4ˆJÜ˜8Ÿ>™>¨!Ñ,Ö-�Ø $§¡¨h²q¸!°t©n×.GÑ.GÓ.IÓ J�
˜1“ñ .àÐð	 ,r%   c                 ó  >• [        U 5        U R                  USS9nU R                  nUR                  S   UR                  S   :w  a4  [	        SUR                  S   U R                  R                  S   4-  5      e[        XR                  5      nU R                  S:X  d  U R                  (       a  UnSnOÕ[        U[        R                  5      n[        R                  " U5      nX'   n[        R                  " U5      nUR                  5       (       av  [        R                  " UR                  S   5      U   n[        U S5      (       a  U R                   U   n["        R$                  " S	U S
U R                   S35        USS2U4   n[&        R(                  " U5      (       aÚ  U R                  S:X  a  [	        S5      eUc  UR*                  n	O [        UR*                  U R                  5      n	[        R,                  " [        R                  " [/        UR0                  5      S-
  [2        S9[        R4                  " UR0                  5      5      U	   n
XJ   R7                  UR8                  SS9UR*                  U	'   OhUc  UnO	USS2U4   n[        R:                  " USS9n[        R,                  " XL5      n[        R<                  " UR?                  5       5      SSS2   nXÑU'   [@        TU ]…  U5      n[@        TU ]‰  X5      $ )a   Impute all missing values in `X`.

Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
    The input data to complete.

Returns
-------
X_imputed : {ndarray, sparse matrix} of shape                 (n_samples, n_features_out)
    `X` with imputed values.
Fr§   r'   r   z)X has %d features per sample, expected %dr|   NÚfeature_names_in_z/Skipping features without any observed values: zI. At least one non-missing value is needed for imputation with strategy='z'.r”   rÇ   )r�   rÅ   éÿÿÿÿ)#r   r¢   r›   r°   r   r   r"   r   rE   r6   r7   rÐ   Úflatnonzeror˜   ÚarangerU   rÛ   ÚwarningsÚwarnrZ   r[   r¯   Úrepeatr·   r²   Úintr±   rÑ   r   r¶   ÚwhererÍ   rƒ   rW   r_   )rH   r!   r»   r¸   Úvalid_statisticsÚvalid_statistics_indexesÚinvalid_maskÚ
valid_maskÚinvalid_featuresrÄ   ÚindexesÚmask_valid_featuresÚ	n_missingÚvaluesÚcoordinatesr^   r„   s                   €r#   rV   ÚSimpleImputer.transform*  s¸  ø€ ô 	˜Ôà× Ñ  ¨5Ð Ð1ˆØ×%Ñ%ˆ
à�7‰7�1‰:˜×)Ñ)¨!Ñ,Ó,ÜØ;Ø—7‘7˜1‘:˜t×/Ñ/×5Ñ5°aÑ8Ð9ñ:óð ô ! ×$7Ñ$7Ó8ˆð �=‰=˜JÓ&¨$×*B×*BØ)ÐØ'+Ñ$ô % Z´·±Ó8ˆLÜŸš¨Ó5ˆJØ)Ñ5ÐÜ')§~¢~°jÓ'AÐ$à×Ñ×!Ñ!Ü#%§9¢9¨Q¯W©W°Q©ZÓ#8¸Ñ#FÐ ä˜4Ð!4×5Ñ5Ø'+×'=Ñ'=Ð>NÑ'OÐ$Ü—’ðØ(Ð)ð *6Ø6:·m±m°_ÀBðHôð
 ’aÐ1Ð1Ñ2�ô �;Š;�q�>‰>Ø×"Ñ" aÓ'Ü ð%óð ð ,Ñ3Ø'×,Ñ,‘Dä$ Q§V¡V¨T×-@Ñ-@ÓA�DÜŸ)š)Ü—I’Iœc !§(¡(›m¨aÑ/´sÑ;¼R¿WºWÀQÇXÁXÓ=Nóàñ�ð  0Ñ8×?Ñ?ÀÇÁÈeÐ?ÐT�—‘�t’ð (Ñ/Ø&2Ñ#à&2²1Ð6NÐ3NÑ&OÐ#ÜŸšÐ2¸Ñ;ˆIÜ—Y’YÐ/Ó;ˆFÜŸ(š(Ð#6×#@Ñ#@Ó#BÓCÁDÀbÀDÑIˆKà#ˆk‰Nä‘gÑ2°<Ó@ˆä‰wÑ-¨aÓ=Ð=r%   c                 ó6  • [        U 5        U R                  (       d  [        SU R                   S35      e[        U R                  R
                  5      nUR                  S   U-
  nUSS2SU24   R                  5       nUSS2US24   R                  [        5      n[        U R                  5      nUR                  S   U4n[        R                  " U5      nXXSS2U R                  R
                  4'   UR                  [        5      n	Su  p«U
[        UR                  5      :  ac  [        R                  " USS2U4   5      (       d!  UR                  U
   USS2U4'   U
S-  n
US-  nOUS-  nU
[        UR                  5      :  a  Mc  U R                  X‰'   U$ )a�  Convert the data back to the original representation.

Inverts the `transform` operation performed on an array.
This operation can only be performed after :class:`SimpleImputer` is
instantiated with `add_indicator=True`.

Note that `inverse_transform` can only invert the transform in
features that have binary indicators for missing values. If a feature
has no missing values at `fit` time, the feature won't have a binary
indicator, and the imputation done at `transform` time won't be
inverted.

.. versionadded:: 0.24

Parameters
----------
X : array-like of shape                 (n_samples, n_features + n_features_missing_indicator)
    The imputed data to be reverted to original data. It has to be
    an augmented array of imputed data and the missing indicator mask.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    The original `X` with missing values as it was prior
    to imputation.
zr'inverse_transform' works only when 'SimpleImputer' is instantiated with 'add_indicator=True'. Got 'add_indicator=z
' instead.r'   Nr   )r   r   )r   rD   r   r·   rO   Ú	features_r°   r�   rÑ   rÒ   r›   r6   ÚzerosÚTÚallr"   )rH   r!   Ún_features_missingÚnon_empty_feature_countÚarray_imputedr¸   Ún_features_originalÚshape_originalÚ
X_originalÚ	full_maskÚimputed_idxÚoriginal_idxs               r#   Úinverse_transformÚSimpleImputer.inverse_transform�  s�  € ô8 	˜Ôà×!×!Üð&ð '+×&8Ñ&8Ð%9ð :ðóð ô ! §¡×!:Ñ!:Ó;ÐØ"#§'¡'¨!¡*Ð/AÑ"AÐØš!Ð5Ð5Ð5Ð5Ñ6×;Ñ;Ó=ˆØšÐ3Ñ4Ð4Ñ5×<Ñ<¼TÓBˆä! $×"2Ñ"2Ó3ÐØŸ'™' !™*Ð&9Ð:ˆÜ—X’X˜nÓ-ˆ
Ø3?’1�d—o‘o×/Ñ/Ð/Ñ0Ø×%Ñ%¤dÓ+ˆ	à$(Ñ!ˆØœC §¡Ó0Ó0Ü—6’6˜*¢Q¨ _Ñ5×6Ñ6Ø.;¯o©o¸kÑ.J�
š1˜l˜?Ñ+Ø˜qÑ �Ø Ñ!‘à Ñ!�ð œC §¡Ó0Õ0ð !%× 3Ñ 3ˆ
ÑØÐr%   c                 óh   • S[        U R                  5      =(       d    [        U R                  5      0$ rj   )r   r"   r   rl   s    r#   rm   ÚSimpleImputer._more_tags¿  s/   € àœ d×&9Ñ&9Ó:÷ 2Ü˜T×0Ñ0Ó1ð
ð 	
r%   c                 óÊ   • [        U S5        [        X5      n[        R                  " [	        U R
                  [        R                  5      5      nX   nU R                  X15      $ )áo  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.
Ún_features_in_)r   r   r6   rÐ   r   r›   r7   rg   )rH   re   Únon_missing_maskrd   s       r#   rb   Ú#SimpleImputer.get_feature_names_outÅ  sR   € ô( 	˜Ð.Ô/Ü0°ÓFˆÜŸ>š>¬)°D×4DÑ4DÄbÇfÁfÓ*MÓNÐØÑ0ˆØ×<Ñ<¸UÓSÐSr%   )r™   r�   r€   r›   r   r)   )ro   rp   rq   rr   rs   r@   rF   r   Úcallablert   ru   r6   r7   rI   r¢   r
   r¬   r©   rª   rV   rý   rm   rb   rv   Ú__classcell__)r„   s   @r#   rx   rx   “   s¶   ø‡ ñ@ðD$Ø
×
-Ñ
-ð$ñ ÒFÓGØð
ð &Ø�ò$Ð˜Dó ð —v‘vØØØØØ!÷ð ò&^ñ@ °Ñ5ó&ó 6ð&õP+õZ?õBU>òn<ò|
÷Tò Tr%   rx   c                   óð   • \ rS rSr% Sr\" 5       /\" SS15      /S\" S15      /S/S.r\\	S'   \
R                  SSS	S.S
 jrS rS rSS jr\" S	S9SS j5       rS r\" S	S9SS j5       rSS jrS rSrg)rN   ià  a  Binary indicators for missing values.

Note that this component typically should not be used in a vanilla
:class:`~sklearn.pipeline.Pipeline` consisting of transformers and a
classifier, but rather could be added using a
:class:`~sklearn.pipeline.FeatureUnion` or
:class:`~sklearn.compose.ColumnTransformer`.

Read more in the :ref:`User Guide <impute>`.

.. versionadded:: 0.20

Parameters
----------
missing_values : int, float, str, np.nan or None, default=np.nan
    The placeholder for the missing values. All occurrences of
    `missing_values` will be imputed. For pandas' dataframes with
    nullable integer dtypes with missing values, `missing_values`
    should be set to `np.nan`, since `pd.NA` will be converted to `np.nan`.

features : {'missing-only', 'all'}, default='missing-only'
    Whether the imputer mask should represent all or a subset of
    features.

    - If `'missing-only'` (default), the imputer mask will only represent
      features containing missing values during fit time.
    - If `'all'`, the imputer mask will represent all features.

sparse : bool or 'auto', default='auto'
    Whether the imputer mask format should be sparse or dense.

    - If `'auto'` (default), the imputer mask will be of same type as
      input.
    - If `True`, the imputer mask will be a sparse matrix.
    - If `False`, the imputer mask will be a numpy array.

error_on_new : bool, default=True
    If `True`, :meth:`transform` will raise an error when there are
    features with missing values that have no missing values in
    :meth:`fit`. This is applicable only when `features='missing-only'`.

Attributes
----------
features_ : ndarray of shape (n_missing_features,) or (n_features,)
    The features indices which will be returned when calling
    :meth:`transform`. They are computed during :meth:`fit`. If
    `features='all'`, `features_` is equal to `range(n_features)`.

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

    .. versionadded:: 0.24

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

See Also
--------
SimpleImputer : Univariate imputation of missing values.
IterativeImputer : Multivariate imputation of missing values.

Examples
--------
>>> import numpy as np
>>> from sklearn.impute import MissingIndicator
>>> X1 = np.array([[np.nan, 1, 3],
...                [4, 0, np.nan],
...                [8, 1, 0]])
>>> X2 = np.array([[5, 1, np.nan],
...                [np.nan, 2, 3],
...                [2, 4, 0]])
>>> indicator = MissingIndicator()
>>> indicator.fit(X1)
MissingIndicator()
>>> X2_tr = indicator.transform(X2)
>>> X2_tr
array([[False,  True],
       [ True, False],
       [False, False]])
úmissing-onlyró   rB   Úauto©r"   Úfeaturesr   rL   rF   Tc                ó4   • Xl         X l        X0l        X@l        g r)   r  )rH   r"   r  r   rL   s        r#   rI   ÚMissingIndicator.__init__<  s   € ð -ÔØ ŒØŒØ(Õr%   c                 óâ  • U R                   (       d  [        XR                  5      nOUn[        R                  " U5      (       ap  UR                  5         U R                  S:X  a  UR                  SS9nU R                  SL a  UR                  5       nOŽUR                  S:X  a  UR                  5       nOmU R                   (       d  [        XR                  5      nOUnU R                  S:X  a  UR                  SS9nU R                  SL a  [        R                  " U5      nU R                  S:X  a&  [        R                  " UR                   S   5      nX$4$ [        R"                  " W5      nX$4$ )	a8  Compute the imputer mask and the indices of the features
containing missing values.

Parameters
----------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
    The input data with missing values. Note that `X` has been
    checked in :meth:`fit` and :meth:`transform` before to call this
    function.

Returns
-------
imputer_mask : {ndarray, sparse matrix} of shape         (n_samples, n_features)
    The imputer mask of the original data.

features_with_missing : ndarray of shape (n_features_with_missing)
    The features containing missing values.
r	  r   rÅ   FÚcsrTró   r'   )Ú_precomputedr   r"   rZ   r[   Úeliminate_zerosr  Úgetnnzr   Útoarrayr   Útocscr¶   Ú
csc_matrixr6   rÞ   r°   rÝ   )rH   r!   Úimputer_maskrë   Úfeatures_indicess        r#   Ú_get_missing_features_infoÚ+MissingIndicator._get_missing_features_infoI  s0  € ð( × × Ü$ Q×(;Ñ(;Ó<‰LàˆLä�;Š;�q�>‰>Ø×(Ñ(Ô*à�}‰} Ó.Ø(×/Ñ/°QÐ/Ð7�	à�{‰{˜eÒ#Ø+×3Ñ3Ó5‘Ø×$Ñ$¨Ó-Ø+×1Ñ1Ó3�øà×$×$Ü(¨×,?Ñ,?Ó@‘à �à�}‰} Ó.Ø(×,Ñ,°!Ð,Ð4�	à�{‰{˜dÒ"Ü!Ÿ}š}¨\Ó:�à�=‰=˜EÓ!Ü!Ÿyšy¨¯©°©Ó4Ðð Ð-Ð-ô  "Ÿ~š~¨iÓ8ÐàÐ-Ð-r%   c                 ó|  • [        U R                  5      (       d  SnOSnU R                  UUSS US9n[        XR                  5        UR                  R
                  S;  a$  [        SR                  UR                  5      5      e[        R                  " U5      (       a  U R                  S:X  a  [        S5      eU$ )	NTr�   )rŽ   r  )r�   r�   r   r’   r“   zþMissingIndicator does not support data with dtype {0}. Please provide either a numeric array (with a floating point or integer dtype) or categorical data represented either as an array with integer dtype or an array of string values with an object dtype.r   zSSparse input with missing_values=0 is not supported. Provide a dense array instead.)
r   r"   rš   r$   r   r   r   r   rZ   r[   )rH   r!   r�   r’   s       r#   r¢   Ú MissingIndicator._validate_input  s¼   € Ü˜T×0Ñ0×1Ñ1Ø#Ñà*ÐØ×ÑØØØ(ØØ-ð  ð 
ˆô 	˜A×2Ñ2Ô3Ø�7‰7�<‰<Ð3Ó3Üð(÷
 )/©¨q¯w©w«óð ô �;Š;�q�>‰>˜d×1Ñ1°QÓ6ô ð!óð ð ˆr%   Nc                 óf  • U(       a>  [        US5      (       a  UR                  R                  S:X  d  [        S5      eSU l        OSU l        U R                  (       d  U R                  USS9nOU R                  USS9  UR                  S   U l        U R                  U5      nUS   U l
        US	   $ )
aç  Fit the transformer on `X`.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
    Input data, where `n_samples` is the number of samples and
    `n_features` is the number of features.
    If `precomputed=True`, then `X` is a mask of the input data.

precomputed : bool
    Whether the input data is a mask.

Returns
-------
imputer_mask : {ndarray, sparse matrix} of shape (n_samples,         n_features)
    The imputer mask of the original data.
r   Úbú4precomputed is True but the input data is not a maskTFr§   )r�   r'   r   )rU   r   r   r   r  r¢   Ú_check_n_featuresr°   Ú_n_featuresr  rð   )rH   r!   r«   rM   Úmissing_features_infos        r#   rP   ÚMissingIndicator._fit¡  s¬   € ö& Ü˜A˜w×'Ñ'¨A¯G©G¯L©L¸CÓ,?Ü Ð!WÓXÐXØ $ˆDÕà %ˆDÔð × × Ø×$Ñ$ Q¨tÐ$Ð4‰Að ×"Ñ" 1¨DÐ"Ñ1àŸ7™7 1™:ˆÔà $× ?Ñ ?ÀÓ BÐØ.¨qÑ1ˆŒà$ QÑ'Ð'r%   r¤   c                 ó(   • U R                  X5        U $ )aZ  Fit the transformer on `X`.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
    Input data, where `n_samples` is the number of samples and
    `n_features` is the number of features.

y : Ignored
    Not used, present for API consistency by convention.

Returns
-------
self : object
    Fitted estimator.
)rP   )rH   r!   r«   s      r#   r¬   ÚMissingIndicator.fitÊ  s   € ð$ 	�	‰	�!Œàˆr%   c                 ó6  • [        U 5        U R                  (       d  U R                  USS9nO6[        US5      (       a  UR                  R
                  S:X  d  [        S5      eU R                  U5      u  p#U R                  S:X  a’  [        R                  " X0R                  5      nU R                  (       a*  UR                  S:”  a  [        SR                  U5      5      eU R                  R                  U R                  :  a  US	S	2U R                  4   nU$ )
ax  Generate missing values indicator for `X`.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
    The input data to complete.

Returns
-------
Xt : {ndarray, sparse matrix} of shape (n_samples, n_features)         or (n_samples, n_features_with_missing)
    The missing indicator for input data. The data type of `Xt`
    will be boolean.
Fr§   r   r  r  r	  r   zSThe features {} have missing values in transform but have no missing values in fit.N)r   r  r¢   rU   r   r   r   r  r  r6   Ú	setdiff1drð   rL   r1   r   r!  )rH   r!   r  r  Úfeatures_diff_fit_transs        r#   rV   ÚMissingIndicator.transformà  sí   € ô 	˜Ôð × × Ø×$Ñ$ Q¨uÐ$Ð5‰Aä˜A˜w×'Ñ'¨A¯G©G¯L©L¸CÓ,?Ü Ð!WÓXÐXà!%×!@Ñ!@ÀÓ!CÑˆà�=‰=˜NÓ*Ü&(§l¢l°8¿^¹^Ó&LÐ#Ø× × Ð%<×%AÑ%AÀAÓ%EÜ ðç$™fÐ%<Ó=óð ð �~‰~×"Ñ" T×%5Ñ%5Ó5Ø+ªA¨t¯~©~Ð,=Ñ>�àÐr%   c                 ó–   • U R                  X5      nU R                  R                  U R                  :  a  USS2U R                  4   nU$ )a¾  Generate missing values indicator for `X`.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
    The input data to complete.

y : Ignored
    Not used, present for API consistency by convention.

Returns
-------
Xt : {ndarray, sparse matrix} of shape (n_samples, n_features)         or (n_samples, n_features_with_missing)
    The missing indicator for input data. The data type of `Xt`
    will be boolean.
N)rP   rð   r1   r!  )rH   r!   r«   r  s       r#   Úfit_transformÚMissingIndicator.fit_transform	  sB   € ð& —y‘y “ˆà�>‰>×Ñ ×!1Ñ!1Ó1Ø'ª¨4¯>©>Ð(9Ñ:ˆLàÐr%   c                 óø   • [        U S5        [        X5      nU R                  R                  R	                  5       n[
        R                  " XR                      Vs/ s H
  nU SU 3PM     sn[        S9$ s  snf )r  r  Ú_rÇ   )	r   r   r„   ro   Úlowerr6   Úasarrayrð   r2   )rH   re   ÚprefixÚfeature_names       r#   rb   Ú&MissingIndicator.get_feature_names_out#  s{   € ô( 	˜Ð.Ô/Ü0°ÓFˆØ—‘×(Ñ(×.Ñ.Ó0ˆÜ�zŠzð %3·>±>Ò$Bóâ$B�Lð �(˜!˜L˜>Ó*Ù$Bñô ñ
ð 	
ùòs   ÁA7c                 ó   • SSS// S.$ )NTÚ2darrayÚstring)rk   ÚX_typesÚpreserves_dtyper*   rl   s    r#   rm   ÚMissingIndicator._more_tagsB  s   € àØ! 8Ð,Ø!ñ
ð 	
r%   )r!  r  rL   r  rð   r"   r   )NFr)   )ro   rp   rq   rr   rs   r   r   rF   rt   ru   r6   r7   rI   r  r¢   rP   r
   r¬   rV   r+  rb   rm   rv   r*   r%   r#   rN   rN   à  s±   ‡ ñRñj )›?Ð+Ù °Ð 7Ó8Ð9Ø™j¨&¨Ó2Ð3Ø"˜ñ	$Ð˜Dó ð —v‘vØØØõ)ò4.òl ôD'(ñR °Ñ5óó 6ðò*'ñR °Ñ5óó 6ðô2
õ>
r%   rN   )(r   rß   Úcollectionsr   Ú	functoolsr   Útypingr   Únumpyr6   Únumpy.marÈ   Úscipyr   rZ   Úbaser   r	   r
   Úutils._maskr   Úutils._missingr   r   Úutils._param_validationr   r   Úutils.fixesr   Úutils.sparsefuncsr   Úutils.validationr   r   r   r$   r>   r@   rx   rN   r*   r%   r#   Ú<module>rG     s{   ðó
 Û Ý Ý Ý ã Ý Ý ç @Ñ @Ý #ß 8ß ?Ý Ý +ß UÑ Uò	
ò"5ôJGAÐ# ]ô GAôTJ	T�Lô J	TôZg
Ð'¨õ g
r%   