summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-03-25 10:11:43 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-03-25 10:36:28 +0000
commitb87fca27261f79be20ab06a222ed2330d60d9f2c (patch)
tree00907ad5fffa7d13f99b1cf60398c624063f807e /numpy/lib/npyio.py
parenta2c4d3230d58a5c4569ab2c7f13bdf9499b71dd4 (diff)
downloadnumpy-b87fca27261f79be20ab06a222ed2330d60d9f2c.tar.gz
MAINT: Remove asbytes where a b prefix would suffice
Since we only need to support python 2, we can remove any case where we just pass a single string literal and use the b prefix instead. What we can't do is transform asbytes("tests %d" % num), because %-formatting fails on bytes in python 3.x < 3.5.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 54a37fbad..dc1c951e7 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -397,7 +397,7 @@ def load(file, mmap_mode=None, allow_pickle=True, fix_imports=True,
try:
# Code to distinguish from NumPy binary files and pickles.
- _ZIP_PREFIX = asbytes('PK\x03\x04')
+ _ZIP_PREFIX = b'PK\x03\x04'
N = len(format.MAGIC_PREFIX)
magic = fid.read(N)
# If the file size is less than N, we need to make sure not
@@ -856,7 +856,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
# Compile regex for comments beforehand
comments = (re.escape(comment) for comment in comments)
- regex_comments = re.compile(asbytes('|').join(comments))
+ regex_comments = re.compile(b'|'.join(comments))
user_converters = converters
if delimiter is not None:
delimiter = asbytes(delimiter)
@@ -958,7 +958,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
line = asbytes(line)
if comments is not None:
line = regex_comments.split(asbytes(line), maxsplit=1)[0]
- line = line.strip(asbytes('\r\n'))
+ line = line.strip(b'\r\n')
if line:
return line.split(delimiter)
else:
@@ -1576,11 +1576,11 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
if names is True:
if comments in first_line:
first_line = (
- asbytes('').join(first_line.split(comments)[1:]))
+ b''.join(first_line.split(comments)[1:]))
first_values = split_line(first_line)
except StopIteration:
# return an empty array if the datafile is empty
- first_line = asbytes('')
+ first_line = b''
first_values = []
warnings.warn('genfromtxt: Empty input file: "%s"' % fname, stacklevel=2)
@@ -1605,7 +1605,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
if names is True:
names = validate_names([_bytes_to_name(_.strip())
for _ in first_values])
- first_line = asbytes('')
+ first_line = b''
elif _is_string_like(names):
names = validate_names([_.strip() for _ in names.split(',')])
elif names:
@@ -1644,7 +1644,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
user_missing_values = missing_values or ()
# Define the list of missing_values (one column: one list)
- missing_values = [list([asbytes('')]) for _ in range(nbcols)]
+ missing_values = [list([b'']) for _ in range(nbcols)]
# We have a dictionary: process it field by field
if isinstance(user_missing_values, dict):
@@ -1684,7 +1684,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
entry.append(value)
# We have a string : apply it to all entries
elif isinstance(user_missing_values, bytes):
- user_value = user_missing_values.split(asbytes(","))
+ user_value = user_missing_values.split(b",")
for entry in missing_values:
entry.extend(user_value)
# We have something else: apply it to all entries
@@ -1977,7 +1977,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
if usemask and names:
for (name, conv) in zip(names or (), converters):
missing_values = [conv(_) for _ in conv.missing_values
- if _ != asbytes('')]
+ if _ != b'']
for mval in missing_values:
outputmask[name] |= (output[name] == mval)
# Construct the final array