-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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: Validate that See Also section items do not contain the pandas. prefix #23145
Conversation
Codecov Report
@@ Coverage Diff @@
## master #23145 +/- ##
=======================================
Coverage 92.22% 92.22%
=======================================
Files 169 169
Lines 51261 51261
=======================================
Hits 47277 47277
Misses 3984 3984
Continue to review full report at Codecov.
|
The one I posted is a slightly different issue also affecting the 'See Also' section.(23135/23136) I think you may have missed pushing a commit somehow, because I'm only seeing the blank line changes. |
Hello @thoo! Thanks for updating the PR.
Comment last updated on October 15, 2018 at 17:29 Hours UTC |
@getschomp Thanks. I just updated. |
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.
Good start, added some comments, still some things to be fixed.
scripts/validate_docstrings.py
Outdated
@@ -499,7 +499,8 @@ def validate_one(func_name): | |||
if not rel_desc: | |||
errs.append('Missing description for ' | |||
'See Also "{}" reference'.format(rel_name)) | |||
|
|||
if rel_name[:7].lower() == 'pandas.': |
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 think it's more pythonic to write if rel_name.startwith('pandas.'):
(or you could do the .lower()
before the startswith()
but I don't think it's needed here.
scripts/validate_docstrings.py
Outdated
@@ -499,7 +499,8 @@ def validate_one(func_name): | |||
if not rel_desc: | |||
errs.append('Missing description for ' | |||
'See Also "{}" reference'.format(rel_name)) | |||
|
|||
if rel_name[:7].lower() == 'pandas.': | |||
errs.append('{} should not have prefix `pandas`'.format(rel_name)) |
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 think the error message is good, but it'd be even more explicit to say something like 'pandas.DataFrame.head' in the 'See Also' section does not need the 'pandas' prefix, use 'DataFrame.head' instead.
What do you think?
The PEP8 validation reported a line > 80 characters, I guess is this one.
@@ -334,6 +334,14 @@ def method(self, foo=None, bar=None): | |||
pass | |||
|
|||
|
|||
class BadSeeAlso(object): |
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.
Can you place the test classes in the same order as the sections in the docstring (summaries, parameters, returns, see also...)
def prefix_pandas(self): | ||
""" | ||
Return prefix with `pandas` from See Also sec | ||
""" |
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.
What's bad in this test? It doesn't have the See Also
section, so the new error will not be raised here.
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.
@datapythonista Can I get more hints ? :). I wasn't sure what I was doing in the test section. Thanks.
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's difficult to explain unit testing in a github comment, but the idea of a unit test is that you want to check that things work automatically. I guess after implementing the error for the pandas prefix, you run the program for a docstring with the prefix, and saw that the error was correctly reported. You need to do the same here, but with code. Most of the stuff is already build, the main thing to do is to write a docstring that should generate the error (this is what goes in this part of the code). And then a program runs the validate_docstrings.py
, and makes sure that the error is generated. This is already implemented if you add the method with the docstring you want to validate, and the expected message in the @pytest.mark.parametrize
you updated.
@@ -564,6 +572,9 @@ def test_bad_generic_functions(self, func): | |||
assert errors | |||
|
|||
@pytest.mark.parametrize("klass,func,msgs", [ | |||
#SeeAlso tests |
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.
There are missing spaces here, including after the #
which is a formatting error.
Thanks. I will work on them. |
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.
@datapythonista Could you please take a look? Hope everything is resolved.
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.
Looking better, added some comments.
doc/source/cookbook.rst
Outdated
@@ -1234,25 +1234,19 @@ The `method` argument within `DataFrame.corr` can accept a callable in addition | |||
n = len(x) | |||
a = np.zeros(shape=(n, n)) | |||
b = np.zeros(shape=(n, n)) | |||
|
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.
can you make sure this file does not appear in the Files changes
diff. The cookbook should be untouched in this PR.
|
||
See Also | ||
-------- | ||
pandas.Series.rename : Alter Series index labels or name |
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.
Can you add a period at he end? This is required in the see also description, and this test should only have wrong the pandas.
prefix.
Can you add another item, but without the pandas prefix, so we see that when there is more than one item the reported one is the wrong one.
|
||
def prefix_pandas(self): | ||
""" | ||
Return prefix with `pandas` from See Also sec |
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.
Can you briefly describe the test here. It'll be more useful than this sentence (see other tests for reference). Also, make sure there are no two spaces together, and that the text finishes with a period.
@@ -600,7 +613,10 @@ def test_bad_generic_functions(self, func): | |||
pytest.param('BadReturns', 'no_description', ('foo',), | |||
marks=pytest.mark.xfail), | |||
pytest.param('BadReturns', 'no_punctuation', ('foo',), | |||
marks=pytest.mark.xfail) | |||
marks=pytest.mark.xfail), | |||
# SeeAlso tests |
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.
missing space between See Also
marks=pytest.mark.xfail), | ||
# SeeAlso tests | ||
('BadSeeAlso', 'prefix_pandas', | ||
('section does not need `pandas` prefix',)), |
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.
can you check for the whole message. It's useful to see what's the exact error reported, and that the item being reported is indeed the one with the prefix.
bcb33b8
to
6e7ab2a
Compare
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.
not sure if one of the lines is more than 80 characters, but if the CI is green, lgtm.
@WillAyd do you want to take a look?
scripts/validate_docstrings.py
Outdated
if rel_name.startswith('pandas.'): | ||
errs.append('{} in `See Also` section does not ' | ||
'need `pandas` prefix, use {} instead.' | ||
.format(rel_name, rel_name.replace('pandas.', ''))) |
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'd use rel_name[len('pandas.'):]
instead of the replace. I don't think in practice will make a difference, but in a case like pandas.somemod.pandas.MyClass
the replace wouldn't work as expected.
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.
Sure. I will update it right away.
6a0d30a
to
67ed7f4
Compare
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.
lgtm, thanks!
Can you check the azure error, and make sure it's green, so we can merge? |
The error is from miniconda package.
|
…ndas * repo_org/master: (23 commits) DOC: Add docstring validations for "See Also" section (pandas-dev#23143) TST: Fix test assertion (pandas-dev#23357) BUG: Handle Period in combine (pandas-dev#23350) REF: SparseArray imports (pandas-dev#23329) CI: Migrate some CircleCI jobs to Azure (pandas-dev#22992) DOC: update the is_month_start/is_month_end docstring (pandas-dev#23051) Partialy fix issue pandas-dev#23334 - isort pandas/core/groupby directory (pandas-dev#23341) TST: Add base test for extensionarray setitem pandas-dev#23300 (pandas-dev#23304) API: Add sparse Acessor (pandas-dev#23183) PERF: speed up CategoricalIndex.get_loc (pandas-dev#23235) fix and test incorrect case in delta_to_nanoseconds (pandas-dev#23302) BUG: Handle Datetimelike data in DataFrame.combine (pandas-dev#23317) TST: re-enable gbq tests (pandas-dev#23303) Switched references of App veyor to azure pipelines in the contributing CI section (pandas-dev#23311) isort imports-io (pandas-dev#23332) DOC: Added a Multi Index example for the Series.sum method (pandas-dev#23279) REF: Make PeriodArray an ExtensionArray (pandas-dev#22862) DOC: Added Examples for Series max (pandas-dev#23298) API/ENH: tz_localize handling of nonexistent times: rename keyword + add shift option (pandas-dev#22644) BUG: Let MultiIndex.set_levels accept any iterable (pandas-dev#23273) (pandas-dev#23291) ...
@WillAyd, can you take a look and merge if you're happy? |
Thanks @thoo |
…xamples * repo_org/master: DOC: Validate that See Also section items do not contain the pandas. prefix (pandas-dev#23145) API/TST: make hasnans always return python booleans (pandas-dev#23349)
Fix #23136
Please also see similar PR #23143