summaryrefslogtreecommitdiff
path: root/numpy/core/shape_base.py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2018-10-27 12:23:15 -0700
committerStephan Hoyer <shoyer@google.com>2018-10-27 12:45:25 -0700
commitbfe0921f9bdd6b347982a9c998b8b1890040ba5b (patch)
tree394c19504aa07a4e7ae308da3cffa728a564f66a /numpy/core/shape_base.py
parent45718fd73bc286e127772ee455d721d9a58665b3 (diff)
downloadnumpy-bfe0921f9bdd6b347982a9c998b8b1890040ba5b.tar.gz
DEP: deprecate passing a generator to stack functions
Fixes gh-12263 We can't support generators with dispatch for ``__array_function__``.
Diffstat (limited to 'numpy/core/shape_base.py')
-rw-r--r--numpy/core/shape_base.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py
index 71a23f438..4cb7a30f4 100644
--- a/numpy/core/shape_base.py
+++ b/numpy/core/shape_base.py
@@ -5,6 +5,8 @@ __all__ = ['atleast_1d', 'atleast_2d', 'atleast_3d', 'block', 'hstack',
import functools
import operator
+import types
+import warnings
from . import numeric as _nx
from . import overrides
@@ -204,11 +206,23 @@ def atleast_3d(*arys):
return res
-def _vstack_dispatcher(tup):
- return tup
+def _arrays_for_stack_dispatcher(arrays, stacklevel=4):
+ if isinstance(arrays, types.GeneratorType):
+ warnings.warn('arrays to stack should be passed as a sequence, not a '
+ 'generator. Support for generators is deprecated as of '
+ 'NumPy 1.16 and will raise an error in the future. '
+ 'Note also that dispatch with __array_function__ is not '
+ 'supported when passing arrays as a generator.',
+ FutureWarning, stacklevel=stacklevel)
+ return ()
+ return arrays
-@array_function_dispatch(_vstack_dispatcher)
+def _vhstack_dispatcher(tup):
+ return _arrays_for_stack_dispatcher(tup)
+
+
+@array_function_dispatch(_vhstack_dispatcher)
def vstack(tup):
"""
Stack arrays in sequence vertically (row wise).
@@ -264,11 +278,7 @@ def vstack(tup):
return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
-def _hstack_dispatcher(tup):
- return tup
-
-
-@array_function_dispatch(_hstack_dispatcher)
+@array_function_dispatch(_vhstack_dispatcher)
def hstack(tup):
"""
Stack arrays in sequence horizontally (column wise).
@@ -325,6 +335,7 @@ def hstack(tup):
def _stack_dispatcher(arrays, axis=None, out=None):
+ arrays = _arrays_for_stack_dispatcher(arrays, stacklevel=6)
for a in arrays:
yield a
if out is not None: