summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/format.py4
-rw-r--r--numpy/lib/function_base.py6
-rw-r--r--numpy/lib/index_tricks.py4
-rw-r--r--numpy/lib/tests/test__datasource.py2
-rw-r--r--numpy/lib/tests/test_index_tricks.py4
-rw-r--r--numpy/lib/tests/test_io.py4
-rw-r--r--numpy/lib/tests/test_regression.py9
-rw-r--r--numpy/lib/utils.py4
8 files changed, 27 insertions, 10 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 1e508f3e5..bff582f7d 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -334,7 +334,7 @@ def read_array_header_1_0(fp):
# "descr" : dtype.descr
try:
d = safe_eval(header)
- except SyntaxError, e:
+ except SyntaxError as e:
msg = "Cannot parse header: %r\nException: %r"
raise ValueError(msg % (header, e))
if not isinstance(d, dict):
@@ -356,7 +356,7 @@ def read_array_header_1_0(fp):
raise ValueError(msg % (d['fortran_order'],))
try:
dtype = numpy.dtype(d['descr'])
- except TypeError, e:
+ except TypeError as e:
msg = "descr is not a valid dtype descriptor: %r"
raise ValueError(msg % (d['descr'],))
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 65f4ecb05..02dd0ceaf 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1381,8 +1381,10 @@ def _nanop(op, fill, a, axis=None):
y = array(a, subok=True)
# We only need to take care of NaN's in floating point arrays
- if np.issubdtype(y.dtype, np.integer):
+ dt = y.dtype
+ if np.issubdtype(dt, np.integer) or np.issubdtype(dt, np.bool_):
return op(y, axis=axis)
+
mask = isnan(a)
# y[mask] = fill
# We can't use fancy indexing here as it'll mess w/ MaskedArrays
@@ -3051,7 +3053,7 @@ def percentile(a, q, axis=None, out=None, overwrite_input=False):
[ 3, 2, 1]])
>>> np.percentile(a, 50)
3.5
- >>> np.percentile(a, 0.5, axis=0)
+ >>> np.percentile(a, 50, axis=0)
array([ 6.5, 4.5, 2.5])
>>> np.percentile(a, 50, axis=1)
array([ 7., 2.])
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 852c5f6fd..15a1a559d 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -535,7 +535,9 @@ class ndindex(object):
# Fixing nditer would be more work but should be done eventually,
# and then this entire __new__ method can be removed.
def __new__(cls, *shape):
- if len(shape) == 0 or (len(shape) == 1 and len(shape[0]) == 0):
+ if len(shape) == 1 and isinstance(shape[0], tuple):
+ shape = shape[0]
+ if len(shape) == 0:
class zero_dim_iter(object):
def __init__(self):
self._N = 1
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py
index ed5af516f..3f8697507 100644
--- a/numpy/lib/tests/test__datasource.py
+++ b/numpy/lib/tests/test__datasource.py
@@ -92,7 +92,7 @@ class TestDataSourceOpen(TestCase):
self.assertRaises(IOError, self.ds.open, url)
try:
self.ds.open(url)
- except IOError, e:
+ except IOError as e:
# Regression test for bug fixed in r4342.
assert_(e.errno is None)
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index 43160ffb7..a6e65ef56 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -245,6 +245,10 @@ def test_ndindex():
x = list(np.ndindex((1, 2, 3)))
assert_array_equal(x, expected)
+ # Test use of scalars and tuples
+ x = list(np.ndindex((3,)))
+ assert_array_equal(x, list(np.ndindex(3)))
+
# Make sure size argument is optional
x = list(np.ndindex())
assert_equal(x, [()])
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index f8caeedb6..b7fa94448 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -151,7 +151,7 @@ class TestSavezLoad(RoundtripTest, TestCase):
arr = np.random.randn(500, 500)
try:
np.savez(tmp, arr=arr)
- except OSError, err:
+ except OSError as err:
error_list.append(err)
finally:
os.remove(tmp)
@@ -207,7 +207,7 @@ class TestSavezLoad(RoundtripTest, TestCase):
for i in range(1, 1025):
try:
np.load(tmp)["data"]
- except Exception, e:
+ except Exception as e:
raise AssertionError("Failed to load data from a file: %s" % e)
finally:
os.remove(tmp)
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index 71400d112..270da73e3 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -218,5 +218,14 @@ class TestRegression(TestCase):
data = [((((0,1), (2,3), (4,5)), ((6,7), (8,9), (10,11))),)]
assert_equal(x, np.array(data, dtype=dt))
+ def test_nansum_with_boolean(self):
+ # gh-2978
+ a = np.zeros(2, dtype=np.bool)
+ try:
+ np.nansum(a)
+ except:
+ raise AssertionError()
+
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index dc6c16767..820e6d8f9 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -1154,11 +1154,11 @@ def safe_eval(source):
walker = SafeEval()
try:
ast = compiler.parse(source, mode="eval")
- except SyntaxError, err:
+ except SyntaxError as err:
raise
try:
return walker.visit(ast)
- except SyntaxError, err:
+ except SyntaxError as err:
raise
#-----------------------------------------------------------------------------