-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Support inplace clip (#15388) #16462
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
Conversation
@@ -4149,6 +4153,8 @@ def clip(self, lower=None, upper=None, axis=None, *args, **kwargs): | |||
upper : float or array_like, default None | |||
axis : int or string axis name, optional | |||
Align object with lower and upper along the given axis. | |||
inplace : boolean, default False | |||
Whether to perform the operation in place on the data |
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.
needs a versionadded tag.
@@ -4220,6 +4231,8 @@ def clip_upper(self, threshold, axis=None): | |||
threshold : float or array_like | |||
axis : int or string axis name, optional | |||
Align object with threshold along the given axis. | |||
inplace : boolean, default False | |||
Whether to perform the operation in place on the data |
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.
same
@@ -4247,6 +4262,8 @@ def clip_lower(self, threshold, axis=None): | |||
threshold : float or array_like | |||
axis : int or string axis name, optional | |||
Align object with threshold along the given axis. | |||
inplace : boolean, default False | |||
Whether to perform the operation in place on the data |
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.
same
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.
minor comment. pls add a whatsnew entry (0.21.0) in enhancements.
pandas/tests/frame/test_analytics.py
Outdated
clipped_df = df.clip(lb, ub, axis=0) | ||
original = df.copy() | ||
|
||
if 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.
you can just do
clipped_df = df.clip(lb, ub, axis=0, inplace=inplace)
if inplace:
clipped_df = df
note this doesn't offer any perf benefit (actually doing this is a bit tricky), but ok. |
b3488d4
to
2e7f8c1
Compare
Codecov Report
@@ Coverage Diff @@
## master #16462 +/- ##
=========================================
Coverage ? 90.42%
=========================================
Files ? 161
Lines ? 51036
Branches ? 0
=========================================
Hits ? 46151
Misses ? 4885
Partials ? 0
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16462 +/- ##
==========================================
+ Coverage 90.39% 90.42% +0.02%
==========================================
Files 161 161
Lines 51036 51045 +9
==========================================
+ Hits 46136 46159 +23
+ Misses 4900 4886 -14
Continue to review full report at Codecov.
|
2e7f8c1
to
f6fa959
Compare
@jreback, thanks. I fixed all of the comments and pushed to my branch. |
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.
minor comments. needs a rebase on master though. I think you might have some conflicts. ping when green.
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -35,6 +35,7 @@ Other Enhancements | |||
- ``RangeIndex.append`` now returns a ``RangeIndex`` object when possible (:issue:`16212`) | |||
- :func:`to_pickle` has gained a protocol parameter (:issue:`16252`). By default, this parameter is set to `HIGHEST_PROTOCOL <https://docs.python.org/3/library/pickle.html#data-stream-format>`__ | |||
- :func:`api.types.infer_dtype` now infers decimals. (:issue: `15690`) | |||
- :func:`clip` now supports inplace trimming. (:issue: `15388`) |
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.
no, DataFrame.clip()
and Series.cip()
have gained an inplace
argument.
pandas/tests/frame/test_analytics.py
Outdated
clipped_df = df.clip(lb, ub, axis=0) | ||
original = df.copy() | ||
|
||
|
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.
nit. extra line.
de16f27
to
58dd405
Compare
58dd405
to
62ee43b
Compare
thanks! |
git diff upstream/master --name-only -- '*.py' | flake8 --diff