o
    թZh#                     @   s   d dl Z d dlmZmZmZ d dlmZ e j	dddgdd Z
dd	 Zd
d Zdd Zdd Ze j	dddgdd Zdd Zdd Ze j	dg dg dfg dg dfgdd Zd d! Zd"d# ZdS )$    N)	DataFrameIndexSerieszn, frac)   N)Ng?c                 C   s   dgd dgd  }t ||d}|dj| |d}dgd dgd  }t ||d|jd}t|| |dd j| |d}t|d|jd	}t|| d S 
N   
   r   abr
   nfracindexr   namer   r   groupbysampler   tmassert_frame_equalr   assert_series_equal)r   r   valuesdfresultexpected r   _/var/www/html/lang_env/lib/python3.10/site-packages/pandas/tests/groupby/methods/test_sample.py)test_groupby_sample_balanced_groups_shape   s   r   c                  C   s   dgd dgd  } t | | d}|djdd}dgd dgd  } t | | d|jd	}t|| |dd
 jdd}t| d
|jd}t|| d S )Nr   r   r      r	   r
      r   r   r   r   r   r   r   r   r   r   r   r   +test_groupby_sample_unbalanced_groups_shape   s   r$   c                  C   s   dgd dgd  } t | | dg dd}|djdd}dgd dgd  } t | | d|jd}t|| |dd	 jdd}t| d	|jd
}t|| d S )Nr      r   r	   )r   r   r   r   r   r   r   r
   r"   r   r   r   r#   r   r   r   ,test_groupby_sample_index_value_spans_groups(   s   r&   c                  C   s   t ddgddgd} d}tjt|d | djddd W d    n1 s)w   Y  tjt|d | dd	 jddd W d    d S 1 sMw   Y  d S )
Nr   r   r	   z0Please enter a value for `frac` OR `n`, not bothmatchr
   g      ?r   r   r   pytestZraises
ValueErrorr   r   r   msgr   r   r   %test_groupby_sample_n_and_frac_raises6      "r.   c                  C   s   t ddgddgd} d}tjt|d | djddd	 W d    n1 s)w   Y  tjt|d | dd
 jddd	 W d    d S 1 sMw   Y  d S )Nr   r   r	   zJReplace has to be set to `True` when upsampling the population `frac` > 1.r'   r
         ?Fr   replacer   r)   r,   r   r   r   :test_groupby_sample_frac_gt_one_without_replacement_raisesA   r/   r3   r   r0   c                 C   s   t ddgddgd}| dk rd}nd}tjt|d |dj| d	 W d    n1 s/w   Y  tjt|d |dd
 j| d	 W d    d S 1 sRw   Y  d S )Nr   r   r	   r   z=A negative number of rows requested. Please provide `n` >= 0.z$Only integers accepted as `n` valuesr'   r
   r"   r   r)   )r   r   r-   r   r   r   $test_groupby_sample_invalid_n_raisesL   s   "r5   c                  C   s   dgd dgd  } t | | d}|djddd}dgd	 dgd	  } t | | d|jd
}t|| |dd jddd}t| d|jd}t|| d S )Nr   r   r   r	   r
   g       @Tr1   r    r   r   r   r   r#   r   r   r   test_groupby_sample_oversample\   s   r6   c                  C   s   dgd dgd  } t | | d}|djd d d}t ddgddgd|jd}t|| |dd jd d d}tddgd|jd	}t|| d S r   r   r#   r   r   r   %test_groupby_sample_without_n_or_fracj   s   r7   zindex, expected_index)wxyz)r8   r8   r:   r:   )r%      r!      )r%   r%   r!   r!   c                 C   s   dgd dgd  }t ||dt| d}|djddg dd}t ||dt|d}t|| |dd	 jddg dd}t|d	t|d
}t|| d S )Nr   r   r	   r   r
   T)r   r   r   r   )r   r2   weightsr   r   )r   r   r   r   r   r   r   r   )r   Zexpected_indexr   r   r   r   r   r   r    test_groupby_sample_with_weightsw   s   r?   c                  C   sl   dgd dgd  } t | | | d}|dddg jd d d}t ddgddgd	|jd
}t|| d S )Nr   r   r   )r
   r   cr
   r   r@   r   )r   r@   r   )r   r   r   r   r   r   r#   r   r   r   #test_groupby_sample_with_selections   s
   rA   c                  C   s4   t g g d} | d}| }| }t|| d S )Nr	   r
   )r   r   r   r   r   )r   Z
groupby_dfr   r   r   r   r   %test_groupby_sample_with_empty_inputs   s
   
rB   )r*   Zpandasr   r   r   Zpandas._testingZ_testingr   markZparametrizer   r$   r&   r.   r3   r5   r6   r7   r?   rA   rB   r   r   r   r   <module>   s(    



