summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-02-09 08:55:38 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-02-09 08:55:38 +0000
commit622e6867a9b500d30333d157eaffdf44d3c52fe1 (patch)
treed9eeefc4a023ead32d8b14a6efd0fddb0cf80075 /numpy
parente4df04ac07a6442d711a34cfa64d64c033f4f1a8 (diff)
downloadnumpy-622e6867a9b500d30333d157eaffdf44d3c52fe1.tar.gz
Fixed bug in unicode change.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/arrayprint.py3
-rw-r--r--numpy/core/src/scalartypes.inc.src6
-rw-r--r--numpy/core/src/ucsnarrow.c7
3 files changed, 12 insertions, 4 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index c22580cf9..4e5db082a 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -164,6 +164,9 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ',
data.imag, precision, suppress_small, sign=1)
format_function = lambda x, f1 = real_format, f2 = imag_format: \
_formatComplex(x, f1, f2)
+ elif issubclass(dtype, _nt.unicode_):
+ format = "%s"
+ format_function = lambda x, f = format: repr(x)
else:
format = '%s'
format_function = lambda x, f = format: format % str(x)
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index 1ef8372f2..bdf5402db 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -2390,8 +2390,12 @@ PyArray_DescrFromScalar(PyObject *sc)
type_num = descr->type_num;
if (type_num == PyArray_STRING)
descr->elsize = PyString_GET_SIZE(sc);
- else if (type_num == PyArray_UNICODE)
+ else if (type_num == PyArray_UNICODE) {
descr->elsize = PyUnicode_GET_DATA_SIZE(sc);
+#ifndef Py_UNICODE_WIDE
+ descr->elsize <<= 1;
+#endif
+ }
else {
descr->elsize = \
((PyVoidScalarObject *)sc)->ob_size;
diff --git a/numpy/core/src/ucsnarrow.c b/numpy/core/src/ucsnarrow.c
index a105ebe27..9eb668b77 100644
--- a/numpy/core/src/ucsnarrow.c
+++ b/numpy/core/src/ucsnarrow.c
@@ -15,12 +15,12 @@ static int
PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)
{
register int i;
- int surrpairs = 0;
+ int numucs2 = 0;
PyArray_UCS4 chr;
for (i=0; i<ucs4length; i++) {
chr = *ucs4++;
if (chr > 0xffff) {
- surrpairs++;
+ numucs2++;
chr -= 0x10000L;
*ucs2++ = 0xD800 + (Py_UNICODE) (chr >> 10);
*ucs2++ = 0xDC00 + (Py_UNICODE) (chr & 0x03FF);
@@ -28,8 +28,9 @@ PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length)
else {
*ucs2++ = (Py_UNICODE) chr;
}
+ numucs2++;
}
- return ucs4length + surrpairs;
+ return numucs2;
}