Closed
Description
In the process of working on #4622, it was realised that np.broadcas_arrays
do not work for void arrays with object fields, because in the process of changing new strides and shapes in as_strided
, the dtype
gets lost, and this cannot just be reset when object fields are present. While obviously this is somewhat of a corner case, it might still be good to see if it can be fixed easily, perhaps by doing something that preserves the dtype, or by bypassing the test for object fields.
import numpy as np
dt = np.dtype([('x', 'i8'), ('y', '?'), ('z', 'O')])
b = np.array([(1, True, None), (2, False, [3, 4, 5])], dtype=dt)
c = np.array([[-1], [-2]])
b_strided, c_strided = np.broadcast_arrays(b, c)
TypeError Traceback (most recent call last)
...
/usr/lib/python3/dist-packages/numpy/lib/stride_tricks.py in as_strided(x, shape, strides)
31 # Make sure dtype is correct in case of custom dtype
32 if array.dtype.kind == 'V':
---> 33 array.dtype = x.dtype
34 return array
35
TypeError: Cannot change data-type for object array.
Metadata
Metadata
Assignees
Labels
No labels