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:
parent
7fb1a3130a
commit
c1b5b802ec
|
@ -137,11 +137,17 @@ class ASCIItable():
|
||||||
if isinstance(labels,list):
|
if isinstance(labels,list):
|
||||||
idx = []
|
idx = []
|
||||||
for label in labels:
|
for label in labels:
|
||||||
|
try:
|
||||||
|
idx.append(label+0)
|
||||||
|
except TypeError:
|
||||||
try:
|
try:
|
||||||
idx.append(self.labels.index(label))
|
idx.append(self.labels.index(label))
|
||||||
except(ValueError):
|
except ValueError:
|
||||||
idx.append(-1)
|
idx.append(-1)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
idx = label+0
|
||||||
|
except TypeError:
|
||||||
try:
|
try:
|
||||||
idx = self.labels.index(labels)
|
idx = self.labels.index(labels)
|
||||||
except(ValueError):
|
except(ValueError):
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue