Skip to content

CLN: move clip to core/generic (adds to Panel as well), related to (GH2747) #4798

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
Sep 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ Computations / Descriptive Stats
:toctree: generated/

Panel.abs
Panel.clip
Panel.clip_lower
Panel.clip_upper
Panel.count
Panel.cummax
Panel.cummin
Expand Down
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
- Refactor ``rename`` methods to core/generic.py; fixes ``Series.rename`` for (:issue:`4605`), and adds ``rename``
with the same signature for ``Panel``
- Series (for index) / Panel (for items) now as attribute access to its elements (:issue:`1903`)
- Refactor ``clip`` methods to core/generic.py (:issue:`4798`)
- Refactor of ``_get_numeric_data/_get_bool_data`` to core/generic.py, allowing Series/Panel functionaility
- Refactor of Series arithmetic with time-like objects (datetime/timedelta/time
etc.) into a separate, cleaned up wrapper class. (:issue:`4613`)
Expand Down
3 changes: 2 additions & 1 deletion doc/source/v0.13.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ and behaviors. Series formerly subclassed directly from ``ndarray``. (:issue:`40
- Refactor ``Series.reindex`` to core/generic.py (:issue:`4604`, :issue:`4618`), allow ``method=`` in reindexing
on a Series to work
- ``Series.copy`` no longer accepts the ``order`` parameter and is now consistent with ``NDFrame`` copy
- Refactor ``rename`` methods to core/generic.py; fixes ``Series.rename`` for (:issue`4605`), and adds ``rename``
- Refactor ``rename`` methods to core/generic.py; fixes ``Series.rename`` for (:issue:`4605`), and adds ``rename``
with the same signature for ``Panel``
- Refactor ``clip`` methods to core/generic.py (:issue:`4798`)
- Refactor of ``_get_numeric_data/_get_bool_data`` to core/generic.py, allowing Series/Panel functionaility
- ``Series`` (for index) / ``Panel`` (for items) now allow attribute access to its elements (:issue:`1903`)

Expand Down
41 changes: 0 additions & 41 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4396,47 +4396,6 @@ def f(arr):

data = self._get_numeric_data() if numeric_only else self
return data.apply(f, axis=axis)

def clip(self, lower=None, upper=None):
"""
Trim values at input threshold(s)

Parameters
----------
lower : float, default None
upper : float, default None

Returns
-------
clipped : DataFrame
"""

# GH 2747 (arguments were reversed)
if lower is not None and upper is not None:
lower, upper = min(lower, upper), max(lower, upper)

return self.apply(lambda x: x.clip(lower=lower, upper=upper))

def clip_upper(self, threshold):
"""
Trim values above threshold

Returns
-------
clipped : DataFrame
"""
return self.apply(lambda x: x.clip_upper(threshold))

def clip_lower(self, threshold):
"""
Trim values below threshold

Returns
-------
clipped : DataFrame
"""
return self.apply(lambda x: x.clip_lower(threshold))

def rank(self, axis=0, numeric_only=None, method='average',
na_option='keep', ascending=True):
"""
Expand Down
62 changes: 62 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,68 @@ def f(x):

return obj

def clip(self, lower=None, upper=None, out=None):
"""
Trim values at input threshold(s)

Parameters
----------
lower : float, default None
upper : float, default None

Returns
-------
clipped : Series
"""
if out is not None: # pragma: no cover
raise Exception('out argument is not supported yet')

# GH 2747 (arguments were reversed)
if lower is not None and upper is not None:
lower, upper = min(lower, upper), max(lower, upper)

result = self
if lower is not None:
result = result.clip_lower(lower)
if upper is not None:
result = result.clip_upper(upper)

return result

def clip_upper(self, threshold):
"""
Return copy of input with values above given value truncated

See also
--------
clip

Returns
-------
clipped : same type as input
"""
if isnull(threshold):
raise ValueError("Cannot use an NA value as a clip threshold")

return self.where((self <= threshold) | isnull(self), threshold)

def clip_lower(self, threshold):
"""
Return copy of the input with values below given value truncated

See also
--------
clip

Returns
-------
clipped : same type as input
"""
if isnull(threshold):
raise ValueError("Cannot use an NA value as a clip threshold")

return self.where((self >= threshold) | isnull(self), threshold)

def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
group_keys=True, squeeze=False):
"""
Expand Down
58 changes: 0 additions & 58 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2102,64 +2102,6 @@ def autocorr(self):
"""
return self.corr(self.shift(1))

def clip(self, lower=None, upper=None, out=None):
"""
Trim values at input threshold(s)

Parameters
----------
lower : float, default None
upper : float, default None

Returns
-------
clipped : Series
"""
if out is not None: # pragma: no cover
raise Exception('out argument is not supported yet')

result = self
if lower is not None:
result = result.clip_lower(lower)
if upper is not None:
result = result.clip_upper(upper)

return result

def clip_upper(self, threshold):
"""
Return copy of series with values above given value truncated

See also
--------
clip

Returns
-------
clipped : Series
"""
if isnull(threshold):
raise ValueError("Cannot use an NA value as a clip threshold")

return self.where((self <= threshold) | isnull(self), threshold)

def clip_lower(self, threshold):
"""
Return copy of series with values below given value truncated

See also
--------
clip

Returns
-------
clipped : Series
"""
if isnull(threshold):
raise ValueError("Cannot use an NA value as a clip threshold")

return self.where((self >= threshold) | isnull(self), threshold)

def dot(self, other):
"""
Matrix multiplication with DataFrame or inner-product with Series objects
Expand Down