# Buggy code
def mean(self, axis=None, dtype=None, out=None, keepdims=np._NoValue):
    """
    Returns the average of the array elements along given axis.

    Masked entries are ignored, and result elements which are not
    finite will be masked.

    Refer to `numpy.mean` for full documentation.

    See Also
    --------
    ndarray.mean : corresponding function for ndarrays
    numpy.mean : Equivalent function
    numpy.ma.average: Weighted average.

    Examples
    --------
    >>> a = np.ma.array([1,2,3], mask=[False, False, True])
    >>> a
    masked_array(data = [1 2 --],
                 mask = [False False  True],
           fill_value = 999999)
    >>> a.mean()
    1.5

    """
    kwargs = {} if keepdims is np._NoValue else {"keepdims": keepdims}

    if self._mask is nomask:
        result = super(MaskedArray, self).mean(axis=axis, dtype=dtype, **kwargs)
    else:
        dsum = self.sum(axis=axis, dtype=dtype, **kwargs)
        cnt = self.count(axis=axis, **kwargs)
        if cnt.shape == () and (cnt == 0):
            result = masked
        else:
            result = dsum * 1.0 / cnt
    if out is not None:
        out.flat = result
        if isinstance(out, MaskedArray):
            outmask = getattr(out, "_mask", nomask)
            if outmask is nomask:
                outmask = out._mask = make_mask_none(out.shape)
            outmask.flat = getattr(result, "_mask", nomask)
        return out
    return result


# Traceback (AttributeError)
In [7]: foo.mean() == bar.mean()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-3b824b0972e3> in <module>()
----> 1 foo.mean() == bar.mean()

/users/___/.local/lib/python2.7/site-packages/numpy/ma/core.pyc in __eq__(self, other)
3705                         mask = np.all([[f[n].all() for n in mask.dtype.names]
3706                                         for f in mask], axis=axis)
-> 3707                 check._mask = mask
3708         return check
3709     #

AttributeError: 'numpy.bool_' object has no attribute '_mask'

In [8]: foo.mean() != bar.mean()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-0947fa5da1ed> in <module>()
----> 1 foo.mean() != bar.mean()

/users/___/.local/lib/python2.7/site-packages/numpy/ma/core.pyc in __ne__(self, other)
3738                         mask = np.all([[f[n].all() for n in mask.dtype.names]
3739                                         for f in mask], axis=axis)
-> 3740                 check._mask = mask
3741         return check
3742     #

# Fixed code
def mean(self, axis=None, dtype=None, out=None, keepdims=np._NoValue):
    """
    Returns the average of the array elements along given axis.

    Masked entries are ignored, and result elements which are not
    finite will be masked.

    Refer to `numpy.mean` for full documentation.

    See Also
    --------
    ndarray.mean : corresponding function for ndarrays
    numpy.mean : Equivalent function
    numpy.ma.average: Weighted average.

    Examples
    --------
    >>> a = np.ma.array([1,2,3], mask=[False, False, True])
    >>> a
    masked_array(data = [1 2 --],
                 mask = [False False  True],
           fill_value = 999999)
    >>> a.mean()
    1.5

    """
    kwargs = {} if keepdims is np._NoValue else {"keepdims": keepdims}

    if self._mask is nomask:
        result = super(MaskedArray, self).mean(axis=axis, dtype=dtype, **kwargs)[()]
    else:
        dsum = self.sum(axis=axis, dtype=dtype, **kwargs)
        cnt = self.count(axis=axis, **kwargs)
        if cnt.shape == () and (cnt == 0):
            result = masked
        else:
            result = dsum * 1.0 / cnt
    if out is not None:
        out.flat = result
        if isinstance(out, MaskedArray):
            outmask = getattr(out, "_mask", nomask)
            if outmask is nomask:
                outmask = out._mask = make_mask_none(out.shape)
            outmask.flat = getattr(result, "_mask", nomask)
        return out
    return result