diff options
-rw-r--r-- | numpy/core/arrayprint.py | 2 | ||||
-rw-r--r-- | numpy/distutils/system_info.py | 3 | ||||
-rw-r--r-- | numpy/f2py/auxfuncs.py | 3 | ||||
-rw-r--r-- | numpy/lib/arrayterator.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_arrayterator.py | 4 | ||||
-rw-r--r-- | numpy/ma/core.py | 3 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 4 | ||||
-rw-r--r-- | numpy/ma/tests/test_old_ma.py | 4 | ||||
-rw-r--r-- | numpy/ma/timer_comparison.py | 21 | ||||
-rw-r--r-- | numpy/oldnumeric/ma.py | 3 | ||||
-rwxr-xr-x | tools/py3tool.py | 9 |
11 files changed, 51 insertions, 9 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 536b26f40..2367f76e1 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -29,6 +29,8 @@ _line_width = 75 _nan_str = 'NaN' _inf_str = 'Inf' +if sys.version_info[0] >= 3: + from functools import reduce def set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, suppress=None, diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index ab375246f..15c18c6a1 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -132,6 +132,9 @@ from numpy.distutils.misc_util import is_sequence, is_string from numpy.distutils.command.config import config as cmd_config from numpy.distutils.compat import get_exception +if sys.version_info[0] >= 3: + from functools import reduce + # Determine number of bits import platform _bits = {'32bit':32,'64bit':64} diff --git a/numpy/f2py/auxfuncs.py b/numpy/f2py/auxfuncs.py index fe037f065..3121f710e 100644 --- a/numpy/f2py/auxfuncs.py +++ b/numpy/f2py/auxfuncs.py @@ -32,6 +32,9 @@ options={} debugoptions=[] wrapfuncs = 1 +if sys.version_info[0] >= 3: + from functools import reduce + def outmess(t): if options.get('verbose',1): sys.stdout.write(t) diff --git a/numpy/lib/arrayterator.py b/numpy/lib/arrayterator.py index d4a91b001..3f07cd263 100644 --- a/numpy/lib/arrayterator.py +++ b/numpy/lib/arrayterator.py @@ -14,6 +14,10 @@ from operator import mul __all__ = ['Arrayterator'] +import sys +if sys.version_info[0] >= 3: + from functools import reduce + class Arrayterator(object): """ Buffered iterator for big arrays. diff --git a/numpy/lib/tests/test_arrayterator.py b/numpy/lib/tests/test_arrayterator.py index c600d45eb..3dce009d3 100644 --- a/numpy/lib/tests/test_arrayterator.py +++ b/numpy/lib/tests/test_arrayterator.py @@ -4,6 +4,10 @@ import numpy as np from numpy.random import randint from numpy.lib import Arrayterator +import sys +if sys.version_info[0] >= 3: + from functools import reduce + def test(): np.random.seed(np.arange(10)) diff --git a/numpy/ma/core.py b/numpy/ma/core.py index cb29d57b1..402916501 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -79,6 +79,9 @@ 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) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 74bd2f722..7494de4cd 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -19,6 +19,10 @@ from numpy.ma.core import * pi = np.pi +import sys +if sys.version_info[0] >= 3: + from functools import reduce + #.............................................................................. class TestMaskedArray(TestCase): "Base test class for MaskedArrays." diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py index 4887a228c..cf169dd70 100644 --- a/numpy/ma/tests/test_old_ma.py +++ b/numpy/ma/tests/test_old_ma.py @@ -5,6 +5,10 @@ from numpy.core.numerictypes import float32 from numpy.ma.core import umath from numpy.testing import * +import sys +if sys.version_info[0] >= 3: + from functools import reduce + pi = numpy.pi def eq(v,w, msg=''): result = allclose(v,w) diff --git a/numpy/ma/timer_comparison.py b/numpy/ma/timer_comparison.py index 282931494..57cccf0b4 100644 --- a/numpy/ma/timer_comparison.py +++ b/numpy/ma/timer_comparison.py @@ -1,5 +1,6 @@ import timeit +import sys import numpy as np from numpy import float_ import np.core.fromnumeric as fromnumeric @@ -10,8 +11,10 @@ np.seterr(all='ignore') pi = np.pi +if sys.version_info[0] >= 3: + from functools import reduce + class moduletester: - #----------------------------------- def __init__(self, module): self.module = module self.allequal = module.allequal @@ -46,7 +49,7 @@ class moduletester: except AttributeError: self.umath = module.core.umath self.testnames = [] - #........................ + def assert_array_compare(self, comparison, x, y, err_msg='', header='', fill_value=True): """Asserts that a comparison relation between two masked arrays is satisfied @@ -100,19 +103,19 @@ class moduletester: except ValueError: msg = build_err_msg([x, y], err_msg, header=header, names=('x', 'y')) raise ValueError(msg) - #............................ + def assert_array_equal(self, x, y, err_msg=''): """Checks the elementwise equality of two masked arrays.""" self.assert_array_compare(self.equal, x, y, err_msg=err_msg, header='Arrays are not equal') - #---------------------------------- + def test_0(self): "Tests creation" x = np.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] xm = self.masked_array(x, mask=m) xm[0] - #---------------------------------- + def test_1(self): "Tests creation" x = np.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.]) @@ -126,13 +129,13 @@ class moduletester: zm = self.masked_array(z, mask=[0,1,0,0]) xf = np.where(m1, 1.e+20, x) xm.set_fill_value(1.e+20) - #..... + assert((xm-ym).filled(0).any()) #fail_if_equal(xm.mask.astype(int_), ym.mask.astype(int_)) s = x.shape assert(xm.size == reduce(lambda x,y:x*y, s)) assert(self.count(xm) == len(m1) - reduce(lambda x,y:x+y, m1)) - #..... + for s in [(4,3), (6,2)]: x.shape = s y.shape = s @@ -141,7 +144,7 @@ class moduletester: xf.shape = s assert(self.count(xm) == len(m1) - reduce(lambda x,y:x+y, m1)) - #---------------------------------- + def test_2(self): "Tests conversions and indexing" x1 = np.array([1,2,4,3]) @@ -193,7 +196,7 @@ class moduletester: m3 = self.make_mask(m, copy=1) assert(m is not m3) - #---------------------------------- + def test_3(self): "Tests resize/repeat" x4 = self.arange(4) diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py index 532e4f905..1284c6019 100644 --- a/numpy/oldnumeric/ma.py +++ b/numpy/oldnumeric/ma.py @@ -18,6 +18,9 @@ from numpy.core.numerictypes import bool_, typecodes import numpy.core.numeric as numeric import warnings +if sys.version_info[0] >= 3: + from functools import reduce + # Ufunc domain lookup for __array_wrap__ ufunc_domain = {} # Ufunc fills lookup for __array__ diff --git a/tools/py3tool.py b/tools/py3tool.py index 46bf924bf..258484fc9 100755 --- a/tools/py3tool.py +++ b/tools/py3tool.py @@ -39,6 +39,15 @@ EXTRA_2TO3_FLAGS = { 'numpy/core/defchararray.py': '-x unicode', 'numpy/compat/py3k.py': '-x unicode', 'numpy/ma/timer_comparison.py': 'skip', + 'numpy/distutils/system_info.py': '-x reduce', + 'numpy/f2py/auxfuncs.py': '-x reduce', + 'numpy/lib/arrayterator.py': '-x reduce', + 'numpy/lib/tests/test_arrayterator.py': '-x reduce', + 'numpy/ma/core.py': '-x reduce', + 'numpy/ma/tests/test_core.py': '-x reduce', + 'numpy/ma/tests/test_old_ma.py': '-x reduce', + 'numpy/ma/timer_comparison.py': '-x reduce', + 'numpy/oldnumeric/ma.py': '-x reduce', } def main(): |