Skip to content

Commit 1bcf68e

Browse files
committed
BUG: small API change in Series.clip arg order, enable np.clip to be used also, GH #272
1 parent 566304f commit 1bcf68e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ feedback on the library.
5555
- Deprecated `nanRep` argument in various `to_string` and `to_csv` functions
5656
in favor of `na_rep`. Will be removed in 0.6 (GH #275)
5757
- Renamed `delimiter` to `sep` in `DataFrame.from_csv` for consistency
58+
- Changed order of `Series.clip` arguments to match those of `numpy.clip` and
59+
added (unimplemented) `out` argument so `numpy.clip` can be called on a
60+
Series (GH #272)
5861
- Series functions renamed (and thus deprecated) in 0.4 series have been
5962
removed:
6063

pandas/core/series.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ def autocorr(self):
967967
"""
968968
return self.corr(self.shift(1))
969969

970-
def clip(self, upper=None, lower=None):
970+
def clip(self, lower=None, upper=None, out=None):
971971
"""
972972
Trim values at input threshold(s)
973973
@@ -980,6 +980,9 @@ def clip(self, upper=None, lower=None):
980980
-------
981981
clipped : Series
982982
"""
983+
if out is not None: # pragma: no cover
984+
raise Exception('out argument is not supported yet')
985+
983986
result = self
984987
if lower is not None:
985988
result = result.clip_lower(lower)

pandas/tests/test_series.py

+5
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,11 @@ def test_clip(self):
843843
self.assertEqual(self.ts.clip(lower=val).min(), val)
844844
self.assertEqual(self.ts.clip(upper=val).max(), val)
845845

846+
result = self.ts.clip(-0.5, 0.5)
847+
expected = np.clip(self.ts, -0.5, 0.5)
848+
assert_series_equal(result, expected)
849+
self.assert_(isinstance(expected, Series))
850+
846851
def test_valid(self):
847852
ts = self.ts.copy()
848853
ts[::2] = np.NaN

0 commit comments

Comments
 (0)