Ë
    ÷Q(h•>  ã                   óœ   — d dl m Z  d dlmZmZ d dlmZ d dlmZ d dlZ	d dl
mZ d dlmZ ddlmZmZmZ dd	lmZ dd
lmZ  G d„ dee«      Zy)é    )Úarray)ÚIterableÚMapping)ÚNumber)Ú
itemgetterN)Úmetadata_routingé   )ÚBaseEstimatorÚTransformerMixinÚ_fit_context)Úcheck_array)Úcheck_is_fittedc                   óü   ‡ — e Zd ZU dZdej
                  iZdegdgdgdœZe	e
d<   ej                  ddddœd	„Zdd
dddœd„Z ed¬«      dd„«       Zd„ Z ed¬«      dd„«       Ze	fd„Zd„ Zdd„Zdd„Zˆ fd„Zˆ xZS )ÚDictVectorizera¨  Transforms lists of feature-value mappings to vectors.

    This transformer turns lists of mappings (dict-like objects) of feature
    names to feature values into Numpy arrays or scipy.sparse matrices for use
    with scikit-learn estimators.

    When feature values are strings, this transformer will do a binary one-hot
    (aka one-of-K) coding: one boolean-valued feature is constructed for each
    of the possible string values that the feature can take on. For instance,
    a feature "f" that can take on the values "ham" and "spam" will become two
    features in the output, one signifying "f=ham", the other "f=spam".

    If a feature value is a sequence or set of strings, this transformer
    will iterate over the values and will count the occurrences of each string
    value.

    However, note that this transformer will only do a binary one-hot encoding
    when feature values are of type string. If categorical features are
    represented as numeric values such as int or iterables of strings, the
    DictVectorizer can be followed by
    :class:`~sklearn.preprocessing.OneHotEncoder` to complete
    binary one-hot encoding.

    Features that do not occur in a sample (mapping) will have a zero value
    in the resulting array/matrix.

    For an efficiency comparison of the different feature extractors, see
    :ref:`sphx_glr_auto_examples_text_plot_hashing_vs_dict_vectorizer.py`.

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

    Parameters
    ----------
    dtype : dtype, default=np.float64
        The type of feature values. Passed to Numpy array/scipy.sparse matrix
        constructors as the dtype argument.
    separator : str, default="="
        Separator string used when constructing new features for one-hot
        coding.
    sparse : bool, default=True
        Whether transform should produce scipy.sparse matrices.
    sort : bool, default=True
        Whether ``feature_names_`` and ``vocabulary_`` should be
        sorted when fitting.

    Attributes
    ----------
    vocabulary_ : dict
        A dictionary mapping feature names to feature indices.

    feature_names_ : list
        A list of length n_features containing the feature names (e.g., "f=ham"
        and "f=spam").

    See Also
    --------
    FeatureHasher : Performs vectorization using only a hash function.
    sklearn.preprocessing.OrdinalEncoder : Handles nominal/categorical
        features encoded as columns of arbitrary data types.

    Examples
    --------
    >>> from sklearn.feature_extraction import DictVectorizer
    >>> v = DictVectorizer(sparse=False)
    >>> D = [{'foo': 1, 'bar': 2}, {'foo': 3, 'baz': 1}]
    >>> X = v.fit_transform(D)
    >>> X
    array([[2., 0., 1.],
           [0., 1., 3.]])
    >>> v.inverse_transform(X) == [{'bar': 2.0, 'foo': 1.0},
    ...                            {'baz': 1.0, 'foo': 3.0}]
    True
    >>> v.transform({'foo': 4, 'unseen_feature': 3})
    array([[0., 0., 4.]])
    Ú	dict_typeÚno_validationÚboolean©ÚdtypeÚ	separatorÚsparseÚsortÚ_parameter_constraintsú=Tc                ó<   — || _         || _        || _        || _        y ©Nr   )Úselfr   r   r   r   s        úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/feature_extraction/_dict_vectorizer.pyÚ__init__zDictVectorizer.__init__j   s   € ØˆŒ
Ø"ˆŒØˆŒØˆ�	ó    FN©ÚfittingÚtransformingÚindicesÚvaluesc                óN  — |D ]   }	t        |	t        «      r|›| j                  ›|	›�}
d}	nt        dt	        |	«      › d�«      ‚|r#|
|vrt        |«      ||
<   |j                  |
«       |sŒh|
|v sŒm|j                  ||
   «       |j                  | j                  |	«      «       Œ¢ y)z)Add feature names for iterable of stringsé   zUnsupported type z; in iterable value. Only iterables of string are supported.N)Ú
isinstanceÚstrr   Ú	TypeErrorÚtypeÚlenÚappendr   )r   ÚfÚvÚfeature_namesÚvocabr"   r#   r$   r%   ÚvvÚfeature_names              r   Ú_add_iterable_elementz$DictVectorizer._add_iterable_elementp   s¬   € ð ò 	.ˆBÜ˜"œcÔ"Ù+,¨d¯nªn¹bÐA�Ø‘äØ'¬¨R« zð 2!ð !óð ñ
 ˜<¨uÑ4Ü&)¨-Ó&8��lÑ#Ø×$Ñ$ \Ô2â °Ò 5Ø—‘˜u \Ñ2Ô3Ø—‘˜dŸj™j¨›nÕ-ñ!	.r    )Úprefer_skip_nested_validationc                 óN  — g }i }|D ]Í  }|j                  «       D ]¸  \  }}t        |t        «      r|›| j                  ›|›�}nit        |t        «      s|€|}nTt        |t
        «      rt        dt        |«      › d|› d|› d�«      ‚t        |t        «      rd}| j                  ||||«       €Œ•||vsŒšt        |«      ||<   |j                  |«       Œº ŒÏ | j                  r.|j                  «        t        |«      D �	�ci c]  \  }	}||	“Œ
 }}	}|| _        || _        | S c c}}	w )a)  Learn a list of feature name -> indices mappings.

        Parameters
        ----------
        X : Mapping or iterable over Mappings
            Dict(s) or Mapping(s) from feature names (arbitrary Python
            objects) to feature values (strings or convertible to dtype).

            .. versionchanged:: 0.24
               Accepts multiple string values for one categorical feature.

        y : (ignored)
            Ignored parameter.

        Returns
        -------
        self : object
            DictVectorizer class instance.
        NzUnsupported value type ú for ú: z$.
Mapping objects are not supported.)Úitemsr(   r)   r   r   r   r*   r+   r   r4   r,   r-   r   Ú	enumerateÚfeature_names_Úvocabulary_)
r   ÚXÚyr0   r1   Úxr.   r/   r3   Úis
             r   ÚfitzDictVectorizer.fit�   s?  € ð* ˆØˆàò 	;ˆAØŸ™›	ò ;‘��1Ü˜a¤Ô%Ù/0°$·.².Á!Ð#D‘LÜ ¤6Ô*¨q¨yØ#$‘LÜ ¤7Ô+Ü#Ø1´$°q³'°ð ;Ø ˜c  A 3ð '=ð=óð ô
   ¤8Ô,Ø#'�LØ×.Ñ.¨q°!°]ÀEÔJàÑ+Ø#¨5Ò0Ü.1°-Ó.@˜˜lÑ+Ø%×,Ñ,¨\Õ:ñ%;ð	;ð* �9Š9Ø×ÑÔ Ü&/°Ó&>×?™d˜a �Q˜‘TÐ?ˆEÑ?à+ˆÔØ ˆÔàˆùó @s   ÄD!c                 ó¬  — t        d«      j                  dk(  sJ d«       ‚| j                  }|rg }i }n| j                  }| j                  }d}t        |t        «      r|gn|}t        d«      }dg}g }	|D �]8  }
|
j                  «       D �]  \  }}t        |t        «      r|›| j                  ›|›�}d}n{t        |t        «      s|€|}nft        |t        «      s,t        |t        «      rd }| j                  ||||||||	¬«       n*t        dt        |«      › d	|› d
|› dt        |«      › d�	«      ‚|€Œª|r#||vrt        |«      ||<   |j!                  |«       ||v sŒÔ|j!                  ||   «       |	j!                  | j                  |«      «       �Œ
 |j!                  t        |«      «       �Œ; t        |«      dk(  rt#        d«      ‚t%        j&                  |t$        j(                  ¬«      }t        |«      dz
  t        |«      f}t+        j,                  |	||f||¬«      }|rs| j.                  rg|j/                  «        t%        j0                  t        |«      t$        j2                  ¬«      }t5        |«      D ]  \  }}||   ||<   |||<   Œ |d d …|f   }| j6                  r|j9                  «        n|j;                  «       }|r|| _        || _        |S )Nr@   é   z¯sizeof(int) != 4 on your platform; please report this at https://github.com/scikit-learn/scikit-learn/issues and include the output from platform.platform() in your bug reportTr   r'   r!   zUnsupported value Type r7   r8   z.
z objects are not supported.zSample sequence X is empty.©r   )Úshaper   )r   Úitemsizer   r;   r<   r(   r   r9   r)   r   r   r   r4   r*   r+   r,   r-   Ú
ValueErrorÚnpÚ
frombufferÚintcÚspÚ
csr_matrixr   ÚemptyÚint32r:   r   Úsort_indicesÚtoarray)r   r=   r"   r   r0   r1   r#   r$   Úindptrr%   r?   r.   r/   r3   rE   Úresult_matrixÚ	map_indexÚnew_vals                     r   Ú
_transformzDictVectorizer._transformÅ   sß  € ô
 �S‹z×"Ñ" aÒ'ð 	
ðNó	
Ð'ð —
‘
ˆÙØˆMØ‰Eà ×/Ñ/ˆMØ×$Ñ$ˆEàˆô ˜a¤Ô)ˆQ‰C¨qˆä˜“*ˆØ�ˆð ˆð ó #	(ˆAØŸ™›	ó  5‘��1Ü˜a¤Ô%Ù/0°$·.².Á!Ð#D�LØ‘AÜ ¤6Ô*¨q¨yØ#$‘LÜ# A¤wÔ/´J¸qÄ(Ô4KØ#'�LØ×.Ñ.ØØØ%ØØ 'Ø%1Ø 'Ø%ð /õ 	ô $Ø1´$°q³'°ð ;Ø ˜c  A 3 cÜ ›7˜)Ð#>ð@óð ð  Ñ+Ù <°uÑ#<Ü.1°-Ó.@˜˜lÑ+Ø%×,Ñ,¨\Ô:à# uÒ,ØŸ™ u¨\Ñ':Ô;ØŸ™ d§j¡j°£mÖ4ðA 5ðD �M‰Mœ#˜g›,Ö'ðG#	(ôJ ˆv‹;˜!ÒÜÐ:Ó;Ð;ä—-‘- ¬r¯w©wÔ7ˆÜ�V“˜q‘¤# e£*Ð-ˆäŸ™Ø�W˜fÐ%¨U¸%ô
ˆñ
 �t—y’yØ×ÑÔ ÜŸ™¤ ]Ó!3¼2¿8¹8ÔDˆIÜ'¨Ó6ò #‘
�˜Ø%*¨1¡X�	˜'Ñ"Ø"��a’ð#ð *ª!¨Y¨,Ñ7ˆMà�;Š;Ø×&Ñ&Õ(à)×1Ñ1Ó3ˆMáØ"/ˆDÔØ$ˆDÔàÐr    c                 ó(   — | j                  |d¬«      S )a¬  Learn a list of feature name -> indices mappings and transform X.

        Like fit(X) followed by transform(X), but does not require
        materializing X in memory.

        Parameters
        ----------
        X : Mapping or iterable over Mappings
            Dict(s) or Mapping(s) from feature names (arbitrary Python
            objects) to feature values (strings or convertible to dtype).

            .. versionchanged:: 0.24
               Accepts multiple string values for one categorical feature.

        y : (ignored)
            Ignored parameter.

        Returns
        -------
        Xa : {array, sparse matrix}
            Feature vectors; always 2-d.
        T©r"   )rU   )r   r=   r>   s      r   Úfit_transformzDictVectorizer.fit_transform(  s   € ð0 �‰˜q¨$ˆÓ/Ð/r    c                 óÀ  — t        | d«       t        |ddg¬«      }|j                  d   }| j                  }t	        |«      D �cg c]	  } |«       ‘Œ }}t        j                  |«      r0t        |j                  «       Ž D ]  \  }}|||f   ||   ||   <   Œ |S t        |«      D ]2  \  }}	t        ||dd…f   «      D ]  \  }}
|
dk7  sŒ|||f   |	||   <   Œ Œ4 |S c c}w )aN  Transform array or sparse matrix X back to feature mappings.

        X must have been produced by this DictVectorizer's transform or
        fit_transform method; it may only have passed through transformers
        that preserve the number of features and their order.

        In the case of one-hot/one-of-K coding, the constructed feature
        names and values are returned rather than the original ones.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Sample matrix.
        dict_type : type, default=dict
            Constructor for feature mappings. Must conform to the
            collections.Mapping API.

        Returns
        -------
        D : list of dict_type objects of shape (n_samples,)
            Feature mappings for the samples in X.
        r;   ÚcsrÚcsc)Úaccept_sparser   N)
r   r   rE   r;   ÚrangerK   ÚissparseÚzipÚnonzeror:   )r   r=   r   Ú	n_samplesÚnamesÚ_Údictsr@   ÚjÚdr/   s              r   Úinverse_transformz DictVectorizer.inverse_transformB  sÿ   € ô. 	˜Ð.Ô/ô ˜¨%°¨Ô8ˆØ—G‘G˜A‘Jˆ	à×#Ñ#ˆÜ&+¨IÓ&6Ö7 ‘•Ð7ˆÐ7ä�;‰;�qŒ>Ü˜QŸY™Y›[Ð)ò -‘��1Ø%& q¨! t¡W��a‘˜˜q™Ò"ð-ð ˆô " %Ó(ò .‘��1Ü% a¨ª1¨¡gÓ.ò .‘D�A�qØ˜A“vØ&'¨¨1¨¡g˜˜% ™(šñ.ð.ð
 ˆùò 8s   ÁCc                 óD   — t        | ddg«       | j                  |d¬«      S )a  Transform feature->value dicts to array or sparse matrix.

        Named features not encountered during fit or fit_transform will be
        silently ignored.

        Parameters
        ----------
        X : Mapping or iterable over Mappings of shape (n_samples,)
            Dict(s) or Mapping(s) from feature names (arbitrary Python
            objects) to feature values (strings or convertible to dtype).

        Returns
        -------
        Xa : {array, sparse matrix}
            Feature vectors; always 2-d.
        r;   r<   FrW   )r   rU   )r   r=   s     r   Ú	transformzDictVectorizer.transformm  s'   € ô" 	˜Ð/°Ð?Ô@Ø�‰˜q¨%ˆÓ0Ð0r    c                 óð   — t        | d«       t        d„ | j                  D «       «      r#| j                  D �cg c]  }t        |«      ‘Œ }}n| j                  }t	        j
                  |t        ¬«      S c c}w )a^  Get output feature names for transformation.

        Parameters
        ----------
        input_features : array-like of str or None, default=None
            Not used, present here for API consistency by convention.

        Returns
        -------
        feature_names_out : ndarray of str objects
            Transformed feature names.
        r;   c              3   ó>   K  — | ]  }t        |t        «       –— Œ y ­wr   )r(   r)   )Ú.0Únames     r   ú	<genexpr>z7DictVectorizer.get_feature_names_out.<locals>.<genexpr>�  s   è ø€ ÒI¨T”:˜d¤CÓ(Ô(ÑIùs   ‚rD   )r   Úanyr;   r)   rH   ÚasarrayÚobject)r   Úinput_featuresrm   r0   s       r   Úget_feature_names_outz$DictVectorizer.get_feature_names_out�  sb   € ô 	˜Ð.Ô/ÜÑI°T×5HÑ5HÔIÔIØ37×3FÑ3FÖG¨4œS �YÐGˆMÑGà ×/Ñ/ˆMÜ�z‰z˜-¬vÔ6Ð6ùò Hs   ·A3c                 ó0  — t        | d«       |st        j                  |«      d   }| j                  }i }|D ]  }t	        |«      |||   <   Œ || _        t        |j                  «       t        d«      ¬«      D ��cg c]  \  }}|‘Œ	 c}}| _        | S c c}}w )a=  Restrict the features to those in support using feature selection.

        This function modifies the estimator in-place.

        Parameters
        ----------
        support : array-like
            Boolean mask or list of indices (as returned by the get_support
            member of feature selectors).
        indices : bool, default=False
            Whether support is a list of indices.

        Returns
        -------
        self : object
            DictVectorizer class instance.

        Examples
        --------
        >>> from sklearn.feature_extraction import DictVectorizer
        >>> from sklearn.feature_selection import SelectKBest, chi2
        >>> v = DictVectorizer()
        >>> D = [{'foo': 1, 'bar': 2}, {'foo': 3, 'baz': 1}]
        >>> X = v.fit_transform(D)
        >>> support = SelectKBest(chi2, k=2).fit(X, [0, 1])
        >>> v.get_feature_names_out()
        array(['bar', 'baz', 'foo'], ...)
        >>> v.restrict(support.get_support())
        DictVectorizer()
        >>> v.get_feature_names_out()
        array(['bar', 'foo'], ...)
        r;   r   r'   )Úkey)	r   rH   Úwherer;   r,   r<   Úsortedr9   r   )r   Úsupportr$   rb   Ú	new_vocabr@   r.   s          r   ÚrestrictzDictVectorizer.restrict•  s›   € ôB 	˜Ð.Ô/áÜ—h‘h˜wÓ'¨Ñ*ˆGà×#Ñ#ˆØˆ	Øò 	1ˆAÜ"% i£.ˆI�e˜A‘hÒð	1ð %ˆÔä  §¡Ó!2¼
À1»ÔF÷
Ù�!�QŠAó
ˆÔð ˆùó	
s   Á;Bc                 óh   •— t         ‰| �  «       }d|j                  _        d|j                  _        |S )NTF)ÚsuperÚ__sklearn_tags__Ú
input_tagsÚdictÚtwo_d_array)r   ÚtagsÚ	__class__s     €r   r}   zDictVectorizer.__sklearn_tags__Ç  s-   ø€ Ü‰wÑ'Ó)ˆØ#ˆ�‰ÔØ&+ˆ�‰Ô#Øˆr    r   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚUNUSEDÚ4_DictVectorizer__metadata_request__inverse_transformr)   r   r   Ú__annotations__rH   Úfloat64r   r4   r   rA   rU   rX   rg   ri   rs   rz   r}   Ú__classcell__)r‚   s   @r   r   r      sÇ   ø… ñJðZ .9Ð:J×:QÑ:QÐ,RÐ)ð !Ø�UØ�+Ø�ñ	$Ð˜Dó ð !#§
¡
°cÀ$ÈTô ð ØØØô.ñ> °Ô5ò3ó 6ð3òjañF °Ô5ò0ó 6ð0ð2 .2ó )òV1ó(7ó(0÷dð r    r   )r   Úcollections.abcr   r   Únumbersr   Úoperatorr   ÚnumpyrH   Úscipy.sparser   rK   Úsklearn.utilsr   Úbaser
   r   r   Úutilsr   Úutils.validationr   r   © r    r   ú<module>r–      s9   ðõ ß -Ý Ý ã Ý å *ç @Ñ @Ý Ý .ôxÐ% }õ xr    