diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-03-25 10:11:43 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-03-25 10:36:28 +0000 |
commit | b87fca27261f79be20ab06a222ed2330d60d9f2c (patch) | |
tree | 00907ad5fffa7d13f99b1cf60398c624063f807e /numpy/lib/_iotools.py | |
parent | a2c4d3230d58a5c4569ab2c7f13bdf9499b71dd4 (diff) | |
download | numpy-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/_iotools.py')
-rw-r--r-- | numpy/lib/_iotools.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index 312a9f02a..304bba3d3 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -44,7 +44,7 @@ def _is_bytes_like(obj): Check whether obj behaves like a bytes object. """ try: - obj + asbytes('') + obj + b'' except (TypeError, ValueError): return False return True @@ -189,7 +189,7 @@ class LineSplitter(object): return lambda input: [_.strip() for _ in method(input)] # - def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): + def __init__(self, delimiter=None, comments=b'#', autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): @@ -218,7 +218,7 @@ class LineSplitter(object): def _delimited_splitter(self, line): if self.comments is not None: line = line.split(self.comments)[0] - line = line.strip(asbytes(" \r\n")) + line = line.strip(b" \r\n") if not line: return [] return line.split(self.delimiter) @@ -227,7 +227,7 @@ class LineSplitter(object): def _fixedwidth_splitter(self, line): if self.comments is not None: line = line.split(self.comments)[0] - line = line.strip(asbytes("\r\n")) + line = line.strip(b"\r\n") if not line: return [] fixed = self.delimiter @@ -434,9 +434,9 @@ def str2bool(value): """ value = value.upper() - if value == asbytes('TRUE'): + if value == b'TRUE': return True - elif value == asbytes('FALSE'): + elif value == b'FALSE': return False else: raise ValueError("Invalid boolean") @@ -529,7 +529,7 @@ class StringConverter(object): _mapper.extend([(nx.floating, float, nx.nan), (complex, _bytes_to_complex, nx.nan + 0j), (nx.longdouble, nx.longdouble, nx.nan), - (nx.string_, bytes, asbytes('???'))]) + (nx.string_, bytes, b'???')]) (_defaulttype, _defaultfunc, _defaultfill) = zip(*_mapper) @@ -631,7 +631,7 @@ class StringConverter(object): # None if default is None: try: - default = self.func(asbytes('0')) + default = self.func(b'0') except ValueError: default = None dtype = self._getdtype(default) @@ -676,11 +676,11 @@ class StringConverter(object): self.func = lambda x: int(float(x)) # Store the list of strings corresponding to missing values. if missing_values is None: - self.missing_values = set([asbytes('')]) + self.missing_values = set([b'']) else: if isinstance(missing_values, bytes): - missing_values = missing_values.split(asbytes(",")) - self.missing_values = set(list(missing_values) + [asbytes('')]) + missing_values = missing_values.split(b",") + self.missing_values = set(list(missing_values) + [b'']) # self._callingfunction = self._strict_call self.type = self._dtypeortype(dtype) @@ -801,7 +801,7 @@ class StringConverter(object): self.iterupgrade(value) def update(self, func, default=None, testing_value=None, - missing_values=asbytes(''), locked=False): + missing_values=b'', locked=False): """ Set StringConverter attributes directly. @@ -838,7 +838,7 @@ class StringConverter(object): self.type = self._dtypeortype(self._getdtype(default)) else: try: - tester = func(testing_value or asbytes('1')) + tester = func(testing_value or b'1') except (TypeError, ValueError): tester = None self.type = self._dtypeortype(self._getdtype(tester)) |