diff options
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: |