From 04fddc0a2d017eef03345f9b3afb0622c9d50584 Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Tue, 25 Sep 2012 18:41:12 -0400 Subject: [PATCH 1/3] TST: Add failing test for unicode array with object dtype --- numpy/core/tests/test_arrayprint.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 0cd78c27e2e7..acad628f350f 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -147,6 +147,10 @@ def test_formatter_reset(self): np.set_printoptions(formatter={'float_kind':None}) assert_equal(repr(x), "array([ 0., 1., 2.])") +def test_unicode_object_array(): + x = np.array([u'\xe9'], dtype=object) + assert_equal(repr(x), "array([u'\\xe9'], dtype=object)") + if __name__ == "__main__": From 8e0a542830e336a036ab9ca64a7ccf87d1953c40 Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Tue, 25 Sep 2012 18:41:27 -0400 Subject: [PATCH 2/3] BUG: Use numpystr for arrayprint fallback instead of str --- numpy/core/arrayprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 19be452e518f..f3add44630da 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -308,7 +308,7 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ', elif issubclass(dtypeobj, _nt.datetime64): format_function = formatdict['datetime'] else: - format_function = formatdict['str'] + format_function = formatdict['numpystr'] # skip over "[" next_line_prefix = " " From 0f5bbfaec635de96892e003457a1d638bf0c3786 Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Wed, 26 Sep 2012 09:27:37 -0400 Subject: [PATCH 3/3] TST: Change expected output for Python 3. --- numpy/core/tests/test_arrayprint.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index acad628f350f..2a2a97336746 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -1,3 +1,5 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- import sys import numpy as np from numpy.testing import * @@ -148,8 +150,13 @@ def test_formatter_reset(self): assert_equal(repr(x), "array([ 0., 1., 2.])") def test_unicode_object_array(): + import sys + if sys.version_info[0] >= 3: + expected = "array(['é'], dtype=object)" + else: + expected = "array([u'\\xe9'], dtype=object)" x = np.array([u'\xe9'], dtype=object) - assert_equal(repr(x), "array([u'\\xe9'], dtype=object)") + assert_equal(repr(x), expected)