Skip to content
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: update the pandas.DataFrame.clip_lower docstring #20289

71 changes: 64 additions & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5716,24 +5716,81 @@ def clip_upper(self, threshold, axis=None, inplace=False):

def clip_lower(self, threshold, axis=None, inplace=False):
"""
Return copy of the input with values below given value(s) truncated.
Trim the caller's values below a given `threshold`.

Elements below the `threshold` will be changed to match the
`threshold` value(s).

Parameters
----------
threshold : float or array_like
axis : int or string axis name, optional
threshold : float or array-like
Lower value(s) to which the input value(s) will be trimmed.
axis : {0 or 'index', 1 or 'columns', None}, default None
Align object with threshold along the given axis.
inplace : boolean, default False
Whether to perform the operation in place on the data
.. versionadded:: 0.21.0
Whether to perform the operation in place on the data.

.. versionadded:: 0.21.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I forgot some discussion about it, but don't we want a See Also section? I think clip and clip_upper should be listed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good spot we definitely still want this - @adatasetaday can you add back in?

I know we had some back and forth about Series.clip_lower being self-referential with the shared doc system. If you find that confusing just remove that one entry, but all the rest should remain

See Also
--------
clip
DataFrame.clip : General purpose method to trim `DataFrame` values to
given threshold(s)
DataFrame.clip_upper : Trim `DataFrame` values above given
threshold(s)
Series.clip : General purpose method to trim `Series` values to given
threshold(s)
Series.clip_upper : Trim `Series` values above given threshold(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, for DataFrame.clip_lower we would like to have in See Also:

  • Series.clip_lower
  • DataFrame.clip
  • DataFrame.clip_upper

So, the same in Series and nothing else from Series. And the similar from the same class (DataFrame). As this is being reused by both Series and DataFrame, I'd probably list all clip, clip_lower and clip_upper, but I'm not sure. @jreback ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only caveat here is that the user is working on a doc that is shared by Series and DataFrame. Mentioned earlier that without further updates (i.e. implementing substitution) that the clip_lower reference would be self-referential half of the time.

I advised just removing it to not get hung up on it for now, the other option would be to explicitly list both DataFrame.clip_lower and Series.clip_lower and live with the fact that one will be self referencing. No strong preference on my end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was waiting for a little clarification, since I'm not sure how to proceed. I can go either way, but I haven't seen a conclusive definition. Was a decision made on how to proceed with these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, in another ticket the final implementation just listed everything. As @WillAyd says in some cases the same method being documented will be self-referenced, but it's not a big issue.


Returns
-------
clipped : same type as input
type of caller
Original data with values trimmed.

Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job here - I think the examples are very clear

--------
>>> df = pd.DataFrame({'a': [-1, -2, -100],
... 'b': [1, 2, 100]},
... index = ['foo', 'bar', 'foobar'])

>>> df
a b
foo -1 1
bar -2 2
foobar -100 100

Clip to a scalar value

>>> df.clip_lower(0)
a b
foo 0 1
bar 0 2
foobar 0 100

Clip to an array along the index axis

>>> df.clip_lower([0, 5, 10], axis=0)
a b
foo 0 1
bar 5 5
foobar 10 100

Clip to an array along the column axis

>>> df.clip_lower([-5, 10], axis=1)
a b
foo -1 10
bar -2 10
foobar -5 100

Clip in place

>>> df.clip_lower(0, inplace=True)
>>> df
a b
foo 0 1
bar 0 2
foobar 0 100
"""
return self._clip_with_one_bound(threshold, method=self.ge,
axis=axis, inplace=inplace)
Expand Down