-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
__array_prepare__ produces bad shape for np.ma.masked #8505
Copy link
Copy link
Closed
Description
A somewhat contrived example
>>> source = np.ma.masked # comes from user function, could be anything
>>> source = np.asanyarray(source) # force to array, so we can try to copy the type
>>> outarr = np.zeros((2, 2)) # allocate a raw ndarray for the result
>>> bad = source.__array_prepare__(outarr) # prepare that raw array for operations
>>> bad.shape
(2, 2)
>>> bad.data.shape
() # uh oh
>>> bad.mask.shape
() # spaghettiosWhich leads to failures like
>>> res.transpose((1, 0))
Traceback (most recent call last):
File "<pyshell#78>", line 1, in <module>
np.asanyarray(np.ma.masked).__array_prepare__(np.zeros((2, 2))).transpose((1, 0))
File "C:\Program Files\Python 3.5\lib\site-packages\numpy\ma\core.py", line 2509, in wrapped_method
result = getattr(self._data, funcname)(*args, **params)
ValueError: axes don't match arrayThis come up when trying to invoke #8441 on masked arrays.
Is this a bug, or an invalid use of __array_prepare__?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels