[Numpy-discussion] Problem with loadtxt

Warren Weckesser warren.weckesser@enthought....
Wed Aug 18 17:52:45 CDT 2010


Scott MacDonald wrote:
> Yes it should, sorry I must have copied and pasted wrong.
>
> I did some more research and found this bug report:
>
> http://projects.scipy.org/numpy/ticket/1163
>
> I guess this is still open?  I am using numpy 1.4.1
>
>

According to that ticket, it is doing int(float(x)) when the dtype is a 
subclass of int.  This allows it to handle text like "123.45" or "1e4" 
properly; passing either of those directly to int() will raise a ValueError.

Perhaps something like this would work for int dtypes:

    try:
        value = int(text)
    except ValueError:
        value = int(float(text))



Warren


>
> On Wed, Aug 18, 2010 at 2:42 PM, Friedrich Romstedt 
> <friedrichromstedt@gmail.com <mailto:friedrichromstedt@gmail.com>> wrote:
>
>     2010/8/18 Scott MacDonald <scott.p.macdonald@gmail.com
>     <mailto:scott.p.macdonald@gmail.com>>:
>     > In [42]: c = StringIO("5399354557888517120")
>
>     Well, should't it be StringIO("5399354557888517312")?  Maybe I'm
>     missing sth.
>
>     Friedrich
>     _______________________________________________
>     NumPy-Discussion mailing list
>     NumPy-Discussion@scipy.org <mailto:NumPy-Discussion@scipy.org>
>     http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>   



More information about the NumPy-Discussion mailing list