diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2019-05-07 01:14:55 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2019-05-07 01:14:55 -0700 |
commit | db595a0c4064956d2f2f904ed4a76443322bb7e9 (patch) | |
tree | d1214d25e5f1427f47ca0dfe70c53089d770c932 /numpy/lib/tests/test_format.py | |
parent | 340cf9875b911ba858fe6e99147ed29f5e7f0df3 (diff) | |
download | numpy-db595a0c4064956d2f2f904ed4a76443322bb7e9.tar.gz |
BUG/ENH: Create npy format 3.0
This version encodes the dtype as utf8 instead of latin1.
Unfortunately we need to create a new version to make this change, because we did not limit ourselves to ASCII in versions 1 and 2.
Fixes gh-7391
Diffstat (limited to 'numpy/lib/tests/test_format.py')
-rw-r--r-- | numpy/lib/tests/test_format.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index 2ebd483d5..2cf799723 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -287,6 +287,7 @@ from io import BytesIO import numpy as np from numpy.testing import ( assert_, assert_array_equal, assert_raises, assert_raises_regex, + assert_warns ) from numpy.lib import format @@ -882,3 +883,27 @@ def test_empty_npz(): fname = os.path.join(tempdir, "nothing.npz") np.savez(fname) np.load(fname) + + +def test_unicode_field_names(): + # gh-7391 + arr = np.array([ + (1, 3), + (1, 2), + (1, 3), + (1, 2) + ], dtype=[ + ('int', int), + (u'\N{CJK UNIFIED IDEOGRAPH-6574}\N{CJK UNIFIED IDEOGRAPH-5F62}', int) + ]) + fname = os.path.join(tempdir, "unicode.npy") + with open(fname, 'wb') as f: + format.write_array(f, arr, version=(3, 0)) + with open(fname, 'rb') as f: + arr2 = format.read_array(f) + assert_array_equal(arr, arr2) + + # notifies the user that 3.0 is selected + with open(fname, 'wb') as f: + with assert_warns(UserWarning): + format.write_array(f, arr, version=None) |