-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Add tests for docstring Validation Script + py27 compat #20061
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20061 +/- ##
=======================================
Coverage 92.08% 92.08%
=======================================
Files 169 169
Lines 50706 50706
=======================================
Hits 46691 46691
Misses 4015 4015
Continue to review full report at Codecov.
|
Tested, works great, thanks! |
could you add a test for this somewhere? (need to make sure the test runner runs this); or can you have the lint.sh script actually run (a sub-set of this). that way we know changes to this will be good. |
Fair point. The only issue with CI here is going to be the location of the files in the scripts folder, which I assume pytest nor the tests themselves would have access to given it's outside of the top level Have to think it over but if you have any ideas on how to ideally configure the imports for testing let me know |
can just add pandas/tests/scripts might be ok |
Hello @WillAyd! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 13, 2018 at 20:40 Hours UTC |
Latest commit will fail but should be a starting point for a test module. @jorisvandenbossche @datapythonista I took these examples directly from the guide, but it looks like even the examples in the guide fail the validation script. In this case do you know if it's the script or the examples that need to be updated? Here are the major failures quasi-summarized:
Curious to hear how you would like to approach the above |
scripts/validate_docstrings.py
Outdated
@@ -186,12 +185,11 @@ def signature_parameters(self): | |||
# accessor classes have a signature, but don't want to show this | |||
return tuple() | |||
try: | |||
signature = inspect.signature(self.method_obj) | |||
params = self.method_obj.__code__.co_varnames |
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.
unfortunately, this does not give the correct result (it seems to give some extra names). Eg
In [156]: pd.DataFrame.apply.__code__.co_varnames
Out[156]:
('self',
'func',
'axis',
'broadcast',
'raw',
'reduce',
'result_type',
'args',
'kwds',
'frame_apply',
'op')
the last two should not be there
With the new version of the script, an error of the kind:
becomes under python2
(obtained with |
As I stated in gitter, fixing the remaining issues for py2 support would be great, but I think changing |
Thanks @toobaz and @jorisvandenbossche. So it looks like there are a couple of things to do here and with the sprint being tomorrow I'm wondering if it's even worth trying to get the compatibility to work and rather doing as @toobaz suggested and just explicitly requiring python3. I think the bigger issue is that the test cases here taken from the doc don't pass the script. @jorisvandenbossche I saw your clarification on the |
|
||
@pytest.fixture(autouse=True, scope="class") | ||
def import_scripts(self): | ||
up = os.path.dirname |
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.
pretty magical can you add a comment
@@ -0,0 +1,327 @@ | |||
import os |
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 the CI is actually running this?
@datapythonista @jorisvandenbossche @TomAugspurger in the last commit I blended a few things together, namely:
I copied most of the test cases from the document, but even then some of them weren't passing the validation script so I took a few liberties to modify. Ideally we would build out test cases to unit test particular aspects of the validation script, but for now I've just done a blanket pass for success / failures. |
scripts/validate_docstrings.py
Outdated
errs.append('No returns section found') | ||
if not doc.returns and "return" in doc.method_source: | ||
errs.append('No Returns section found') | ||
if "yield" in doc.method_source: |
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.
This would ideally have the same structure as the returns check directly above it, but I think there's a bug in numpy doc where it doesn't parse Yields sections
andas/tests/scripts/test_validate_docstrings.py .............. [100%]
|
The issue with 'Yields' stems from the fact that we include a copy of Is there a particular reason we decided to copy that package into pandas rather than manage as a dependency? @jorisvandenbossche |
Long story involving many awful hacks :)
#18147
I think the final blocker is numpy/numpydoc#106
…On Tue, Mar 13, 2018 at 11:27 AM, William Ayd ***@***.***> wrote:
The issue with 'Yields' stems from the fact that we include a copy of
numpydocstr directly in pandas, but it doesn't appear to be a recent
version (Yields support was added back in numpydoc 0.6)
Is there a particular reason we decided to copy that package into pandas
rather than manage as a dependency? @jorisvandenbossche
<https://github.com/jorisvandenbossche>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20061 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIh5OJJnGHIl2AEy0XJdw5IBzt5sBks5td_N3gaJpZM4SjWJQ>
.
|
Not sure why I originally added a One failure in Travis is around clipboard tests so unrelated imo. Any other feedback lmk |
Any other feedback on this change? Hoping to avoid more rebasing :-) |
lgtm, just wanted to run it for some docstrings before merging it, and didn't have the time. But will do during the weekend. |
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.
This looks good to me!
Quickly skimmed through the code and changes look good to me. Some nice improvements! And tried some docstrings and seems to work nicely.
One thing (but not necessarily for this PR), when doing the check that a parameter description ends with a '.', we should check that the last line does not contain 'versionadded' (that's a typical false positive in the script that should not be hard to catch)
if hasattr(self.method_obj, '_accessors') and ( | ||
self.method_name.split('.')[-1] in | ||
self.method_obj._accessors): | ||
# accessor classes have a signature but don't want to show this |
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.
This does not seem to work for me. Eg checking pandas.Series.dt
with the script complains about parameter 'data' not being documented.
(but anyhow, it is better as on master, there it raises an attribute error somewhere in the script)
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 to know. I’d be happy to open that up as a follow up issue here - worth adding dedicated tests for accessors
I've been doing tests, and besides what @jorisvandenbossche said, there are few other cases where the script still does not work (unrelated to this PR). For example Merging, so we can keep improving the scripts and the docs in separate PRs. Thanks a lot @WillAyd, I know it's been a lot of work this PR, but it'll help a lot. |
@datapythonista what is wrong for |
@jorisvandenbossche not sure what was the problem, I was executing the validation for all docstrings, and it failed, but probably caused by something in my changes. I fixed the problem with |
The scripts directory is not visible if the installation is not inplace. Follow-up to pandas-devgh-20061.
this broke all of the wheel building: something wrong with the imports |
@jreback are the tests run there for an wheel installed version of pandas? (because I suppose that then the scripts directory is not available?) If that is the case, easiest solution is probably to check the existence of the script, and otherwise simply skip the tests |
Ah, this is already discussed in #22413 |
If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to pandas-devgh-20061.
If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to pandas-devgh-20061.
If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to pandas-devgh-20061.
If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to gh-20061.
@WillAyd the test log output on travis et al now includes output of the validation script from running it in its tests. We should maybe capture stdout for the tests here to avoid that? |
Makes sense - opened #22483 for that. On the road for the next few days so wouldn’t be able to get around to it personally until next week, though it’s out there for the community to pick up as well :-) |
Since I rebased, I'm getting an error related to this PR (I believe), but only in the 3.6 travis job (https://travis-ci.org/pandas-dev/pandas/jobs/422781966 and https://travis-ci.org/pandas-dev/pandas/jobs/422883422):
The relevant section from the docstring is:
and I can't see what's wrong with it. How can one have a line-break in there, or is this just not supported / a bug? |
@h-vetinari it's not related to this PR, but to this one: #19952 |
If the pandas is not inplace, the scripts directory will not exist, and the tests will fail. Follow-up to pandas-devgh-20061.
When I run
Should this one also fix **kwds? Thanks. |
git diff upstream/master -u -- "*.py" | flake8 --diff
@jorisvandenbossche @toobaz a few edits here should make it work for both Py3 and Py2 users