From 2e346ec1e1000c11f484708e2997b7b95808a00d Mon Sep 17 00:00:00 2001 From: pierregm Date: Mon, 26 Jan 2009 21:04:26 +0000 Subject: * _iotools.StringConverter : - add a _checked attribute to indicate whether the converter has been upgraded or not. - switched the default value for bool to False * io.genfromtxt: - fixed for the case where a whole column is masked: switch to bool or the common dtype (if needed) --- numpy/lib/io.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'numpy/lib/io.py') diff --git a/numpy/lib/io.py b/numpy/lib/io.py index 5a3a077cb..2967ba17d 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -883,18 +883,21 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, skiprows=0, # Reset the dtype data = rows if dtype is None: - # Get the dtypes from the first row - coldtypes = [np.array(val).dtype for val in data[0]] - # Find the columns with strings, and take the largest number of chars. - strcolidx = [i for (i, v) in enumerate(coldtypes) if v.char == 'S'] + # Get the dtypes from the types of the converters + coldtypes = [conv.type for conv in converters] + # Find the columns with strings... + strcolidx = [i for (i, v) in enumerate(coldtypes) + if v in (type('S'), np.string_)] + # ... and take the largest number of chars. for i in strcolidx: coldtypes[i] = "|S%i" % max(len(row[i]) for row in data) # if names is None: # If the dtype is uniform, don't define names, else use '' - base = coldtypes[0] - if np.all([(dt == base) for dt in coldtypes]): - (ddtype, mdtype) = (base, np.bool) + base = set([c.type for c in converters if c._checked]) + + if len(base) == 1: + (ddtype, mdtype) = (list(base)[0], np.bool) else: ddtype = [('', dt) for dt in coldtypes] mdtype = [('', np.bool) for dt in coldtypes] -- cgit v1.2.1