-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix docstring of functions created with the deprecate() function #24215
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
Merged
TomAugspurger
merged 4 commits into
pandas-dev:master
from
datapythonista:fix_deprecate_func_doc
Dec 13, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
54a584c
Fix docstring of functions created with the deprecate() function
datapythonista 24c20ec
Removing unused import
datapythonista cc29112
Allowing deprecate to be used with functions without docstring
datapythonista 7315e63
Making isort happy with the import ordering and spacing (and making m…
datapythonista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from textwrap import dedent | ||
|
||
import pytest | ||
|
||
from pandas.util._decorators import deprecate | ||
|
||
import pandas.util.testing as tm | ||
|
||
|
||
def new_func(): | ||
""" | ||
This is the summary. The deprecate directive goes next. | ||
|
||
This is the extended summary. The deprecate directive goes before this. | ||
""" | ||
return 'new_func called' | ||
|
||
|
||
def new_func_no_docstring(): | ||
return 'new_func_no_docstring called' | ||
|
||
|
||
def new_func_wrong_docstring(): | ||
"""Summary should be in the next line.""" | ||
return 'new_func_wrong_docstring called' | ||
|
||
|
||
def new_func_with_deprecation(): | ||
""" | ||
This is the summary. The deprecate directive goes next. | ||
|
||
.. deprecated:: 1.0 | ||
Use new_func instead. | ||
|
||
This is the extended summary. The deprecate directive goes before this. | ||
""" | ||
pass | ||
|
||
|
||
def test_deprecate_ok(): | ||
depr_func = deprecate('depr_func', new_func, '1.0', | ||
msg='Use new_func instead.') | ||
|
||
with tm.assert_produces_warning(FutureWarning): | ||
result = depr_func() | ||
|
||
assert result == 'new_func called' | ||
assert depr_func.__doc__ == dedent(new_func_with_deprecation.__doc__) | ||
|
||
|
||
def test_deprecate_no_docstring(): | ||
depr_func = deprecate('depr_func', new_func_no_docstring, '1.0', | ||
msg='Use new_func instead.') | ||
with tm.assert_produces_warning(FutureWarning): | ||
result = depr_func() | ||
assert result == 'new_func_no_docstring called' | ||
|
||
|
||
def test_deprecate_wrong_docstring(): | ||
with pytest.raises(AssertionError, match='deprecate needs a correctly ' | ||
'formatted docstring'): | ||
deprecate('depr_func', new_func_wrong_docstring, '1.0', | ||
msg='Use new_func instead.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
are these inplace of tests_deprecate_kwarg.py? (this is pretty new)
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.
No, they are different. We have an old (I guess)
deprecate
that is used to deprecateargmax
(andargmin
) withdeprecate('argmax', idmax)
.The function was not tested, and I had to modify it, because it was injecting the
.. deprecate::
directive in a way that the docstring format was wrong.