diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-02-26 21:31:14 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-02-26 21:35:44 -0800 |
commit | 6d950b383bff4ac2448b3f6a1e7573e7ea176051 (patch) | |
tree | 4681d3a78072848bf5c5dee343a9a2f99c1dfa9e /numpy/core | |
parent | 6462068ee40344ebe9a60b3ddcad0e9590d5a260 (diff) | |
download | numpy-6d950b383bff4ac2448b3f6a1e7573e7ea176051.tar.gz |
DEP: Deprecate np.sum(generator)
Fixes #10652
Introduced in a13aad3ac33b629f3e696b4d4d5dbf4b5605d567
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/fromnumeric.py | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index de85c1143..6c7ef4c1f 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1881,6 +1881,12 @@ def sum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue): if keepdims is not np._NoValue: kwargs['keepdims'] = keepdims if isinstance(a, _gentype): + # 2018-02-25, 1.15.0 + warnings.warn( + "Calling np.sum(generator) is deprecated, and in the future will give a different result. " + "Use np.sum(np.from_iter(generator)) or the python sum builtin instead.", + DeprecationWarning, stacklevel=2) + res = _sum_(a) if out is not None: out[...] = res diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index fe0c7cc5f..5e6f14a39 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -481,5 +481,11 @@ class TestBincount(_DeprecationTestCase): self.assert_deprecated(lambda: np.bincount([1, 2, 3], minlength=None)) +class TestGeneratorSum(_DeprecationTestCase): + # 2018-02-25, 1.15.0 + def test_generator_sum(self): + self.assert_deprecated(np.sum, args=((i for i in range(5)),)) + + if __name__ == "__main__": run_module_suite() |