Skip to content
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

Layout indexes don't support slices #333

Closed
nsmith- opened this issue Jul 13, 2020 · 1 comment · Fixed by #337
Closed

Layout indexes don't support slices #333

nsmith- opened this issue Jul 13, 2020 · 1 comment · Fixed by #337
Labels
feature New feature or request

Comments

@nsmith-
Copy link
Contributor

nsmith- commented Jul 13, 2020

Sometimes, when building arrays at a low level, it is useful to manipulate Index64 and similar from python.
The usual getitem method does not accept python slices, however:

import awkward1
a = awkward1.Array([[1, 2, 3], [4, 5], [6]])
a.layout.offsets[:-1]

gives:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-53dc196bd178> in <module>
      2 
      3 a = awkward1.Array([[1, 2, 3], [4, 5], [6]])
----> 4 a.layout.offsets[:-1]

TypeError: __getitem__(): incompatible function arguments. The following argument types are supported:
    1. (self: awkward1._ext.Index64, arg0: int) -> int
    2. (self: awkward1._ext.Index64, arg0: int, arg1: int) -> awkward1._ext.Index64

Invoked with: <Index64 i="[0 3 5 6]" offset="0" length="4" at="0x7f869cad1a00"/>, slice(None, -1, None)

Amusingly, one can do a.layout.offsets.__getitem__(0, -1)

@nsmith- nsmith- added the bug (unverified) The problem described would be a bug, but needs to be triaged label Jul 13, 2020
@jpivarski jpivarski added feature New feature or request and removed bug (unverified) The problem described would be a bug, but needs to be triaged labels Jul 13, 2020
@jpivarski
Copy link
Member

Since this is a known fact about these low-level objects, it might make more sense to call this a feature request. But yeah, it would definitely make life easier for developers who are building things on top of Awkward if they could treat Index as a normal array-like object.

@jpivarski jpivarski linked a pull request Jul 15, 2020 that will close this issue
14 tasks
jpivarski added a commit that referenced this issue Jul 15, 2020
jpivarski added a commit that referenced this issue Jul 16, 2020
* Test 32-bit and 64-bit Windows format strings.

* Restore buildtest.

* Added util::dtype enum and converters.

* NumpyArray and NumpyForm take a util::dtype argument.

* Replaced one #ifdef _MSC_VER.

* Centralized 'dtype_name'.

* Replaced PrimitiveType::Dtype with the new util::dtype.

* Reducer.preferred_type and Reducer.return_type are no longer used.

* Removed 'format' dependence from reducers, considerably simplifying them.

* Removed 'format_' from 'tostring_part'.

* Put Windows/32-bit integer promotion rules back in.

* Removed '#ifdef' from 'tojson_part'.

* Removed '#ifdef' from 'mergeable'.

* Removed '#ifdef' from 'merge', but its behavior does not match np.concatenate.

* Merge (ak.concatenate) follows the same type-promotion rules as np.concatenate.

* Removed '#ifdef' from 'sort' and 'argsort'.

* Removed '#ifdef' from 'copy_to'.

* All compiler '#if' checks for interpreting 'format' are replaced by 'dtype' now.

* Fixed #333.

* Form.from_numpy now exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants