diff options
author | Bhargav Mangipudi <bhargav.mangipudi@gmail.com> | 2015-10-16 14:36:05 -0700 |
---|---|---|
committer | Joseph K. Bradley <joseph@databricks.com> | 2015-10-16 14:36:05 -0700 |
commit | 1ec0a0dc2819d3db3555799cb78c2946f652bff4 (patch) | |
tree | b241bb2acaafe4e3e1722302b93e85089671b817 /python | |
parent | ac09a3a465f3b57f3964c5fd621ab0d2216e2354 (diff) | |
download | spark-1ec0a0dc2819d3db3555799cb78c2946f652bff4.tar.gz spark-1ec0a0dc2819d3db3555799cb78c2946f652bff4.tar.bz2 spark-1ec0a0dc2819d3db3555799cb78c2946f652bff4.zip |
[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.
Diffstat (limited to 'python')
-rw-r--r-- | python/pyspark/mllib/linalg/__init__.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/python/pyspark/mllib/linalg/__init__.py b/python/pyspark/mllib/linalg/__init__.py index d903b9030d..5276eb41cf 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: |