diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2020-06-18 07:26:22 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2020-06-18 07:26:22 -0400 |
commit | 2d31d06d5f03782f4319aefd20a66bd4196db7c3 (patch) | |
tree | c4f16a29e67c7a6d8addbe048e1be224b3f3dc32 /numpy/lib/npyio.py | |
parent | be11d11793b894669cb7f3b0ad9dfcca06df9a3e (diff) | |
download | numpy-2d31d06d5f03782f4319aefd20a66bd4196db7c3.tar.gz |
MAINT: lib: In loadtxt, validate ndmin argument earlier.
Validation of `ndmin` is moved to the beginning of the function,
so we don't read the entire file only to raise an exception at
the end because of a bad argument.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 64b628796..d681d7d12 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1021,6 +1021,10 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, # Main body of loadtxt. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # Check correctness of the values of `ndmin` + if ndmin not in [0, 1, 2]: + raise ValueError('Illegal value of ndmin keyword: %s' % ndmin) + # Type conversions for Py3 convenience if comments is not None: if isinstance(comments, (str, bytes)): @@ -1167,9 +1171,6 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, X.shape = (1, -1) # Verify that the array has at least dimensions `ndmin`. - # Check correctness of the values of `ndmin` - if ndmin not in [0, 1, 2]: - raise ValueError('Illegal value of ndmin keyword: %s' % ndmin) # Tweak the size and shape of the arrays - remove extraneous dimensions if X.ndim > ndmin: X = np.squeeze(X) |