summaryrefslogtreecommitdiff
path: root/numpy/core/tests/test_multiarray.py
diff options
context:
space:
mode:
authorChris Billington <chrisjbillington@gmail.com>2018-03-09 06:18:04 +1100
committerCharles Harris <charlesr.harris@gmail.com>2018-03-08 12:18:04 -0700
commit6fb8622539ad547c76be38757d6841d70e23b065 (patch)
tree17224f86a080893e54d68c01a3341c6e95503e06 /numpy/core/tests/test_multiarray.py
parenta3c05b1c2ddbc61be6f5a7eaf7f8f431a4b1479c (diff)
downloadpython-numpy-6fb8622539ad547c76be38757d6841d70e23b065.tar.gz
python-numpy-6fb8622539ad547c76be38757d6841d70e23b065.tar.bz2
python-numpy-6fb8622539ad547c76be38757d6841d70e23b065.zip
ENH: Allow dtype field names to be unicode in Python2 (#10672)
ENH: Allow dtype field names to be ascii encoded unicode in Python2
Diffstat (limited to 'numpy/core/tests/test_multiarray.py')
-rw-r--r--numpy/core/tests/test_multiarray.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index fba169ebf..43bfb0635 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -4693,10 +4693,15 @@ class TestRecord(object):
y['a']
def test_unicode_field_names(self):
- # Unicode field names are not allowed on Py2
- title = u'b'
- assert_raises(TypeError, np.dtype, [(title, int)])
- assert_raises(TypeError, np.dtype, [(('a', title), int)])
+ # Unicode field names are converted to ascii on Python 2:
+ encodable_name = u'b'
+ assert_equal(np.dtype([(encodable_name, int)]).names[0], b'b')
+ assert_equal(np.dtype([(('a', encodable_name), int)]).names[0], b'b')
+
+ # But raises UnicodeEncodeError if it can't be encoded:
+ nonencodable_name = u'\uc3bc'
+ assert_raises(UnicodeEncodeError, np.dtype, [(nonencodable_name, int)])
+ assert_raises(UnicodeEncodeError, np.dtype, [(('a', nonencodable_name), int)])
def test_field_names(self):
# Test unicode and 8-bit / byte strings can be used