[Numpy-tickets] [NumPy] #525: Inconsistency in the length of buffers of unicode scalars
NumPy
numpy-tickets@scipy....
Tue May 22 09:36:50 CDT 2007
#525: Inconsistency in the length of buffers of unicode scalars
------------------------+---------------------------------------------------
Reporter: faltet | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.0.3 Release
Component: numpy.core | Version: devel
Severity: normal | Keywords:
------------------------+---------------------------------------------------
I think there is an inconsistency here:
{{{
>>> import sys
>>> sys.maxunicode
65535 # using python with UCS2 here
>>> u=numpy.unicode_('popo')
>>> u.data
<read-only buffer for 0x82276e0, size 16, offset 0 at 0xb7dc3780>
>>> len(u.data)
8 # should be 16!
>>> u=numpy.array(u'popo')
>>> u.data
<read-write buffer for 0x82454d0, size 16, offset 0 at 0xb7dc3780>
>>> len(u.data)
16 # This works fine for 0-dim arrays
}}}
This prevents thinks like:
{{{
>>> numpy.ndarray(buffer=numpy.unicode_('popo'), dtype='uint32', shape=4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: buffer is too small for requested array
}}}
to work correctly.
However, the above works well in UCS4 Python interpreters:
{{{
>>> import sys
>>> sys.maxunicode
1114111
>>> import numpy
>>> u=numpy.unicode_('popo')
>>> u.data
<read-only buffer for 0x8203b60, size 16, offset 0 at 0xb7283640>
>>> len(u.data)
16
>>> numpy.ndarray(buffer=u, dtype='uint32', shape=4)
array([112, 111, 112, 111], dtype=uint32) # Works fine
}}}
Thanks
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/525>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list