Skip to content

DOC: make return type documentation of series methods consistent #35409 #36862

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
merged 8 commits into from
Oct 10, 2020
23 changes: 13 additions & 10 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ def as_ordered(self, inplace=False):

Returns
-------
Categorical
Ordered Categorical.
Categorical or None
Ordered Categorical or None if ``inplace=True``.
"""
inplace = validate_bool_kwarg(inplace, "inplace")
return self.set_ordered(True, inplace=inplace)
Expand All @@ -741,8 +741,8 @@ def as_unordered(self, inplace=False):

Returns
-------
Categorical
Unordered Categorical.
Categorical or None
Unordered Categorical or None if ``inplace=True``.
"""
inplace = validate_bool_kwarg(inplace, "inplace")
return self.set_ordered(False, inplace=inplace)
Expand Down Expand Up @@ -848,8 +848,7 @@ def rename_categories(self, new_categories, inplace=False):
Returns
-------
cat : Categorical or None
With ``inplace=False``, the new categorical is returned.
With ``inplace=True``, there is no return value.
Categorical with removed categories or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -917,7 +916,8 @@ def reorder_categories(self, new_categories, ordered=None, inplace=False):

Returns
-------
cat : Categorical with reordered categories or None if inplace.
cat : Categorical or None
Categorical with removed categories or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -957,7 +957,8 @@ def add_categories(self, new_categories, inplace=False):

Returns
-------
cat : Categorical with new categories added or None if inplace.
cat : Categorical or None
Categorical with new categories added or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -1007,7 +1008,8 @@ def remove_categories(self, removals, inplace=False):

Returns
-------
cat : Categorical with removed categories or None if inplace.
cat : Categorical or None
Categorical with removed categories or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -1054,7 +1056,8 @@ def remove_unused_categories(self, inplace=False):

Returns
-------
cat : Categorical with unused categories dropped or None if inplace.
cat : Categorical or None
Categorical with unused categories dropped or None if ``inplace=True``.

See Also
--------
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def eval(

Returns
-------
ndarray, numeric scalar, DataFrame, Series
ndarray, numeric scalar, DataFrame, Series, or None
The completion value of evaluating the given code or None if ``inplace=True``.

Raises
------
Expand Down
32 changes: 17 additions & 15 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3251,8 +3251,9 @@ def query(self, expr, inplace=False, **kwargs):

Returns
-------
DataFrame
DataFrame resulting from the provided query expression.
DataFrame or None
DataFrame resulting from the provided query expression or
None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -3399,8 +3400,8 @@ def eval(self, expr, inplace=False, **kwargs):

Returns
-------
ndarray, scalar, or pandas object
The result of the evaluation.
ndarray, scalar, pandas object, or None
The result of the evaluation or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -4117,8 +4118,9 @@ def drop(

Returns
-------
DataFrame
DataFrame without the removed index or column labels.
DataFrame or None
DataFrame without the removed index or column labels or
None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -4272,8 +4274,8 @@ def rename(

Returns
-------
DataFrame
DataFrame with the renamed axis labels.
DataFrame or None
DataFrame with the renamed axis labels or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -4501,8 +4503,8 @@ def set_index(

Returns
-------
DataFrame
Changed row labels.
DataFrame or None
Changed row labels or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -4964,8 +4966,8 @@ def dropna(self, axis=0, how="any", thresh=None, subset=None, inplace=False):

Returns
-------
DataFrame
DataFrame with NA entries dropped from it.
DataFrame or None
DataFrame with NA entries dropped from it or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -5100,7 +5102,7 @@ def drop_duplicates(

Returns
-------
DataFrame
DataFrame or None
DataFrame with duplicates removed or None if ``inplace=True``.

See Also
Expand Down Expand Up @@ -5423,8 +5425,8 @@ def sort_index(

Returns
-------
DataFrame
The original DataFrame sorted by the labels.
DataFrame or None
The original DataFrame sorted by the labels or None if ``inplace=True``.

See Also
--------
Expand Down
20 changes: 10 additions & 10 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def set_axis(self, labels, axis: Axis = 0, inplace: bool = False):
Returns
-------
renamed : %(klass)s or None
An object of type %(klass)s if inplace=False, None otherwise.
An object of type %(klass)s or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -1096,7 +1096,7 @@ def rename_axis(self, mapper=lib.no_default, **kwargs):
Returns
-------
Series, DataFrame, or None
The same type as the caller or None if `inplace` is True.
The same type as the caller or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -4326,7 +4326,7 @@ def sort_values(
Returns
-------
DataFrame or None
DataFrame with sorted values if inplace=False, None otherwise.
DataFrame with sorted values or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -6461,8 +6461,8 @@ def replace(

Returns
-------
{klass}
Object after replacement.
{klass} or None
Object after replacement or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -6896,9 +6896,9 @@ def interpolate(

Returns
-------
Series or DataFrame
Series or DataFrame or None
Returns the same object type as the caller, interpolated at
some or all ``NaN`` values.
some or all ``NaN`` values or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -7494,9 +7494,9 @@ def clip(

Returns
-------
Series or DataFrame
Series or DataFrame or None
Same type as calling object with the values outside the
clip boundaries replaced.
clip boundaries replaced or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -9050,7 +9050,7 @@ def where(

Returns
-------
Same type as caller
Same type as caller or None if ``inplace=True``.

See Also
--------
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,8 @@ def set_names(self, names, level=None, inplace: bool = False):

Returns
-------
Index
The same type as the caller or None if inplace is True.
Index or None
The same type as the caller or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -1421,8 +1421,8 @@ def rename(self, name, inplace=False):

Returns
-------
Index
The same type as the caller or None if inplace is True.
Index or None
The same type as the caller or None if ``inplace=True``.

See Also
--------
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,8 @@ def set_levels(self, levels, level=None, inplace=None, verify_integrity=True):

Returns
-------
new index (of same type and class...etc)
new index (of same type and class...etc) or None
The same type as the caller or None if ``inplace=True``.

Examples
--------
Expand Down Expand Up @@ -961,7 +962,8 @@ def set_codes(self, codes, level=None, inplace=None, verify_integrity=True):

Returns
-------
new index (of same type and class...etc)
new index (of same type and class...etc) or None
The same type as the caller or None if ``inplace=True``.

Examples
--------
Expand Down
26 changes: 13 additions & 13 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):

Returns
-------
Series or DataFrame
Series or DataFrame or None
When `drop` is False (the default), a DataFrame is returned.
The newly created columns will come first in the DataFrame,
followed by the original Series values.
Expand Down Expand Up @@ -1911,8 +1911,8 @@ def drop_duplicates(self, keep="first", inplace=False) -> Optional["Series"]:

Returns
-------
Series
Series with duplicates dropped.
Series or None
Series with duplicates dropped or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -3129,8 +3129,8 @@ def sort_values(

Returns
-------
Series
Series ordered by values.
Series or None
Series ordered by values or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -3375,8 +3375,8 @@ def sort_index(

Returns
-------
Series
The original Series sorted by the labels.
Series or None
The original Series sorted by the labels or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -4304,8 +4304,8 @@ def rename(

Returns
-------
Series
Series with index labels or name altered.
Series or None
Series with index labels or name altered or None if ``inplace=True``.

See Also
--------
Expand Down Expand Up @@ -4418,8 +4418,8 @@ def drop(

Returns
-------
Series
Series with specified index labels removed.
Series or None
Series with specified index labels removed or None if ``inplace=True``.

Raises
------
Expand Down Expand Up @@ -4807,8 +4807,8 @@ def dropna(self, axis=0, inplace=False, how=None):

Returns
-------
Series
Series with NA entries dropped from it.
Series or None
Series with NA entries dropped from it or None if ``inplace=True``.

See Also
--------
Expand Down