ó
    Ñ]jo  ã                  ó°   • S 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
Jr  \(       a  SSKJr  SSKJr  SS	 jr        SS
 jr            SS jrg)zH
Module containing utilities for NDFrame.sample() and .GroupBy.sample()
é    )Úannotations)ÚTYPE_CHECKINGN)Úlib)ÚABCDataFrameÚ	ABCSeries)ÚAxisInt)ÚNDFramec                ó  • [        U[        5      (       a  UR                  U R                  U   5      n[        U[        5      (       a7  [        U [
        5      (       a  US:X  a   X   nO[        S5      e[        S5      e[        U [        5      (       a  U R                  nOU R                  nU" USS9R                  n[        U5      U R                  U   :w  a  [        S5      e[        R                  " U5      (       a  [        S	5      eUS:  R                  5       (       a  [        S
5      e[         R"                  " U5      nUR                  5       (       a  UR%                  5       nSX'   U$ ! [         a  n[        S5      UeSnAff = f)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*weight vector may not include `inf` valuesz.weight vector many not include negative values)Ú
isinstancer   ÚreindexÚaxesÚstrr   ÚKeyErrorÚ
ValueErrorÚ_constructorÚ_constructor_slicedÚ_valuesÚlenÚshaper   Úhas_infsÚanyÚnpÚisnanÚcopy)ÚobjÚweightsÚaxisÚerrÚfuncÚmissings         ÚO/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pandas/core/sample.pyÚpreprocess_weightsr$      sd  € ô �'œ9×%Ñ%Ø—/‘/ #§(¡(¨4¡.Ó1ˆô �'œ3×ÑÜ�cœ<×(Ñ(Ø�q‹yðØ!™l‘Gô !ð"óð ô ØRóð ô �#”y×!Ñ!Ø×Ñ‰à×&Ñ&ˆá�7 )Ñ,×4Ñ4€Gä
ˆ7ƒ|�s—y‘y ‘Ó&ÜÐPÓQÐQä
‡|‚|�G×ÑÜÐEÓFÐFà�!‰×Ñ×ÑÜÐIÓJÐJä�hŠh�wÓ€GØ‡{�{‡}�}à—,‘,“.ˆØˆÑØ€NøôI  ó Ü"ØEóàðûðús   Á%E0 Å0
FÅ:FÆFc                óî   • U c  Uc  Sn U $ U b  Ub  [        S5      eU b(  U S:  a  [        S5      eU S-  S:w  a  [        S5      e U $ Uc   eUS:”  a  U(       d  [        S5      eUS:  a  [        S5      eU $ )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*   Q   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                ó  • UbS  UR                  5       nUS:w  a  X5-  nO[        S5      eUc   eU(       d!  XR                  5       -  S:”  a  [        S5      eUR                  XX#S9R	                  [
        R                  SS9$ )a  
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_lenr-   r)   r   Úrandom_stateÚ
weight_sums         r#   Úsampler7   v   s•   € ð8 ÑØ—[‘[“]ˆ
Ø˜‹?ØÑ*‰GäÐCÓDÐDàÑ"Ð"Ð"Þ˜4§+¡+£-Ñ/°!Ó3Üð&óð ð ×Ñ˜w¸7ÐÐN×UÑUÜ
�‰�eð Vð ð r+   )r   r	   r   r   Úreturnú
np.ndarray)r'   ú
int | Noner(   zfloat | Noner)   Úboolr8   r:   )r4   Úintr-   r<   r)   r;   r   znp.ndarray | Noner5   z+np.random.RandomState | np.random.Generatorr8   r9   )Ú__doc__Ú
__future__r   Útypingr   Únumpyr   Úpandas._libsr   Úpandas.core.dtypes.genericr   r   Úpandas._typingr   Úpandas.core.genericr	   r$   r*   r7   © r+   r#   Ú<module>rF      s‘   ðñõ #å  ã å ÷ö
 Ý&å+ô6ðr"Øð"Ø%ð"Ø04ð"àô"ðJ-Øð-à
ð-ð ð-ð ð	-ð
 >ð-ð õ-r+   