Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Add void field at end of dtype.descr to match itemsize #6361

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

Merged
merged 2 commits into from
Sep 27, 2015

Conversation

seberg
Copy link
Member

@seberg seberg commented Sep 25, 2015

dtype.descr returns void fields to explain the padding part of
the dtype. The last void field for the itemsize itself was however
not included.

Closes gh-6359

dtype.descr returns void fields to explain the padding part of
the dtype. The last void field for the itemsize itself was however
not included.

Closes numpygh-6359
@seberg
Copy link
Member Author

seberg commented Sep 25, 2015

I would not say I know too much about these descriptors, but it seems right to add the void field at the end as well....

@ahaldane
Copy link
Member

This sounds right to me, but maybe we should re-read the Array Interface docs and PEP-3118 to be sure.

@ahaldane
Copy link
Member

Yes, those docs suggest this is the right fix. Consider:

>>> my_dtype = np.dtype({'names':['A', 'B'], 'formats':['f4', 'f4'], 
...                      'offsets': [0, 8], 'itemsize':16})
>>> a = np.ones(10, dtype=my_dtype)
>>> a.__array_interface__
{'data': (93829939730032, False),
 'descr': [('A', '<f4'), ('', '|V4'), ('B', '<f4')],
 'shape': (10,),
 'strides': None,
 'typestr': '|V16',
 'version': 3}

Note that typestr says there are 16 bytes, yet descr only describes 12 bytes. But in the Array Interface docs it says of descr, "The only requirement is that the number of bytes represented in the typestr key is the same as the total number of bytes represented here."

So we do need to add the void at the end.

@ahaldane
Copy link
Member

Also __array_interface__ only has one dedicated unit test, the function test_array_interface. Maybe it makes sense to put your test next to that one, so further __array_interface__ tests can agglomerate there?

@seberg
Copy link
Member Author

seberg commented Sep 27, 2015

I just added a duplicate of the test there. While the behaviour is identical, no pain in just duplicating to make sure this stays identical even if it might some day be ripped apart.

@ahaldane
Copy link
Member

LGTM. I will let this sit a few hours and then I'm happy to merge.

Also, for future reference I noticed that there is a test test_trailing_padding a little higher in that file, in the PEP3118 test. It tests for the ability of _dtype_from_pep3118 to convert a buffer spec with trailing padding bytes into a dtype. Not sure it always does the right thing because _dtype_from_pep3118('ixxxi') hides the padding but _dtype_from_pep3118('ixx') doesn't.

Anyway, that can be left for a later fix. Both descr and buffer specs need some attention, when converting them back to dtypes.

charris referenced this pull request Sep 27, 2015
ahaldane added a commit that referenced this pull request Sep 27, 2015
BUG: Add void field at end of dtype.descr to match itemsize
@ahaldane ahaldane merged commit 986a98c into numpy:master Sep 27, 2015
@ahaldane
Copy link
Member

Merged. Thanks @seberg.

@seberg seberg deleted the issue6359 branch September 28, 2015 06:13
@charris charris added this to the 1.10.0 release milestone Sep 28, 2015
charris referenced this pull request in charris/numpy Oct 29, 2015
This reverts commit a600a5c, reversing
changes made to 77fb742.

The expanded warning led to incompatibilities with with Numpy 1.9, which
had already the future behavior for the cases covered by the extended
warning conditions. Rather than roll back the behavior of 1.9 only to
reimplement it later, it is thought better to preserve it and move on.
charris referenced this pull request Oct 30, 2015
Revert "Merge pull request #6376 from charris/backport-gh-6361"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants