[Numpy-discussion] MaskedArray, view, and fill_value

Thomas Robitaille thomas.robitaille@gmail....
Fri Oct 26 13:54:46 CDT 2012


Hi everyone,

Could someone explain the following behavior?

    >>> from numpy import ma
    >>> x = ma.array([1,2,3])
    >>> x.fill_value = 1
    >>> x.view(ma.MaskedArray)
    masked_array(data = [1 2 3],
                 mask = False,
           fill_value = 999999)

i.e. the fill_value gets reset. It looks from ma/core.py like it is deliberate:

    # Make sure to reset the _fill_value if needed
    if getattr(output, '_fill_value', None) is not None:
        output._fill_value = None

but this doesn't make any sense to me... Any ideas? I'm thinking maybe
it should be:

    # Make sure to reset the _fill_value if needed
    if getattr(output, '_fill_value', None) is not None and dtype is not None:
        output._fill_value = None

because then it would make sense to reset the fill_value if the dtype
has changed. Any thoughts?

Thanks,
Tom


More information about the NumPy-Discussion mailing list