diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-06 07:42:08 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-06 07:42:08 -0700 |
commit | 49a8902a673d6fb2ba9ca446fc652aa9d2e55e1b (patch) | |
tree | e71c0d8f6123307860a58796ed840bf32526b3fe /numpy/core | |
parent | 3c8fc14665548c71a9cd144b2e16d9309a92e255 (diff) | |
parent | 4394515cd5632a7f110993ff75033d407d10861d (diff) | |
download | numpy-49a8902a673d6fb2ba9ca446fc652aa9d2e55e1b.tar.gz |
Merge pull request #3191 from charris/2to3-apply-imports-fixer
2to3: Apply `imports` fixer.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/__init__.py | 6 | ||||
-rw-r--r-- | numpy/core/numeric.py | 35 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 6 | ||||
-rw-r--r-- | numpy/core/records.py | 4 | ||||
-rw-r--r-- | numpy/core/setup.py | 26 | ||||
-rw-r--r-- | numpy/core/tests/test_print.py | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 17 |
7 files changed, 54 insertions, 46 deletions
diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py index f055d289e..d2f7c3c8c 100644 --- a/numpy/core/__init__.py +++ b/numpy/core/__init__.py @@ -62,10 +62,10 @@ def _ufunc_reduce(func): import sys -if sys.version_info[0] < 3: - import copy_reg as copyreg -else: +if sys.version_info[0] >= 3: import copyreg +else: + import copy_reg as copyreg copyreg.pickle(ufunc, _ufunc_reduce, _ufunc_reconstruct) # Unclutter namespace (must keep _ufunc_reconstruct for unpickling) diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 25f977254..5f4504eb9 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1,5 +1,22 @@ from __future__ import division, absolute_import +import sys +import warnings +from . import multiarray +from . import umath +from .umath import * +from . import numerictypes +from .numerictypes import * +import collections + +if sys.version_info[0] >= 3: + import pickle +else: + import cPickle as pickle + +loads = pickle.loads + + __all__ = ['newaxis', 'ndarray', 'flatiter', 'nditer', 'nested_iters', 'ufunc', 'arange', 'array', 'zeros', 'count_nonzero', 'empty', 'broadcast', 'dtype', 'fromstring', 'fromfile', @@ -24,19 +41,10 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'nditer', 'nested_iters', 'ufunc', 'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS', 'ComplexWarning'] -import sys -import warnings -from . import multiarray -from . import umath -from .umath import * -from . import numerictypes -from .numerictypes import * -import collections - - if sys.version_info[0] < 3: __all__.extend(['getbuffer', 'newbuffer']) + class ComplexWarning(RuntimeWarning): """ The warning raised when casting a complex dtype to a real dtype. @@ -1861,9 +1869,6 @@ def base_repr(number, base=2, padding=0): res.append('-') return ''.join(reversed(res or '0')) -from cPickle import load, loads -_cload = load -_file = open def load(file): """ @@ -1880,8 +1885,8 @@ def load(file): """ if isinstance(file, type("")): - file = _file(file,"rb") - return _cload(file) + file = open(file, "rb") + return pickle.load(file) # These are all essentially abbreviations # These might wind up in a special abbreviations module diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index a1af9d80d..8bf0cc880 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -98,7 +98,11 @@ import sys # we don't export these for import *, but we do want them accessible # as numerictypes.bool, etc. -from __builtin__ import bool, int, long, float, complex, object, unicode, str +if sys.version_info[0] >= 3: + from builtins import bool, int, long, float, complex, object, unicode, str +else: + from __builtin__ import bool, int, long, float, complex, object, unicode, str + from numpy.compat import bytes if sys.version_info[0] >= 3: diff --git a/numpy/core/records.py b/numpy/core/records.py index 385f9866d..7a9481b38 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -595,8 +595,8 @@ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None, >>> r.col2 chararray(['dbe', 'de'], dtype='|S3') - >>> import cPickle - >>> print cPickle.loads(cPickle.dumps(r)) + >>> import pickle + >>> print pickle.loads(pickle.dumps(r)) [(456, 'dbe', 1.2) (2, 'de', 1.3)] """ diff --git a/numpy/core/setup.py b/numpy/core/setup.py index c65012126..ea20b11d2 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -4,12 +4,14 @@ import imp import os import sys import shutil +import pickle +import copy +import warnings +import re from os.path import join from numpy.distutils import log from distutils.dep_util import newer from distutils.sysconfig import get_config_var -import warnings -import re from setup_common import * @@ -25,11 +27,9 @@ NPY_RELAXED_STRIDES_CHECKING = (os.environ.get('NPY_RELAXED_STRIDES_CHECKING', " # configuration informations between extensions is not easy. # Using a pickled-based memoize does not work because config_cmd is an instance # method, which cPickle does not like. -try: - import cPickle as _pik -except ImportError: - import pickle as _pik -import copy +# +# Use pickle in all cases, as cPickle is gone in python3 and the difference +# in time is only in build. -- Charles Harris, 2013-03-30 class CallOnceOnly(object): def __init__(self): @@ -40,25 +40,25 @@ class CallOnceOnly(object): def check_types(self, *a, **kw): if self._check_types is None: out = check_types(*a, **kw) - self._check_types = _pik.dumps(out) + self._check_types = pickle.dumps(out) else: - out = copy.deepcopy(_pik.loads(self._check_types)) + out = copy.deepcopy(pickle.loads(self._check_types)) return out def check_ieee_macros(self, *a, **kw): if self._check_ieee_macros is None: out = check_ieee_macros(*a, **kw) - self._check_ieee_macros = _pik.dumps(out) + self._check_ieee_macros = pickle.dumps(out) else: - out = copy.deepcopy(_pik.loads(self._check_ieee_macros)) + out = copy.deepcopy(pickle.loads(self._check_ieee_macros)) return out def check_complex(self, *a, **kw): if self._check_complex is None: out = check_complex(*a, **kw) - self._check_complex = _pik.dumps(out) + self._check_complex = pickle.dumps(out) else: - out = copy.deepcopy(_pik.loads(self._check_complex)) + out = copy.deepcopy(pickle.loads(self._check_complex)) return out PYTHON_HAS_UNICODE_WIDE = True diff --git a/numpy/core/tests/test_print.py b/numpy/core/tests/test_print.py index 67021c20e..e2469ec7b 100644 --- a/numpy/core/tests/test_print.py +++ b/numpy/core/tests/test_print.py @@ -6,7 +6,11 @@ import nose import locale import sys -from StringIO import StringIO + +if sys.version_info[0] >= 3: + from io import StringIO +else: + from StringIO import StringIO _REF = {np.inf: 'inf', -np.inf: '-inf', np.nan: 'nan'} diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 4fa554b12..8d3b35bb9 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -7,8 +7,9 @@ import gc import copy import warnings import tempfile -from StringIO import StringIO from os import path +from io import BytesIO + import numpy as np from numpy.testing import ( run_module_suite, TestCase, assert_, assert_equal, @@ -18,10 +19,6 @@ from numpy.testing import ( from numpy.testing.utils import _assert_valid_refcount, WarningManager from numpy.compat import asbytes, asunicode, asbytes_nested -if sys.version_info[0] >= 3: - import io - StringIO = io.BytesIO - rlevel = 1 class TestRegression(TestCase): @@ -37,7 +34,7 @@ class TestRegression(TestCase): def test_pickle_transposed(self,level=rlevel): """Ticket #16""" a = np.transpose(np.array([[2,9],[7,0],[3,8]])) - f = StringIO() + f = BytesIO() pickle.dump(a,f) f.seek(0) b = pickle.load(f) @@ -90,7 +87,7 @@ class TestRegression(TestCase): def test_char_dump(self,level=rlevel): """Ticket #50""" - f = StringIO() + f = BytesIO() ca = np.char.array(np.arange(1000,1010),itemsize=4) ca.dump(f) f.seek(0) @@ -322,7 +319,7 @@ class TestRegression(TestCase): def test_unpickle_dtype_with_object(self,level=rlevel): """Implemented in r2840""" dt = np.dtype([('x',int),('y',np.object_),('z','O')]) - f = StringIO() + f = BytesIO() pickle.dump(dt,f) f.seek(0) dt_ = pickle.load(f) @@ -386,7 +383,6 @@ class TestRegression(TestCase): def test_pickle_dtype(self,level=rlevel): """Ticket #251""" - import pickle pickle.dumps(np.float) def test_swap_real(self, level=rlevel): @@ -725,10 +721,9 @@ class TestRegression(TestCase): def test_unicode_scalar(self, level=rlevel): """Ticket #600""" - import cPickle x = np.array(["DROND", "DROND1"], dtype="U6") el = x[1] - new = cPickle.loads(cPickle.dumps(el)) + new = pickle.loads(pickle.dumps(el)) assert_equal(new, el) def test_arange_non_native_dtype(self, level=rlevel): |