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.
This commit is contained in:
Philip Eisenlohr 2013-12-09 15:45:18 +00:00
parent 7fb1a3130a
commit c1b5b802ec
1 changed files with 18 additions and 10 deletions

View File

@ -138,14 +138,20 @@ class ASCIItable():
idx = [] idx = []
for label in labels: for label in labels:
try: try:
idx.append(self.labels.index(label)) idx.append(label+0)
except(ValueError): except TypeError:
idx.append(-1) try:
idx.append(self.labels.index(label))
except ValueError:
idx.append(-1)
else: else:
try: try:
idx = self.labels.index(labels) idx = label+0
except(ValueError): except TypeError:
idx = -1 try:
idx = self.labels.index(labels)
except(ValueError):
idx = -1
return idx return idx
@ -210,9 +216,9 @@ class ASCIItable():
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_append(self, def data_append(self,
what): what):
try: if isinstance(what,list):
for item in what: self.data_append(item) for item in what: self.data_append(item)
except TypeError: else:
self.data += [str(what)] self.data += [str(what)]
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@ -249,5 +255,7 @@ class ASCIItable():
else: indices = self.labels_index(labels) # use specified columns else: indices = self.labels_index(labels) # use specified columns
self.data_rewind() 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