spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkbrad...@apache.org
Subject spark git commit: [SPARK-11050] [MLLIB] PySpark SparseVector can return wrong index in e…
Date Fri, 16 Oct 2015 21:36:10 GMT
Repository: spark
Updated Branches:
  refs/heads/master ac09a3a46 -> 1ec0a0dc2


[SPARK-11050] [MLLIB] PySpark SparseVector can return wrong index in e…

…rror message

For negative indices in the SparseVector, we update the index value. If we have an incorrect
index
at this point, the error message has the incorrect *updated* index instead of the original
one. This
change contains the fix for the same.

Author: Bhargav Mangipudi <bhargav.mangipudi@gmail.com>

Closes #9069 from bhargav/spark-10759.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/1ec0a0dc
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/1ec0a0dc
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/1ec0a0dc

Branch: refs/heads/master
Commit: 1ec0a0dc2819d3db3555799cb78c2946f652bff4
Parents: ac09a3a
Author: Bhargav Mangipudi <bhargav.mangipudi@gmail.com>
Authored: Fri Oct 16 14:36:05 2015 -0700
Committer: Joseph K. Bradley <joseph@databricks.com>
Committed: Fri Oct 16 14:36:05 2015 -0700

----------------------------------------------------------------------
 python/pyspark/mllib/linalg/__init__.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/1ec0a0dc/python/pyspark/mllib/linalg/__init__.py
----------------------------------------------------------------------
diff --git a/python/pyspark/mllib/linalg/__init__.py b/python/pyspark/mllib/linalg/__init__.py
index d903b90..5276eb4 100644
--- a/python/pyspark/mllib/linalg/__init__.py
+++ b/python/pyspark/mllib/linalg/__init__.py
@@ -764,10 +764,11 @@ class SparseVector(Vector):
         if not isinstance(index, int):
             raise TypeError(
                 "Indices must be of type integer, got type %s" % type(index))
+
+        if index >= self.size or index < -self.size:
+            raise ValueError("Index %d out of bounds." % index)
         if index < 0:
             index += self.size
-        if index >= self.size or index < 0:
-            raise ValueError("Index %d out of bounds." % index)
 
         insert_index = np.searchsorted(inds, index)
         if insert_index >= inds.size:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org


Mime
View raw message