def to_numpy(x):
    """
    Converts x into a numpy array. It is used to convert pandas Series and
    DataFrames into numpy objects.
    """
    if x is None:
        return x

    func = getattr(x, "to_numpy", None)
    if not callable(func):
        return x

    return x.to_numpy()