[Scipy-svn] r4465 - in trunk/scipy/cluster: . tests

scipy-svn@scip... scipy-svn@scip...
Mon Jun 23 09:37:09 CDT 2008


Author: cdavid
Date: 2008-06-23 09:37:03 -0500 (Mon, 23 Jun 2008)
New Revision: 4465

Modified:
   trunk/scipy/cluster/tests/test_vq.py
   trunk/scipy/cluster/vq.py
Log:
Fix #505 in scipy.cluster: unhelpful message when size 0 arrays are input.

Modified: trunk/scipy/cluster/tests/test_vq.py
===================================================================
--- trunk/scipy/cluster/tests/test_vq.py	2008-06-23 14:30:58 UTC (rev 4464)
+++ trunk/scipy/cluster/tests/test_vq.py	2008-06-23 14:37:03 UTC (rev 4465)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 # David Cournapeau
-# Last Change: Tue Jul 03 08:00 PM 2007 J
+# Last Change: Mon Jun 23 11:00 PM 2008 J
 
 # For now, just copy the tests from sandbox.pyem, so we can check that
 # kmeans works OK for trivial examples.
@@ -152,5 +152,14 @@
         kmeans2(data, 3, minit = 'random')
         kmeans2(data, 3, minit = 'points')
 
+    def test_kmeans2_empty(self):
+        """Ticket #505."""
+        try:
+            kmeans2([], 2)
+            raise AssertionError("This should not succeed.")
+        except ValueError, e:
+            # OK, that's what we expect
+            pass
+
 if __name__ == "__main__":
     nose.run(argv=['', __file__])

Modified: trunk/scipy/cluster/vq.py
===================================================================
--- trunk/scipy/cluster/vq.py	2008-06-23 14:30:58 UTC (rev 4464)
+++ trunk/scipy/cluster/vq.py	2008-06-23 14:37:03 UTC (rev 4465)
@@ -633,6 +633,9 @@
     else:
         raise ValueError("Input of rank > 2 not supported")
 
+    if N.size(data) < 1:
+        raise ValueError("Input has 0 items.")
+
     # If k is not a single value, then it should be compatible with data's
     # shape
     if N.size(k) > 1 or minit == 'matrix':



More information about the Scipy-svn mailing list