summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/setup_common.py3
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src33
-rw-r--r--numpy/core/src/multiarray/item_selection.c4
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src6
-rw-r--r--numpy/core/src/multiarray/shape.c3
-rw-r--r--numpy/core/tests/test_deprecations.py11
-rw-r--r--numpy/core/tests/test_multiarray.py20
-rw-r--r--numpy/core/tests/test_regression.py10
-rw-r--r--numpy/ma/tests/test_core.py38
-rw-r--r--numpy/ma/tests/test_old_ma.py11
10 files changed, 98 insertions, 41 deletions
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index 85e92d923..e66b1653a 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -99,7 +99,8 @@ MANDATORY_FUNCS = ["sin", "cos", "tan", "sinh", "cosh", "tanh", "fabs",
# replacement implementation. Note that some of these are C99 functions.
OPTIONAL_STDFUNCS = ["expm1", "log1p", "acosh", "asinh", "atanh",
"rint", "trunc", "exp2", "log2", "hypot", "atan2", "pow",
- "copysign", "nextafter", "ftello", "fseeko"]
+ "copysign", "nextafter", "ftello", "fseeko",
+ "strtoll", "strtoull"]
OPTIONAL_HEADERS = [
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index 4043b5490..8e22afa31 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -105,6 +105,31 @@ MyPyLong_AsUnsigned@Type@ (PyObject *obj)
/**end repeat**/
+static npy_longlong
+npy_strtoll(const char *str, char **endptr, int base)
+{
+#if defined HAVE_STRTOLL
+ return strtoll(str, endptr, base);
+#elif defined _MSC_VER
+ return _strtoi64(str, endptr, base);
+#else
+ /* ok on 64 bit posix */
+ return PyOS_strtol(str, endptr, base);
+#endif
+}
+
+static npy_ulonglong
+npy_strtoull(const char *str, char **endptr, int base)
+{
+#if defined HAVE_STRTOULL
+ return strtoull(str, endptr, base);
+#elif defined _MSC_VER
+ return _strtoui64(str, endptr, base);
+#else
+ /* ok on 64 bit posix */
+ return PyOS_strtoul(str, endptr, base);
+#endif
+}
/*
*****************************************************************************
@@ -1506,8 +1531,10 @@ BOOL_scan(FILE *fp, npy_bool *ip, void *NPY_UNUSED(ignore),
* #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_datetime, npy_timedelta#
- * #func = (l, ul)*5, l, l#
- * #btype = (npy_long, npy_ulong)*5, npy_long, npy_long#
+ * #func = (PyOS_strtol, PyOS_strtoul)*4, npy_strtoll, npy_strtoull,
+ * npy_strtoll*2#
+ * #btype = (npy_long, npy_ulong)*4, npy_longlong, npy_ulonglong,
+ * npy_longlong*2#
*/
static int
@fname@_fromstr(char *str, @type@ *ip, char **endptr,
@@ -1515,7 +1542,7 @@ static int
{
@btype@ result;
- result = PyOS_strto@func@(str, endptr, 10);
+ result = @func@(str, endptr, 10);
*ip = (@type@) result;
return 0;
}
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index d6e0980c6..b2bf17f4c 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -2030,12 +2030,12 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2,
NPY_BEGIN_THREADS_DESCR(PyArray_DESCR(ap2));
error = argbinsearch((const char *)PyArray_DATA(ap1),
(const char *)PyArray_DATA(ap2),
- (const char *)PyArray_DATA(ap3),
+ (const char *)PyArray_DATA(sorter),
(char *)PyArray_DATA(ret),
PyArray_SIZE(ap1), PyArray_SIZE(ap2),
PyArray_STRIDES(ap1)[0],
PyArray_DESCR(ap2)->elsize,
- PyArray_STRIDES(ap3)[0], NPY_SIZEOF_INTP, ap2);
+ PyArray_STRIDES(sorter)[0], NPY_SIZEOF_INTP, ap2);
NPY_END_THREADS_DESCR(PyArray_DESCR(ap2));
if (error < 0) {
PyErr_SetString(PyExc_ValueError,
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index a1c95995a..110bef248 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -1082,7 +1082,11 @@ gentype_richcompare(PyObject *self, PyObject *other, int cmp_op)
if (arr == NULL) {
return NULL;
}
- ret = Py_TYPE(arr)->tp_richcompare(arr, other, cmp_op);
+ /*
+ * Call via PyObject_RichCompare to ensure that other.__eq__
+ * has a chance to run when necessary
+ */
+ ret = PyObject_RichCompare(arr, other, cmp_op);
Py_DECREF(arr);
return ret;
}
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 3d1543e56..d5fde5b97 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -93,7 +93,8 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,
|| (PyArray_BASE(self) != NULL)
|| (((PyArrayObject_fields *)self)->weakreflist != NULL)) {
PyErr_SetString(PyExc_ValueError,
- "cannot resize an array references or is referenced\n"\
+ "cannot resize an array that "\
+ "references or is referenced\n"\
"by another array in this way. Use the resize function");
return NULL;
}
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index a2b30c3c9..a1f4664a5 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -454,10 +454,11 @@ class TestIdentityComparisonDepreactions(_DeprecationTestCase):
assert_raises(FutureWarning, np.equal, a, a)
assert_raises(FutureWarning, np.not_equal, a, a)
# And the other do not warn:
- np.less(a, a)
- np.greater(a, a)
- np.less_equal(a, a)
- np.greater_equal(a, a)
+ with np.errstate(invalid='ignore'):
+ np.less(a, a)
+ np.greater(a, a)
+ np.less_equal(a, a)
+ np.greater_equal(a, a)
def test_comparison_error(self):
@@ -477,7 +478,7 @@ class TestIdentityComparisonDepreactions(_DeprecationTestCase):
a = np.array([np.array([1, 2, 3]), None], dtype=object)
self.assert_deprecated(np.equal, args=(a, a))
self.assert_deprecated(np.not_equal, args=(a, a))
-
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 8b2bc1d82..bc3670653 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1212,11 +1212,15 @@ class TestMethods(TestCase):
dt = 'M8[D]'
if dt == '?':
a = np.array([1, 0], dtype=dt)
- s = [1, 0]
+ # We want the sorter array to be of a type that is different
+ # from np.intp in all platforms, to check for #4698
+ s = np.array([1, 0], dtype=np.int16)
out = np.array([1, 0])
else:
a = np.array([3, 4, 1, 2, 0], dtype=dt)
- s = [4, 2, 3, 0, 1]
+ # We want the sorter array to be of a type that is different
+ # from np.intp in all platforms, to check for #4698
+ s = np.array([4, 2, 3, 0, 1], dtype=np.int16)
out = np.array([3, 4, 1, 2, 0], dtype=np.intp)
b = a.searchsorted(a, 'l', s)
assert_equal(b, out)
@@ -2440,6 +2444,18 @@ class TestIO(object):
y = np.fromstring('1 0 -2.3 0.0', sep=' ', dtype=np.bool_)
assert_array_equal(v, y)
+ def test_uint64_fromstring(self):
+ d = np.fromstring("9923372036854775807 104783749223640",
+ dtype=np.uint64, sep=' ');
+ e = np.array([9923372036854775807, 104783749223640], dtype=np.uint64)
+ assert_array_equal(d, e)
+
+ def test_int64_fromstring(self):
+ d = np.fromstring("-25041670086757 104783749223640",
+ dtype=np.int64, sep=' ');
+ e = np.array([-25041670086757, 104783749223640], dtype=np.int64)
+ assert_array_equal(d, e)
+
def test_empty_files_binary(self):
f = open(self.filename, 'w')
f.close()
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index f3e34c109..9f40d7b54 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1993,6 +1993,16 @@ class TestRegression(TestCase):
assert_(not op.eq(lhs, rhs))
assert_(op.ne(lhs, rhs))
+ def test_richcompare_scalar_and_subclass(self):
+ # gh-4709
+ class Foo(np.ndarray):
+ def __eq__(self, other):
+ return "OK"
+ x = np.array([1,2,3]).view(Foo)
+ assert_equal(10 == x, "OK")
+ assert_equal(np.int32(10) == x, "OK")
+ assert_equal(np.array([10]) == x, "OK")
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 02a1c8c40..e6f659041 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -808,27 +808,29 @@ class TestMaskedArrayArithmetic(TestCase):
def test_count_func(self):
# Tests count
- ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
- ott1= array([0., 1., 2., 3.])
- if sys.version_info[0] >= 3:
- self.assertTrue(isinstance(count(ott), np.integer))
- else:
- self.assertTrue(isinstance(count(ott), int))
- assert_equal(3, count(ott))
assert_equal(1, count(1))
assert_equal(0, array(1, mask=[1]))
+
+ ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
+ res = count(ott)
+ self.assertTrue(res.dtype.type is np.intp)
+ assert_equal(3, res)
+
ott = ott.reshape((2, 2))
- assert_(isinstance(count(ott, 0), ndarray))
- if sys.version_info[0] >= 3:
- assert_(isinstance(count(ott), np.integer))
- else:
- assert_(isinstance(count(ott), int))
- assert_equal(3, count(ott))
- assert_(getmask(count(ott, 0)) is nomask)
- assert_equal([1, 2], count(ott, 0))
- assert_equal(type(count(ott, 0)), type(count(ott1, 0)))
- assert_equal(count(ott, 0).dtype, count(ott1, 0).dtype)
- assert_raises(IndexError, ott1.count, 1)
+ res = count(ott)
+ assert_(res.dtype.type is np.intp)
+ assert_equal(3, res)
+ res = count(ott, 0)
+ assert_(isinstance(res, ndarray))
+ assert_equal([1, 2], res)
+ assert_(getmask(res) is nomask)
+
+ ott= array([0., 1., 2., 3.])
+ res = count(ott, 0)
+ assert_(isinstance(res, ndarray))
+ assert_(res.dtype.type is np.intp)
+
+ assert_raises(IndexError, ott.count, 1)
def test_minmax_func(self):
# Tests minimum and maximum.
diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py
index 27d699385..87c2133d7 100644
--- a/numpy/ma/tests/test_old_ma.py
+++ b/numpy/ma/tests/test_old_ma.py
@@ -153,19 +153,14 @@ class TestMa(TestCase):
def test_xtestCount(self):
# Test count
ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0])
- if sys.version_info[0] >= 3:
- self.assertTrue(isinstance(count(ott), np.integer))
- else:
- self.assertTrue(isinstance(count(ott), int))
+ self.assertTrue(count(ott).dtype.type is np.intp)
self.assertEqual(3, count(ott))
self.assertEqual(1, count(1))
self.assertTrue(eq(0, array(1, mask=[1])))
ott = ott.reshape((2, 2))
+ self.assertTrue(count(ott).dtype.type is np.intp)
assert_(isinstance(count(ott, 0), np.ndarray))
- if sys.version_info[0] >= 3:
- assert_(isinstance(count(ott), np.integer))
- else:
- assert_(isinstance(count(ott), int))
+ self.assertTrue(count(ott).dtype.type is np.intp)
self.assertTrue(eq(3, count(ott)))
assert_(getmask(count(ott, 0)) is nomask)
self.assertTrue(eq([1, 2], count(ott, 0)))