summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik M. Bray <erik.bray@lri.fr>2016-08-29 19:06:38 +0200
committerErik M. Bray <erik.bray@lri.fr>2016-08-29 19:06:38 +0200
commit12ea33a6fe73f6597cc301ebcb23cb44644addd5 (patch)
treed54c4fe540ce10a828653a53382f52fea77361be
parent9266c2dfb97248dd20719c12ff9a009a71d941aa (diff)
downloadnumpy-12ea33a6fe73f6597cc301ebcb23cb44644addd5.tar.gz
Adds a regression test that demonstrates the issue.
-rw-r--r--numpy/core/tests/test_function_base.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/numpy/core/tests/test_function_base.py b/numpy/core/tests/test_function_base.py
index 0fabb2588..8b4f5b4ac 100644
--- a/numpy/core/tests/test_function_base.py
+++ b/numpy/core/tests/test_function_base.py
@@ -260,6 +260,42 @@ class TestLinspace(TestCase):
assert type(ls) is PhysicalQuantity2
assert_equal(ls, linspace(0.0, 1.0, 1))
+ def test_array_interface(self):
+ # Regression test for https://github.com/numpy/numpy/pull/6659
+ # Ensure that start/stop can be objects that implement
+ # __array_interface__ and are convertible to numeric scalars
+
+ class Arrayish(object):
+ """
+ A generic object that supports the __array_interface__ and hence
+ can in principle be converted to a numeric scalar, but is not
+ otherwise recognized as numeric, but also happens to support
+ multiplication by floats.
+
+ Data should be an object that implements the buffer interface,
+ and contains at least 4 bytes.
+ """
+
+ def __init__(self, data):
+ self._data = data
+
+ @property
+ def __array_interface__(self):
+ # Ideally should be `'shape': ()` but the current interface
+ # does not allow that
+ return {'shape': (1,), 'typestr': '<i4', 'data': self._data,
+ 'version': 3}
+
+ def __mul__(self, other):
+ # For the purposes of this test any multiplication is an
+ # identity operation :)
+ return self
+
+ one = Arrayish(array(1, dtype='<i4'))
+ five = Arrayish(array(5, dtype='<i4'))
+
+ assert_equal(linspace(one, five), linspace(1, 5))
+
def test_denormal_numbers(self):
# Regression test for gh-5437. Will probably fail when compiled
# with ICC, which flushes denormals to zero