-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Changes from 4 commits
d1bb286
22a256f
5312dd0
ba4c362
13c9d82
4e2e0d7
e48d49b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5716,24 +5716,75 @@ 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. | ||
|
||
See Also | ||
-------- | ||
clip | ||
.. versionadded:: 0.21.0 | ||
|
||
Returns | ||
------- | ||
clipped : same type as input | ||
Series or DataFrame | ||
Same type as caller. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this method may be it's a bit obvious, but for consistency I'd say in the description what this method returns (e.g. Original data with values trimmed). The note about the time is all right (not sure if other methods have it as part of the type or the description). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would any of these work? Series or DataFrame (same type as caller) Series or DataFrame There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They look great. If you want to take a look at the latest merged pull requests, I think this happens in few, and may be there is a way more standard than another. If you don't find any, from my side you can choose whatever you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on what I see in the code, this seems to be the most common format type of caller I was thinking that there would be some value in creating PRs for standarizing these kind of things. For example, do one that fixes the axis parameters in ALL methods to match the format agreed in the discussions in this sprint. Another one could be done to make sure there is no period after the versionadded (which a lot of them have it, probably due to the validating script complaining if it was not there). Would this be a good idea? Who should I contact if I want to take care of some of these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to do it. I'd probably wait until most of the PRs from the sprint are closed, to avoid conflicts. And more than contacting someone, you can create an issue (or one per change) with what you're planning to do, you can get some discussion and feedback before doing all the work. |
||
|
||
Examples | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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': [0.740518, 0.450228, 0.710404, -0.771225], | ||
... 'b': [0.040507, -0.45121, 0.760925, 0.010624]}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I find the data used in #20212 easier to understand. It requires a decent amount of concentration to see what the examples are doing with so many decimal numbers. |
||
|
||
>>> df | ||
a b | ||
0 0.740518 0.040507 | ||
1 0.450228 -0.451210 | ||
2 0.710404 0.760925 | ||
3 -0.771225 0.010624 | ||
|
||
Clip to a scalar value | ||
|
||
>>> df.clip_lower(0.2) | ||
a b | ||
0 0.740518 0.200000 | ||
1 0.450228 0.200000 | ||
2 0.710404 0.760925 | ||
3 0.200000 0.200000 | ||
|
||
Clip to an array along the index axis | ||
|
||
>>> df.clip_lower([0.2, 0.4, 0.6, 0.8], axis=0) | ||
a b | ||
0 0.740518 0.200000 | ||
1 0.450228 0.400000 | ||
2 0.710404 0.760925 | ||
3 0.800000 0.800000 | ||
|
||
Clip to an array along the column axis | ||
|
||
>>> df.clip_lower([0.5, 0.0], axis=1) | ||
a b | ||
0 0.740518 0.040507 | ||
1 0.500000 0.000000 | ||
2 0.710404 0.760925 | ||
3 0.500000 0.010624 | ||
|
||
Clip in place | ||
|
||
>>> df.clip_lower(0.2, inplace=True) | ||
>>> df | ||
a b | ||
0 0.740518 0.200000 | ||
1 0.450228 0.200000 | ||
2 0.710404 0.760925 | ||
3 0.200000 0.200000 | ||
""" | ||
return self._clip_with_one_bound(threshold, method=self.ge, | ||
axis=axis, inplace=inplace) | ||
|
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.
Sorry if I forgot some discussion about it, but don't we want a
See Also
section? I thinkclip
andclip_upper
should be listed.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.
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