summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Reddy <tyler.je.reddy@gmail.com>2019-04-11 17:53:17 -0700
committerGitHub <noreply@github.com>2019-04-11 17:53:17 -0700
commitf4a24b1f4779d1b9966efe2ad79cba21241ce500 (patch)
tree9905873d51698795fb1552e67c9da2159fda3681
parentb619c6d1d72b45b001c31a844a8a63c49b7f9e05 (diff)
parent54294f17cf78b4209c18b1724f948861f6580661 (diff)
downloadnumpy-f4a24b1f4779d1b9966efe2ad79cba21241ce500.tar.gz
Merge pull request #13301 from eric-wieser/remove-descr-again
BUG: Fix crash when calling savetxt on a padded array
-rw-r--r--numpy/lib/npyio.py2
-rw-r--r--numpy/lib/tests/test_io.py12
2 files changed, 12 insertions, 2 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index d702859fa..beeba1334 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1379,7 +1379,7 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
# Complex dtype -- each field indicates a separate column
else:
- ncol = len(X.dtype.descr)
+ ncol = len(X.dtype.names)
else:
ncol = X.shape[1]
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 7ef25538b..835344429 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -347,13 +347,23 @@ class TestSaveTxt(object):
assert_raises(ValueError, np.savetxt, c, np.array(1))
assert_raises(ValueError, np.savetxt, c, np.array([[[1], [2]]]))
- def test_record(self):
+ def test_structured(self):
a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')])
c = BytesIO()
np.savetxt(c, a, fmt='%d')
c.seek(0)
assert_equal(c.readlines(), [b'1 2\n', b'3 4\n'])
+ def test_structured_padded(self):
+ # gh-13297
+ a = np.array([(1, 2, 3),(4, 5, 6)], dtype=[
+ ('foo', 'i4'), ('bar', 'i4'), ('baz', 'i4')
+ ])
+ c = BytesIO()
+ np.savetxt(c, a[['foo', 'baz']], fmt='%d')
+ c.seek(0)
+ assert_equal(c.readlines(), [b'1 3\n', b'4 6\n'])
+
@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
def test_multifield_view(self):
a = np.ones(1, dtype=[('x', 'i4'), ('y', 'i4'), ('z', 'f4')])