summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarray/multiarray_tests.c.src29
-rw-r--r--numpy/core/tests/test_multiarray.py16
2 files changed, 45 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src
index f22b7462d..0aea85f66 100644
--- a/numpy/core/src/multiarray/multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/multiarray_tests.c.src
@@ -557,6 +557,30 @@ fail:
return NULL;
}
+
+#if !defined(NPY_PY3K)
+static PyObject *
+int_subclass(PyObject *dummy, PyObject *args)
+{
+
+ PyObject *result = NULL;
+ PyObject *scalar_object = NULL;
+
+ if (!PyArg_UnpackTuple(args, "test_int_subclass", 1, 1, &scalar_object))
+ return NULL;
+
+ if (PyInt_Check(scalar_object))
+ result = Py_True;
+ else
+ result = Py_False;
+
+ Py_INCREF(result);
+
+ return result;
+
+}
+#endif
+
static PyMethodDef Multiarray_TestsMethods[] = {
{"test_neighborhood_iterator",
test_neighborhood_iterator,
@@ -573,6 +597,11 @@ static PyMethodDef Multiarray_TestsMethods[] = {
{"test_inplace_increment",
inplace_increment,
METH_VARARGS, NULL},
+#if !defined(NPY_PY3K)
+ {"test_int_subclass",
+ int_subclass,
+ METH_VARARGS, NULL},
+#endif
{NULL, NULL, 0, NULL} /* Sentinel */
};
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 6cd24a76f..c298b4f1d 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -95,6 +95,22 @@ class TestAttributes(TestCase):
assert_equal(self.one.dtype.str[1], 'i')
assert_equal(self.three.dtype.str[1], 'f')
+ def test_int_subclassing(self):
+ # Regression test for https://github.com/numpy/numpy/pull/3526
+
+ numpy_int = np.int_(0)
+
+ if sys.version_info[0] >= 3:
+ # On Py3k int_ should not inherit from int, because it's not fixed-width anymore
+ assert_equal(isinstance(numpy_int, int), False)
+ else:
+ # Otherwise, it should inherit from int...
+ assert_equal(isinstance(numpy_int, int), True)
+
+ # ... and fast-path checks on C-API level should also work
+ from numpy.core.multiarray_tests import test_int_subclass
+ assert_equal(test_int_subclass(numpy_int), True)
+
def test_stridesattr(self):
x = self.one
def make_array(size, offset, strides):