-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Inconsistent return type documentation for functions with "inplace" option #35409
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
Comments
I will take this issue if it gets any support. |
Thanks for raising this issue, correcting the documentation as you mentioned is certainly welcomed. I would recommend not making it a parenthetical statement as it does not provide context nor expand upon the previous sentence, but is essential to the correctness. |
take |
take |
The following methods have the inplace keyword argument. DataFrame
Series
Other
|
I'm going to change the "returns" section of their docstrings as follow.
to
If the docstring already has a similar description, does it need to be modified to make the description consistent across all methods? |
Then, in the example of https://pandas.pydata.org/docs/dev/reference/api/pandas.CategoricalIndex.add_categories.html , would be as follows.
to
|
And I found the source link is wrong in https://pandas.pydata.org/docs/dev/reference/api/pandas.CategoricalIndex.add_categories.html . Should This link jump to the following link? pandas/pandas/core/arrays/categorical.py Line 943 in 40daf00
If corrections are needed, I'll set up a separate issue. |
+1 on editing of docstrings, including making them consistent. It looks like you are right, and yes a separate issue should be raised. |
Thank you for reply. |
Location of the documentation
This proposal concerns all methods with the
inplace
keyword argument. Three examples:1 (Return type described as "blah-blah-type or
None
ifinplace=True
) https://pandas.pydata.org/docs/dev/reference/api/pandas.CategoricalIndex.add_categories.html?highlight=inplace2 (Return type specified, but doesn't mention
None
) https://pandas.pydata.org/docs/dev/reference/api/pandas.Series.interpolate.html?highlight=inplaceDocumentation problem
Many methods in pandas have keyword argument
inplace
. Wheninplace=True
is supplied, the method updatesself
and returnsNone
. Wheninplace=False
is supplied, the method does not affectself
and returns a changed copy ofself
.Some of these functions' return types are documented as "Returns blah-type if inplace=True". Others just say "Returns blah-type". This is confusing because it suggests inconsistencies in behavior that are not really there.
Suggested fix for documentation
Find all methods with the
inplace
keyword argument. Change the "returns" section of their docstrings to this form:Also change all the formal return type signatures to the form "--> Optional[Foo]" if they aren't all already like that.
The text was updated successfully, but these errors were encountered: