Skip to content

numpy.void and numpy.ma.mvoid with structured dtypes should support indexing with multiple fields #7262

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

Closed
gerritholl opened this issue Feb 16, 2016 · 1 comment

Comments

@gerritholl
Copy link
Contributor

A structured ndarray can be indexed with multiple fields:

In [14]: X = numpy.empty(shape=1, dtype="(2)3S,(2)3U")

In [15]: X[["f0","f1"]]
Out[15]: 
array([([b'', b''], ['', ''])], 
      dtype=[('f0', 'S3', (2,)), ('f1', '<U3', (2,))])

However, the corresponding numpy.void type cannot:

In [16]: X[0][["f0","f1"]]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-16-4f230bb69b0d> in <module>()
----> 1 X[0][["f0","f1"]]

IndexError: invalid index

The same is true for masked arrays.

For consistently, numpy.void with a structured dtype should support indexing with multiple fields exactly like numpy.ndarray does.

@ahaldane
Copy link
Member

I actually had fixed this in #6208, but I backpedaled because mutli-field subscripts work strangely (see #6053). My plan was to get #6053 in first, and then go back and enable this.

#6208 has already partially set up the fix: All that's left is to change the if(Py_Ustring_Check(ind) in voidtype_subscript to test for an array of strings too.

ahaldane added a commit to ahaldane/numpy that referenced this issue Jun 17, 2016
This commit attempts to make structure assignment more consistent, and
then changes multi-field indices to return a view instead of a copy.

Assignment between structures now works "by field position" rather than
"by field name".

Fixes numpy#2353, fixes numpy#6085, fixes numpy#3351, fixes numpy#6085, fixes numpy#6314,
fixes numpy#2346, fixes numpy#7058, fixes numpy#3641, fixes numpy#5994, fixes numpy#7262,
fixes numpy#7493
@charris charris closed this as completed in 7412b85 Sep 9, 2017
theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this issue Oct 23, 2017
This commit attempts to make structure assignment more consistent, and
then changes multi-field indices to return a view instead of a copy.

Assignment between structures now works "by field position" rather than
"by field name".

Fixes numpy#2353, fixes numpy#6085, fixes numpy#3351, fixes numpy#6085, fixes numpy#6314,
fixes numpy#2346, fixes numpy#7058, fixes numpy#3641, fixes numpy#5994, fixes numpy#7262,
fixes numpy#7493
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants