[Numpy-discussion] np.loadtxt : yet a new implementation...

Ryan May rmay31@gmail....
Wed Dec 3 10:41:56 CST 2008


Pierre GM wrote:
>> I think that treating an explicitly-passed-in ' ' delimiter as
>> identical to 'no delimiter' is a bad idea. If I say that ' ' is the
>> delimiter, or '\t' is the delimiter, this should be treated *just*
>> like ',' being the delimiter, where the expected output is:
>> ['1', '2', '3', '4', '', '5']
>>
> 
> Valid point.
> Well, all, stay tuned for yet another "yet another implementation..."
> 

Found a problem.  If you read the names from the file and specify 
usecols, you end up with the first N names read from the file as the 
fields in your output (where N is the number of entries in usecols), 
instead of having the names of the columns you asked for.

For instance:

 >>>from StringIO import StringIO
 >>>from genload_proposal import loadtxt
 >>>f = StringIO('stid stnm relh tair\nnrmn 121 45 9.1')
 >>>loadtxt(f, usecols=('stid', 'relh', 'tair'), names=True, dtype=None)
array(('nrmn', 45, 9.0999999999999996),
       dtype=[('stid', '|S4'), ('stnm', '<i8'), ('relh', '<f8')])

What I want to come out is:

array(('nrmn', 45, 9.0999999999999996),
       dtype=[('stid', '|S4'), ('relh', '<i8'), ('tair', '<f8')])

I've attached a version that fixes this by setting a flag internally if 
the names are read from the file.  If this flag is true, at the end the 
names are filtered down to only the ones that are given in usecols.

I also have one other thought.  Is there any way we can make this handle 
object arrays, or rather, a field containing objects, specifically 
datetime objects?  Right now, this does not work because calling view 
does not work for object arrays.  I'm just looking for a simple way to 
store date/time in my record array (currently a string field).

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
-------------- next part --------------
A non-text attachment was scrubbed...
Name: genload_proposal.py
Type: text/x-python
Size: 27642 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081203/127c205a/attachment-0001.py 


More information about the Numpy-discussion mailing list