Skip to content

Commit e2803ad

Browse files
committed
Review changes
1 parent 5739e14 commit e2803ad

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
New function ``unstack()``
2-
--------------------------
1+
New function `numpy.unstack`
2+
----------------------------
33

4-
A new function ``unstack()``, which splits an array into a tuple of arrays
5-
along an axis. It serves as the inverse of ``np.stack()``.
4+
A new function ``np.unstack(array, axis=...)`` was added, which splits
5+
an array into a tuple of arrays along an axis. It serves as the inverse
6+
of `numpy.stack`.

numpy/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ from numpy._core.shape_base import (
397397
hstack as hstack,
398398
stack as stack,
399399
vstack as vstack,
400+
unstack as unstack,
400401
)
401402

402403
from numpy.lib import (

numpy/_core/shape_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def stack(arrays, axis=0, out=None, *, dtype=None, casting="same_kind"):
457457
return _nx.concatenate(expanded_arrays, axis=axis, out=out,
458458
dtype=dtype, casting=casting)
459459

460-
def _unstack_dispatcher(x, *, axis=None):
460+
def _unstack_dispatcher(x, /, *, axis=None):
461461
return (x,)
462462

463463
@array_function_dispatch(_unstack_dispatcher)

numpy/_core/shape_base.pyi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,17 @@ def stack(
120120
@overload
121121
def unstack(
122122
array: _ArrayLike[_SCT],
123-
axis: int = 0
123+
/,
124+
*,
125+
axis: int = ...,
124126
) -> tuple[NDArray[_SCT], ...]: ...
127+
@overload
128+
def unstack(
129+
array: ArrayLike,
130+
/,
131+
*,
132+
axis: int = ...,
133+
) -> tuple[NDArray[Any], ...]: ...
125134

126135
@overload
127136
def block(arrays: _ArrayLike[_SCT]) -> NDArray[_SCT]: ...

numpy/typing/tests/data/reveal/shape_base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ assert_type(np.kron(AR_f8, AR_f8), npt.NDArray[np.floating[Any]])
5454
assert_type(np.tile(AR_i8, 5), npt.NDArray[np.int64])
5555
assert_type(np.tile(AR_LIKE_f8, [2, 2]), npt.NDArray[Any])
5656

57-
assert_type(np.unstack(AR_i8, 5), list[npt.NDArray[np.int64]])
58-
assert_type(np.unstack(AR_LIKE_f8, 5), list[npt.NDArray[Any]])
57+
assert_type(np.unstack(AR_i8, axis=0), list[npt.NDArray[np.int64]])
58+
assert_type(np.unstack(AR_LIKE_f8, axis=0), list[npt.NDArray[Any]])

0 commit comments

Comments
 (0)