-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
slicing a slice with an array without expanding the slice #10580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
54a5ded
9cab2ac
91e316f
5c467ca
697be5d
e966756
4d828ed
78a79ab
8fef773
005d5bc
a217e6a
9386108
94577ab
3d316a9
ea45bde
fdc90a2
7f3694c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
get_valid_numpy_dtype, | ||
is_duck_array, | ||
is_duck_dask_array, | ||
is_full_slice, | ||
is_scalar, | ||
is_valid_numpy_dtype, | ||
to_0d_array, | ||
|
@@ -298,17 +299,29 @@ def slice_slice(old_slice: slice, applied_slice: slice, size: int) -> slice: | |
return slice(start, stop, step) | ||
|
||
|
||
def slice_slice_by_array(old_slice, array, size): | ||
normalized = normalize_slice(old_slice, size) | ||
new_indexer = array * normalized.step + normalized.start | ||
|
||
if np.any(new_indexer >= normalized.stop): | ||
raise IndexError("indices out of bounds") # TODO: more helpful error message | ||
|
||
return new_indexer | ||
|
||
|
||
def _index_indexer_1d(old_indexer, applied_indexer, size: int): | ||
if isinstance(applied_indexer, slice) and applied_indexer == slice(None): | ||
if is_full_slice(applied_indexer): | ||
# shortcut for the usual case | ||
return old_indexer | ||
if isinstance(old_indexer, slice): | ||
if isinstance(applied_indexer, slice): | ||
indexer = slice_slice(old_indexer, applied_indexer, size) | ||
elif isinstance(applied_indexer, integer_types): | ||
indexer = range(*old_indexer.indices(size))[applied_indexer] # type: ignore[assignment] | ||
elif is_full_slice(old_indexer): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this fix point (3) in #10311 (comment)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, because for vectorized indexing we use |
||
indexer = applied_indexer | ||
else: | ||
indexer = _expand_slice(old_indexer, size)[applied_indexer] | ||
indexer = slice_slice_by_array(old_indexer, applied_indexer, size) | ||
else: | ||
indexer = old_indexer[applied_indexer] | ||
return indexer | ||
|
Uh oh!
There was an error while loading. Please reload this page.