Skip to content

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

Merged
merged 1 commit into from
May 25, 2017

Conversation

guygoldberg
Copy link
Contributor

@guygoldberg guygoldberg commented May 23, 2017

  • [V] closes clip inplace? #15388
  • [V] tests added / passed
  • [V] passes git diff upstream/master --name-only -- '*.py' | flake8 --diff
  • whatsnew entry

@@ -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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor

@jreback jreback left a 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.

clipped_df = df.clip(lb, ub, axis=0)
original = df.copy()

if inplace:
Copy link
Contributor

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

@jreback
Copy link
Contributor

jreback commented May 23, 2017

note this doesn't offer any perf benefit (actually doing this is a bit tricky), but ok.

@jreback jreback added Enhancement Numeric Operations Arithmetic, Comparison, and Logical operations labels May 23, 2017
@guygoldberg guygoldberg force-pushed the 15388-inplace-clip branch from b3488d4 to 2e7f8c1 Compare May 24, 2017 04:48
@codecov
Copy link

codecov bot commented May 24, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@044feb5). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #16462   +/-   ##
=========================================
  Coverage          ?   90.42%           
=========================================
  Files             ?      161           
  Lines             ?    51036           
  Branches          ?        0           
=========================================
  Hits              ?    46151           
  Misses            ?     4885           
  Partials          ?        0
Flag Coverage Δ
#multiple 88.26% <100%> (?)
#single 40.16% <19.04%> (?)
Impacted Files Coverage Δ
pandas/core/generic.py 92.16% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 044feb5...2e7f8c1. Read the comment docs.

@codecov
Copy link

codecov bot commented May 24, 2017

Codecov Report

Merging #16462 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.26% <100%> (+0.02%) ⬆️
#single 40.16% <19.04%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 92.16% <100%> (+0.03%) ⬆️
pandas/util/testing.py 80.79% <0%> (+0.19%) ⬆️
pandas/plotting/_converter.py 65.05% <0%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7962c5...62ee43b. Read the comment docs.

@guygoldberg guygoldberg force-pushed the 15388-inplace-clip branch from 2e7f8c1 to f6fa959 Compare May 24, 2017 04:58
@guygoldberg
Copy link
Contributor Author

@jreback, thanks. I fixed all of the comments and pushed to my branch.

Copy link
Contributor

@jreback jreback left a 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.

@@ -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`)
Copy link
Contributor

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.

clipped_df = df.clip(lb, ub, axis=0)
original = df.copy()


Copy link
Contributor

Choose a reason for hiding this comment

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

nit. extra line.

@guygoldberg guygoldberg force-pushed the 15388-inplace-clip branch from de16f27 to 58dd405 Compare May 25, 2017 07:10
@guygoldberg guygoldberg force-pushed the 15388-inplace-clip branch from 58dd405 to 62ee43b Compare May 25, 2017 07:45
@jreback jreback added this to the 0.21.0 milestone May 25, 2017
@jreback jreback merged commit 348afeb into pandas-dev:master May 25, 2017
@jreback
Copy link
Contributor

jreback commented May 25, 2017

thanks!

stangirala pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clip inplace?
2 participants