From 0b5be6b26ff019bd605c984fe100a132d24423e9 Mon Sep 17 00:00:00 2001 From: Moi Date: Sat, 29 Sep 2018 20:02:04 +0200 Subject: [PATCH 1/7] updated the docstring of Series.dot method --- pandas/core/series.py | 55 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 83f80c305c5eb..eec9b90728b0f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2080,16 +2080,61 @@ def autocorr(self, lag=1): def dot(self, other): """ - Matrix multiplication with DataFrame or inner-product with Series - objects. Can also be called using `self @ other` in Python >= 3.5. + Compute the dot product between the Series and the columns of other. + + This method computes the dot product between the Series and another one, + or the Series and each columns of a DataFrame, or the Series and each + columns of a array. + + It can also be called using `self @ other` in Python >= 3.5. Parameters ---------- - other : Series or DataFrame - + other : Series, DataFrame or array-like. + The other object to compute the dot product with its columns. + Returns ------- - dot_product : scalar or Series + scalar, Series or numpy.ndarray + return the dot product of the Series and other if other is a Series, + the Series of the dot product of Series and each rows of other if + other is a DataFrame or a numpy.ndarray between the Series and each + columns of the numpy array. + + Note + ---- + The Series and other has to share the same index if other is a Series or + a DataFrame. + + See Also + -------- + DataFrame.dot: Compute dot product with the columns of the DataFrameself. + + Examples + -------- + >>> ser = pd.Series([0,1,2,3]) + >>> ser2 = pd.Series([-1,2,-3,4]) + >>> ser.dot(ser2) + 8 + >>> df = pd.DataFrame([[0,1],[-2,3],[4,-5],[6,7]]) + >>> ser.dot(df) + 0 24 + 1 14 + dtype: int64 + >>> arr = [[0,1],[-2,3],[4,-5],[6,7]] + >>> ser.dot(arr) + array([24, 14]) + + If the Series don't share the same index, the dot product can't be + computed + + >>> ser3 = pd.Series({'a': 0, 'b': 1, 'c': 2, 'd': 3}) + >>> ser.dot(ser3) + ValueError: matrices are not aligned + + >>> ser4 = pd.Series({'d': 0, 'c': 1, 'b': 2, 'a': 3}) + >>> ser3.dot(ser4) + 4 """ from pandas.core.frame import DataFrame if isinstance(other, (Series, DataFrame)): From b05ab98cc9d6a0e6ea5b5db12042af71571b24a6 Mon Sep 17 00:00:00 2001 From: Moi Date: Sat, 29 Sep 2018 20:16:09 +0200 Subject: [PATCH 2/7] Updated the docstring of Series.dot --- pandas/core/series.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index eec9b90728b0f..7731671d94064 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2084,15 +2084,15 @@ def dot(self, other): This method computes the dot product between the Series and another one, or the Series and each columns of a DataFrame, or the Series and each - columns of a array. + columns of an array. It can also be called using `self @ other` in Python >= 3.5. Parameters ---------- - other : Series, DataFrame or array-like. + other : Series, DataFrame or array-like The other object to compute the dot product with its columns. - + Returns ------- scalar, Series or numpy.ndarray @@ -2101,14 +2101,14 @@ def dot(self, other): other is a DataFrame or a numpy.ndarray between the Series and each columns of the numpy array. - Note - ---- - The Series and other has to share the same index if other is a Series or - a DataFrame. - See Also -------- - DataFrame.dot: Compute dot product with the columns of the DataFrameself. + DataFrame.dot: Compute dot product with the columns of the DataFrame. + + Notes + ----- + The Series and other has to share the same index if other is a Series or + a DataFrame. Examples -------- @@ -2126,12 +2126,9 @@ def dot(self, other): array([24, 14]) If the Series don't share the same index, the dot product can't be - computed + computed. >>> ser3 = pd.Series({'a': 0, 'b': 1, 'c': 2, 'd': 3}) - >>> ser.dot(ser3) - ValueError: matrices are not aligned - >>> ser4 = pd.Series({'d': 0, 'c': 1, 'b': 2, 'a': 3}) >>> ser3.dot(ser4) 4 From 7ff583914b022897212f819e75878ca9f68481c5 Mon Sep 17 00:00:00 2001 From: Moi Date: Sat, 29 Sep 2018 20:22:12 +0200 Subject: [PATCH 3/7] DOC: updated the docstring of Series.dot --- pandas/core/series.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 7731671d94064..ad92d38f26bf3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2082,9 +2082,9 @@ def dot(self, other): """ Compute the dot product between the Series and the columns of other. - This method computes the dot product between the Series and another one, - or the Series and each columns of a DataFrame, or the Series and each - columns of an array. + This method computes the dot product between the Series and another + one, or the Series and each columns of a DataFrame, or the Series and + each columns of an array. It can also be called using `self @ other` in Python >= 3.5. @@ -2096,10 +2096,10 @@ def dot(self, other): Returns ------- scalar, Series or numpy.ndarray - return the dot product of the Series and other if other is a Series, - the Series of the dot product of Series and each rows of other if - other is a DataFrame or a numpy.ndarray between the Series and each - columns of the numpy array. + return the dot product of the Series and other if other is a + Series, the Series of the dot product of Series and each rows of + other if other is a DataFrame or a numpy.ndarray between the Series + and each columns of the numpy array. See Also -------- @@ -2107,8 +2107,8 @@ def dot(self, other): Notes ----- - The Series and other has to share the same index if other is a Series or - a DataFrame. + The Series and other has to share the same index if other is a Series + or a DataFrame. Examples -------- From 75c6d74b3a6318837552ea8ec99143525e53fd31 Mon Sep 17 00:00:00 2001 From: Moi Date: Sat, 29 Sep 2018 22:07:42 +0200 Subject: [PATCH 4/7] Comments taken into account --- pandas/core/series.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ad92d38f26bf3..a3e40589cce2d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2096,7 +2096,7 @@ def dot(self, other): Returns ------- scalar, Series or numpy.ndarray - return the dot product of the Series and other if other is a + Return the dot product of the Series and other if other is a Series, the Series of the dot product of Series and each rows of other if other is a DataFrame or a numpy.ndarray between the Series and each columns of the numpy array. @@ -2104,6 +2104,7 @@ def dot(self, other): See Also -------- DataFrame.dot: Compute dot product with the columns of the DataFrame. + Series.mul: Multiplication of series and other, element-wise. Notes ----- @@ -2112,26 +2113,18 @@ def dot(self, other): Examples -------- - >>> ser = pd.Series([0,1,2,3]) - >>> ser2 = pd.Series([-1,2,-3,4]) - >>> ser.dot(ser2) + >>> s = pd.Series([0, 1, 2, 3]) + >>> other = pd.Series([-1, 2, -3, 4]) + >>> s.dot(other) 8 >>> df = pd.DataFrame([[0,1],[-2,3],[4,-5],[6,7]]) - >>> ser.dot(df) + >>> s.dot(df) 0 24 1 14 dtype: int64 - >>> arr = [[0,1],[-2,3],[4,-5],[6,7]] - >>> ser.dot(arr) + >>> arr = np.array([[0, 1], [-2, 3], [4, -5], [6, 7]]) + >>> s.dot(arr) array([24, 14]) - - If the Series don't share the same index, the dot product can't be - computed. - - >>> ser3 = pd.Series({'a': 0, 'b': 1, 'c': 2, 'd': 3}) - >>> ser4 = pd.Series({'d': 0, 'c': 1, 'b': 2, 'a': 3}) - >>> ser3.dot(ser4) - 4 """ from pandas.core.frame import DataFrame if isinstance(other, (Series, DataFrame)): From aa929a5e43d3f69c6b4f093128a83f2a413af73b Mon Sep 17 00:00:00 2001 From: Moi Date: Sat, 29 Sep 2018 22:11:39 +0200 Subject: [PATCH 5/7] Comments taken into account --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index a3e40589cce2d..ce245e34c95ed 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2117,7 +2117,7 @@ def dot(self, other): >>> other = pd.Series([-1, 2, -3, 4]) >>> s.dot(other) 8 - >>> df = pd.DataFrame([[0,1],[-2,3],[4,-5],[6,7]]) + >>> df = pd.DataFrame([[0 ,1], [-2, 3], [4, -5], [6, 7]]) >>> s.dot(df) 0 24 1 14 From 2895f94ac0a49dc7945df0bc57de112c12bf4679 Mon Sep 17 00:00:00 2001 From: Moi Date: Tue, 2 Oct 2018 22:51:25 +0200 Subject: [PATCH 6/7] added example s @ other --- pandas/core/series.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index ce245e34c95ed..439e5c1540b83 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2117,6 +2117,8 @@ def dot(self, other): >>> other = pd.Series([-1, 2, -3, 4]) >>> s.dot(other) 8 + >>> s @ other + 8 >>> df = pd.DataFrame([[0 ,1], [-2, 3], [4, -5], [6, 7]]) >>> s.dot(df) 0 24 From 14432a5c06afce5febb8d92888a6bea74abe7f2a Mon Sep 17 00:00:00 2001 From: Moi Date: Sun, 7 Oct 2018 13:28:59 +0200 Subject: [PATCH 7/7] Updated typo --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 439e5c1540b83..fe02d80073a09 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2103,7 +2103,7 @@ def dot(self, other): See Also -------- - DataFrame.dot: Compute dot product with the columns of the DataFrame. + DataFrame.dot: Compute the matrix product with the DataFrame. Series.mul: Multiplication of series and other, element-wise. Notes