-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: fix DataFrame.sample doctests and reformat the docstring #22937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello @Moisan! Thanks for submitting the PR.
|
pandas/core/generic.py
Outdated
@@ -4340,7 +4340,7 @@ def sample(self, n=None, frac=None, replace=False, weights=None, | |||
being sampled. | |||
If weights do not sum to 1, they will be normalized to sum to 1. | |||
Missing values in the weights column will be treated as zero. | |||
inf and -inf values not allowed. | |||
`inf` and `-inf` values not allowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is code literals, then it should be double-backticks and quoted
``'inf'``
which is a bit noise. How about "infinite values are not allowed.?
pandas/core/generic.py
Outdated
|
||
See Also | ||
-------- | ||
numpy.choice: Generates a random sample from a given 1-D numpy array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpy.random.choice
?
pandas/core/generic.py
Outdated
@@ -4350,58 +4350,57 @@ def sample(self, n=None, frac=None, replace=False, weights=None, | |||
|
|||
Returns | |||
------- | |||
A new object of same type as caller. | |||
Series or DataFrame: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The colon at the end is not needed in this case.
pandas/core/generic.py
Outdated
@@ -4350,58 +4350,57 @@ def sample(self, n=None, frac=None, replace=False, weights=None, | |||
|
|||
Returns | |||
------- | |||
A new object of same type as caller. | |||
Series or DataFrame: | |||
A new object of same type as caller. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to briefly describe what is returned, not only the type.
pandas/core/generic.py
Outdated
>>> df = pd.DataFrame(np.random.randn(50, 4), columns=list('ABCD')) | ||
>>> df = pd.DataFrame({'A': range(0, 500, 10), | ||
... 'B': range(0, 100, 2), | ||
... 'C': range(0, 250, 5)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need so much data, and being arbitrary. Something like the animal datasets we've been using with 6 or 8 rows should be better to illustrate the resample method.
Codecov Report
@@ Coverage Diff @@
## master #22937 +/- ##
==========================================
- Coverage 92.19% 92.18% -0.01%
==========================================
Files 169 169
Lines 50833 50833
==========================================
- Hits 46863 46862 -1
- Misses 3970 3971 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, and very good example.
Thanks for another excellent PR @Moisan |
git diff upstream/master -u -- "*.py" | flake8 --diff
Based on #22459. Fix the docstring for DataFrame.sample. I also updated
ci/doctests.sh
.I was on the fence if I should remove mentions of
Panels
since it is deprecated.