Skip to content
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

Setting ma fill_value of object and long int dtypes doesn't work if the fill_value has already been used #9798

Open
eric-wieser opened this issue Sep 30, 2017 · 0 comments

Comments

@eric-wieser
Copy link
Member

eric-wieser commented Sep 30, 2017

This relates to this comment

# 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?

@eric-wieser 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant