# [Scipy-svn] r6731 - trunk/scipy/sparse

scipy-svn@scip... scipy-svn@scip...
Sat Sep 11 19:53:23 CDT 2010

```Author: ptvirtan
Date: 2010-09-11 19:53:22 -0500 (Sat, 11 Sep 2010)
New Revision: 6731

Modified:
trunk/scipy/sparse/dok.py
Log:
3K: sparse: operator module no longer contains isSequenceType

Modified: trunk/scipy/sparse/dok.py
===================================================================
--- trunk/scipy/sparse/dok.py	2010-09-12 00:53:10 UTC (rev 6730)
+++ trunk/scipy/sparse/dok.py	2010-09-12 00:53:22 UTC (rev 6731)
@@ -4,7 +4,6 @@

__all__ = ['dok_matrix', 'isspmatrix_dok']

-import operator
from itertools import izip

import numpy as np
@@ -12,6 +11,13 @@
from base import spmatrix, isspmatrix
from sputils import isdense, getdtype, isshape, isintlike, isscalarlike, upcast

+try:
+    from operator import isSequenceType as _is_sequence
+except ImportError:
+    def _is_sequence(x):
+        return (hasattr(x, '__len__') or hasattr(x, '__next__')
+                or hasattr(x, 'next'))
+
class dok_matrix(spmatrix, dict):
"""
Dictionary Of Keys based sparse matrix.
@@ -137,7 +143,7 @@
if isinstance(i, slice):
# Is there an easier way to do this?
seq = xrange(i.start or 0, i.stop or self.shape[0], i.step or 1)
-            elif operator.isSequenceType(i):
+            elif _is_sequence(i):
seq = i
else:
# Make sure i is an integer. (But allow it to be a subclass of int).
@@ -176,7 +182,7 @@
if isinstance(j, slice):
# Is there an easier way to do this?
seq = xrange(j.start or 0, j.stop or self.shape[1], j.step or 1)
-            elif operator.isSequenceType(j):
+            elif _is_sequence(j):
seq = j
else:
# j is not an integer
@@ -232,7 +238,7 @@
if isinstance(i, slice):
# Is there an easier way to do this?
seq = xrange(i.start or 0, i.stop or self.shape[0], i.step or 1)
-            elif operator.isSequenceType(i):
+            elif _is_sequence(i):
seq = i
else:
# Make sure i is an integer. (But allow it to be a subclass of int).
@@ -273,7 +279,7 @@
# Process j
if isinstance(j, slice):
seq = xrange(j.start or 0, j.stop or self.shape[1], j.step or 1)
-                elif operator.isSequenceType(j):
+                elif _is_sequence(j):
seq = j
else:
# j is not an integer

```