
    -if              
          S SK r S SKrS SKrS SKJr  S SKJrJr  S SKr	S SK
Jr  S SK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JrJrJrJrJrJrJrJr  S r S r!S r"S r#S r$S$S jr%S S.S jr&SSS.S jr'S r(S r)S r*\" S/\" \ RV                  SSSS9S/S// SQSS/S.SS 9SSSSSS.S! j5       r,SSS".S# jr-g)%    N)UserList)compressislice)issparse)PYARROW_VERSION_BELOW_17   )_is_numpy_namespaceget_namespace)Intervalvalidate_params)_approximate_mode)	_check_sample_weight_is_arraylike_not_scalar_is_pandas_df_is_polars_df_or_series_is_pyarrow_data_use_interchange_protocolcheck_arraycheck_consistent_lengthcheck_random_statec                    [        U 5      u  pEU(       a  UR                  XUS9$ [        U 5      (       a  US:X  a  [        R                  " U5      n[        U[        5      (       a  [        U5      nUS:X  a  XS4   $ U SS2U4   $ )zAIndex an array or scipy.sparse consistently across NumPy version.axisboolr   .N)r
   taker   npasarray
isinstancetuplelist)arraykey	key_dtyper   xpis_array_apis         J/var/www/html/venv/lib/python3.13/site-packages/sklearn/utils/_indexing.py_array_indexingr'      sw    $U+Bwwuw--9.jjo#u3i"ai5c?:U1c6]:    c                 <   [        U5      (       a  [        R                  " U5      nUS:X  a?  [        U[        5      (       d*  [        R
                  " U5      (       d  U R                  XS9$ US:X  a  U R                  OU R                  nU(       a	  USS2U4   $ XA   $ )z%Index a pandas dataframe or a series.intr   N)	r   r   r   r   sliceisscalarr   ilocloc)Xr"   r#   r   indexers        r&   _pandas_indexingr1   +   s~    $$jjoE:c5#9#9R[[=M=M vvcv%% &.!&&AEE"&wq#v8GL8r(   c                     [         R                  " U5      (       d  [        U[        5      (       a  X   $ US:X  a  [	        [        X5      5      $ U Vs/ s H  o0U   PM	     sn$ s  snf )zIndex a Python list.r   )r   r,   r   r+   r    r   )r/   r"   r#   idxs       r&   _list_indexingr4   :   sV    	{{3:c511vFHQ$%%!"cscFc"""s   A$c                    [        U[        R                  5      (       a  UR                  5       nO;[        R                  " U5      (       d   [        U[
        5      (       d  [        U5      nUS:X  a	  U SS2U4   $ US:X  a  U R                  U5      $ X   n[        R                  " U5      (       aL  [        U R                  5      S:X  a3  [        R                  S   nUR                  UR                  S5      5      $ U$ )z#Index a polars dataframe or series.r   Nr      polarsr   )r   r   ndarraytolistr,   r+   r    filterlenshapesysmodulesSeriesrow)r/   r"   r#   r   	X_indexedpls         r&   _polars_indexingrC   F   s     #rzz""jjlkk#*S%"8"83iqy CyFxx} I	{{3CLA- [["yyq)**r(   c                    [         R                  " U5      n[        U[        5      (       a  [        UR                  [
        5      (       aN  U R                  R                  UR                  5      nU R                  R                  UR                  5      S-   nO+UR                  (       d  SOUR                  nUR                  nUR                  (       d  SOUR                  n[        [        XVU5      5      nUS:X  a  US:X  a9  [        U[        5      (       d$  [         R                  " U5      R                  5       nUS:X  a5  [         R                  " U5      R                  5       S   R                  5       nU(       a  U R                  U5      $ U R!                  U5      $ U(       a'  [#        U S5      (       a  U/nO=X   R%                  5       $ [        U[        5      (       d  [         R                  " U5      nUS:X  aX  [&        (       a;  SSKn[        XR*                  5      (       d  UR-                  XR/                  5       S9nU R1                  U5      n	OU R3                  U5      n	U(       a^  [5        [7        U SS/5      5      S:X  aC  [8        R:                  S	   n
U
R-                  U	R=                  5       S   R?                  5       5      $ U	$ )
zIndex a pyarrow data.r   r   r*   r   r<   N)typer6   pyarrow) r   r,   r   r+   stopstrcolumn_namesindexstartstepr    ranger   r9   nonzerocolumnselecthasattras_pyr   rF   BooleanArrayr!   bool_r:   r   r;   getattrr=   r>   	to_pylistvalues)r/   r"   r#   r   
scalar_keyrK   rG   rL   rF   rA   pas              r&   _pyarrow_indexingrZ   c   s   S!J#uchh$$NN((3E>>''1A5D YYACIIE88Dqchh5d+,qyjd&;&;**S/((*C**S/))+A.557C88C= xx} 1g%C6<<>!T""jjoF $#c#7#788mmCmmom>HHSM	 FF3K	c'!Wqc23q8 [[#xx	++-a0779::r(   Tc                    Sn[         S[        S[        S[        R                  S0nSSSSSSS.nU c  g[        U [        UR                  5       5      5      (       a   U[        U 5         $ [        U [        5      (       at  U(       d  [        S5      eU R                  c  U R                  c  g[        U R                  5      n[        U R                  5      nUb  Ub  XV:w  a  [        U5      eUb  U$ U$ [        U [         [        ["        45      (       aX  [%        U 5      nU Vs1 s H  n[        U5      iM     n	nU	(       d  g['        U	5      S:w  a  [        U5      eU	R)                  5       $ [+        U S	5      (       a  [-        U 5      u  pU(       a_  [/        U
5      (       dO  U
R1                  U R2                  S5      (       a  gU
R1                  U R2                  S
5      (       a  g[        U5      e X@R2                  R4                     $ [        U5      e! [         a    [        U5      ef = fs  snf ! [         a    [        U5      ef = f)aG  Determine the data type of key.

Parameters
----------
key : scalar, slice or array-like
    The key from which we want to infer the data type.

accept_slice : bool, default=True
    Whether or not to raise an error if the key is a slice.

Returns
-------
dtype : {'int', 'str', 'bool', None}
    Returns the data type of key.
z~No valid specification of the columns. Only a scalar, list or slice of all integers or all strings, or boolean mask is allowedr*   rH   r   )iubOUSNzBOnly array-like or scalar are supported. A Python slice was given.r   dtypeintegral)r*   rH   r   r   rT   r   r   keysrE   KeyError
ValueErrorr+   	TypeErrorrK   rG   _determine_key_typer    r   setr;   poprQ   r
   r	   isdtyperb   kind)r"   accept_sliceerr_msgdtype_to_strarray_dtype_to_strkey_start_typekey_stop_type
unique_keyeltkey_typer$   r%   s               r&   rh   rh      s'   "	  UD&"((FKL {#u\..0122	&S	** #uT  99!1,SYY7+CHH5%-*C. ))%!! #eX.//X
8BC
',
Cx=AW%%||~sG(-  3B 7 7zz#))V,,CIIz22 ))*)))..99 W
Y  	&W%%	&* D*  * ))*s   H #H-1H2 H*2Ir   c                   Uc  U $ US;  a  [        SR                  U5      5      e[        U5      nUS:X  a  US:X  a  [        S5      eUS:X  a   [        U [        5      (       a  [        S5      eUS:X  a8  [        [        U SS/5      5      =nS	:w  a  [        S
[        U 5       SU S35      eUS:X  a1  US:X  a+  [        U 5      (       d  [        U 5      (       d  [        S5      e[        U S5      (       a
  [        XX2S9$ [        U 5      (       a
  [        XX2S9$ [        U 5      (       a
  [        XX2S9$ [        U 5      (       a  [         R"                  " S[$        S9e[        U S5      (       a
  ['        XX2S9$ [)        XU5      $ )a  Return rows, items or columns of X using indices.

.. warning::

    This utility is documented, but **private**. This means that
    backward compatibility might be broken without any deprecation
    cycle.

Parameters
----------
X : array-like, sparse-matrix, list, pandas.DataFrame, pandas.Series
    Data from which to sample rows, items or columns. `list` are only
    supported when `axis=0`.
indices : bool, int, str, slice, array-like
    - If `axis=0`, boolean and integer array-like, integer slice,
      and scalar integer are supported.
    - If `axis=1`:
        - to select a single column, `indices` can be of `int` type for
          all `X` types and `str` only for dataframe. The selected subset
          will be 1D, unless `X` is a sparse matrix in which case it will
          be 2D.
        - to select multiples columns, `indices` can be one of the
          following: `list`, `array`, `slice`. The type used in
          these containers can be one of the following: `int`, 'bool' and
          `str`. However, `str` is only supported when `X` is a dataframe.
          The selected subset will be 2D.
axis : int, default=0
    The axis along which `X` will be subsampled. `axis=0` will select
    rows while `axis=1` will select columns.

Returns
-------
subset
    Subset of X on axis 0 or 1.

Notes
-----
CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are
not supported.

Examples
--------
>>> import numpy as np
>>> from sklearn.utils import _safe_indexing
>>> data = np.array([[1, 2], [3, 4], [5, 6]])
>>> _safe_indexing(data, 0, axis=0)  # select the first row
array([1, 2])
>>> _safe_indexing(data, 0, axis=1)  # select the first column
array([1, 3, 5])
)r   r   zR'axis' should be either 0 (to index rows) or 1 (to index  column). Got {} instead.r   rH   z.String indexing is not supported with 'axis=0'r   z!axis=1 is not supported for listsr<   r6   zm'X' should be a 2D NumPy array, 2D sparse matrix or dataframe when indexing the columns (i.e. 'axis=1'). Got z instead with z dimension(s).FSpecifying the columns using strings is only supported for dataframes.r-   r   zA data object with support for the dataframe interchange protocolwas passed, but scikit-learn does currently not know how to handle this kind of data. Some array/list indexing will be tried.)messagecategory)rf   formatrh   r   r    r;   rU   rE   r   r   rQ   r1   r   rC   r   rZ   warningswarnUserWarningr'   r4   )r/   indicesr   indices_dtypendims        r&   _safe_indexingr      s   f 6((.t
 	

 (0Mqy]e+IJJqyZ4((<==qyc'!Wqc":;;dA7)>$~?
 	
 		U"q!!%>q%A%AT
 	
 q&
  MEE	 	#	#MEE	!		 ]FF	"1	%	%
 mmD !	
 	
 q'q=DDa-88r(   )row_indexercolumn_indexerc                ,   Uc  [        SSS5      OUnUc  [        SSS5      OUn[        U S5      (       aI  [        R                  " 5          [        R                  " S[
        5        XR                  X#4'   SSS5        gXX#4'   g! , (       d  f       g= f)a:  Safe assignment to a numpy array, sparse matrix, or pandas dataframe.

Parameters
----------
X : {ndarray, sparse-matrix, dataframe}
    Array to be modified. It is expected to be 2-dimensional.

values : ndarray
    The values to be assigned to `X`.

row_indexer : array-like, dtype={int, bool}, default=None
    A 1-dimensional array to select the rows of interest. If `None`, all
    rows are selected.

column_indexer : array-like, dtype={int, bool}, default=None
    A 1-dimensional array to select the columns of interest. If `None`, all
    columns are selected.
Nr-   ignore)r+   rQ   r{   catch_warningssimplefilterFutureWarningr-   )r/   rW   r   r   s       r&   _safe_assignr   b  s    & .9-@%dD)kK#1#9dD$~  q&$$& !!(M:28FF;./ '& *0+
%& '&s   +B
Bc                      [        [        R                  " U5      U 5      n[        R
                  " U5      R                  5       $ ! [         a  n[	        SUS-
   SU S35      UeS nAff = f)Nzall features must be in [0, r   z] or [-z, 0])r   r   arange
IndexErrorrf   
atleast_1dr9   )r"   	n_columnsr3   es       r&   #_get_column_indices_for_bool_or_intr     sn    RYYy137
 ==$$&&	  *9q=/4P
	s    A 
A+A&&A+c                 v   [        U5      n[        U 5      (       a  [        U R                  5       X5      $ U R                  S   n[        U[        [        45      (       a	  U(       d  / $ US;   a  [        X5      $  U R                  n[        U[        5      (       a  U/nO[        U[        5      (       af  UR                  UR                  pvUb  UR!                  U5      nUb  UR!                  U5      S-   nOUS-   n[        [#        [%        U5      Xg5      5      $ [        U5      n / nU HS  n	UR!                  U	5      n
[        U
[&        R(                  5      (       d  [        SU S35      eUR+                  U
5        MU     U$ ! [         a    [        S5      ef = f! [,         a  n[        S5      UeSnAff = f)zGet feature column indices for input data X and key.

For accepted values of `key`, see the docstring of
:func:`_safe_indexing`.
r   r   r*   rw   NzSelected columns, z, are not unique in dataframe/A given column is not a column of the dataframe)rh   r   _get_column_indices_interchange__dataframe__r<   r   r    r   r   columnsAttributeErrorrf   rH   r+   rK   rG   get_locr   rM   numbersIntegralappendre   )r/   r"   r#   r   all_columnsr   rK   rG   column_indicescolcol_idxr   s               r&   _get_column_indicesr     s    $C(I ##.q/@#QQ
I#e}%%c		o	%23BB	))K
 c3eGU##))SXX4 #++E2"**4014 1}uY/=>>3iG	WN%--c2!'7+;+;<<$,WI5RS  %%g.  A  	X 	:  	WNOUVV	Ws%   ;F 'AF F
F8'F33F8c                    U R                  5       n[        U[        [        45      (       a	  U(       d  / $ US;   a  [	        X5      $ [        U R                  5       5      n[        U[        5      (       a  UR                  S;  a  [        S5      eUR                  UR                  peUb  UR                  U5      nUb  UR                  U5      S-   nOUS-   n[        [        [        U5      XV5      5      $ [        R                  " U5      (       a  U/OUn U Vs/ s H  oR                  U5      PM     sn$ s  snf ! [          a  n	[!        S5      U	eSn	A	ff = f)zBSame as _get_column_indices but for X with __dataframe__ protocol.r   )r   Nzkey.step must be 1 or NoneNr   r   )num_columnsr   r    r   r   rI   r+   rL   NotImplementedErrorrK   rG   rJ   r   rM   r   r,   rf   )
X_interchanger"   r#   r   rI   rK   rG   selected_columnsr   r   s
             r&   r   r     s7    ))+I#e}%%c		o	%23BBM6689c5!!xxy()*FGG))SXX4 $**51#))$/!3 1}uY/=>>$&KK$4$4C5#	W7GH7G&&s+7GHHH 	WNOUVV	Ws*   D< D74D< 7D< <
EEEbooleanleft)closedrandom_state)
array-likezsparse matrixNr   )replace	n_samplesr   stratifysample_weight)prefer_skip_nested_validationc           
         Un[        U5      n[        U5      S:X  a  gUS   n[        US5      (       a  UR                  S   O
[        U5      nUc  UnOXa:  a  U (       d  [	        SXa4-  5      e[        U6   Ub  U (       d  [        S5      eUb  Ub  [        S5      eUcy  U (       aD  Ub+  [        XG[        R                  S9nXDR                  5       -  nOSnUR                  UUUSS	9n	GOd[        R                  " U5      n	UR                  U	5        U	SU n	GO6[        US
SS9n
U
R                  S:X  aE  [        R                   " U
 Vs/ s H#  nSR#                  UR%                  S5      5      PM%     sn5      n
[        R&                  " U
SS9u  pUR                  S   n[        R(                  " U5      n[        R*                  " [        R,                  " USS9[        R.                  " U5      SS 5      n[1        XU5      n/ n	[3        U5       H+  nUR                  UU   UU   U S9nU	R5                  U5        M-     UR7                  U	5      n	U Vs/ s H%  n[9        U5      (       a  UR;                  5       OUPM'     nnU Vs/ s H  n[=        UU	5      PM     nn[        U5      S:X  a  US   $ U$ s  snf s  snf s  snf )aI  Resample arrays or sparse matrices in a consistent way.

The default strategy implements one step of the bootstrapping
procedure.

Parameters
----------
*arrays : sequence of array-like of shape (n_samples,) or             (n_samples, n_outputs)
    Indexable data-structures can be arrays, lists, dataframes or scipy
    sparse matrices with consistent first dimension.

replace : bool, default=True
    Implements resampling with replacement. It must be set to True
    whenever sampling with non-uniform weights: a few data points with very large
    weights are expected to be sampled several times with probability to preserve
    the distribution induced by the weights. If False, this will implement
    (sliced) random permutations.

n_samples : int, default=None
    Number of samples to generate. If left to None this is
    automatically set to the first dimension of the arrays.
    If replace is False it should not be larger than the length of
    arrays.

random_state : int, RandomState instance or None, default=None
    Determines random number generation for shuffling
    the data.
    Pass an int for reproducible results across multiple function calls.
    See :term:`Glossary <random_state>`.

stratify : {array-like, sparse matrix} of shape (n_samples,) or             (n_samples, n_outputs), default=None
    If not None, data is split in a stratified fashion, using this as
    the class labels.

sample_weight : array-like of shape (n_samples,), default=None
    Contains weight values to be associated with each sample. Values are
    normalized to sum to one and interpreted as probability for sampling
    each data point.

    .. versionadded:: 1.7

Returns
-------
resampled_arrays : sequence of array-like of shape (n_samples,) or             (n_samples, n_outputs)
    Sequence of resampled copies of the collections. The original arrays
    are not impacted.

See Also
--------
shuffle : Shuffle arrays or sparse matrices in a consistent way.

Examples
--------
It is possible to mix sparse and dense arrays in the same run::

  >>> import numpy as np
  >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])
  >>> y = np.array([0, 1, 2])

  >>> from scipy.sparse import coo_matrix
  >>> X_sparse = coo_matrix(X)

  >>> from sklearn.utils import resample
  >>> X, X_sparse, y = resample(X, X_sparse, y, random_state=0)
  >>> X
  array([[1., 0.],
         [2., 1.],
         [1., 0.]])

  >>> X_sparse
  <Compressed Sparse Row sparse matrix of dtype 'float64'
      with 4 stored elements and shape (3, 2)>

  >>> X_sparse.toarray()
  array([[1., 0.],
         [2., 1.],
         [1., 0.]])

  >>> y
  array([0, 1, 0])

  >>> resample(y, n_samples=2, random_state=0)
  array([0, 1])

Example using stratification::

  >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]
  >>> resample(y, n_samples=5, replace=False, stratify=y,
  ...          random_state=0)
  [1, 1, 1, 0, 1]
r   Nr<   z@Cannot sample %d out of arrays with dim %d when replace is FalsezCResampling with sample_weight is only implemented for replace=True.zDResampling with sample_weight is only implemented for stratify=None.)rb   T)sizepr   F)	ensure_2drb   r6    rH   )return_inverse	mergesort)rl   )r   r   )r   r;   rQ   r<   rf   r   r   r   r   float64sumchoicer   shuffler   r   r!   joinastypeuniquebincountsplitargsortcumsumr   rM   extendpermutationr   tocsrr   )r   r   r   r   r   arraysmax_n_samplesfirstr   r~   yr@   classes	y_indices	n_classesclass_countsclass_indicesn_ir\   	indices_iaresampled_arrayss                         r&   resampler     s   ` M%l3L
6{a1IE")%"9"9As5zI!

#gN()
 	

 V$ !Q
 	
  X%9!R
 	
 ( 4!

! "$5$5$77"))"	 * G ii	*G  )n}-G E>66Q; C##((3::e#45CDAYYq>MM!$	{{9- JJy{3RYY|5LSb5Q
  \Jy!A$++M!,<c!fg+VINN9% " **73 8>>v!8A;;aggiA-vF><BCFqq'2FC
!""= D0 ?Cs   *J3,J8J=)r   r   c                     [        USXS.6$ )a	  Shuffle arrays or sparse matrices in a consistent way.

This is a convenience alias to ``resample(*arrays, replace=False)`` to do
random permutations of the collections.

Parameters
----------
*arrays : sequence of indexable data-structures
    Indexable data-structures can be arrays, lists, dataframes or scipy
    sparse matrices with consistent first dimension.

random_state : int, RandomState instance or None, default=None
    Determines random number generation for shuffling
    the data.
    Pass an int for reproducible results across multiple function calls.
    See :term:`Glossary <random_state>`.

n_samples : int, default=None
    Number of samples to generate. If left to None this is
    automatically set to the first dimension of the arrays.  It should
    not be larger than the length of arrays.

Returns
-------
shuffled_arrays : sequence of indexable data-structures
    Sequence of shuffled copies of the collections. The original arrays
    are not impacted.

See Also
--------
resample : Resample arrays or sparse matrices in a consistent way.

Examples
--------
It is possible to mix sparse and dense arrays in the same run::

  >>> import numpy as np
  >>> X = np.array([[1., 0.], [2., 1.], [0., 0.]])
  >>> y = np.array([0, 1, 2])

  >>> from scipy.sparse import coo_matrix
  >>> X_sparse = coo_matrix(X)

  >>> from sklearn.utils import shuffle
  >>> X, X_sparse, y = shuffle(X, X_sparse, y, random_state=0)
  >>> X
  array([[0., 0.],
         [2., 1.],
         [1., 0.]])

  >>> X_sparse
  <Compressed Sparse Row sparse matrix of dtype 'float64'
      with 3 stored elements and shape (3, 2)>

  >>> X_sparse.toarray()
  array([[0., 0.],
         [2., 1.],
         [1., 0.]])

  >>> y
  array([2, 1, 0])

  >>> shuffle(y, n_samples=2, random_state=0)
  array([0, 1])
F)r   r   r   )r   )r   r   r   s      r&   r   r     s    D 	) r(   )T).r   r=   r{   collectionsr   	itertoolsr   r   numpyr   scipy.sparser   sklearn.utils.fixesr   
_array_apir	   r
   _param_validationr   r   extmathr   
validationr   r   r   r   r   r   r   r   r   r'   r1   r4   rC   rZ   rh   r   r   r   r   r   r   r   r    r(   r&   <module>r      s     
    &  ! 8 : 8 &
 
 
	;9	#:8vQh () m9` ,0 "0J'3lWD ;w//DH$O'(9&- #'	 x 	x v #'$ Dr(   