-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Partial fix for docstring validation for parameters #28765
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
BUG: Partial fix for docstring validation for parameters #28765
Conversation
Using signature allows the validation to get to the root function when a function is decorated. This reduced a significant amount of the errors in the string.py file
Check for variations on "*args, **kwargs" while loading in the documentation parameters, and load them in separately if found.
Pep8 conformity
Using signature allows the validation to get to the root function when a function is decorated. This reduced a significant amount of the errors in the string.py file
Check for variations on "*args, **kwargs" while loading in the documentation parameters, and load them in separately if found.
Pep8 conformity
Those functions cause issues during the testing. This has most likely been covered by some PR merged already.
…ix_docstring_validation
There are tests for the doctoring validator - if making changes there also will need a test case(s) |
Thank you! I'm working out the bugs introduced right now. |
Desc was being loaded in without being turned into a string. This was causing issues when indexes were used to check capitalization and the final period.
@WillAyd Would you like me to write tests for decorated functions? That was the main point addressed by this PR. If so, just let me know, and I can do that before this is merged. Also, I'm having trouble figuring out why I'm not passing the automated linting check. Do you have any ideas? |
For some reason black didn't catch the validation script the first time. It should be fixed now.
Never mind, I found it. Sorry for all the really little commits, I just recently started working with pandas, so I'm getting used to all the small things that need to be done first. |
Tests added to test_validate_docstrings that check that it handles decorated functions as predicted.
Hello @Nabel0721! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-10-13 19:10:49 UTC |
Fixed trailing whitespace on two lines.
I added tests for decorators. Look over it and see if there are any more you'd like me to add. If I have an idea of what to make I should be able to do it no problem, I'm just not sure what exactly would need to be added. The changes I made to the validation script were just to account for oversights, not to add functionality, so there weren't any new features to test. |
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.
Thanks for working on this.
There are two unrelated changes here, one changing how we obtain the paramters from the docstring, and one from the signature. Do you mind addressing them in separate PRs? The one of the docstrings is quite simple I think, but I don't quite understand the other one. And in case we change our mind and we want to revert, we won't want to revert both.
Regarding inspect.signature
, can you point me to an example where this change is fixing a validation error. I'm sure you know what you're doing, but would like to understand what's going on, and I fail to see if we're fixing bugs, or just using a nicer API.
Thanks!
So, here's a code example to show what the difference is between from functools import wraps
from inspect import getfullargspec, signature
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
"""
This is hidden documentation that we don't want
"""
print("The wrapper is doing stuff!")
return func(*args, **kwargs)
return wrapper
@decorator
def add(a, b, *, absolute=False):
"""
This method adds a and b, with the absolute value optionally taken
"""
return abs(a+b) if absolute else a+b
print(f"Using getfullargspec: {getfullargspec(add)}")
print(f"Using signature {signature(add)}") The following script prints out:
|
I'll put together a separate PR for the splitting on ", ". You're right that these two issues are pretty distinctly separate, and should be kept that way. |
Thanks a lot for the detail explanation on signature vs getfullargsspec. Is there any case in pandas where this is an issue right now, and that it's fixed with this PR? We've got |
Most of the PR02 errors we're getting from We could run the check on the object returned by |
Ah, I see. Do you think it makes sense to add one of the Series.str methods to the unit tests? Also, it'd probably make sense to generate the errors json with and without these changes, and find the differences, and see if the result is the expected one. |
Yeah, I did that when I first made the changes, but I can send two files with the differences. |
One file is taken from current master, so there'll be some changes that were fixed by other PRs. The main ones to look at are under Series.str. A lot of the errors are gone after applying the fix. |
Reverting back to master's version so the issue can be addressed in another PR.
Sounds great. Let's split the two different things, and merge them then. |
c2cdcde
to
17176c2
Compare
Update Local Version
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 good, just couple of last comments
I added a parameter to the test so that it's more visible, and changed the validation script to use a generator straight into a tuple. I also switched off of using `items`, since it's a set and therefore might give different orders for the parameters.
Fixed line length and whitespace requirements
Updating to most recent version
Update branch
Remove a test that doesn't quite examine the error we'd like.
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.
just one last comment, to make things simpler, and we're good to go
Switched to using a builtin decorator
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 @Nabel0721, nice improvement
Read through history but not entirely clear - what does this end up improving upon? |
Whenever we use a decorator on a function that follows normal decorator conventions (wrapping the original function, passing in the arguments and returning the result with some added functionality) we were losing the signature of the original function. The result was that the script would look for |
Makes sense. I think generally we are inconsistent in how we maintain signatures, annotations, etc... with wrapped functions, so would welcome general ideas you have for that |
We were doing it manually until now with |
Yeah, honestly we could just replace the entire function with a call to
inspect.unwrap
|
Great, please tag me when you open the PR. Thanks! |
Ideally, we should only be working with signatures and wrapped functions using the builtin tools from the inspect library whenever possible. I'm fairly certain that this is what numpy uses as well, so it will create consistency with the imported docstring stuff from them. |
I didn't see that Python had that unwapping functionality, that's why I implemented |
This PR addresses #20298, does not close.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
This changes the method used to find arguments from
inspect.getfullargspec
toinspect.signature
and changes the handling accordingly. It also now checks for "*args, **kwargs" and other variations as a doc parameter, and splits them up so they can be checked against.