-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
np.ma.asarray looses mask for str array #18551
Copy link
Copy link
Closed
Labels
Description
Mask is lost when np.ma.asarray is called with masked and non-masked arrays and the masked array is of str type.
This behavior is a change from 1.18.5 to 1.19+.
When the masked array is of int type the mask is preserved.
Reproducing code example:
import numpy as np
masked_str = np.ma.masked_array(['a', 'b'], mask=[True, False])
normal_int = np.arange(2)
np.ma.asarray([masked_str, normal_int])=>
masked_array(
data=[['a', 'b'],
['0', '1']],
mask=False,
fill_value='N/A',
dtype='<U21')import numpy as np
masked_int = np.ma.masked_array([1, 2], mask=[True, False])
normal_int = np.arange(2)
np.ma.asarray([masked_int, normal_int])=>
masked_array(
data=[[--, 2],
[0, 1]],
mask=[[ True, False],
[False, False]],
fill_value=999999)NumPy/Python version information:
1.20.1 3.8.6 (default, Jan 27 2021, 15:42:20)
[GCC 10.2.0]
Reactions are currently unavailable