Re: [Numpy-discussion] Py3: numpy.rec.array fails with open file

2011-05-25 Thread Christoph Gohlke


On 5/25/2011 7:23 PM, Charles R Harris wrote:
>
>
> On Wed, May 25, 2011 at 7:29 PM, Christoph Gohlke  > wrote:
>
> Hello,
>
> the following code raises a ValueError on Python 3, but works as
> expected with Python 2:
>
> > >> import sys, numpy
> > >> fd = open(sys.executable, 'rb')
> > >> numpy.rec.array(fd, dtype=[('_', 'b')])
> Traceback (most recent call last):
>File "", line 1, in 
>File "C:\Python32\lib\site-packages\numpy\core\records.py", line 799,
> in array
>  raise ValueError("Unknown input type")
> ValueError: Unknown input type
>
>
> The problem seems to be the test for file objects in
> numpy/compat/py3k.py:
>
>  def isfileobj(f):
>  return isinstance(f, io.FileIO)
>
> If this is updated to include _io.BufferedReader, the type of `fd`,
> numpy.rec.array works with file objects opened in 'rb' mode:
>
> def isfileobj(f):
>  return isinstance(f, (io.FileIO, io._io.BufferedReader))
>
> Tested with numpy 1.6.0 on Windows.
>
>
> Seems reasonable. Can you open a ticket and make a test for this?
>
> Chuck
>
>

Opened ticket #1843  with 
test case and possible fix attached.

Anyway, this is easy to work around by using numpy.rec.fromfile() 
instead of numpy.rec.array().

Christoph

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Py3: numpy.rec.array fails with open file

2011-05-25 Thread Charles R Harris
On Wed, May 25, 2011 at 7:29 PM, Christoph Gohlke  wrote:

> Hello,
>
> the following code raises a ValueError on Python 3, but works as
> expected with Python 2:
>
> >>> import sys, numpy
> >>> fd = open(sys.executable, 'rb')
> >>> numpy.rec.array(fd, dtype=[('_', 'b')])
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Python32\lib\site-packages\numpy\core\records.py", line 799,
> in array
> raise ValueError("Unknown input type")
> ValueError: Unknown input type
>
>
> The problem seems to be the test for file objects in numpy/compat/py3k.py:
>
> def isfileobj(f):
> return isinstance(f, io.FileIO)
>
> If this is updated to include _io.BufferedReader, the type of `fd`,
> numpy.rec.array works with file objects opened in 'rb' mode:
>
>def isfileobj(f):
> return isinstance(f, (io.FileIO, io._io.BufferedReader))
>
> Tested with numpy 1.6.0 on Windows.
>
>
Seems reasonable. Can you open a ticket and make a test for this?

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Py3: numpy.rec.array fails with open file

2011-05-25 Thread Christoph Gohlke
Hello,

the following code raises a ValueError on Python 3, but works as 
expected with Python 2:

>>> import sys, numpy
>>> fd = open(sys.executable, 'rb')
>>> numpy.rec.array(fd, dtype=[('_', 'b')])
Traceback (most recent call last):
   File "", line 1, in 
   File "C:\Python32\lib\site-packages\numpy\core\records.py", line 799, 
in array
 raise ValueError("Unknown input type")
ValueError: Unknown input type


The problem seems to be the test for file objects in numpy/compat/py3k.py:

 def isfileobj(f):
 return isinstance(f, io.FileIO)

If this is updated to include _io.BufferedReader, the type of `fd`, 
numpy.rec.array works with file objects opened in 'rb' mode:

def isfileobj(f):
 return isinstance(f, (io.FileIO, io._io.BufferedReader))

Tested with numpy 1.6.0 on Windows.

Christoph






___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion