Skip to content

Commit ccaa428

Browse files
committed
Merge PR #2750
2 parents ac9f5bc + 8b77ace commit ccaa428

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pandas 0.11.0
6666
correctly
6767
- astype on datetimes to object are now handled (as well as NaT
6868
conversions to np.nan)
69+
- arguments to DataFrame.clip were inconsistent to numpy and Series clipping
70+
(GH2747_)
6971

7072
**Bug Fixes**
7173

@@ -80,6 +82,7 @@ pandas 0.11.0
8082
.. _GH2778: https://github.com/pydata/pandas/issues/2778
8183
.. _GH2793: https://github.com/pydata/pandas/issues/2793
8284
.. _GH2751: https://github.com/pydata/pandas/issues/2751
85+
.. _GH2747: https://github.com/pydata/pandas/issues/2747
8386

8487
pandas 0.10.1
8588
=============

pandas/core/frame.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -5038,7 +5038,7 @@ def f(arr):
50385038
data = self._get_numeric_data() if numeric_only else self
50395039
return data.apply(f, axis=axis)
50405040

5041-
def clip(self, upper=None, lower=None):
5041+
def clip(self, lower=None, upper=None):
50425042
"""
50435043
Trim values at input threshold(s)
50445044
@@ -5051,6 +5051,11 @@ def clip(self, upper=None, lower=None):
50515051
-------
50525052
clipped : DataFrame
50535053
"""
5054+
5055+
# GH 2747 (arguments were reversed)
5056+
if lower is not None and upper is not None:
5057+
lower, upper = min(lower,upper), max(lower,upper)
5058+
50545059
return self.apply(lambda x: x.clip(lower=lower, upper=upper))
50555060

50565061
def clip_upper(self, threshold):

pandas/tests/test_frame.py

+16
Original file line numberDiff line numberDiff line change
@@ -6993,6 +6993,22 @@ def test_clip(self):
69936993
double = self.frame.clip(upper=median, lower=median)
69946994
self.assert_(not (double.values != median).any())
69956995

6996+
def test_dataframe_clip(self):
6997+
6998+
# GH #2747
6999+
df = DataFrame(np.random.randn(1000,2))
7000+
7001+
for lb, ub in [(-1,1),(1,-1)]:
7002+
clipped_df = df.clip(lb, ub)
7003+
7004+
lb, ub = min(lb,ub), max(ub,lb)
7005+
lb_mask = df.values <= lb
7006+
ub_mask = df.values >= ub
7007+
mask = ~lb_mask & ~ub_mask
7008+
self.assert_((clipped_df.values[lb_mask] == lb).all() == True)
7009+
self.assert_((clipped_df.values[ub_mask] == ub).all() == True)
7010+
self.assert_((clipped_df.values[mask] == df.values[mask]).all() == True)
7011+
69967012
def test_get_X_columns(self):
69977013
# numeric and object columns
69987014

0 commit comments

Comments
 (0)