Skip to content

Commit 179de43

Browse files
committed
BUG: DataFrame.clip arguments were inconsistent to numpy and Series.clip, closes GH pandas-dev#2747
1 parent 3ba3119 commit 179de43

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

RELEASE.rst

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Where to get it
2222
* Binary installers on PyPI: http://pypi.python.org/pypi/pandas
2323
* Documentation: http://pandas.pydata.org
2424

25+
**API Changes**
26+
27+
- arguments to DataFrame.clip were inconsistent to numpy and Series clipping (GH2747_)
28+
29+
.. _GH2747: https://github.com/pydata/pandas/issues/2747
30+
2531
pandas 0.10.1
2632
=============
2733

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5029,7 +5029,7 @@ def f(arr):
50295029
data = self._get_numeric_data() if numeric_only else self
50305030
return data.apply(f, axis=axis)
50315031

5032-
def clip(self, upper=None, lower=None):
5032+
def clip(self, lower=None, upper=None):
50335033
"""
50345034
Trim values at input threshold(s)
50355035

pandas/tests/test_frame.py

+15
Original file line numberDiff line numberDiff line change
@@ -6470,6 +6470,21 @@ def test_clip(self):
64706470
double = self.frame.clip(upper=median, lower=median)
64716471
self.assert_(not (double.values != median).any())
64726472

6473+
def test_dataframe_clip(self):
6474+
6475+
lb = -1
6476+
ub = 1
6477+
6478+
# GH #2747
6479+
df = DataFrame(np.random.randn(1000,2))
6480+
lb_mask = df.values <= lb
6481+
ub_mask = df.values >= ub
6482+
mask = ~lb_mask & ~ub_mask
6483+
clipped_df = df.clip(lb, ub)
6484+
self.assert_((clipped_df.values[lb_mask] == lb).all() == True)
6485+
self.assert_((clipped_df.values[ub_mask] == ub).all() == True)
6486+
self.assert_((clipped_df.values[mask] == df.values[mask]).all() == True)
6487+
64736488
def test_get_X_columns(self):
64746489
# numeric and object columns
64756490

0 commit comments

Comments
 (0)