Skip to content
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

DOC: fix DataFrame.sample doctests and reformat the docstring #22937

Merged
merged 2 commits into from
Oct 8, 2018

Conversation

Moisan
Copy link
Contributor

@Moisan Moisan commented Oct 2, 2018

  • tests added / passed
  • passes 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.

@pep8speaks
Copy link

Hello @Moisan! Thanks for submitting the PR.

@jschendel jschendel added the Docs label Oct 2, 2018
@jschendel jschendel added this to the 0.24.0 milestone Oct 2, 2018
@@ -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.
Copy link
Contributor

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.?


See Also
--------
numpy.choice: Generates a random sample from a given 1-D numpy array.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy.random.choice?

@@ -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:
Copy link
Member

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.

@@ -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.
Copy link
Member

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.

>>> 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)})
Copy link
Member

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
Copy link

codecov bot commented Oct 3, 2018

Codecov Report

Merging #22937 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.6% <100%> (ø) ⬆️
#single 42.36% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 96.65% <100%> (-0.02%) ⬇️
pandas/core/groupby/grouper.py 97.42% <0%> (-0.74%) ⬇️
pandas/core/dtypes/dtypes.py 95.85% <0%> (-0.26%) ⬇️
pandas/core/arrays/categorical.py 95.62% <0%> (-0.13%) ⬇️
pandas/io/pytables.py 92.44% <0%> (-0.05%) ⬇️
pandas/core/nanops.py 95.14% <0%> (ø) ⬆️
pandas/core/indexes/multi.py 95.45% <0%> (ø) ⬆️
pandas/core/frame.py 97.2% <0%> (ø) ⬆️
pandas/core/series.py 93.75% <0%> (ø) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ce06b5...db19144. Read the comment docs.

@jreback
Copy link
Contributor

jreback commented Oct 7, 2018

@datapythonista

Copy link
Member

@datapythonista datapythonista left a 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.

@datapythonista datapythonista merged commit ce1f81f into pandas-dev:master Oct 8, 2018
@datapythonista
Copy link
Member

Thanks for another excellent PR @Moisan

@Moisan Moisan deleted the docstring_sample branch October 9, 2018 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants