diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2018-10-29 15:05:55 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-29 15:05:55 -0500 |
| commit | e726c045c72833d5c826e8a13f889746ee0bfdf4 (patch) | |
| tree | dc337946b0785d365ba23f4c7b7b22060b51d8be /numpy/core/shape_base.py | |
| parent | b2b532081b4b7fc15f97ffedb30a975aef835137 (diff) | |
| parent | 00640218fcbc5d71f22550a9368da92358c8de96 (diff) | |
| download | numpy-e726c045c72833d5c826e8a13f889746ee0bfdf4.tar.gz | |
Merge pull request #12280 from shoyer/stack-generator-warning
DEP: deprecate passing a generator to stack functions
Diffstat (limited to 'numpy/core/shape_base.py')
| -rw-r--r-- | numpy/core/shape_base.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/numpy/core/shape_base.py b/numpy/core/shape_base.py index 71a23f438..3edf0824e 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,22 @@ def atleast_3d(*arys): return res -def _vstack_dispatcher(tup): - return tup +def _arrays_for_stack_dispatcher(arrays, stacklevel=4): + if not hasattr(arrays, '__getitem__') and hasattr(arrays, '__iter__'): + warnings.warn('arrays to stack must be passed as a "sequence" type ' + 'such as list or tuple. Support for non-sequence ' + 'iterables such as generators is deprecated as of ' + 'NumPy 1.16 and will raise an error in the future.', + 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 +277,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 +334,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: |
