Skip to content
Snippets Groups Projects
Commit 1ec0a0dc authored by Bhargav Mangipudi's avatar Bhargav Mangipudi Committed by Joseph K. Bradley
Browse files

[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.
parent ac09a3a4
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment