diff options
| author | warren <warren.weckesser@gmail.com> | 2022-06-18 17:49:54 -0400 |
|---|---|---|
| committer | warren <warren.weckesser@gmail.com> | 2022-06-18 17:49:54 -0400 |
| commit | a9a364b9782d2a615de858c07640e88d9d141992 (patch) | |
| tree | 14527cb9c5ff58c6b9ee826c8c679ac2fdcd4129 /numpy | |
| parent | d592523b5a7482e3486fc1bb694b9c570be30365 (diff) | |
| download | numpy-a9a364b9782d2a615de858c07640e88d9d141992.tar.gz | |
BUG: lib: A loadtxt error message had two values reversed.
Fix the reversed arguments to the call of PyErr_Format() that generates
the exception for an invalid index in usecols.
Also fix the format characters in several other calls of PyErr_Format()
where the arguments are Py_ssize_t.
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/multiarray/textreading/rows.c | 10 | ||||
| -rw-r--r-- | numpy/lib/tests/test_loadtxt.py | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/numpy/core/src/multiarray/textreading/rows.c b/numpy/core/src/multiarray/textreading/rows.c index 86c01d189..a72fb79d9 100644 --- a/numpy/core/src/multiarray/textreading/rows.c +++ b/numpy/core/src/multiarray/textreading/rows.c @@ -91,7 +91,7 @@ create_conv_funcs( if (column < -num_fields || column >= num_fields) { PyErr_Format(PyExc_ValueError, "converter specified for column %zd, which is invalid " - "for the number of fields %d.", column, num_fields); + "for the number of fields %zd.", column, num_fields); goto error; } if (column < 0) { @@ -319,7 +319,7 @@ read_rows(stream *s, if (!usecols && (actual_num_fields != current_num_fields)) { PyErr_Format(PyExc_ValueError, - "the number of columns changed from %d to %d at row %zu; " + "the number of columns changed from %zd to %zd at row %zd; " "use `usecols` to select a subset and avoid this error", actual_num_fields, current_num_fields, row_count+1); goto error; @@ -382,9 +382,9 @@ read_rows(stream *s, } if (NPY_UNLIKELY((col < 0) || (col >= current_num_fields))) { PyErr_Format(PyExc_ValueError, - "invalid column index %d at row %zu with %d " + "invalid column index %zd at row %zd with %zd " "columns", - usecols[i], current_num_fields, row_count+1); + usecols[i], row_count+1, current_num_fields); goto error; } } @@ -419,7 +419,7 @@ read_rows(stream *s, } PyErr_Format(PyExc_ValueError, "could not convert string %.100R to %S at " - "row %zu, column %d.", + "row %zd, column %zd.", string, field_types[f].descr, row_count, col+1); Py_DECREF(string); npy_PyErr_ChainExceptionsCause(exc, val, tb); diff --git a/numpy/lib/tests/test_loadtxt.py b/numpy/lib/tests/test_loadtxt.py index 2f191f145..0b8fe3c47 100644 --- a/numpy/lib/tests/test_loadtxt.py +++ b/numpy/lib/tests/test_loadtxt.py @@ -253,7 +253,7 @@ def test_ragged_usecols(): txt = StringIO("0,0,XXX\n0\n0,XXX,XXX,0,XXX\n") with pytest.raises(ValueError, - match="invalid column index -2 at row 1 with 2 columns"): + match="invalid column index -2 at row 2 with 1 columns"): # There is no -2 column in the second row: np.loadtxt(txt, dtype=float, delimiter=",", usecols=[0, -2]) |
