DEP: Finalize the non-sequence stacking deprecation#23019
Merged
charris merged 1 commit intonumpy:mainfrom Jan 17, 2023
Merged
Conversation
7a748fd to
4f886e3
Compare
seberg
commented
Jan 16, 2023
| return () | ||
| return arrays | ||
| def _arrays_for_stack_dispatcher(arrays): | ||
| if not hasattr(arrays, "__getitem__"): |
Member
Author
There was a problem hiding this comment.
I didn't really see a reason to check whether it isn't an iterator. If it doesn't have an __iter__ it seems OK to rely on tuple(arrays) failing.
Python is weird (IMO) about:
class obj:
def __len__(self):
return 3
def __getitem__(self, x):
return x
ignoring the length (and thus iterating forever trying to find the end), but that is not something we need to worry about here.
charris
reviewed
Jan 17, 2023
numpy/core/shape_base.py
Outdated
| @@ -453,7 +449,7 @@ def stack(arrays, axis=0, out=None, *, dtype=None, casting="same_kind"): | |||
| """ | |||
| if not overrides.ARRAY_FUNCTION_ENABLED: | |||
| # raise warning if necessary | |||
Member
Author
There was a problem hiding this comment.
A, good catch. Maybe it still makes sense, but changed it to # reject non-sequences (and make tuple), since "warning" is definitely wrong now.
charris
approved these changes
Jan 17, 2023
The `__array_function__` API currently will exhaust iterators so we cannot accept sequences reasonably. Checking for `__getitem__` is presumably enough to reject that (and was what the deprecation used). Future changes could allow this again, although it is not a useful API anyway, since we have to materialize the iterable in any case.
4f886e3 to
ff78e59
Compare
Member
|
Thanks Sebastian. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
__array_function__API currently will exhaust iterators so we cannot accept sequences reasonably. Checking for__getitem__is presumably enough to reject that (and was what the deprecation used).Future changes could allow this again, although it is not a useful API anyway, since we have to materialize the iterable in any case.