zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
U
¬ý°d¦ã@sždZddlmZddlmZddlZddlmZddl    m
Z
ddl m Z m Z er\ddlmZd    d
d d œd d„Zdddddœdd„Zdddddd dœdd„ZdS)zH
Module containing utilities for NDFrame.sample() and .GroupBy.sample()
é)Ú annotations)Ú TYPE_CHECKINGN)Úlib)ÚAxisInt)Ú ABCDataFrameÚ    ABCSeries)ÚNDFramerrz
np.ndarray)ÚobjÚaxisÚreturnc
Cst|tƒr| |j|¡}t|tƒr„t|tƒr||dkrrz ||}Wqztk
rn}ztdƒ|‚W5d}~XYqzXq„tdƒ‚ntdƒ‚t|tƒr–|j}n|j    }||ddj
}t |ƒ|j |krÄtdƒ‚t  |¡rÖtd    ƒ‚|dk ¡rêtd
ƒ‚t |¡}| ¡r| ¡}d||<|S) 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).
    rz+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)Zdtypez5Weights and axis to be sampled must be of same lengthz*weight vector may not include `inf` valuesz.weight vector many not include negative values)Ú
isinstancerZreindexZaxesÚstrrÚKeyErrorÚ
ValueErrorZ _constructorZ_constructor_slicedZ_valuesÚlenÚshaperZhas_infsÚanyÚnpÚisnanÚcopy)r    Úweightsr
ÚerrÚfuncÚmissing©rúId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/sample.pyÚpreprocess_weightssD    
 
 
 ÿþÿÿ
 
 
 
rz
int | Nonez float | NoneÚbool)ÚnÚfracÚreplacer cCs’|dkr|dkrd}nx|dk    r0|dk    r0tdƒ‚n^|dk    r^|dkrHtdƒ‚|ddkrŽtdƒ‚n0|dk    sjt‚|dkr~|s~tdƒ‚|dkrŽtdƒ‚|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.
    Néz0Please enter a value for `frac` OR `n`, not bothrz=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ÚAssertionError)rr r!rrrÚprocess_sampling_sizeOs* 
ÿ 
  ÿÿr$Úintznp.ndarray | Nonez+np.random.RandomState | np.random.Generator)Úobj_lenÚsizer!rÚ random_stater cCsH|dk    r*| ¡}|dkr"||}ntdƒ‚|j||||djtjddS)ac
    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]
    Nrz$Invalid weights: weights sum to zero)r'r!ÚpF)r)ÚsumrÚchoiceZastyperZintp)r&r'r!rr(Z
weight_sumrrrÚsamplets
ÿr,)Ú__doc__Ú
__future__rÚtypingrÚnumpyrZ pandas._libsrZpandas._typingrZpandas.core.dtypes.genericrrZpandas.core.genericrrr$r,rrrrÚ<module>s     9%