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
U
­ý°d½ã    @sâddlZddlmZmZmZddlmZej     dddg¡dd„ƒZ
dd    „Z d
d „Z d d „Z dd„Zej     dddg¡dd„ƒZdd„Zdd„Zej     dddddgddddgfddd d!gddd d gfg¡d"d#„ƒZd$d%„Zd&d'„ZdS)(éN)Ú    DataFrameÚIndexÚSerieszn, frac)éN)Ngš™™™™™É?cCs¢dgddgd}t||dœƒ}| d¡j||d}dgddgd}t||dœ|jd}t ||¡| d¡dj||d}t|d|jd    }t ||¡dS©
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úWd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/tests/groupby/test_sample.pyÚ)test_groupby_sample_balanced_groups_shape s rcCsždgddgd}t||dœƒ}| d¡jdd}dgddgd}t||dœ|jd    }t ||¡| d¡d
jdd}t|d
|jd }t ||¡dS) Nrrrér    r
é©r rr rr©rrrrrrrÚ+test_groupby_sample_unbalanced_groups_shapes r$cCs®dgddgd}t||dœddddddgd}| d¡jdd}dgddgd}t||dœ|jd}t ||¡| d¡djdd}t|d|jd    }t ||¡dS)
Nrérr    rr
r"r rrr#rrrÚ,test_groupby_sample_index_value_spans_groups(s r&c    Cs~tddgddgdœƒ}d}tjt|d| d¡jdddW5QRXtjt|d| d¡d    jdddW5QRXdS)
Nrrr    z0Please enter a value for `frac` OR `n`, not both©Úmatchr
gð?r r ©rÚpytestZraisesÚ
ValueErrorrr©rÚmsgrrrÚ%test_groupby_sample_n_and_frac_raises6s r.c    Cs~tddgddgdœƒ}d}tjt|d| d¡jddd    W5QRXtjt|d| d¡d
jddd    W5QRXdS) Nrrr    zJReplace has to be set to `True` when upsampling the population `frac` > 1.r'r
çø?F©rÚreplacer r)r,rrrÚ:test_groupby_sample_frac_gt_one_without_replacement_raisesAs r2r éÿÿÿÿr/c    Csˆtddgddgdœƒ}|dkr$d}nd}tjt|d| d¡j|d    W5QRXtjt|d| d¡d
j|d    W5QRXdS) Nrrr    rz=A negative number of rows requested. Please provide `n` >= 0.z$Only integers accepted as `n` valuesr'r
r"r r))r rr-rrrÚ$test_groupby_sample_invalid_n_raisesLsr4cCs¢dgddgd}t||dœƒ}| d¡jddd}dgd    dgd    }t||dœ|jd
}t ||¡| d¡d jddd}t|d |jd }t ||¡dS) Nrrrr    r
g@Tr0r rr rrr#rrrÚtest_groupby_sample_oversample\s r5cCsšdgddgd}t||dœƒ}| d¡jddd}tddgddgdœ|jd}t ||¡| d¡djddd}tddgd|jd    }t ||¡dSrrr#rrrÚ%test_groupby_sample_without_n_or_fracjs r6zindex, expected_indexÚwÚxÚyÚzr%ér!écCs®dgddgd}t||dœt|ƒd}| d¡jddddddgd}t||dœt|ƒd}t ||¡| d¡d    jddddddgd}t|d    t|ƒd
}t ||¡dS) Nrrr    rr
Tr)r r1Úweightsr r)rrrrrrrr)rZexpected_indexrrrrrrrÚ test_groupby_sample_with_weightsws "r>cCsldgddgd}t|||dœƒ}| d¡ddgjddd}tddgddgd    œ|jd
}t ||¡dS) Nrrr)r
r Úcr
r r?r )r r?r)rrrrrrr#rrrÚ#test_groupby_sample_with_selections‰s
r@cCs4tggdœƒ}| d¡}| ¡}|}t ||¡dS)Nr    r
)rrrrr)rZ
groupby_dfrrrrrÚ%test_groupby_sample_with_empty_inputs“s
 
rA)r*ZpandasrrrZpandas._testingZ_testingrÚmarkZ parametrizerr$r&r.r2r4r5r6r>r@rArrrrÚ<module>s& 
 
 .þ