You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# without reading `fill_value`
>>> a = np.ma.array([None])
>>> a.fill_value = object()
>>> a.fill_value
<object object at 0x000000000066A0E0>
# with reading `fill_value`
>>> a = np.ma.array([None])
>>> a.fill_value
'?'
>>> a.fill_value = object()
>>> a.fill_value
'<'
This fails because after reading fill_value for the first time, _fill_value.dtype is S1, which becomes fixed for the lifetime of the object.
In general, the problem is that a.fill_value.dtype is not a.dtype:
>>> np.ma.array(1, np.int8).fill_value.dtype
dtype('int32') # maybe defensible, handy if the array is upcast later
>>> np.ma.array(1, np.int64).fill_value.dtype
dtype('int32') # unacceptable loss of range (maybe windows only)!
>>> np.ma.array(1, object).fill_value.dtype
dtype('S1') # this issue
It's tricky to fix this without breaking code that assumes np.ma.array(1, np.int8).fill_value = 999999. Do we care about that code?
The text was updated successfully, but these errors were encountered:
eric-wieser
changed the title
Setting ma fill_value of object dtypes doesn't work if the fill_value has already been used
Setting ma fill_value of object and long int dtypes doesn't work if the fill_value has already been used
Sep 30, 2017
This relates to this comment
This fails because after reading
fill_value
for the first time,_fill_value.dtype
isS1
, which becomes fixed for the lifetime of the object.In general, the problem is that
a.fill_value.dtype
is nota.dtype
:It's tricky to fix this without breaking code that assumes
np.ma.array(1, np.int8).fill_value = 999999
. Do we care about that code?The text was updated successfully, but these errors were encountered: