summaryrefslogtreecommitdiff
path: root/numpy/lib/format.py
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-15 17:03:58 -0800
committerSeth Troisi <sethtroisi@google.com>2020-01-20 15:22:57 -0800
commit9a21ec857b22ff0140a7f71a12f2cc943f163404 (patch)
tree1f8b26a1bb346fab26d2210de286d29011bf2bf1 /numpy/lib/format.py
parentb753aa7a3a2c958e70826fb8af3b56db5c758819 (diff)
downloadnumpy-9a21ec857b22ff0140a7f71a12f2cc943f163404.tar.gz
[MAINT] Cleanup python2 sys.version checks
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r--numpy/lib/format.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 15a74518b..114bae287 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -162,7 +162,6 @@ evolved with time and this document is more current.
"""
import numpy
-import sys
import io
import warnings
from numpy.lib.utils import safe_eval
@@ -213,10 +212,7 @@ def magic(major, minor):
raise ValueError("major version must be 0 <= major < 256")
if minor < 0 or minor > 255:
raise ValueError("minor version must be 0 <= minor < 256")
- if sys.version_info[0] < 3:
- return MAGIC_PREFIX + chr(major) + chr(minor)
- else:
- return MAGIC_PREFIX + bytes([major, minor])
+ return MAGIC_PREFIX + bytes([major, minor])
def read_magic(fp):
""" Read the magic string to get the version of the file format.
@@ -234,10 +230,7 @@ def read_magic(fp):
if magic_str[:-2] != MAGIC_PREFIX:
msg = "the magic string is not correct; expected %r, got %r"
raise ValueError(msg % (MAGIC_PREFIX, magic_str[:-2]))
- if sys.version_info[0] < 3:
- major, minor = map(ord, magic_str[-2:])
- else:
- major, minor = magic_str[-2:]
+ major, minor = magic_str[-2:]
return major, minor
def _has_metadata(dt):
@@ -542,10 +535,7 @@ def _filter_header(s):
"""
import tokenize
- if sys.version_info[0] >= 3:
- from io import StringIO
- else:
- from StringIO import StringIO
+ from io import StringIO
tokens = []
last_token_was_number = False
@@ -738,12 +728,10 @@ def read_array(fp, allow_pickle=False, pickle_kwargs=None):
try:
array = pickle.load(fp, **pickle_kwargs)
except UnicodeError as err:
- if sys.version_info[0] >= 3:
- # Friendlier error message
- raise UnicodeError("Unpickling a python object failed: %r\n"
- "You may need to pass the encoding= option "
- "to numpy.load" % (err,))
- raise
+ # Friendlier error message
+ raise UnicodeError("Unpickling a python object failed: %r\n"
+ "You may need to pass the encoding= option "
+ "to numpy.load" % (err,))
else:
if isfileobj(fp):
# We can use the fast fromfile() function.