Skip to content

Fix unicode repr object #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = " "
Expand Down
11 changes: 11 additions & 0 deletions numpy/core/tests/test_arrayprint.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import numpy as np
from numpy.testing import *
Expand Down Expand Up @@ -147,6 +149,15 @@ 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():
import sys
if sys.version_info[0] >= 3:
expected = "array(['é'], dtype=object)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we care, but if it's desireable to keep the source files as ascii, I think this line could be written

expected = u"array(['\xe9'], dtype=object)"

and work on both py2 and py3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, that's if we're running stuff through 2to3. If not then we can leave off the u at the beginning and I believe it should still work (though be slightly more confusing).

else:
expected = "array([u'\\xe9'], dtype=object)"
x = np.array([u'\xe9'], dtype=object)
assert_equal(repr(x), expected)



if __name__ == "__main__":
Expand Down