def num_or_none(x):
    """Given a value x it cast as int, float or None

    :param x: The value to transform and return
    :returns: Either None or x cast to an int/float

    """
    if x is None:
        return None
    if isinstance(x, (int, float)):
        return x
    try:
        return int(x)
    except ValueError:
        return float(x)
