Skip to content

numpy.lib.stride_tricks.as_strided() does not preserve some structured dtypes #26

Description

@fjarri

In the commit 2293b43 a test for numpy.lib.stride_tricks.as_strided() was added in array.py checking that it preserves a structured dtype. It works for the rather simple type there, but stops working for types with padding set through offsets parameter:

import numpy
from numpy.lib.stride_tricks import as_strided

dtype = numpy.dtype({
    'names':['i1','nested','i2'],
    'formats':['<u4',[('v', '<u8')],'<u4'],
    'offsets':[0,8,16], 'itemsize':24})

arr = numpy.zeros((128,), dtype)

print(dtype)
print(new_arr.dtype)

Output:

{'names':['i1','nested','i2'], 'formats':['<u4',[('v', '<u8')],'<u4'], 'offsets':[0,8,16], 'itemsize':24}
[('i1', '<u4'), ('f1', 'V4'), ('nested', [('v', '<u8')]), ('i2', '<u4'), ('f4', 'V4')]

Apparently, as_strided() adds some dummy fields in this case and removes offsets. The alternative version of as_strided() in array.py does preserve them, but since the numpy one passes the test, it does not get invoked.

Is it the planned behavior?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions