diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-03-28 17:13:53 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-02 11:23:58 -0600 |
commit | 09a52ed47bb26498c97a579ce1147861df696d84 (patch) | |
tree | 39bbddec620188f8cf09a5eb51370b0db1236219 /numpy/oldnumeric/compat.py | |
parent | a939f2aa83e7d37d5e35e7c2a8c539c59f682598 (diff) | |
download | numpy-09a52ed47bb26498c97a579ce1147861df696d84.tar.gz |
2to3: Apply `imports` fixer.
The `imports` fixer deals with the standard packages that have been
renamed, removed, or methods that have moved.
cPickle -- removed, use pickle
commands -- removed, getoutput, getstatusoutput moved to subprocess
urlparse -- removed, urlparse moved to urllib.parse
cStringIO -- removed, use StringIO or io.StringIO
copy_reg -- renamed copyreg
_winreg -- renamed winreg
ConfigParser -- renamed configparser
__builtin__ -- renamed builtins
In the case of `cPickle`, it is imported as `pickle` when python < 3 and
performance may be a consideration, but otherwise plain old `pickle` is
used.
Dealing with `StringIO` is a bit tricky. There is an `io.StringIO`
function in the `io` module, available since Python 2.6, but it expects
unicode whereas `StringIO.StringIO` expects ascii. The Python 3
equivalent is then `io.BytesIO`. What I have done here is used BytesIO
for anything that is emulating a file for testing purposes. That is more
explicit than using a redefined StringIO as was done before we dropped
support for Python 2.4 and 2.5.
Closes #3180.
Diffstat (limited to 'numpy/oldnumeric/compat.py')
-rw-r--r-- | numpy/oldnumeric/compat.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/numpy/oldnumeric/compat.py b/numpy/oldnumeric/compat.py index 46c3c727f..b63226571 100644 --- a/numpy/oldnumeric/compat.py +++ b/numpy/oldnumeric/compat.py @@ -3,6 +3,17 @@ """ from __future__ import division, absolute_import +import sys +import copy +import pickle +from pickle import dump, dumps + +import numpy.core.multiarray as multiarray +import numpy.core.umath as um +from numpy.core.numeric import array +from . import functions + + __all__ = ['NewAxis', 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype', 'LittleEndian', 'arrayrange', 'matrixmultiply', @@ -13,13 +24,6 @@ __all__ = ['NewAxis', 'Unpickler', 'Pickler' ] -import numpy.core.multiarray as multiarray -import numpy.core.umath as um -from numpy.core.numeric import array -from . import functions -import sys - -from cPickle import dump, dumps mu = multiarray @@ -47,8 +51,7 @@ def DumpArray(m, fp): m.dump(fp) def LoadArray(fp): - import cPickle - return cPickle.load(fp) + return pickle.load(fp) def array_constructor(shape, typecode, thestr, Endian=LittleEndian): if typecode == "O": @@ -70,8 +73,7 @@ def pickle_array(a): (a.shape, a.dtype.char, a.tostring(), LittleEndian)) def loads(astr): - import cPickle - arr = cPickle.loads(astr.replace('Numeric', 'numpy.oldnumeric')) + arr = pickle.loads(astr.replace('Numeric', 'numpy.oldnumeric')) return arr def load(fp): @@ -97,7 +99,6 @@ def _LoadArray(fp): else: return m -import pickle, copy if sys.version_info[0] >= 3: class Unpickler(pickle.Unpickler): # XXX: should we implement this? It's not completely straightforward |