
    Mh                        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         D/var/www/html/env/lib/python3.13/site-packages/pandas/core/sample.pypreprocess_weightsr$      sd    '9%%//#((4.1 '3c<((qy!lG !"  R  #y!!&&7),44G
7|syy&PQQ
||GEFF!IJJhhwG{{}},,.NI   "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*   P   s     	yT\, H+ 
4+KLL	
q5O  q5A:CDD  H !8G8  !8R  H    c                    Ub&  UR                  5       nUS:w  a  X5-  nO[        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 zero)sizer)   pF)r   )sumr   choiceastyper   intp)obj_lenr-   r)   r   random_state
weight_sums         r#   sampler6   u   sb    8 [[]
?*GCDDw7NUU
e V  r+   )r   r	   r   r   return
np.ndarray)r'   
int | Noner(   zfloat | Noner)   boolr7   r9   )r3   intr-   r;   r)   r:   r   znp.ndarray | Noner4   z+np.random.RandomState | np.random.Generatorr7   r8   )__doc__
__future__r   typingr   numpyr   pandas._libsr   pandas.core.dtypes.genericr   r   pandas._typingr   pandas.core.genericr	   r$   r*   r6    r+   r#   <module>rE      s    #    
 &+6r""%"04""J%%
% % 	%
 >% %r+   