8000 ENH: More explicit error message for np.savetxt · pitrou/numpy@1761a64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1761a64

Browse files
committed
ENH: More explicit error message for np.savetxt
1 parent 0afa5fc commit 1761a64

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

numpy/lib/npyio.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,12 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
10881088
fh.write(asbytes(format % tuple(row2) + newline))
10891089
else:
10901090
for row in X:
1091-
fh.write(asbytes(format % tuple(row) + newline))
1091+
try:
1092+
fh.write(asbytes(format % tuple(row) + newline))
1093+
except TypeError:
1094+
raise TypeError("Mismatch between array dtype ('%s') and "
1095+
"format specifier ('%s')"
1096+
% (str(X.dtype), format))
10921097
if len(footer) > 0:
10931098
footer = footer.replace('\n', '\n' + comments)
10941099
fh.write(asbytes(comments + footer + newline))

0 commit comments

Comments
 (0)
0