summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2012-03-18 00:00:57 -0600
committerCharles Harris <charlesr.harris@gmail.com>2012-03-18 00:00:57 -0600
commit6fd716c0a5fb7ae7c114c844f700857c093debff (patch)
treeb8a99099c161f9ee676af510e7397452c6fb87f1
parentdc4fd6462ab6f59f69b20f0148adeb96646942f0 (diff)
downloadnumpy-6fd716c0a5fb7ae7c114c844f700857c093debff.tar.gz
BUG: Fix test for Python version < 2.6.
Copied python implementation of combinations from python 2.7 itertools.combinations documentation into test_maskna. Combinations wasn't part of itertools before Python 2.6.
-rw-r--r--numpy/core/tests/test_maskna.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/numpy/core/tests/test_maskna.py b/numpy/core/tests/test_maskna.py
index e17798db4..5aeb1d668 100644
--- a/numpy/core/tests/test_maskna.py
+++ b/numpy/core/tests/test_maskna.py
@@ -3,7 +3,30 @@ from numpy.compat import asbytes
from numpy.testing import *
import sys, warnings
from numpy.testing.utils import WarningManager
-import itertools
+
+
+def combinations(iterable, r):
+ # copied from 2.7 documentation in order to support
+ # Python < 2.6
+ # combinations('ABCD', 2) --> AB AC AD BC BD CD
+ # combinations(range(4), 3) --> 012 013 023 123
+ pool = tuple(iterable)
+ n = len(pool)
+ if r > n:
+ return
+ indices = range(r)
+ yield tuple(pool[i] for i in indices)
+ while True:
+ for i in reversed(range(r)):
+ if indices[i] != i + n - r:
+ break
+ else:
+ return
+ indices[i] += 1
+ for j in range(i+1, r):
+ indices[j] = indices[j-1] + 1
+ yield tuple(pool[i] for i in indices)
+
def test_array_maskna_flags():
a = np.arange(3)
@@ -464,7 +487,7 @@ def test_array_maskna_view_dtype():
same_size = []
diff_size = []
- for x in itertools.combinations(tcs, 2):
+ for x in combinations(tcs, 2):
if np.dtype(x[0]).itemsize == np.dtype(x[1]).itemsize:
same_size.append(x)
else: diff_size.append(x)