-
Notifications
You must be signed in to change notification settings - Fork 89
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
RuntimeError when slicing two dimensions using a masked array #1305
Comments
That's right. This has reached some unconsidered code path. It is faithfully reproduced in v2: import awkward as ak
x = ak._v2.Array([[5.]])
y = ak._v2.Array([True])
x[ak._v2.mask(y, [True]), 0]
and it would probably be easier to debug in v2, as that's Python code. The " When descending through a layout tree, we might have an In v2, we use The slice of array[slice_dimension_1, slice_dimension_2] Awkward Array supports this as much as it has to and extends it in a different way: by requiring the nested structure of the slicer and the sliced to match (broadcastable): jagged_jagged_array[another_jagged_jagged_array] What happens when you mix the two is minimally tested: jagged_jagged_array[a_jagged_array, deeper_index] A semantics has been defined: the |
The assertions in Therefore, it's also something we don't support. The code written above now raises an intentional error, and hopefully it would be clear what's going on and how to proceed if you run into it again: >>> array = ak._v2.Array([[3.14]])
>>> first_slice = ak._v2.Array([True, None])[:1] # type: 1 * ?bool
>>> first_slice
<Array [True] type='1 * ?bool'>
>>> second_slice = 0
>>> array[first_slice, second_slice]
|
* Fixes #1305 by raising an exception on mixed Awkward/NumPy slices. * Don't let Index._metadata be an nplike.
* Fix: tentative fix for empty slice lists * Test: validate fix * Update tests/v2/test_1593-empty-slice-list-record.py Co-authored-by: ioanaif <[email protected]> * Fix: convert `[]` into `slice(0, 0)` This bypasses the `slice_fields` mechanism, which is really orthogonal to the content length `_getitem` implementations. * Refactor: check explicitly for iterables with lengths * Test: fix to match v1 * Fix: normalise [] to empty array * Fix: return `NumpyLike.array` instead of index * Fix: support empty Index64 * Docs: add small docstring elucidating getitem_broadcast * Fix: update `getitem_next_array_wrap` to accept `outer_length` argument * Fix: remove list special-case * Fix: pass list length to `getitem_next_array_wrap` * feat: raise error if unsupported indexing used This prevents the second-case of advanced indexing referred to in https://numpy.org/doc/stable/user/basics.indexing.html#basics-indexing:~:text=In%20the%20first,just%20like%20slicing from being used * test: fix use of v1 record * fix: respect zero-length of regular array * test: respect new error during indexing * test: fix expected output of slice * test: fix expected output of slice * test: fix expected output of slice * fix: return view in `TypeTracerArray.view` * feat: add `TypeTracerArray.astype` * feat: raise `ValueError` for mixed indices This changes #1305 * refactor: move NumPy index validation into broadcasting This also renames various utility functions to make the concerns more apparent. * fix: actually raise exception * refactor: remove unneeded length check Co-authored-by: ioanaif <[email protected]>
…#1597) * Fix: tentative fix for empty slice lists * Test: validate fix * Update tests/v2/test_1593-empty-slice-list-record.py Co-authored-by: ioanaif <[email protected]> * Fix: convert `[]` into `slice(0, 0)` This bypasses the `slice_fields` mechanism, which is really orthogonal to the content length `_getitem` implementations. * Refactor: check explicitly for iterables with lengths * Test: fix to match v1 * Fix: normalise [] to empty array * Fix: return `NumpyLike.array` instead of index * Fix: support empty Index64 * Docs: add small docstring elucidating getitem_broadcast * Fix: update `getitem_next_array_wrap` to accept `outer_length` argument * Fix: remove list special-case * Fix: pass list length to `getitem_next_array_wrap` * feat: raise error if unsupported indexing used This prevents the second-case of advanced indexing referred to in https://numpy.org/doc/stable/user/basics.indexing.html#basics-indexing:~:text=In%20the%20first,just%20like%20slicing from being used * test: fix use of v1 record * fix: respect zero-length of regular array * test: respect new error during indexing * test: fix expected output of slice * test: fix expected output of slice * test: fix expected output of slice * fix: return view in `TypeTracerArray.view` * feat: add `TypeTracerArray.astype` * feat: raise `ValueError` for mixed indices This changes scikit-hep#1305 * refactor: move NumPy index validation into broadcasting This also renames various utility functions to make the concerns more apparent. * fix: actually raise exception * refactor: remove unneeded length check Co-authored-by: ioanaif <[email protected]>
Version of Awkward Array
1.8.0rc3
Description and code to reproduce
Please consider the following
The last line will raise the following error
RuntimeError: ListOffsetArray::getitem_next(SliceAt): !advanced.is_empty_advanced()
I don't think the line should raise an error and I am unsure what the error message is telling me.
The text was updated successfully, but these errors were encountered: