add a new feature sample() into groupby
State: closed

- [ ] closes #33175
- [ ] 0 tests added / 0 passed
- [ ] passes `black pandas`
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`



Labels:

Comments:
Hello @echozzy629! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

* In the file [`pandas/core/base.py`](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py):

> [Line 441:17](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L441): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 442:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L442): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (106 > 88 characters)
> [Line 443:17](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L443): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 443:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L443): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (137 > 88 characters)
> [Line 444:28](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L444): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 446:34](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L446): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 447:32](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L447): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 449:32](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L449): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 450:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/base.py#L450): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (96 > 88 characters)

* In the file [`pandas/core/groupby/groupby.py`](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py):

> [Line 1459:1](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1459): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 1468:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1468): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (119 > 88 characters)
> [Line 1474:1](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1474): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 1483:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1483): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (97 > 88 characters)
> [Line 1487:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1487): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (93 > 88 characters)
> [Line 1494:26](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1494): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1495:1](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1495): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 1496:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1496): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1497:13](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1497): [E116](https://duckduckgo.com/?q=pep8%20E116) unexpected indentation (comment)
> [Line 1497:13](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1497): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1498:17](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1498): [E711](https://duckduckgo.com/?q=pep8%20E711) comparison to None should be 'if cond is None:'
> [Line 1499:23](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1499): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1500:1](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1500): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 1501:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1501): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1502:19](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1502): [E711](https://duckduckgo.com/?q=pep8%20E711) comparison to None should be 'if cond is None:'
> [Line 1503:23](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1503): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1503:38](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1503): [E226](https://duckduckgo.com/?q=pep8%20E226) missing whitespace around arithmetic operator
> [Line 1505:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1505): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1506:63](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1506): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1507:23](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1507): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1508:63](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1508): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1510:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1510): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1514:64](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1514): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1516:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1516): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1518:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1518): [E115](https://duckduckgo.com/?q=pep8%20E115) expected an indented block (comment)
> [Line 1518:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1518): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1519:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1519): [E115](https://duckduckgo.com/?q=pep8%20E115) expected an indented block (comment)
> [Line 1519:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1519): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1520:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1520): [E115](https://duckduckgo.com/?q=pep8%20E115) expected an indented block (comment)
> [Line 1522:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1522): [E115](https://duckduckgo.com/?q=pep8%20E115) expected an indented block (comment)
> [Line 1522:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1522): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1524:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1524): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (112 > 88 characters)
> [Line 1525:1](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1525): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 1526:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1526): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1527:25](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1527): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1529:16](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1529): [E111](https://duckduckgo.com/?q=pep8%20E111) indentation is not a multiple of four
> [Line 1529:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1529): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (119 > 88 characters)
> [Line 1530:1](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1530): [W293](https://duckduckgo.com/?q=pep8%20W293) blank line contains whitespace
> [Line 1532:22](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1532): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1536:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1536): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1536:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1536): [E303](https://duckduckgo.com/?q=pep8%20E303) too many blank lines (2)
> [Line 1537:16](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1537): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1537:30](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1537): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1539:16](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1539): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1539:51](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1539): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1540:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1540): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (130 > 88 characters)
> [Line 1543:13](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1543): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1545:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1545): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (90 > 88 characters)
> [Line 1547:17](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1547): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1552:21](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1552): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1553:22](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1553): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1556:28](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1556): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1557:32](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1557): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1558:32](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1558): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1562:28](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1562): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1566:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1566): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1567:9](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1567): [E265](https://duckduckgo.com/?q=pep8%20E265) block comment should start with '# '
> [Line 1568:24](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1568): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1569:20](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1569): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1570:15](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1570): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1570:44](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1570): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 1570:60](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1570): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 1570:76](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1570): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ','
> [Line 1571:20](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1571): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1574:26](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1574): [E225](https://duckduckgo.com/?q=pep8%20E225) missing whitespace around operator
> [Line 1574:89](https://github.com/pandas-dev/pandas/blob/5c55ebbc7e72c9d1766bfd883edd370dbb15e40d/pandas/core/groupby/groupby.py#L1574): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (104 > 88 characters)



##### Comment last updated at 2020-04-13 06:38:10 UTC
@echozzy629 

Thanks for the PR please can you fix up the following

- Test failures there seems to be alot (merging master will help for np dev build)
- run flake8 and black 
- Can you please ref the correct issue - currently doesn't look correct.

Our contributing guide might help:
https://pandas.pydata.org/docs/development/contributing.html
 
Thanks @echozzy629 

Is this still active? If so, can you please address @alimcmaster1 's review?

Also, this would close #31775, not #33175
Closing due to lack of response, feel free to reopen if you address @alimcmaster1 's feedback