[Scipy-svn] r6944 - in trunk/scipy/sparse: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Nov 26 18:41:54 EST 2010


Author: warren.weckesser
Date: 2010-11-26 17:41:53 -0600 (Fri, 26 Nov 2010)
New Revision: 6944

Modified:
   trunk/scipy/sparse/dok.py
   trunk/scipy/sparse/tests/test_base.py
Log:
BUG: Fix for ticket 1160 (thanks to derPhil and JustinPeel)

Modified: trunk/scipy/sparse/dok.py
===================================================================
--- trunk/scipy/sparse/dok.py	2010-11-25 10:14:54 UTC (rev 6943)
+++ trunk/scipy/sparse/dok.py	2010-11-26 23:41:53 UTC (rev 6944)
@@ -225,8 +225,9 @@
                 raise IndexError("index out of bounds")
 
             if np.isscalar(value):
-                if value==0 and self.has_key((i,j)):
-                    del self[(i,j)]
+                if value == 0:
+                    if self.has_key((i,j)):
+                        del self[(i,j)]
                 else:
                     dict.__setitem__(self, (i,j), self.dtype.type(value))
             else:

Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2010-11-25 10:14:54 UTC (rev 6943)
+++ trunk/scipy/sparse/tests/test_base.py	2010-11-26 23:41:53 UTC (rev 6944)
@@ -1298,8 +1298,21 @@
         c = csr_matrix(b)
         assert_equal(A.todense(), c.todense())
 
+    def test_ticket1160(self):
+        """Regression test for ticket #1160."""
+        a = dok_matrix((3,3))
+        a[0,0] = 0
+        # This assert would fail, because the above assignment would
+        # incorrectly call __set_item__ even though the value was 0.
+        assert_((0,0) not in a.keys(), "Unexpected entry (0,0) in keys")
+        
+        # Slice assignments were also affected.
+        b = dok_matrix((3,3))
+        b[:,0] = 0
+        assert_(len(b.keys())==0, "Unexpected entries in keys")
 
 
+
 class TestLIL( _TestCommon, _TestHorizSlicing, _TestVertSlicing,
         _TestBothSlicing, _TestGetSet, _TestSolve,
         _TestArithmetic, _TestInplaceArithmetic, _TestFancyIndexing,




More information about the Scipy-svn mailing list