Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1058717

Browse files
committed
MAINT: #2312, Make all tofile failures raise IOError.
Fix two that were raising ValueError instead. Make some style cleanups. Closes #2312.
1 parent 0178b12 commit 1058717

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

numpy/core/src/multiarray/convert.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
8888
if (n3 == 0) {
8989
/* binary data */
9090
if (PyDataType_FLAGCHK(PyArray_DESCR(self), NPY_LIST_PICKLE)) {
91-
PyErr_SetString(PyExc_ValueError, "cannot write " \
92-
"object arrays to a file in " \
93-
"binary mode");
91+
PyErr_SetString(PyExc_IOError,
92+
"cannot write object arrays to a file in binary mode");
9493
return -1;
9594
}
9695

@@ -126,7 +125,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
126125
#endif
127126
NPY_END_ALLOW_THREADS;
128127
if (n < size) {
129-
PyErr_Format(PyExc_ValueError,
128+
PyErr_Format(PyExc_IOError,
130129
"%ld requested and %ld written",
131130
(long) size, (long) n);
132131
return -1;
@@ -143,9 +142,8 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
143142
1, fp) < 1) {
144143
NPY_END_THREADS;
145144
PyErr_Format(PyExc_IOError,
146-
"problem writing element"\
147-
" %"NPY_INTP_FMT" to file",
148-
it->index);
145+
"problem writing element %" NPY_INTP_FMT
146+
" to file", it->index);
149147
Py_DECREF(it);
150148
return -1;
151149
}
@@ -218,7 +216,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
218216
#endif
219217
if (n < n2) {
220218
PyErr_Format(PyExc_IOError,
221-
"problem writing element %"NPY_INTP_FMT\
219+
"problem writing element %" NPY_INTP_FMT
222220
" to file", it->index);
223221
Py_DECREF(strobj);
224222
Py_DECREF(it);
@@ -228,8 +226,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)
228226
if (it->index != it->size-1) {
229227
if (fwrite(sep, 1, n3, fp) < n3) {
230228
PyErr_Format(PyExc_IOError,
231-
"problem writing "\
232-
"separator to file");
229+
"problem writing separator to file");
233230
Py_DECREF(strobj);
234231
Py_DECREF(it);
235232
return -1;

0 commit comments

Comments
 (0)