From c1b5b802ec16a2638f7076da80ec1c47d7ca5de8 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 9 Dec 2013 15:45:18 +0000 Subject: [PATCH] fixed problem of adding strings in "data_append" resulting in infinite recursion. more gracefully check for problems. numpy.loadtxt now correctly transposes single column of data. --- lib/damask/asciitable.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/damask/asciitable.py b/lib/damask/asciitable.py index f74f0f163..046f0a8a5 100644 --- a/lib/damask/asciitable.py +++ b/lib/damask/asciitable.py @@ -138,14 +138,20 @@ class ASCIItable(): idx = [] for label in labels: try: - idx.append(self.labels.index(label)) - except(ValueError): - idx.append(-1) + idx.append(label+0) + except TypeError: + try: + idx.append(self.labels.index(label)) + except ValueError: + idx.append(-1) else: try: - idx = self.labels.index(labels) - except(ValueError): - idx = -1 + idx = label+0 + except TypeError: + try: + idx = self.labels.index(labels) + except(ValueError): + idx = -1 return idx @@ -210,9 +216,9 @@ class ASCIItable(): # ------------------------------------------------------------------ def data_append(self, what): - try: + if isinstance(what,list): for item in what: self.data_append(item) - except TypeError: + else: self.data += [str(what)] # ------------------------------------------------------------------ @@ -249,5 +255,7 @@ class ASCIItable(): else: indices = self.labels_index(labels) # use specified columns self.data_rewind() - return numpy.loadtxt(self.__IO__['in'], usecols=indices) - + theArray = numpy.loadtxt(self.__IO__['in'], usecols=indices) + if len(theArray.shape) < 2: # single column + theArray = theArray.reshape(theArray.shape[0],1) + return theArray