[Numpy-discussion] ANN: Numpy 1.6.0 beta 2

Charles R Harris charlesr.harris at gmail.com
Tue Apr 5 10:57:48 EDT 2011


On Tue, Apr 5, 2011 at 8:12 AM, Charles R Harris
<charlesr.harris at gmail.com>wrote:

>
>
> On Mon, Apr 4, 2011 at 11:22 PM, Chris Barker <Chris.Barker at noaa.gov>wrote:
>
>> On 4/4/11 9:03 PM, josef.pktd at gmail.com wrote:
>> > On Mon, Apr 4, 2011 at 11:42 PM, Charles R Harris
>>
>> >>>    File "/sw/lib/python2.4/site-packages/numpy/lib/_datasource.py",
>> >>> line 477, in open
>> >>>      return _file_openers[ext](found, mode=mode)
>> >>> IOError: invalid mode: Ub
>> >>>
>> >>
>> >> Guess that wasn't tested before ;) I thought that was strange when I
>> saw it.
>> >> The source of the problem is line 2035 in npyio.py. Additionally, Since
>> >> genloadtxt needs to have byte strings the 'rb" mode should probably be
>> used.
>> >> That works on linux, both for python 2 and python 3, but doing that
>> might
>> >> uncover genfromtxt problems on other platforms.
>>
>> > "rb" is fine on Windows with python 3.2, (that's what I tested
>> > initially for this bug)
>>
>> IIUC, "Ub" is undefined -- "U" means universal newlines, which makes no
>> sense when used with "b" for binary. I looked at the code a ways back,
>> and I can't remember the resolution order, but there isn't any checking
>> for incompatible flags.
>>
>> I'd expect that genfromtxt, being txt, and line oriented, should use
>> 'rU'. but if it wants the raw line endings (why would it?) then rb
>> should be fine.
>>
>> Note that if you only test with unix (\n) and dos (\r\n) line endings,
>> it may work with 'b', if it's splitting on '\n', but not if you try it
>> with Mac endings (\r). Of course with OS-X mac endings are getting
>> pretty uncommon.
>>
>>
> The 'Ub' mode doesn't work for '\r' on python 3. This may be a bug in
> python, as it works just fine on python 2.7. It may indeed be desirable to
> read the files as text, but that would require more work on both loadtxt and
> genfromtxt.
>
>
Curiously, 'rbU' and 'rU' do work on 2.4, but not 'Urb',  'Ub', 'Ur', or
'bU'. Due to Python 3 not hadling '\r' in binary mode, the shortest path
forward might be to open files as text and call asbytes on the lines as they
are read.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110405/0b112aee/attachment.html>


More information about the NumPy-Discussion mailing list