Skip to content

Commit

Permalink
MAINT: Minor touchups in npyio (#17796)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
rossbar and mattip committed Nov 19, 2020
1 parent 8fee756 commit b88b2c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 4 additions & 3 deletions numpy/lib/_iotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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

Expand Down
8 changes: 2 additions & 6 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,7 @@ def split_line(line):
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.
Expand Down Expand Up @@ -1030,11 +1027,10 @@ def read_data(chunk_size):

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
Expand Down

0 comments on commit b88b2c0

Please sign in to comment.