Skip to content

MaskedArray min/max methods do not work for dtype object #9103

@LevN0

Description

@LevN0

MaskedArray's min/max methods will raise an exception if its dtype is object. However ndarray min/max methods will work just fine. For example,

>>> test = np.asarray([1,2,3], dtype='object')
>>> test.min()
1

>>> test = np.ma.masked_array([1,2,3], dtype='object', mask=[True, False, False])
>>> test.min()
AttributeError: 'int' object has no attribute 'view'

These methods are useful for cases when having to use Python objects as dtype because your data contains BigInteger and BigDouble (i.e. int and Decimal respectively).

The issue seems to lie in this line in np.ma.core.min,

result = self.filled(fill_value).min(axis=axis, out=out, **kwargs).view(type(self))

The view call will fail when dtype is object, because min(...) will return e.g. int or Decimal, rather than some type of ndarray.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions