aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/ml/linalg
diff options
context:
space:
mode:
authorzero323 <zero323@users.noreply.github.com>2016-10-03 17:57:54 -0700
committerJoseph K. Bradley <joseph@databricks.com>2016-10-03 17:57:54 -0700
commitd8399b600cef706c22d381b01fab19c610db439a (patch)
tree55a0a1ab872fd290d60e156fc3920bb04924327a /python/pyspark/ml/linalg
parent1f31bdaef670dd43999613deae3620f4ddcd1fbf (diff)
downloadspark-d8399b600cef706c22d381b01fab19c610db439a.tar.gz
spark-d8399b600cef706c22d381b01fab19c610db439a.tar.bz2
spark-d8399b600cef706c22d381b01fab19c610db439a.zip
[SPARK-17587][PYTHON][MLLIB] SparseVector __getitem__ should follow __getitem__ contract
## What changes were proposed in this pull request? Replaces` ValueError` with `IndexError` when index passed to `ml` / `mllib` `SparseVector.__getitem__` is out of range. This ensures correct iteration behavior. Replaces `ValueError` with `IndexError` for `DenseMatrix` and `SparkMatrix` in `ml` / `mllib`. ## How was this patch tested? PySpark `ml` / `mllib` unit tests. Additional unit tests to prove that the problem has been resolved. Author: zero323 <zero323@users.noreply.github.com> Closes #15144 from zero323/SPARK-17587.
Diffstat (limited to 'python/pyspark/ml/linalg')
-rw-r--r--python/pyspark/ml/linalg/__init__.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/python/pyspark/ml/linalg/__init__.py b/python/pyspark/ml/linalg/__init__.py
index 05c0ac862f..a5df727fdb 100644
--- a/python/pyspark/ml/linalg/__init__.py
+++ b/python/pyspark/ml/linalg/__init__.py
@@ -713,7 +713,7 @@ class SparseVector(Vector):
"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)
+ raise IndexError("Index %d out of bounds." % index)
if index < 0:
index += self.size
@@ -960,10 +960,10 @@ class DenseMatrix(Matrix):
def __getitem__(self, indices):
i, j = indices
if i < 0 or i >= self.numRows:
- raise ValueError("Row index %d is out of range [0, %d)"
+ raise IndexError("Row index %d is out of range [0, %d)"
% (i, self.numRows))
if j >= self.numCols or j < 0:
- raise ValueError("Column index %d is out of range [0, %d)"
+ raise IndexError("Column index %d is out of range [0, %d)"
% (j, self.numCols))
if self.isTransposed:
@@ -1090,10 +1090,10 @@ class SparseMatrix(Matrix):
def __getitem__(self, indices):
i, j = indices
if i < 0 or i >= self.numRows:
- raise ValueError("Row index %d is out of range [0, %d)"
+ raise IndexError("Row index %d is out of range [0, %d)"
% (i, self.numRows))
if j < 0 or j >= self.numCols:
- raise ValueError("Column index %d is out of range [0, %d)"
+ raise IndexError("Column index %d is out of range [0, %d)"
% (j, self.numCols))
# If a CSR matrix is given, then the row index should be searched