From a216d2d26d0a9275f0da5e97a0ceb6fb40ec1a29 Mon Sep 17 00:00:00 2001 From: frankfqchen Date: Fri, 23 Sep 2016 11:07:31 +0800 Subject: [PATCH] replace function type with function isinstance --- python/pyspark/ml/linalg/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/pyspark/ml/linalg/__init__.py b/python/pyspark/ml/linalg/__init__.py index 05c0ac862fb7..0819b20a75a6 100644 --- a/python/pyspark/ml/linalg/__init__.py +++ b/python/pyspark/ml/linalg/__init__.py @@ -101,7 +101,7 @@ def _vector_size(v): return len(v) elif type(v) in (array.array, list, tuple, xrange): return len(v) - elif type(v) == np.ndarray: + elif isinstance(v, np.ndarray): if v.ndim == 1 or (v.ndim == 2 and v.shape[1] == 1): return len(v) else: @@ -325,7 +325,7 @@ def dot(self, other): ... AssertionError: dimension mismatch """ - if type(other) == np.ndarray: + if isinstance(other, np.ndarray): if other.ndim > 1: assert len(self) == other.shape[0], "dimension mismatch" return np.dot(self.array, other) @@ -492,7 +492,7 @@ def __init__(self, size, *args): assert 1 <= len(args) <= 2, "must pass either 2 or 3 arguments" if len(args) == 1: pairs = args[0] - if type(pairs) == dict: + if isinstance(pairs, dict): pairs = pairs.items() pairs = sorted(pairs) self.indices = np.array([p[0] for p in pairs], dtype=np.int32)