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

25 changes: 17 additions & 8 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6572,7 +6572,10 @@ 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 a threshold truncated.
Trim values below a given threshold.

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

Parameters
----------
Expand All @@ -6597,17 +6600,22 @@ def clip_lower(self, threshold, axis=None, inplace=False):

See Also
--------
Series.clip : Return copy of input with values below and above
thresholds truncated.
Series.clip_upper : Return copy of input with values above
threshold truncated.
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
clipped
Original data with values trimmed.

Examples
--------

Series single threshold clipping:

>>> s = pd.Series([5, 6, 7, 8, 9])
Expand Down Expand Up @@ -6659,17 +6667,18 @@ def clip_lower(self, threshold, axis=None, inplace=False):
`threshold` should be the same length as the axis specified by
`axis`.

>>> df.clip_lower(np.array([3, 3, 5]), axis='index')
>>> df.clip_lower([3, 3, 5], axis='index')
A B
0 3 3
1 3 4
2 5 6

>>> df.clip_lower(np.array([4, 5]), axis='columns')
>>> df.clip_lower([4, 5], axis='columns')
A B
0 4 5
1 4 5
2 5 6

"""
return self._clip_with_one_bound(threshold, method=self.ge,
axis=axis, inplace=inplace)
Expand Down