-
-
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
DOC: Using deprecated sphinx directive instead of non-standard messages in docstrings (#18928) #18934
Conversation
Hello @datapythonista! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 06, 2018 at 13:55 Hours UTC |
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 rule in ci/lint.sh
to search for DEPRECATED (so it will fail linting). looks pretty good otherwise.
scripts/find_deprecated.py
Outdated
@@ -0,0 +1,34 @@ | |||
import re |
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 text describing how to use this & purpose
@@ -13,6 +13,30 @@ def class_name_sort_key(x): | |||
else: |
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 note about using this?
ideally we would also add these scripts in a not in the contributing docs.
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 update for this?
pandas/core/frame.py
Outdated
@@ -3728,8 +3725,8 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False, | |||
|
|||
def sortlevel(self, level=0, axis=0, ascending=True, inplace=False, | |||
sort_remaining=True): | |||
""" | |||
DEPRECATED: use :meth:`DataFrame.sort_index` | |||
""".. deprecated:: 0.20.0 |
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 the first line the simple description
pandas/core/generic.py
Outdated
@@ -4090,8 +4090,8 @@ def _consolidate(self, inplace=False): | |||
return self._constructor(cons_data).__finalize__(self) | |||
|
|||
def consolidate(self, inplace=False): | |||
""" | |||
DEPRECATED: consolidate will be an internal implementation only. | |||
""".. deprecated:: 0.21.0 |
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.
same here
""" | ||
DEPRECATED: as_matrix will be removed in a future version. | ||
Use :meth:`DataFrame.values` instead. | ||
"""Convert the frame to its Numpy-array representation. |
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.
same here
pandas/core/generic.py
Outdated
""" | ||
Deprecated. | ||
Attempt to infer better dtype for object columns | ||
""".. deprecated:: 0.18.0 |
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.
same, can also remove the TODO comment (we keep a separate list of these things)
pandas/core/series.py
Outdated
"""DEPRECATED: Use ``astype(object)`` instead. | ||
""" | ||
.. deprecated :: 0.21.1 | ||
Use ``astype(object) instead. |
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 am not 100% sure, but might need a blank line after these directives (you can build and see if they look ok)
pandas/util/_decorators.py
Outdated
if getattr(wrapper, '__doc__', None) is not None: | ||
wrapper.__doc__ = ('\n'.join(wrap(msg, 70)) + '\n' | ||
+ dedent(wrapper.__doc__)) | ||
msg = msg or 'Use `{alt_name}` instead.' |
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 comment on what you are doing here
also would love some tests in contributing.rst on how to depreciate things (e.g. how to use the decorator is prob enough) |
Thanks for the review @jreback. I updated the pull request, addressing all your comments. Please let me know if there is anything that is not yet clear, or that can be improved. Regarding the blank line after the directive, it doesn't make a difference for sphinx. In both cases the comment about the deprecation is shown inline. |
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.
small comments. ping on green.
pandas/core/series.py
Outdated
@@ -911,8 +915,7 @@ def repeat(self, repeats, *args, **kwargs): | |||
index=new_index).__finalize__(self) | |||
|
|||
def reshape(self, *args, **kwargs): | |||
""" | |||
.. deprecated:: 0.19.0 | |||
""".. deprecated:: 0.19.0 |
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 fix this one?
pandas/core/series.py
Outdated
@@ -971,15 +972,13 @@ def _get_value(self, label, takeable=False): | |||
_get_value.__doc__ = get_value.__doc__ | |||
|
|||
def set_value(self, label, value, takeable=False): | |||
""" | |||
""".. deprecated:: 0.21.0 |
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.
here as well
ci/lint.sh
Outdated
@@ -117,6 +117,10 @@ if [ "$LINT" ]; then | |||
fi | |||
done | |||
echo "Check for incorrect sphinx directives DONE" | |||
|
|||
echo "Check for deprecated messages without sphinx directive" | |||
grep -R --include="*.py" --include="*.pyx" DEPRECATED 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.
can you also look for Deprecated (capitalize first letter), and maybe DEPRECATE
Sure, thanks for the comments @jreback . I'm also implementing a more exhaustive version of What I think it would be useful is to have a script that detects all deprecated stuff, so it can be completely removed at the right time. That's what What I'm implementing now is a version that checks all python files in the project, looks for This way, if when releasing pandas 0.22, everything that was deprecated before 0.19 needs to go away, it can be detected in an easy and reliable way. Does this make sense? |
this would be fine as a double check: #18934 (comment) |
Ah, thanks for pointing it out. I checked for the list in the code, didn't know it was in github. Then, I think I'll update the pull request with your comments, removing the find_deprecated.py script. Later on I'll implement the script, probably in a repo separate from pandas (there is nothing pandas specific in it), and run it to see if there is nothing missing in these tickets. |
@datapythonista that would be great! |
@jreback fixed items in last review. In lint.sh I added DEPRECATE, DEPRECATED and Deprecated, but only if they finish with colon, comma or dot, as it was capturing DeprecatedModule for example. |
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.
couple of comments
@@ -13,6 +13,30 @@ def class_name_sort_key(x): | |||
else: |
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 update for this?
pandas/core/sparse/series.py
Outdated
@@ -256,8 +256,8 @@ def npoints(self): | |||
def from_array(cls, arr, index=None, name=None, copy=False, | |||
fill_value=None, fastpath=False): | |||
""" | |||
DEPRECATED: use the pd.SparseSeries(..) constructor instead. | |||
|
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 the 1-liner description here (IOW the deprecated should not be the first line)
@@ -2978,8 +2979,8 @@ def dropna(self, axis=0, inplace=False, **kwargs): | |||
return self.copy() | |||
|
|||
def valid(self, inplace=False, **kwargs): | |||
"""DEPRECATED. Series.valid will be removed in a future 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.
add the 1 liner here
pandas/core/series.py
Outdated
@@ -2120,8 +2120,8 @@ def nsmallest(self, n=5, keep='first'): | |||
return algorithms.SelectNSeries(self, n=n, keep=keep).nsmallest() | |||
|
|||
def sortlevel(self, level=0, ascending=True, sort_remaining=True): | |||
""" | |||
DEPRECATED: use :meth:`Series.sort_index` | |||
""".. deprecated:: 0.20.0 |
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.
same here
@jreback, I made the requested changes. I agree that the scripts should be added to a note in the contributing documentation, but I'd do that in a separate request if you agree. That's unrelated to this PR, and some standardization of the scripts will be probably required. So I don't think it's a small change. |
just needs a rebase and looks ok. |
Rebased. Thanks @jreback |
lgtm. ping on green. |
@jreback, am I right in assuming that all the stuff deprecated in 0.19 and before can be deleted? If that's the case, I'll submit a PR leaving only the methods and functions with deprecation warning added in 0.20, 0.21 and 0.22. |
things before 0.19.0 should already be removed (except for - couple of ones) |
I submittet the PR's to deprecate |
Thanks for pointing out @topper-123. It looks like I misunderstood something about the git workflow. For I'll compare all the versions I added with #6581 and with github tags, and fix the wrong ones. Thanks for reporting this! |
…es in docstrings (#18928)
@topper-123 I reviewed all the deprecation versions I added, with the release where the commit was introduced (checking @jreback, this should be ready to be merged now. Just to let you know, compared to the changes you already reviewed, I removed from the docstring the Thanks to both! |
thanks @datapythonista very nice! |
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 some review after the fact. In general I am certainly +1 on making how we use things more consistent. But I personally like the "DEPRECATED" in the first one-liner for practical reasons.
"""Read CSV file. | ||
|
||
.. deprecated:: 0.21.0 | ||
Use :func:`pandas.read_csv` instead. |
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.
For this case I actually don't find this an improvement. For deprecated methods, I find it useful that this is clear from the one-liner summary this it is deprecated, so you directly see this in the online api summary tables (on api.rst or on the DataFrame docstring page).
We could also do both?
(I know we don't do this consistently for all deprecated methods as well, but from_csv seems like a more important one)
@@ -3737,12 +3734,13 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False, | |||
|
|||
def sortlevel(self, level=0, axis=0, ascending=True, inplace=False, | |||
sort_remaining=True): | |||
""" | |||
DEPRECATED: use :meth:`DataFrame.sort_index` |
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.
same here
@@ -4108,8 +4108,11 @@ def _consolidate(self, inplace=False): | |||
return self._constructor(cons_data).__finalize__(self) | |||
|
|||
def consolidate(self, inplace=False): | |||
""" | |||
DEPRECATED: consolidate will be an internal implementation only. | |||
"""Compute NDFrame with "consolidated" internals (data of each dtype |
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.
For future reference, please never use 'NDFrame' is user-facing docstrings. Users should not be aware what that means.
@@ -4160,11 +4163,10 @@ def _get_bool_data(self): | |||
# Internal Interface Methods | |||
|
|||
def as_matrix(self, columns=None): | |||
""" | |||
DEPRECATED: as_matrix will be removed in a future 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.
same here
Thanks a lot for you comments @jorisvandenbossche, I see your point, didn't think about it. My main motivation for standardizing the docstrings is to be able to automatically detect the deprecated methods. The I see two solutions here:
I prefer 1, as seems the "right" way to do it. Surely more complex to implement now, but looks cleaner once implemented. What do you think? For the Thanks! |
Doing that in sphinx will probably some overkill IMO, so a pragmatic solution is to do both. I don't think that is a problem, as the |
Out of curiosity, how does the |
git diff upstream/master -u -- "*.py" | flake8 --diff