From 4ce059b92032fcf7520a7c41d6f9b8a7d7176e87 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 9 Apr 2013 19:56:58 -0400 Subject: [PATCH] Give a slightly more clear error on bad array sizes --- nilmdb/client/numpyclient.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nilmdb/client/numpyclient.py b/nilmdb/client/numpyclient.py index cfedaa1..96ee77b 100644 --- a/nilmdb/client/numpyclient.py +++ b/nilmdb/client/numpyclient.py @@ -162,9 +162,12 @@ class StreamInserterNumpy(nilmdb.client.client.StreamInserter): elif array.ndim == 2: # Convert to structured array sarray = numpy.zeros(array.shape[0], dtype=self._dtype) - sarray['timestamp'] = array[:,0] - # Need the squeeze in case sarray['data'] is 1 dimensional - sarray['data'] = numpy.squeeze(array[:,1:]) + try: + sarray['timestamp'] = array[:,0] + # Need the squeeze in case sarray['data'] is 1 dimensional + sarray['data'] = numpy.squeeze(array[:,1:]) + except (IndexError, ValueError): + raise ValueError("wrong number of fields for this data type") array = sarray else: raise ValueError("wrong number of dimensions in array")