summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Hunt <alexander.l.hunt951@gmail.com>2021-03-29 09:41:36 -0400
committerAlexander Hunt <alexander.l.hunt951@gmail.com>2021-03-29 09:41:36 -0400
commitf01ea33f4ed510bf4479af708b43246b351a99a7 (patch)
treee2fe6ea9408d39aade36d9884972d8629641e2bb
parent069827964d57a9f5f99566d74d739864f42cf530 (diff)
parent21bfcb8bec35b1df2e09e080f648a60244184e02 (diff)
downloadnumpy-f01ea33f4ed510bf4479af708b43246b351a99a7.tar.gz
Merge remote-tracking branch 'upstream/main' into main
-rw-r--r--doc/changelog/1.20.2-changelog.rst40
-rw-r--r--doc/source/release.rst1
-rw-r--r--doc/source/release/1.20.2-notes.rst49
-rw-r--r--doc_requirements.txt2
-rw-r--r--numpy/core/src/umath/scalarmath.c.src59
-rw-r--r--numpy/core/tests/test_scalarmath.py81
-rw-r--r--test_requirements.txt2
7 files changed, 231 insertions, 3 deletions
diff --git a/doc/changelog/1.20.2-changelog.rst b/doc/changelog/1.20.2-changelog.rst
new file mode 100644
index 000000000..831cf0332
--- /dev/null
+++ b/doc/changelog/1.20.2-changelog.rst
@@ -0,0 +1,40 @@
+
+Contributors
+============
+
+A total of 7 people contributed to this release. People with a "+" by their
+names contributed a patch for the first time.
+
+* Allan Haldane
+* Bas van Beek
+* Charles Harris
+* Christoph Gohlke
+* Mateusz Sokół +
+* Michael Lamparski
+* Sebastian Berg
+
+Pull requests merged
+====================
+
+A total of 20 pull requests were merged for this release.
+
+* `#18382 <https://github.com/numpy/numpy/pull/18382>`__: MAINT: Update f2py from master.
+* `#18459 <https://github.com/numpy/numpy/pull/18459>`__: BUG: ``diagflat`` could overflow on windows or 32-bit platforms
+* `#18460 <https://github.com/numpy/numpy/pull/18460>`__: BUG: Fix refcount leak in f2py ``complex_double_from_pyobj``.
+* `#18461 <https://github.com/numpy/numpy/pull/18461>`__: BUG: Fix tiny memory leaks when ``like=`` overrides are used
+* `#18462 <https://github.com/numpy/numpy/pull/18462>`__: BUG: Remove temporary change of descr/flags in VOID functions
+* `#18469 <https://github.com/numpy/numpy/pull/18469>`__: BUG: Segfault in nditer buffer dealloc for Object arrays
+* `#18485 <https://github.com/numpy/numpy/pull/18485>`__: BUG: Remove suspicious type casting
+* `#18486 <https://github.com/numpy/numpy/pull/18486>`__: BUG: remove nonsensical comparison of pointer < 0
+* `#18487 <https://github.com/numpy/numpy/pull/18487>`__: BUG: verify pointer against NULL before using it
+* `#18488 <https://github.com/numpy/numpy/pull/18488>`__: BUG: check if PyArray_malloc succeeded
+* `#18546 <https://github.com/numpy/numpy/pull/18546>`__: BUG: incorrect error fallthrough in nditer
+* `#18559 <https://github.com/numpy/numpy/pull/18559>`__: CI: Backport CI fixes from main.
+* `#18599 <https://github.com/numpy/numpy/pull/18599>`__: MAINT: Add annotations for ``dtype.__getitem__``, ``__mul__`` and...
+* `#18611 <https://github.com/numpy/numpy/pull/18611>`__: BUG: NameError in numpy.distutils.fcompiler.compaq
+* `#18612 <https://github.com/numpy/numpy/pull/18612>`__: BUG: Fixed ``where`` keyword for ``np.mean`` & ``np.var`` methods
+* `#18617 <https://github.com/numpy/numpy/pull/18617>`__: CI: Update apt package list before Python install
+* `#18636 <https://github.com/numpy/numpy/pull/18636>`__: MAINT: Ensure that re-exported sub-modules are properly annotated
+* `#18638 <https://github.com/numpy/numpy/pull/18638>`__: BUG: Fix ma coercion list-of-ma-arrays if they do not cast to...
+* `#18661 <https://github.com/numpy/numpy/pull/18661>`__: BUG: Fix small valgrind-found issues
+* `#18671 <https://github.com/numpy/numpy/pull/18671>`__: BUG: Fix small issues found with pytest-leaks
diff --git a/doc/source/release.rst b/doc/source/release.rst
index 1ea46e232..8cc4a5750 100644
--- a/doc/source/release.rst
+++ b/doc/source/release.rst
@@ -6,6 +6,7 @@ Release Notes
:maxdepth: 3
1.21.0 <release/1.21.0-notes>
+ 1.20.2 <release/1.20.2-notes>
1.20.1 <release/1.20.1-notes>
1.20.0 <release/1.20.0-notes>
1.19.5 <release/1.19.5-notes>
diff --git a/doc/source/release/1.20.2-notes.rst b/doc/source/release/1.20.2-notes.rst
new file mode 100644
index 000000000..cdf45b65e
--- /dev/null
+++ b/doc/source/release/1.20.2-notes.rst
@@ -0,0 +1,49 @@
+.. currentmodule:: numpy
+
+==========================
+NumPy 1.20.2 Release Notes
+==========================
+
+NumPy 1,20.2 is a bugfix release containing several fixes merged to the main
+branch after the NumPy 1.20.1 release.
+
+
+Contributors
+============
+
+A total of 7 people contributed to this release. People with a "+" by their
+names contributed a patch for the first time.
+
+* Allan Haldane
+* Bas van Beek
+* Charles Harris
+* Christoph Gohlke
+* Mateusz Sokół +
+* Michael Lamparski
+* Sebastian Berg
+
+Pull requests merged
+====================
+
+A total of 20 pull requests were merged for this release.
+
+* `#18382 <https://github.com/numpy/numpy/pull/18382>`__: MAINT: Update f2py from master.
+* `#18459 <https://github.com/numpy/numpy/pull/18459>`__: BUG: ``diagflat`` could overflow on windows or 32-bit platforms
+* `#18460 <https://github.com/numpy/numpy/pull/18460>`__: BUG: Fix refcount leak in f2py ``complex_double_from_pyobj``.
+* `#18461 <https://github.com/numpy/numpy/pull/18461>`__: BUG: Fix tiny memory leaks when ``like=`` overrides are used
+* `#18462 <https://github.com/numpy/numpy/pull/18462>`__: BUG: Remove temporary change of descr/flags in VOID functions
+* `#18469 <https://github.com/numpy/numpy/pull/18469>`__: BUG: Segfault in nditer buffer dealloc for Object arrays
+* `#18485 <https://github.com/numpy/numpy/pull/18485>`__: BUG: Remove suspicious type casting
+* `#18486 <https://github.com/numpy/numpy/pull/18486>`__: BUG: remove nonsensical comparison of pointer < 0
+* `#18487 <https://github.com/numpy/numpy/pull/18487>`__: BUG: verify pointer against NULL before using it
+* `#18488 <https://github.com/numpy/numpy/pull/18488>`__: BUG: check if PyArray_malloc succeeded
+* `#18546 <https://github.com/numpy/numpy/pull/18546>`__: BUG: incorrect error fallthrough in nditer
+* `#18559 <https://github.com/numpy/numpy/pull/18559>`__: CI: Backport CI fixes from main.
+* `#18599 <https://github.com/numpy/numpy/pull/18599>`__: MAINT: Add annotations for `dtype.__getitem__`, `__mul__` and...
+* `#18611 <https://github.com/numpy/numpy/pull/18611>`__: BUG: NameError in numpy.distutils.fcompiler.compaq
+* `#18612 <https://github.com/numpy/numpy/pull/18612>`__: BUG: Fixed ``where`` keyword for ``np.mean`` & ``np.var`` methods
+* `#18617 <https://github.com/numpy/numpy/pull/18617>`__: CI: Update apt package list before Python install
+* `#18636 <https://github.com/numpy/numpy/pull/18636>`__: MAINT: Ensure that re-exported sub-modules are properly annotated
+* `#18638 <https://github.com/numpy/numpy/pull/18638>`__: BUG: Fix ma coercion list-of-ma-arrays if they do not cast to...
+* `#18661 <https://github.com/numpy/numpy/pull/18661>`__: BUG: Fix small valgrind-found issues
+* `#18671 <https://github.com/numpy/numpy/pull/18671>`__: BUG: Fix small issues found with pytest-leaks
diff --git a/doc_requirements.txt b/doc_requirements.txt
index ba9d3028e..526d5cfba 100644
--- a/doc_requirements.txt
+++ b/doc_requirements.txt
@@ -4,4 +4,4 @@ ipython
scipy
matplotlib
pandas
-pydata-sphinx-theme==0.5.0
+pydata-sphinx-theme==0.5.2
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src
index 86dade0f1..66f97a831 100644
--- a/numpy/core/src/umath/scalarmath.c.src
+++ b/numpy/core/src/umath/scalarmath.c.src
@@ -737,6 +737,9 @@ _@name@_convert2_to_ctypes(PyObject *a, @type@ *arg1,
{
int ret;
ret = _@name@_convert_to_ctype(a, arg1);
+ if (ret == -2) {
+ ret = -3;
+ }
if (ret < 0) {
return ret;
}
@@ -1029,7 +1032,7 @@ static PyObject *
/**begin repeat
*
- * #name = cfloat, cdouble, clongdouble#
+ * #name = cfloat, cdouble#
*
*/
@@ -1047,6 +1050,60 @@ static PyObject *
/**begin repeat
*
+ * #oper = divmod, remainder#
+ *
+ */
+
+/*
+Complex numbers do not support remainder operations. Unfortunately,
+the type inference for long doubles is complicated, and if a remainder
+operation is not defined - if the relevant field is left NULL - then
+operations between long doubles and objects lead to an infinite recursion
+instead of a TypeError. This should ensure that once everything gets
+converted to complex long doubles you correctly get a reasonably
+informative TypeError. This fixes the last part of bug gh-18548.
+*/
+
+static PyObject *
+clongdouble_@oper@(PyObject *a, PyObject *b)
+{
+ npy_clongdouble arg1, arg2;
+
+ BINOP_GIVE_UP_IF_NEEDED(a, b, nb_@oper@, clongdouble_@oper@);
+
+ switch(_clongdouble_convert2_to_ctypes(a, &arg1, b, &arg2)) {
+ case 0:
+ break;
+ case -1:
+ /* one of them can't be cast safely must be mixed-types*/
+ return PyArray_Type.tp_as_number->nb_@oper@(a,b);
+ case -2:
+ /* use default handling */
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
+ return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);
+ case -3:
+ /*
+ * special case for longdouble and clongdouble
+ * because they have a recursive getitem in their dtype
+ */
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ /*
+ * here we do the actual calculation with arg1 and arg2
+ * as a function call.
+ */
+ PyErr_SetString(PyExc_TypeError, "complex long doubles do not support remainder");
+ return NULL;
+}
+
+/**end repeat**/
+
+/**begin repeat
+ *
* #name = half, float, double, longdouble, cfloat, cdouble, clongdouble#
*
*/
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index 0b615edfa..c27a732a7 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -1,9 +1,12 @@
+import contextlib
import sys
import warnings
import itertools
import operator
import platform
import pytest
+from hypothesis import given, settings, Verbosity, assume
+from hypothesis.strategies import sampled_from
import numpy as np
from numpy.testing import (
@@ -707,3 +710,81 @@ class TestBitShifts:
shift_arr = np.array([shift]*32, dtype=dt)
res_arr = op(val_arr, shift_arr)
assert_equal(res_arr, res_scl)
+
+
+@contextlib.contextmanager
+def recursionlimit(n):
+ o = sys.getrecursionlimit()
+ try:
+ sys.setrecursionlimit(n)
+ yield
+ finally:
+ sys.setrecursionlimit(o)
+
+
+objecty_things = [object(), None]
+reasonable_operators_for_scalars = [
+ operator.lt, operator.le, operator.eq, operator.ne, operator.ge,
+ operator.gt, operator.add, operator.floordiv, operator.mod,
+ operator.mul, operator.matmul, operator.pow, operator.sub,
+ operator.truediv,
+]
+
+
+@given(sampled_from(objecty_things),
+ sampled_from(reasonable_operators_for_scalars),
+ sampled_from(types))
+@settings(verbosity=Verbosity.verbose)
+def test_operator_object_left(o, op, type_):
+ try:
+ with recursionlimit(100):
+ op(o, type_(1))
+ except TypeError:
+ pass
+
+
+@given(sampled_from(objecty_things),
+ sampled_from(reasonable_operators_for_scalars),
+ sampled_from(types))
+def test_operator_object_right(o, op, type_):
+ try:
+ with recursionlimit(100):
+ op(type_(1), o)
+ except TypeError:
+ pass
+
+
+@given(sampled_from(reasonable_operators_for_scalars),
+ sampled_from(types),
+ sampled_from(types))
+def test_operator_scalars(op, type1, type2):
+ try:
+ op(type1(1), type2(1))
+ except TypeError:
+ pass
+
+
+@pytest.mark.parametrize("op", reasonable_operators_for_scalars)
+def test_longdouble_inf_loop(op):
+ try:
+ op(np.longdouble(3), None)
+ except TypeError:
+ pass
+ try:
+ op(None, np.longdouble(3))
+ except TypeError:
+ pass
+
+
+@pytest.mark.parametrize("op", reasonable_operators_for_scalars)
+def test_clongdouble_inf_loop(op):
+ if op in {operator.mod} and False:
+ pytest.xfail("The modulo operator is known to be broken")
+ try:
+ op(np.clongdouble(3), None)
+ except TypeError:
+ pass
+ try:
+ op(None, np.longdouble(3))
+ except TypeError:
+ pass
diff --git a/test_requirements.txt b/test_requirements.txt
index 0762d5acf..ab73b2d35 100644
--- a/test_requirements.txt
+++ b/test_requirements.txt
@@ -1,7 +1,7 @@
cython==0.29.22
wheel<0.36.3
setuptools<49.2.0
-hypothesis==6.8.1
+hypothesis==6.8.3
pytest==6.2.2
pytz==2021.1
pytest-cov==2.11.1