def binop(x, y, op):
    """
    Returns op(x,y), where either x or y can be None, to indicate 'missing data'.
    The op() argument is a binary callable, e.g. op=min or op=(lambda x,y:x+y).
    """

    if (x is None) and (y is None):
        return None

    x = x if (x is not None) else 0
    y = y if (y is not None) else 0
    return op(x,y)