Pierre,

Should the following work?

import numpy as np
from StringIO import StringIO

converter = {'date':lambda s: datetime.strptime(s,'%Y-%m-%d %H:%M:%SZ')}
data = np.ndfromtxt(StringIO('2009-02-03 12:00:00Z,72214.0'), delimiter=',',
names=['date','stid'], dtype=None, converters=converter)

Right now, it's giving me the following:

Traceback (most recent call last):
  File "check_oban.py", line 15, in <module>
    converters=converter)
  File "/home/rmay/.local/lib64/python2.5/site-packages/numpy/lib/io.py", line
993, in ndfromtxt
    return genfromtxt(fname, **kwargs)
  File "/home/rmay/.local/lib64/python2.5/site-packages/numpy/lib/io.py", line
842, in genfromtxt
    locked=True)
  File "/home/rmay/.local/lib64/python2.5/site-packages/numpy/lib/_iotools.py",
line 472, in update
    self.type = self._getsubdtype(func('0'))
  File "check_oban.py", line 9, in <lambda>
    lambda s: datetime.strptime(s,'%Y-%m-%d %H:%M:%SZ').replace(tzinfo=UTC)}
  File "/usr/lib64/python2.5/_strptime.py", line 330, in strptime
    (data_string, format))
ValueError: time data did not match format:  data=0  fmt=%Y-%m-%d %H:%M:%SZ

Which comes from a part of the code in updating converters where it passes the
string '0' to the converter.  Are the converters expected to handle what amounts
to bad input even though the file itself has no such problems? Specifying the
dtype doesn't appear to help either.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to