From 51f612c5b0fa022bdf8725350e1321c287dca807 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 10 Mar 2018 14:45:30 +0100 Subject: [PATCH 1/6] DOC: improved the docstring of pandas.Series.clip_upper improved --- pandas/core/generic.py | 60 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a893b2ba1a189..f3293481054fe 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5635,24 +5635,67 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False, def clip_upper(self, threshold, axis=None, inplace=False): """ - Return copy of input with values above given value(s) truncated. + Return copy of the input with values above given value(s) truncated. + + It truncates values above a certain threshold. Threshold can be a single + value or an array, in the latter case it performs the truncation + element-wise. Parameters ---------- threshold : float or array_like + Maximum value allowed. All values above threshold will be + set to this value. axis : int or string axis name, optional Align object with threshold along the given axis. inplace : boolean, default False - Whether to perform the operation in place on the data - .. versionadded:: 0.21.0 + Whether to perform the operation in place on the data. See Also -------- - clip + clip : Return copy of input with values below/above thresholds truncated. + clip_lower : Return copy of input with values below given thresholds. Returns ------- clipped : same type as input + + Examples + -------- + >>> s = pd.Series([1,2,3,4,5,6,7]) + >>> s + 0 1 + 1 2 + 2 3 + 3 4 + 4 5 + 5 6 + 6 7 + dtype: int64 + + >>> s.clip_upper(4) + 0 1 + 1 2 + 2 3 + 3 4 + 4 4 + 5 4 + 6 4 + dtype: int64 + + >>> t = [4,8,7,2,5,4,6] + >>> t + [4, 8, 7, 2, 5, 4, 6] + + >>> s.clip_upper(t) + 0 1 + 1 2 + 2 3 + 3 2 + 4 5 + 5 4 + 6 6 + dtype: int64 """ return self._clip_with_one_bound(threshold, method=self.le, axis=axis, inplace=inplace) @@ -5661,18 +5704,21 @@ def clip_lower(self, threshold, axis=None, inplace=False): """ Return copy of the input with values below given value(s) truncated. + + Parameters ---------- threshold : float or array_like + Minimun value allowed. All values below threshold will be + equaled to the threshold value. axis : int or string axis name, optional Align object with threshold along the given axis. inplace : boolean, default False - Whether to perform the operation in place on the data - .. versionadded:: 0.21.0 + Whether to perform the operation in place on the data. See Also -------- - clip + clip: Returns ------- From da2dac7736deb9eaf1243698d4daba39681dbe98 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 10 Mar 2018 14:52:40 +0100 Subject: [PATCH 2/6] DOC: improved the docstring of pandas.Series.clip_upper improved PEP8 corrections --- pandas/core/generic.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f3293481054fe..286608799f59d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5637,8 +5637,9 @@ def clip_upper(self, threshold, axis=None, inplace=False): """ Return copy of the input with values above given value(s) truncated. - It truncates values above a certain threshold. Threshold can be a single - value or an array, in the latter case it performs the truncation + It truncates values above a certain threshold. Threshold can be a + single value or an array, in the latter case it performs the + truncation element-wise. Parameters @@ -5653,8 +5654,8 @@ def clip_upper(self, threshold, axis=None, inplace=False): See Also -------- - clip : Return copy of input with values below/above thresholds truncated. - clip_lower : Return copy of input with values below given thresholds. + clip : Return input copy with values below/above thresholds truncated. + clip_lower : Return input copy input with values below given thresholds. Returns ------- From 86bc86ee83be19adbd245c805b05cfe2d9041b8f Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 10 Mar 2018 16:17:06 +0100 Subject: [PATCH 3/6] DOC: improved the docstring of pandas.Series.clip_upper improved PEP-8 correctios --- pandas/core/generic.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 286608799f59d..0c157f00923e1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5638,19 +5638,19 @@ def clip_upper(self, threshold, axis=None, inplace=False): Return copy of the input with values above given value(s) truncated. It truncates values above a certain threshold. Threshold can be a - single value or an array, in the latter case it performs the - truncation + single value or an array, in the latter case it performs the truncation element-wise. Parameters ---------- - threshold : float or array_like - Maximum value allowed. All values above threshold will be - set to this value. + threshold : float or array-like + Maximum value allowed. All values above threshold will be set to + this value. axis : int or string axis name, optional Align object with threshold along the given axis. - inplace : boolean, default False + inplace : bool, default False Whether to perform the operation in place on the data. + .. versionadded:: 0.21.0. See Also -------- @@ -5663,39 +5663,33 @@ def clip_upper(self, threshold, axis=None, inplace=False): Examples -------- - >>> s = pd.Series([1,2,3,4,5,6,7]) + >>> s = pd.Series([1, 2, 3, 4, 5]) >>> s 0 1 1 2 2 3 3 4 4 5 - 5 6 - 6 7 dtype: int64 - >>> s.clip_upper(4) + >>> s.clip_upper(3) 0 1 1 2 2 3 - 3 4 - 4 4 - 5 4 - 6 4 + 3 3 + 4 3 dtype: int64 - >>> t = [4,8,7,2,5,4,6] + >>> t = [5, 4, 3, 2, 1] >>> t - [4, 8, 7, 2, 5, 4, 6] + [5, 4, 3, 2, 1] >>> s.clip_upper(t) 0 1 1 2 2 3 3 2 - 4 5 - 5 4 - 6 6 + 4 1 dtype: int64 """ return self._clip_with_one_bound(threshold, method=self.le, @@ -5719,7 +5713,7 @@ def clip_lower(self, threshold, axis=None, inplace=False): See Also -------- - clip: + clip : Return input copy with values below/above thresholds truncated. Returns ------- @@ -5903,6 +5897,7 @@ def at_time(self, time, asof=False): Parameters ---------- time : datetime.time or string + asof : Returns ------- From 3e5397220c9a581a2710db4f89c581f4e7a38409 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sun, 8 Jul 2018 09:39:28 -0500 Subject: [PATCH 4/6] Doc fixup --- pandas/core/generic.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0c157f00923e1..28c6c1e84e743 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5650,7 +5650,7 @@ def clip_upper(self, threshold, axis=None, inplace=False): Align object with threshold along the given axis. inplace : bool, default False Whether to perform the operation in place on the data. - .. versionadded:: 0.21.0. + .. versionadded:: 0.21.0 See Also -------- @@ -5699,8 +5699,6 @@ def clip_lower(self, threshold, axis=None, inplace=False): """ Return copy of the input with values below given value(s) truncated. - - Parameters ---------- threshold : float or array_like @@ -5897,7 +5895,6 @@ def at_time(self, time, asof=False): Parameters ---------- time : datetime.time or string - asof : Returns ------- From d4cac1b03b329e914eaa2a21392cf32125aa414c Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sun, 8 Jul 2018 09:42:41 -0500 Subject: [PATCH 5/6] LINT fixup --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b413df3584678..d253486df9bbb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6568,7 +6568,7 @@ def clip_upper(self, threshold, axis=None, inplace=False): See Also -------- clip : Return input copy with values below/above thresholds truncated. - clip_lower : Return input copy input with values below given thresholds. + clip_lower : Method to truncate values below given thresholds. Returns ------- From 124d7f0096fbee7924020764dcd98fab7ae8ad7a Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sun, 8 Jul 2018 09:43:19 -0500 Subject: [PATCH 6/6] Missing period --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d253486df9bbb..1e08c1e8a1c40 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6561,7 +6561,7 @@ def clip_upper(self, threshold, axis=None, inplace=False): axis : int or string axis name, optional Align object with threshold along the given axis. inplace : boolean, default False - Whether to perform the operation in place on the data + Whether to perform the operation in place on the data. .. versionadded:: 0.21.0