diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/_iotools.py | 9 | ||||
-rw-r--r-- | numpy/lib/tests/test__iotools.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 7 |
3 files changed, 15 insertions, 5 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index 84aff5e5d..7560bf4da 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -506,13 +506,16 @@ class StringConverter: _mapper.extend([(nx.float64, float, nx.nan), (nx.complex128, complex, nx.nan + 0j), (nx.longdouble, nx.longdouble, nx.nan), - (nx.unicode_, asunicode, '???'), - (nx.string_, asbytes, '???'), # If a non-default dtype is passed, fall back to generic # ones (should only be used for the converter) (nx.integer, int, -1), (nx.floating, float, nx.nan), - (nx.complexfloating, complex, nx.nan + 0j),]) + (nx.complexfloating, complex, nx.nan + 0j), + # Last, try with the string types (must be last, because + # `_mapper[-1]` is used as default in some cases) + (nx.unicode_, asunicode, '???'), + (nx.string_, asbytes, '???'), + ]) @classmethod def _getdtype(cls, val): diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py index 6964c1128..a5b787025 100644 --- a/numpy/lib/tests/test__iotools.py +++ b/numpy/lib/tests/test__iotools.py @@ -177,12 +177,12 @@ class TestStringConverter: # test str # note that the longdouble type has been skipped, so the # _status increases by 2. Everything should succeed with - # unicode conversion (5). + # unicode conversion (8). for s in ['a', b'a']: res = converter.upgrade(s) assert_(type(res) is str) assert_equal(res, 'a') - assert_equal(converter._status, 5 + status_offset) + assert_equal(converter._status, 8 + status_offset) def test_missing(self): "Tests the use of missing values." diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 9abde3e11..99d119362 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1567,6 +1567,13 @@ M 33 21.99 test = np.genfromtxt(TextIO(data), delimiter=";", dtype=ndtype, converters=converters) + def test_dtype_with_object_no_converter(self): + # Object without a converter uses bytes: + parsed = np.genfromtxt(TextIO("1"), dtype=object) + assert parsed[()] == b"1" + parsed = np.genfromtxt(TextIO("string"), dtype=object) + assert parsed[()] == b"string" + def test_userconverters_with_explicit_dtype(self): # Test user_converters w/ explicit (standard) dtype data = TextIO('skip,skip,2001-01-01,1.0,skip') |