diff options
author | Ross Barnowski <rossbar@berkeley.edu> | 2020-11-18 22:56:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 08:56:16 +0200 |
commit | b88b2c0c19851810d4ee07f03a7734b6e19dbdaa (patch) | |
tree | bf9a51c10252b66d27983a59a28103fdf2a8269e | |
parent | 8fee756d8c9d2f5fe211fd9feb999c0da8a89821 (diff) | |
download | numpy-b88b2c0c19851810d4ee07f03a7734b6e19dbdaa.tar.gz |
MAINT: Minor touchups in npyio (#17796)
* Simplify logic for encoding kwarg in _decode_line.
* Remove unnecessary else branch from split_line.
* MAINT: rm else branch from loadtxt.
* MAINT: re-nest encoding parsing.
Co-Authored-By: mattip <matti.picus@gmail.com>
* condense return statement.
Co-authored-by: mattip <matti.picus@gmail.com>
-rw-r--r-- | numpy/lib/_iotools.py | 7 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 8 |
2 files changed, 6 insertions, 9 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index f5368526d..a576925d6 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -18,6 +18,8 @@ def _decode_line(line, encoding=None): ---------- line : str or bytes Line to be decoded. + encoding : str + Encoding used to decode `line`. Returns ------- @@ -27,9 +29,8 @@ def _decode_line(line, encoding=None): """ if type(line) is bytes: if encoding is None: - line = line.decode('latin1') - else: - line = line.decode(encoding) + encoding = "latin1" + line = line.decode(encoding) return line diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 805e59bc1..3b2de3e61 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -965,10 +965,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, if comments is not None: line = regex_comments.split(line, maxsplit=1)[0] line = line.strip('\r\n') - if line: - return line.split(delimiter) - else: - return [] + return line.split(delimiter) if line else [] def read_data(chunk_size): """Parse each line, including the first. @@ -1030,11 +1027,10 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, user_converters = converters + byte_converters = False if encoding == 'bytes': encoding = None byte_converters = True - else: - byte_converters = False if usecols is not None: # Allow usecols to be a single int or a sequence of ints |