def METHOD_NAME(data, info):
    """Mask image data if necessary.
    Masking is done if alpha channel is present or
    dataset 'nodata_handling' is set to 'nan_mask'.
    In the latter case even integer data is converted
    to float32 and masked with np.nan.
    """
    if data.bands.size in (2, 4):
        if not np.issubdtype(data.dtype, np.integer):
            raise ValueError("Only integer datatypes can be used as a mask.")
        mask = data.data[-1, :, :] == np.iinfo(data.dtype).min
        data = data.astype(np.float64)
        masked_data = da.stack([da.where(mask, np.nan, data.data[i, :, :])
                                for i in range(data.shape[0])])
        data.data = masked_data
        data = data.sel(bands=BANDS[data.bands.size - 1])
    elif hasattr(data, 'nodatavals') and data.nodatavals:
        data = _handle_nodatavals(data, info.get('nodata_handling', NODATA_HANDLING_FILLVALUE))
    return data