summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/npyio.py4
-rw-r--r--numpy/lib/tests/test_io.py9
2 files changed, 11 insertions, 2 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 05010a2d0..13eb5cefc 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -702,9 +702,9 @@ def _getconv(dtype):
elif issubclass(typ, np.complex):
return lambda x: complex(asstr(x))
elif issubclass(typ, np.bytes_):
- return bytes
+ return asbytes
else:
- return str
+ return asstr
def loadtxt(fname, dtype=float, comments='#', delimiter=None,
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 333891d46..61c9c0636 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -686,6 +686,15 @@ class TestLoadTxt(TestCase):
dtype=dt)
assert_array_equal(x, a)
+ def test_str_dtype(self):
+ # see gh-8033
+ c = ["str1", "str2"]
+
+ for dt in (str, np.bytes_):
+ a = np.array(["str1", "str2"], dtype=dt)
+ x = np.loadtxt(c, dtype=dt)
+ assert_array_equal(x, a)
+
def test_empty_file(self):
with suppress_warnings() as sup:
sup.filter(message="loadtxt: Empty input file:")