diff options
author | pierregm <pierregm@localhost> | 2009-02-05 04:31:51 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-02-05 04:31:51 +0000 |
commit | 911e94dd0a64adae9fb2057fb0210e512a9b7d4a (patch) | |
tree | c41d7f3027db2d581547f09168f2363cac618be9 /numpy/lib/io.py | |
parent | 12750f7b0f6a5aa2cb318848de8e09076eb30fa2 (diff) | |
download | numpy-911e94dd0a64adae9fb2057fb0210e512a9b7d4a.tar.gz |
* genfromtxt : Fixed when a dtype involving objects is explicitly given. Raise a NotImplementedError if the dtype is nested.
* _iotools : make sure StringConverter gets properly initiated when a function returning a np.object is used as input parameter.
Diffstat (limited to 'numpy/lib/io.py')
-rw-r--r-- | numpy/lib/io.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py index 2967ba17d..be1e03d4c 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -17,7 +17,7 @@ from _datasource import DataSource from _compiled_base import packbits, unpackbits from _iotools import LineSplitter, NameValidator, StringConverter, \ - _is_string_like, flatten_dtype + _is_string_like, has_nested_fields, flatten_dtype _file = file _string_like = _is_string_like @@ -703,6 +703,11 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, skiprows=0, there must not be any header in the file (else a :exc:ValueError exception is raised). + Warnings + -------- + * Individual values are not stripped of spaces by default. + When using a custom converter, make sure the function does remove spaces. + See Also -------- numpy.loadtxt : equivalent function when no data is missing. @@ -918,8 +923,15 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, skiprows=0, # First, create the array using a flattened dtype: # [('a', int), ('b1', int), ('b2', float)] # Then, view the array using the specified dtype. - rows = np.array(data, dtype=[('', t) for t in flatdtypes]) - output = rows.view(dtype) + if has_nested_fields(dtype): + if 'O' in (_.char for _ in flatdtypes): + errmsg = "Nested fields involving objects "\ + "are not supported..." + raise NotImplementedError(errmsg) + rows = np.array(data, dtype=[('', t) for t in flatdtypes]) + output = rows.view(dtype) + else: + output = np.array(data, dtype=dtype) # Now, process the rowmasks the same way if usemask: rowmasks = np.array(masks, |