On Sat, Jul 28, 2012 at 11:19 AM, Stefan Krah <stefan-use...@bytereef.org> wrote: > Ond??ej ??ert??k <ondrej.cer...@gmail.com> wrote: >> So at some point, the strings get converted to numpy strings in 3.2, >> but not in 3.3. > > PyArray_Scalar() must return a subtype of PyUnicodeObject. I'm boldly > assuming that data is in utf-32. If so, then this unoptimized version > should work: > > diff --git a/numpy/core/src/multiarray/scalarapi.c > b/numpy/core/src/multiarray/scalarapi.c > index 2e255c0..c134aed 100644 > --- a/numpy/core/src/multiarray/scalarapi.c > +++ b/numpy/core/src/multiarray/scalarapi.c > @@ -643,7 +643,20 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, > PyObject *base) > } > #if PY_VERSION_HEX >= 0x03030000 > if (type_num == NPY_UNICODE) { > - return PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, data, > itemsize/4);
Why doesn't PyUnicode_FromKindAndData return a subtype of PyUnicodeObject? http://docs.python.org/dev/c-api/unicode.html#PyUnicode_FromKindAndData > + PyObject *b, *args; > + b = PyBytes_FromStringAndSize(data, itemsize); > + if (b == NULL) { > + return NULL; > + } > + args = Py_BuildValue("(Os)", b, "utf-32"); > + if (args == NULL) { > + Py_DECREF(b); > + return NULL; > + } > + obj = type->tp_new(type, args, NULL); > + Py_DECREF(b); > + Py_DECREF(args); > + return obj; > } > #endif > if (type->tp_itemsize != 0) { Nice!! I pushed your patch into the PR, now it works great in Python 3.3. There are still other failures: https://gist.github.com/3194707 But this particular bug is fixed. Thanks for your help! Ondrej _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion