Ë
    u™ãjë  ã                  ó´   — d 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
mZ erddlmZmZ ddlmZ 	 	 	 	 	 	 	 	 dd	„Z	 	 	 	 	 	 	 	 dd
„Z	 	 	 	 	 	 	 	 	 	 	 	 dd„Zy)zH
Module containing utilities for NDFrame.sample() and .GroupBy.sample()
é    )Úannotations)ÚTYPE_CHECKINGN)Úlib)ÚABCDataFrameÚ	ABCSeries)ÚAxisIntÚListLike)ÚNDFramec                ó  — t        |t        «      r|j                  | j                  |   «      }t        |t        «      r2t        | t
        «      r|dk(  r	 | |   }nt        d«      ‚t        d«      ‚t        | t        «      r| j                  }n| j                  }t        j                   ||d¬«      j                  t        j                  ¬«      }t        |«      | j                  |   k7  rt        d«      ‚t!        j"                  |«      rt        d	«      ‚|dk  j%                  «       rt        d
«      ‚t        j&                  |«      }|j%                  «       r|j)                  «       }d||<   |S # t        $ r}t        d«      |‚d}~ww xY w)zþ
    Process and validate the `weights` argument to `NDFrame.sample` and
    `.GroupBy.sample`.

    Returns `weights` as an ndarray[np.float64], validated except for normalizing
    weights (because that must be done groupwise in groupby sampling).
    r   z+String passed to weights not a valid columnNzLStrings can only be passed to weights when sampling from rows on a DataFramez@Strings cannot be passed as weights when sampling from a Series.Úfloat64)Údtypez5Weights and axis to be sampled must be of same lengthz+weights vector may not include `inf` valuesz.weights vector may not include negative values)Ú
isinstancer   ÚreindexÚaxesÚstrr   ÚKeyErrorÚ
ValueErrorÚ_constructorÚ_constructor_slicedÚnpÚasarrayÚ_valuesr   ÚlenÚshaper   Úhas_infsÚanyÚisnanÚcopy)ÚobjÚweightsÚaxisÚerrÚfuncÚweights_arrÚmissings          ú]/var/www/html/python-recuperauto-other/env/lib/python3.12/site-packages/pandas/core/sample.pyÚpreprocess_weightsr'      sh  € ô �'œ9Ô%Ø—/‘/ #§(¡(¨4¡.Ó1ˆô �'œ3ÔÜ�cœ<Ô(Ø�qŠyðØ! '™l‘Gô !ð"óð ô ØRóð ô �#”yÔ!Ø×Ñ‰à×&Ñ&ˆä—*‘*™T '°Ô;×CÑCÌ2Ï:É:ÔV€Kä
ˆ;Ó˜3Ÿ9™9 T™?Ò*ÜÐPÓQÐQä
‡|�|�KÔ ÜÐFÓGÐGà�a‰×ÑÔÜÐIÓJÐJä�h‰h�{Ó#€GØ‡{�{„}à!×&Ñ&Ó(ˆØ ˆ�GÑØÐøôI  ò Ü"ØEóàðûðús   ÁE1 Å1	FÅ:FÆFc                óÎ   — | €|€d} | S | �|�t        d«      ‚| �%| dk  rt        d«      ‚| dz  dk7  rt        d«      ‚| S |€J ‚|dkD  r|st        d«      ‚|dk  rt        d«      ‚| S )zâ
    Process and validate the `n` and `frac` arguments to `NDFrame.sample` and
    `.GroupBy.sample`.

    Returns None if `frac` should be used (variable sampling sizes), otherwise returns
    the constant sampling size.
    é   z0Please enter a value for `frac` OR `n`, not bothr   z=A negative number of rows requested. Please provide `n` >= 0.z$Only integers accepted as `n` valueszJReplace has to be set to `True` when upsampling the population `frac` > 1.z@A negative number of rows requested. Please provide `frac` >= 0.)r   )ÚnÚfracÚreplaces      r&   Úprocess_sampling_sizer-   V   s¶   € ð 	€y�T�\Øˆð, €Hð+ 
ˆ˜4Ð+ÜÐKÓLÐLØ	
ˆØˆqŠ5ÜØOóð ð ˆq‰5�AŠ:ÜÐCÓDÐDð €Hð ÐÐÐØ�!Š8™GÜð8óð ð �!Š8ÜØRóð ð €Hó    c                ó  — |�M|j                  «       }|dk7  r||z  }nt        d«      ‚|€J ‚|s!||j                  «       z  dkD  rt        d«      ‚|j                  | |||¬«      j	                  t
        j                  d¬«      S )ad  
    Randomly sample `size` indices in `np.arange(obj_len)`.

    Parameters
    ----------
    obj_len : int
        The length of the indices being considered
    size : int
        The number of values to choose
    replace : bool
        Allow or disallow sampling of the same row more than once.
    weights : np.ndarray[np.float64] or None
        If None, equal probability weighting, otherwise weights according
        to the vector normalized
    random_state: np.random.RandomState or np.random.Generator
        State used for the random sampling

    Returns
    -------
    np.ndarray[np.intp]
    r   z$Invalid weights: weights sum to zeror)   z‘Weighted sampling cannot be achieved with replace=False. Either set replace=True or use smaller weights. See the docstring of sample for details.)Úsizer,   ÚpF)r   )Úsumr   ÚmaxÚchoiceÚastyper   Úintp)Úobj_lenr0   r,   r    Úrandom_stateÚ
weight_sums         r&   Úsampler:   {   s�   € ð8 ÐØ—[‘[“]ˆ
Ø˜Š?Ø 
Ñ*‰GäÐCÓDÐDàÐ"Ð"Ð"Ù˜4 '§+¡+£-Ñ/°!Ò3Üð&óð ð ×Ñ˜w¨T¸7ÀgÐÓN×UÑUÜ
�‰�eð Vó ð r.   )r   r
   r    zstr | ListLiker!   r   Úreturnú
np.ndarray)r*   ú
int | Noner+   zfloat | Noner,   Úboolr;   r=   )r7   Úintr0   r?   r,   r>   r    znp.ndarray | Noner8   z+np.random.RandomState | np.random.Generatorr;   r<   )Ú__doc__Ú
__future__r   Útypingr   Únumpyr   Úpandas._libsr   Úpandas.core.dtypes.genericr   r   Úpandas._typingr   r	   Úpandas.core.genericr
   r'   r-   r:   © r.   r&   ú<module>rI      sµ   ðñõ #å  ã å ÷ñ
 ÷õ
 ,ð8Ø	ð8Ø)ð8Ø18ð8àó8ðv"Øð"Ø%ð"Ø04ð"àó"ðJ-Øð-à
ð-ð ð-ð ð	-ð
 >ð-ð ô-r.   