diff --git a/RELEASE.rst b/RELEASE.rst index 981fa5bed257d..7767129de084a 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -22,6 +22,12 @@ Where to get it * Binary installers on PyPI: http://pypi.python.org/pypi/pandas * Documentation: http://pandas.pydata.org +**API Changes** + + - arguments to DataFrame.clip were inconsistent to numpy and Series clipping (GH2747_) + +.. _GH2747: https://github.com/pydata/pandas/issues/2747 + pandas 0.10.1 ============= diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 301ea9d28d001..d625fb87e3fd5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5029,7 +5029,7 @@ def f(arr): data = self._get_numeric_data() if numeric_only else self return data.apply(f, axis=axis) - def clip(self, upper=None, lower=None): + def clip(self, lower=None, upper=None): """ Trim values at input threshold(s) @@ -5042,6 +5042,11 @@ def clip(self, upper=None, lower=None): ------- 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): diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 09747ba3f09f0..d55e7a7b65fe3 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -6470,6 +6470,22 @@ def test_clip(self): double = self.frame.clip(upper=median, lower=median) self.assert_(not (double.values != median).any()) + def test_dataframe_clip(self): + + # GH #2747 + df = DataFrame(np.random.randn(1000,2)) + + for lb, ub in [(-1,1),(1,-1)]: + clipped_df = df.clip(lb, ub) + + lb, ub = min(lb,ub), max(ub,lb) + lb_mask = df.values <= lb + ub_mask = df.values >= ub + mask = ~lb_mask & ~ub_mask + self.assert_((clipped_df.values[lb_mask] == lb).all() == True) + self.assert_((clipped_df.values[ub_mask] == ub).all() == True) + self.assert_((clipped_df.values[mask] == df.values[mask]).all() == True) + def test_get_X_columns(self): # numeric and object columns