From 06e5af0f0de173cf8d53a2497ac4408e91417f46 Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Wed, 3 Oct 2018 14:50:44 +0530 Subject: [PATCH 01/21] fixed doc-string for combine & combine_first --- pandas/core/series.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 892b24f6ee552..1bf8a601a7506 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2281,30 +2281,41 @@ def _binop(self, other, func, level=None, fill_value=None): def combine(self, other, func, fill_value=None): """ + Combine the Series with a `Series` or `Scalar` according to `func`. + Perform elementwise binary operation on two Series using given function with optional fill value when an index is missing from one Series or - the other + the other. Parameters ---------- other : Series or scalar value + The value(s) to be combined with the `Series`. func : function - Function that takes two scalars as inputs and return a scalar + Function that takes two scalars as inputs and return a scalar. fill_value : scalar value + The optional value to assume when an index + is missing from one Series or the other, The default specifies to use the appropriate NaN value for - the underlying dtype of the Series + the underlying dtype of the Series. Returns ------- - result : Series + result : the combined `Series` object Examples -------- >>> s1 = pd.Series([1, 2]) - >>> s2 = pd.Series([0, 3]) + >>> s2 = pd.Series([0, 3, 4]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) 0 0 1 2 + 2 4 + dtype: int64 + >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2,fill_value=787) + 0 1 + 1 3 + 2 787 dtype: int64 See Also @@ -2352,12 +2363,16 @@ def combine(self, other, func, fill_value=None): def combine_first(self, other): """ - Combine Series values, choosing the calling Series's values - first. Result index will be the union of the two indexes + Combine Series values, choosing the calling Series's values first. + + Notes + ----- + Result index will be the union of the two indexes. Parameters ---------- other : Series + The value(s) to be combined with the `Series`. Returns ------- From 6d1dae636958c136f77dcb66b1536f489e352d06 Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Tue, 9 Oct 2018 14:02:22 +0530 Subject: [PATCH 02/21] clearer examples and PEP8, linting fixes --- pandas/core/series.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1bf8a601a7506..d1f4d5f1819d4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2281,19 +2281,19 @@ def _binop(self, other, func, level=None, fill_value=None): def combine(self, other, func, fill_value=None): """ - Combine the Series with a `Series` or `Scalar` according to `func`. + Combine the Series with a Series or Scalar according to `func`. Perform elementwise binary operation on two Series using given function - with optional fill value when an index is missing from one Series or - the other. + with optional `fill_value` when an index is missing from the Series or + the other value. Parameters ---------- - other : Series or scalar value + other : Series or Scalar The value(s) to be combined with the `Series`. - func : function - Function that takes two scalars as inputs and return a scalar. - fill_value : scalar value + func : Function + `function` that takes two Scalars as inputs and returns a `bool`. + fill_value : Scalar The optional value to assume when an index is missing from one Series or the other, The default specifies to use the appropriate NaN value for @@ -2301,27 +2301,41 @@ def combine(self, other, func, fill_value=None): Returns ------- - result : the combined `Series` object + A Series object. Examples -------- - >>> s1 = pd.Series([1, 2]) - >>> s2 = pd.Series([0, 3, 4]) + >>> import pandas as pd + >>> s1 = pd.Series([1,2]) + >>> s2 = pd.Series([0,3]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) 0 0 1 2 + dtype: int64 + + >>> s2 = pd.Series([0,3,4]) + >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2) + 0 1 + 1 3 2 4 dtype: int64 - >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2,fill_value=787) + + When fill_value is given:- + + >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2, + ... fill_value = 787) 0 1 1 3 2 787 dtype: int64 + If `func` doesn't get a value from either of the two Series, + fill_value` is used. + See Also -------- Series.combine_first : Combine Series values, choosing the calling - Series's values first. + Series' values first """ if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) From 63c6b4b4e0fc117f9a7a64281d81788de535d746 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Tue, 9 Oct 2018 16:27:47 +0530 Subject: [PATCH 03/21] Update series.py --- pandas/core/series.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index d1f4d5f1819d4..3a04ecd102dc5 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2281,23 +2281,23 @@ def _binop(self, other, func, level=None, fill_value=None): def combine(self, other, func, fill_value=None): """ - Combine the Series with a Series or Scalar according to `func`. - - Perform elementwise binary operation on two Series using given function - with optional `fill_value` when an index is missing from the Series or - the other value. + Combine the Series with a Series or scalar according to `func`. + Combine the Series and `other` using `func` to perform elementwise + selection for combined Series. + `fill_value` is assumed when value is missing from one + of the two objects being combined at some index. + Parameters ---------- - other : Series or Scalar + other : Series or scalar The value(s) to be combined with the `Series`. - func : Function - `function` that takes two Scalars as inputs and returns a `bool`. - fill_value : Scalar - The optional value to assume when an index - is missing from one Series or the other, - The default specifies to use the appropriate NaN value for - the underlying dtype of the Series. + func : function + Function that takes two scalars as inputs and returns a `bool`. + fill_value : scalar + The optional value to assume when an index is missing from + one Series or the other. The default specifies to use the + appropriate NaN value for the underlying dtype of the Series. Returns ------- @@ -2306,14 +2306,14 @@ def combine(self, other, func, fill_value=None): Examples -------- >>> import pandas as pd - >>> s1 = pd.Series([1,2]) - >>> s2 = pd.Series([0,3]) + >>> s1 = pd.Series([1, 2]) + >>> s2 = pd.Series([0, 3]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) 0 0 1 2 dtype: int64 - >>> s2 = pd.Series([0,3,4]) + >>> s2 = pd.Series([0, 3, 4]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2) 0 1 1 3 From 52955a36818008a766f9647c3c3d2b885c7aab4b Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Tue, 9 Oct 2018 16:33:09 +0530 Subject: [PATCH 04/21] Update series.py --- pandas/core/series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 3a04ecd102dc5..35e040c2646a9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2301,7 +2301,8 @@ def combine(self, other, func, fill_value=None): Returns ------- - A Series object. + Series + A combined Series object. Examples -------- From bf123bdffc16b09daffd724192171279d3f1e063 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Tue, 9 Oct 2018 23:34:27 +0530 Subject: [PATCH 05/21] fixed PEP8 and moved `See Also` above `Examples` --- pandas/core/series.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 35e040c2646a9..3198c70684c02 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3,6 +3,10 @@ """ from __future__ import division +# pylint: disable=E1101,E1103combine +# pylint: disable=W0703,W0622,W0613,W0201 + +import warnings from textwrap import dedent import warnings @@ -2287,7 +2291,7 @@ def combine(self, other, func, fill_value=None): selection for combined Series. `fill_value` is assumed when value is missing from one of the two objects being combined at some index. - + Parameters ---------- other : Series or scalar @@ -2302,7 +2306,12 @@ def combine(self, other, func, fill_value=None): Returns ------- Series - A combined Series object. + A combined Series object. + + See Also + -------- + Series.combine_first : Combine Series values, choosing the calling + Series' values first Examples -------- @@ -2332,11 +2341,6 @@ def combine(self, other, func, fill_value=None): If `func` doesn't get a value from either of the two Series, fill_value` is used. - - See Also - -------- - Series.combine_first : Combine Series values, choosing the calling - Series' values first """ if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) From de2a6e2f9443c503587682cf47fc963aef430575 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Wed, 10 Oct 2018 12:40:13 +0530 Subject: [PATCH 06/21] fixed PEP8 issue, typo and removed `import` --- pandas/core/series.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 3198c70684c02..50cc6f308083e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3,7 +3,7 @@ """ from __future__ import division -# pylint: disable=E1101,E1103combine +# pylint: disable=E1101,E1103 # pylint: disable=W0703,W0622,W0613,W0201 import warnings @@ -2315,7 +2315,6 @@ def combine(self, other, func, fill_value=None): Examples -------- - >>> import pandas as pd >>> s1 = pd.Series([1, 2]) >>> s2 = pd.Series([0, 3]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) @@ -2331,9 +2330,8 @@ def combine(self, other, func, fill_value=None): dtype: int64 When fill_value is given:- - >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2, - ... fill_value = 787) + ... fill_value = 787) 0 1 1 3 2 787 From 2ee7f4af5ccab0e2b3dc830faca16cf6fc746e5f Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Sat, 3 Nov 2018 14:49:43 +0530 Subject: [PATCH 07/21] Update series.py --- pandas/core/series.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 50cc6f308083e..c4a9353d8551b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2311,7 +2311,7 @@ def combine(self, other, func, fill_value=None): See Also -------- Series.combine_first : Combine Series values, choosing the calling - Series' values first + Series' values first Examples -------- @@ -2329,16 +2329,15 @@ def combine(self, other, func, fill_value=None): 2 4 dtype: int64 - When fill_value is given:- + `fill_value` is the _default comparison value_ + in the function if a value is missing in the series. >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2, - ... fill_value = 787) + ... fill_value=787) 0 1 1 3 2 787 dtype: int64 - If `func` doesn't get a value from either of the two Series, - fill_value` is used. """ if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) From 52c191128fd78c93f10c5d86c8791e66855e2efb Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Tue, 6 Nov 2018 23:18:22 +0530 Subject: [PATCH 08/21] Update series.py --- pandas/core/series.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index c4a9353d8551b..892ada2b8d0a0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2289,16 +2289,16 @@ def combine(self, other, func, fill_value=None): Combine the Series and `other` using `func` to perform elementwise selection for combined Series. - `fill_value` is assumed when value is missing from one - of the two objects being combined at some index. + `fill_value` is assumed when value is missing at some index + from one of the two objects being combined . Parameters ---------- other : Series or scalar The value(s) to be combined with the `Series`. func : function - Function that takes two scalars as inputs and returns a `bool`. - fill_value : scalar + Function that takes two scalars as inputs and returns an element. + fill_value : scalar, default None The optional value to assume when an index is missing from one Series or the other. The default specifies to use the appropriate NaN value for the underlying dtype of the Series. @@ -2329,8 +2329,6 @@ def combine(self, other, func, fill_value=None): 2 4 dtype: int64 - `fill_value` is the _default comparison value_ - in the function if a value is missing in the series. >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2, ... fill_value=787) 0 1 From c92153975bb8bc0f6b765182a6139e483f8cf08d Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Wed, 7 Nov 2018 02:25:56 +0530 Subject: [PATCH 09/21] Update series.py --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 892ada2b8d0a0..be26ed0eba094 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2306,12 +2306,12 @@ def combine(self, other, func, fill_value=None): Returns ------- Series - A combined Series object. + The result of combining the Series with the other object. See Also -------- Series.combine_first : Combine Series values, choosing the calling - Series' values first + Series' values first. Examples -------- From c9a24905d5e97862b3217391a96a2305e08f600d Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Fri, 9 Nov 2018 23:41:35 +0530 Subject: [PATCH 10/21] Reordered Sections- shifted `See Also` to bottom --- pandas/core/series.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index be26ed0eba094..a0f9e92fff6e2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2308,11 +2308,6 @@ def combine(self, other, func, fill_value=None): Series The result of combining the Series with the other object. - See Also - -------- - Series.combine_first : Combine Series values, choosing the calling - Series' values first. - Examples -------- >>> s1 = pd.Series([1, 2]) @@ -2336,6 +2331,11 @@ def combine(self, other, func, fill_value=None): 2 787 dtype: int64 + See Also + -------- + Series.combine_first : Combine Series values, choosing the calling + Series' values first. + """ if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) From 0a006327bc3b4451a9da2490b146b28fba49223c Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Fri, 9 Nov 2018 23:45:51 +0530 Subject: [PATCH 11/21] Reorder `Notes` below ` Examples --- pandas/core/series.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index a0f9e92fff6e2..20a7f7fef5948 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2379,10 +2379,6 @@ def combine_first(self, other): """ Combine Series values, choosing the calling Series's values first. - Notes - ----- - Result index will be the union of the two indexes. - Parameters ---------- other : Series @@ -2404,7 +2400,12 @@ def combine_first(self, other): See Also -------- Series.combine : Perform elementwise operation on two Series - using a given function. + using a given function + + Notes + ----- + Result index will be the union of the two indexes. + """ new_index = self.index.union(other.index) this = self.reindex(new_index, copy=False) From 8c928f5a5a02c2dd4c57ef6a1e32f7b969e4b4d6 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Sat, 10 Nov 2018 00:23:14 +0530 Subject: [PATCH 12/21] Reordered doc-string sections for combine & combine_first Followed link : https://numpydoc.readthedocs.io/en/latest/format.html#sections --- pandas/core/series.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 20a7f7fef5948..e0c40333e3dab 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2308,6 +2308,11 @@ def combine(self, other, func, fill_value=None): Series The result of combining the Series with the other object. + See Also + -------- + Series.combine_first : Combine Series values, choosing the calling + Series' values first. + Examples -------- >>> s1 = pd.Series([1, 2]) @@ -2331,11 +2336,6 @@ def combine(self, other, func, fill_value=None): 2 787 dtype: int64 - See Also - -------- - Series.combine_first : Combine Series values, choosing the calling - Series' values first. - """ if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) @@ -2387,16 +2387,7 @@ def combine_first(self, other): Returns ------- combined : Series - - Examples - -------- - >>> s1 = pd.Series([1, np.nan]) - >>> s2 = pd.Series([3, 4]) - >>> s1.combine_first(s2) - 0 1.0 - 1 4.0 - dtype: float64 - + See Also -------- Series.combine : Perform elementwise operation on two Series @@ -2406,6 +2397,15 @@ def combine_first(self, other): ----- Result index will be the union of the two indexes. + Examples + -------- + >>> s1 = pd.Series([1, np.nan]) + >>> s2 = pd.Series([3, 4]) + >>> s1.combine_first(s2) + 0 1.0 + 1 4.0 + dtype: float64 + """ new_index = self.index.union(other.index) this = self.reindex(new_index, copy=False) From f6099dad169cab393f3430d776dee8e95713d31c Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Tue, 20 Nov 2018 18:36:24 +0530 Subject: [PATCH 13/21] Fixed all typos --- pandas/core/series.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index e0c40333e3dab..5cd56a924d2dc 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2298,8 +2298,8 @@ def combine(self, other, func, fill_value=None): The value(s) to be combined with the `Series`. func : function Function that takes two scalars as inputs and returns an element. - fill_value : scalar, default None - The optional value to assume when an index is missing from + fill_value : scalar, optional + The value to assume when an index is missing from one Series or the other. The default specifies to use the appropriate NaN value for the underlying dtype of the Series. @@ -2386,12 +2386,13 @@ def combine_first(self, other): Returns ------- - combined : Series + Series + The result of combining the Series with the other object. See Also -------- Series.combine : Perform elementwise operation on two Series - using a given function + using a given function Notes ----- From edc15249c1e4f843f8f746e147a229a77a9da36a Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Wed, 21 Nov 2018 00:10:11 +0530 Subject: [PATCH 14/21] Added practical example --- pandas/core/series.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 5cd56a924d2dc..1e96b7445f541 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2290,7 +2290,7 @@ def combine(self, other, func, fill_value=None): Combine the Series and `other` using `func` to perform elementwise selection for combined Series. `fill_value` is assumed when value is missing at some index - from one of the two objects being combined . + from one of the two objects being combined. Parameters ---------- @@ -2316,12 +2316,6 @@ def combine(self, other, func, fill_value=None): Examples -------- >>> s1 = pd.Series([1, 2]) - >>> s2 = pd.Series([0, 3]) - >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2) - 0 0 - 1 2 - dtype: int64 - >>> s2 = pd.Series([0, 3, 4]) >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2) 0 1 @@ -2329,11 +2323,22 @@ def combine(self, other, func, fill_value=None): 2 4 dtype: int64 - >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2, - ... fill_value=787) - 0 1 - 1 3 - 2 787 + >>> arms = pd.Series({'dog':2,'cat': 2,'mouse': 2}) + >>> legs = pd.Series({'dog':2,'cat': 2}) + >>> arms + dog 2 + cat 2 + mouse 2 + dtype: int64 + >>> legs + dog 2 + cat 2 + dtype: int64 + >>> limbs = arms.combine(legs, lambda x1,x2: x1+x2, fill_value=0) + >>> limbs + cat 4 + dog 4 + mouse 2 dtype: int64 """ From 7390f46e6efa173132392b7938768d8f18f18066 Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Wed, 21 Nov 2018 02:36:59 +0530 Subject: [PATCH 15/21] HIGHEST SPEED example in Series.combine() --- pandas/core/series.py | 49 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1e96b7445f541..47ca69aab0946 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3,10 +3,6 @@ """ from __future__ import division -# pylint: disable=E1101,E1103 -# pylint: disable=W0703,W0622,W0613,W0201 - -import warnings from textwrap import dedent import warnings @@ -2315,33 +2311,30 @@ def combine(self, other, func, fill_value=None): Examples -------- - >>> s1 = pd.Series([1, 2]) - >>> s2 = pd.Series([0, 3, 4]) - >>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2) - 0 1 - 1 3 - 2 4 - dtype: int64 + Consider 2 Datasets data_A and data_B containing highest clocked speeds of different birds. - >>> arms = pd.Series({'dog':2,'cat': 2,'mouse': 2}) - >>> legs = pd.Series({'dog':2,'cat': 2}) - >>> arms - dog 2 - cat 2 - mouse 2 - dtype: int64 - >>> legs - dog 2 - cat 2 - dtype: int64 - >>> limbs = arms.combine(legs, lambda x1,x2: x1+x2, fill_value=0) - >>> limbs - cat 4 - dog 4 - mouse 2 + >>> s1 = pd.Series({'falcon': 330, 'eagle': 160, 'swift': 105, 'duck': 30}) + >>> s2 = pd.Series({'falcon': 345, 'eagle': 200, 'swift': 100}) + + Now, to combine the two datasets and view the highest speeds of the birds across the + two datasets + + >>> s1.combine(s2, max) + duck 30 + eagle 200 + falcon 345 + swift 105 dtype: int64 - """ + Considering an average value of birds' speed to be ~40 mph, + + >>> s1.combine(s2, max, fill_value=40) + duck 40 + eagle 200 + falcon 345 + swift 105 + dtype: int64 +""" if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) From 88044362865e32e97c6202084796c2a8f8e51ebe Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Wed, 21 Nov 2018 02:40:28 +0530 Subject: [PATCH 16/21] removed avg speed assumption --- pandas/core/series.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 47ca69aab0946..ea6cd8d45ff05 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2313,23 +2313,23 @@ def combine(self, other, func, fill_value=None): -------- Consider 2 Datasets data_A and data_B containing highest clocked speeds of different birds. - >>> s1 = pd.Series({'falcon': 330, 'eagle': 160, 'swift': 105, 'duck': 30}) - >>> s2 = pd.Series({'falcon': 345, 'eagle': 200, 'swift': 100}) + >>> s1 = pd.Series({'falcon': 330, 'eagle': 160, 'swift': 105}) + >>> s2 = pd.Series({'falcon': 345, 'eagle': 200, 'swift': 100, 'duck': 30}) Now, to combine the two datasets and view the highest speeds of the birds across the two datasets >>> s1.combine(s2, max) - duck 30 - eagle 200 - falcon 345 - swift 105 - dtype: int64 + duck NaN + eagle 200.0 + falcon 345.0 + swift 105.0 + dtype: float64 - Considering an average value of birds' speed to be ~40 mph, + To get the clocked speed of the duck, we can use `fill_value=0` as - >>> s1.combine(s2, max, fill_value=40) - duck 40 + >>> s1.combine(s2, max, fill_value=0) + duck 30 eagle 200 falcon 345 swift 105 From ddd3e12a4e166f07502a52fc0b301a1caf2cf162 Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Wed, 21 Nov 2018 03:28:17 +0530 Subject: [PATCH 17/21] typo fix and explanation for fill_value --- pandas/core/series.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ea6cd8d45ff05..ffaeb5bcdca24 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2306,16 +2306,24 @@ def combine(self, other, func, fill_value=None): See Also -------- - Series.combine_first : Combine Series values, choosing the calling - Series' values first. + Series.combine_first : Combine Series values, choosing the calling Series' values first. Examples -------- - Consider 2 Datasets data_A and data_B containing highest clocked speeds of different birds. - - >>> s1 = pd.Series({'falcon': 330, 'eagle': 160, 'swift': 105}) - >>> s2 = pd.Series({'falcon': 345, 'eagle': 200, 'swift': 100, 'duck': 30}) + Consider 2 Datasets ``s1`` and ``s2`` containing highest clocked speeds of different birds. + >>> s1 = pd.Series({'falcon': 330.0, 'eagle': 160.0}) + >>> s1 + falcon 330.0 + eagle 160.0 + dtype: float64 + >>> s2 = pd.Series({'falcon': 345.0, 'eagle': 200.0, 'duck': 30.0}) + >>> s2 + falcon 345.0 + eagle 200.0 + duck 30.0 + dtype: float64 + Now, to combine the two datasets and view the highest speeds of the birds across the two datasets @@ -2323,17 +2331,17 @@ def combine(self, other, func, fill_value=None): duck NaN eagle 200.0 falcon 345.0 - swift 105.0 dtype: float64 - To get the clocked speed of the duck, we can use `fill_value=0` as - + In the previous example, the resulting value for duck is missing, because the maximum + of a NaN and a float is a NaN. So, in the example, we set ``fill_value=0``, + so the maximum value returned will be the value from some dataset. + >>> s1.combine(s2, max, fill_value=0) - duck 30 - eagle 200 - falcon 345 - swift 105 - dtype: int64 + duck 30.0 + eagle 200.0 + falcon 345.0 + dtype: float64 """ if fill_value is None: fill_value = na_value_for_dtype(self.dtype, compat=False) From 7902672ef4abe21e95b82ddd53826a23f0862672 Mon Sep 17 00:00:00 2001 From: "brute4s99 [LAPTOP]" Date: Wed, 21 Nov 2018 04:09:07 +0530 Subject: [PATCH 18/21] whitespace --- pandas/core/series.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ffaeb5bcdca24..0c6a0a2dd5df0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2306,11 +2306,13 @@ def combine(self, other, func, fill_value=None): See Also -------- - Series.combine_first : Combine Series values, choosing the calling Series' values first. + Series.combine_first : Combine Series values, choosing the calling + Series' values first. Examples -------- - Consider 2 Datasets ``s1`` and ``s2`` containing highest clocked speeds of different birds. + Consider 2 Datasets ``s1`` and ``s2`` containing + highest clocked speeds of different birds. >>> s1 = pd.Series({'falcon': 330.0, 'eagle': 160.0}) >>> s1 @@ -2323,9 +2325,9 @@ def combine(self, other, func, fill_value=None): eagle 200.0 duck 30.0 dtype: float64 - - Now, to combine the two datasets and view the highest speeds of the birds across the - two datasets + + Now, to combine the two datasets and view the highest speeds + of the birds across the two datasets >>> s1.combine(s2, max) duck NaN @@ -2333,10 +2335,11 @@ def combine(self, other, func, fill_value=None): falcon 345.0 dtype: float64 - In the previous example, the resulting value for duck is missing, because the maximum - of a NaN and a float is a NaN. So, in the example, we set ``fill_value=0``, + In the previous example, the resulting value for duck is missing, + because the maximum of a NaN and a float is a NaN. + So, in the example, we set ``fill_value=0``, so the maximum value returned will be the value from some dataset. - + >>> s1.combine(s2, max, fill_value=0) duck 30.0 eagle 200.0 @@ -2394,11 +2397,11 @@ def combine_first(self, other): ------- Series The result of combining the Series with the other object. - + See Also -------- Series.combine : Perform elementwise operation on two Series - using a given function + using a given function. Notes ----- @@ -2412,7 +2415,6 @@ def combine_first(self, other): 0 1.0 1 4.0 dtype: float64 - """ new_index = self.index.union(other.index) this = self.reindex(new_index, copy=False) From e35a038f5f4e598b35cea91dae7f4979bf74e062 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Wed, 21 Nov 2018 04:12:17 +0530 Subject: [PATCH 19/21] indentation fix --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 0c6a0a2dd5df0..b76c08800b6ad 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2307,7 +2307,7 @@ def combine(self, other, func, fill_value=None): See Also -------- Series.combine_first : Combine Series values, choosing the calling - Series' values first. + Series' values first. Examples -------- @@ -2401,7 +2401,7 @@ def combine_first(self, other): See Also -------- Series.combine : Perform elementwise operation on two Series - using a given function. + using a given function. Notes ----- From 02521e72bbc7210c9bd50a507d32851cca08d86f Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Wed, 21 Nov 2018 04:24:53 +0530 Subject: [PATCH 20/21] Update series.py --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index b76c08800b6ad..79e88159a5fb6 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2307,7 +2307,7 @@ def combine(self, other, func, fill_value=None): See Also -------- Series.combine_first : Combine Series values, choosing the calling - Series' values first. + Series' values first. Examples -------- @@ -2401,7 +2401,7 @@ def combine_first(self, other): See Also -------- Series.combine : Perform elementwise operation on two Series - using a given function. + using a given function. Notes ----- From efd42ad52697be13d6b6557a76c4c109d6335fe4 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Wed, 21 Nov 2018 04:33:20 +0530 Subject: [PATCH 21/21] Final commit --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 79e88159a5fb6..b20bcad2aa09f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2307,7 +2307,7 @@ def combine(self, other, func, fill_value=None): See Also -------- Series.combine_first : Combine Series values, choosing the calling - Series' values first. + Series' values first. Examples -------- @@ -2401,7 +2401,7 @@ def combine_first(self, other): See Also -------- Series.combine : Perform elementwise operation on two Series - using a given function. + using a given function. Notes -----