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/ma | |
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/ma')
-rw-r--r-- | numpy/ma/core.py | 42 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 28 | ||||
-rw-r--r-- | numpy/ma/tests/test_mrecords.py | 27 |
3 files changed, 42 insertions, 55 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 3c7206e1c..64cfafe7c 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -22,6 +22,23 @@ Released for unlimited redistribution. # pylint: disable-msg=E1002 from __future__ import division, absolute_import +import sys +import warnings + +import numpy as np +import numpy.core.umath as umath +import numpy.core.numerictypes as ntypes +from numpy import ndarray, amax, amin, iscomplexobj, bool_ +from numpy import array as narray +from numpy.lib.function_base import angle +from numpy.compat import getargspec, formatargspec +from numpy import expand_dims as n_expand_dims + +if sys.version_info[0] >= 3: + from functools import reduce + import pickle +else: + import cPickle as pickle __author__ = "Pierre GF Gerard-Marchant" __docformat__ = "restructuredtext en" @@ -69,23 +86,6 @@ __all__ = ['MAError', 'MaskError', 'MaskType', 'MaskedArray', 'var', 'where', 'zeros'] -import cPickle - -import numpy as np -from numpy import ndarray, amax, amin, iscomplexobj, bool_ -from numpy import array as narray - -import numpy.core.umath as umath -from numpy.lib.function_base import angle -import numpy.core.numerictypes as ntypes -from numpy.compat import getargspec, formatargspec -from numpy import expand_dims as n_expand_dims -import warnings - -import sys -if sys.version_info[0] >= 3: - from functools import reduce - MaskType = np.bool_ nomask = MaskType(0) @@ -7037,7 +7037,7 @@ def dump(a, F): """ if not hasattr(F, 'readline'): F = open(F, 'w') - return cPickle.dump(a, F) + return pickle.dump(a, F) def dumps(a): """ @@ -7052,7 +7052,7 @@ def dumps(a): returned. """ - return cPickle.dumps(a) + return pickle.dumps(a) def load(F): """ @@ -7076,7 +7076,7 @@ def load(F): """ if not hasattr(F, 'readline'): F = open(F, 'r') - return cPickle.load(F) + return pickle.load(F) def loads(strg): """ @@ -7094,7 +7094,7 @@ def loads(strg): dumps : Return a string corresponding to the pickling of a masked array. """ - return cPickle.loads(strg) + return pickle.loads(strg) ################################################################################ def fromfile(file, dtype=float, count= -1, sep=''): diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 383e4a907..7eb4bbed2 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -10,21 +10,20 @@ __author__ = "Pierre GF Gerard-Marchant" import types import warnings +import sys +import pickle import numpy as np +import numpy.ma.core import numpy.core.fromnumeric as fromnumeric from numpy import ndarray from numpy.ma.testutils import * - -import numpy.ma.core from numpy.ma.core import * - from numpy.compat import asbytes, asbytes_nested from numpy.testing.utils import WarningManager pi = np.pi -import sys if sys.version_info[0] >= 3: from functools import reduce @@ -369,20 +368,18 @@ class TestMaskedArray(TestCase): def test_pickling(self): "Tests pickling" - import cPickle a = arange(10) a[::3] = masked a.fill_value = 999 - a_pickled = cPickle.loads(a.dumps()) + a_pickled = pickle.loads(a.dumps()) assert_equal(a_pickled._mask, a._mask) assert_equal(a_pickled._data, a._data) assert_equal(a_pickled.fill_value, 999) def test_pickling_subbaseclass(self): "Test pickling w/ a subclass of ndarray" - import cPickle a = array(np.matrix(list(range(10))), mask=[1, 0, 1, 0, 0] * 2) - a_pickled = cPickle.loads(a.dumps()) + a_pickled = pickle.loads(a.dumps()) assert_equal(a_pickled._mask, a._mask) assert_equal(a_pickled, a) self.assertTrue(isinstance(a_pickled._data, np.matrix)) @@ -390,37 +387,28 @@ class TestMaskedArray(TestCase): def test_pickling_maskedconstant(self): "Test pickling MaskedConstant" - import cPickle mc = np.ma.masked - mc_pickled = cPickle.loads(mc.dumps()) + mc_pickled = pickle.loads(mc.dumps()) assert_equal(mc_pickled._baseclass, mc._baseclass) assert_equal(mc_pickled._mask, mc._mask) assert_equal(mc_pickled._data, mc._data) def test_pickling_wstructured(self): "Tests pickling w/ structured array" - import cPickle a = array([(1, 1.), (2, 2.)], mask=[(0, 0), (0, 1)], dtype=[('a', int), ('b', float)]) - a_pickled = cPickle.loads(a.dumps()) + a_pickled = pickle.loads(a.dumps()) assert_equal(a_pickled._mask, a._mask) assert_equal(a_pickled, a) def test_pickling_keepalignment(self): "Tests pickling w/ F_CONTIGUOUS arrays" - import cPickle a = arange(10) a.shape = (-1, 2) b = a.T - test = cPickle.loads(cPickle.dumps(b)) + test = pickle.loads(pickle.dumps(b)) assert_equal(test, b) -# def test_pickling_oddity(self): -# "Test some pickling oddity" -# import cPickle -# a = array([{'a':1}, {'b':2}, 3], dtype=object) -# test = cPickle.loads(cPickle.dumps(a)) -# assert_equal(test, a) def test_single_element_subscript(self): "Tests single element subscripts of Maskedarrays." diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py index d6f8d9765..3b9296a04 100644 --- a/numpy/ma/tests/test_mrecords.py +++ b/numpy/ma/tests/test_mrecords.py @@ -7,30 +7,30 @@ """ from __future__ import division, absolute_import -__author__ = "Pierre GF Gerard-Marchant ($Author: jarrod.millman $)" -__revision__ = "$Revision: 3473 $" -__date__ = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $' - import sys +import warnings +import pickle + import numpy as np +import numpy.ma.testutils +import numpy.ma as ma from numpy import recarray from numpy.core.records import fromrecords as recfromrecords, \ fromarrays as recfromarrays from numpy.compat import asbytes, asbytes_nested - -import numpy.ma.testutils from numpy.ma.testutils import * - -import numpy.ma as ma from numpy.ma import masked, nomask - -import warnings from numpy.testing.utils import WarningManager - from numpy.ma.mrecords import MaskedRecords, mrecarray, fromarrays, \ fromtextfile, fromrecords, addfield + +__author__ = "Pierre GF Gerard-Marchant ($Author: jarrod.millman $)" +__revision__ = "$Revision: 3473 $" +__date__ = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $' + + #.............................................................................. class TestMRecords(TestCase): "Base test class for MaskedArrays." @@ -293,11 +293,10 @@ class TestMRecords(TestCase): # def test_pickling(self): "Test pickling" - import cPickle base = self.base.copy() mrec = base.view(mrecarray) - _ = cPickle.dumps(mrec) - mrec_ = cPickle.loads(_) + _ = pickle.dumps(mrec) + mrec_ = pickle.loads(_) assert_equal(mrec_.dtype, mrec.dtype) assert_equal_records(mrec_._data, mrec._data) assert_equal(mrec_._mask, mrec._mask) |