-
-
Notifications
You must be signed in to change notification settings - Fork 11k
BUG: Handle subarrays in descr_to_dtype #13433
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,6 +411,7 @@ def teardown_module(): | |
np.array(NbufferT, dtype=np.dtype(Ndescr).newbyteorder('<')), | ||
np.array(PbufferT, dtype=np.dtype(Pdescr).newbyteorder('>')), | ||
np.array(NbufferT, dtype=np.dtype(Ndescr).newbyteorder('>')), | ||
np.zeros(1, dtype=[('c', ('<f8', (5,)), (2,))]) | ||
] | ||
|
||
|
||
|
@@ -628,6 +629,61 @@ def test_pickle_disallow(): | |
assert_raises(ValueError, np.save, path, np.array([None], dtype=object), | ||
allow_pickle=False) | ||
|
||
@pytest.mark.parametrize('dt', [ | ||
np.dtype(np.dtype([('a', np.int8), | ||
('b', np.int16), | ||
('c', np.int32), | ||
], align=True), | ||
(3,)), | ||
np.dtype([('x', np.dtype({'names':['a','b'], | ||
'formats':['i1','i1'], | ||
'offsets':[0,4], | ||
'itemsize':8, | ||
}, | ||
(3,)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests are passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This test is ignoring the |
||
(4,), | ||
)]), | ||
np.dtype([('x', | ||
('<f8', (5,)), | ||
(2,), | ||
)]), | ||
np.dtype([('x', np.dtype(( | ||
np.dtype(( | ||
np.dtype({'names':['a','b'], | ||
'formats':['i1','i1'], | ||
'offsets':[0,4], | ||
'itemsize':8}), | ||
(3,) | ||
)), | ||
(4,) | ||
))) | ||
]), | ||
np.dtype([ | ||
('a', np.dtype(( | ||
np.dtype(( | ||
np.dtype(( | ||
np.dtype([ | ||
('a', int), | ||
('b', np.dtype({'names':['a','b'], | ||
'formats':['i1','i1'], | ||
'offsets':[0,4], | ||
'itemsize':8})), | ||
]), | ||
(3,), | ||
)), | ||
(4,), | ||
)), | ||
(5,), | ||
))) | ||
]), | ||
]) | ||
|
||
def test_descr_to_dtype(dt): | ||
dt1 = format.descr_to_dtype(dt.descr) | ||
assert_equal_(dt1, dt) | ||
arr1 = np.zeros(3, dt) | ||
arr2 = roundtrip(arr1) | ||
assert_array_equal(arr1, arr2) | ||
|
||
def test_version_2_0(): | ||
f = BytesIO() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this is a subarray of structured types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to recurse for subarray types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an interesting case. Top level subarrays are degenerated on arrays (they are added to the dimensions of the array), cannot quickly find a way to create an array with such a dtype, but it somewhat feels like there may have been strange ways to do it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, watch out for structured types like
(int, [('fields', int)])
which have a non-void baseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this one is still broken (although maybe the original issue is solved and this is just another issue). Had a too shallow look at this probably, though :/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the subarray to be at the top level to hit this code-path - nest it inside a structured one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the subarray to be at the top level to hit this code-path - nest it inside a structured one.