def expect_dtypes(*_pos, **named):
    """
    Preprocessing decorator that verifies inputs have expected numpy dtypes.

    Usage
    -----
    >>> from numpy import dtype, arange
    >>> @expect_dtypes(x=dtype(int))
    ... def foo(x, y):
    ...    return x, y
    ...
    >>> foo(arange(3), 'foo')
    (array([0, 1, 2]), 'foo')
    >>> foo(arange(3, dtype=float), 'foo')
    Traceback (most recent call last):
       ...
    TypeError: foo() expected an argument with dtype 'int64' for argument 'x', but got dtype 'float64' instead.  # noqa
    """
    if _pos:
        raise TypeError("expect_dtypes() only takes keyword arguments.")

    for name, type_ in iteritems(named):
        if not isinstance(type_, (dtype, tuple)):
            raise TypeError(
                "expect_dtypes() expected a numpy dtype or tuple of dtypes"
                " for argument {name!r}, but got {dtype} instead.".format(
                    name=name, dtype=dtype,
                )
            )

    def _expect_dtype(_dtype_or_dtype_tuple):
        """
        Factory for dtype-checking functions that work the @preprocess
        decorator.
        """
        # Slightly different messages for dtype and tuple of dtypes.
        if isinstance(_dtype_or_dtype_tuple, tuple):
            allowed_dtypes = _dtype_or_dtype_tuple
        else:
            allowed_dtypes = (_dtype_or_dtype_tuple,)
        template = (
            "%(funcname)s() expected a value with dtype {dtype_str} "
            "for argument '%(argname)s', but got %(actual)r instead."
        ).format(dtype_str=' or '.join(repr(d.name) for d in allowed_dtypes))

        def check_dtype(value):
            return allowed_dtypes not in getattr(value, 'dtype', None)

        def display_bad_value(value):
            # If the bad value has a dtype, but it's wrong, show the dtype
            # name.
            try:
                return value.dtype.name
            except AttributeError:
                return value

        return make_check(
            exc_type=TypeError,
            template=template,
            pred=check_dtype,
            actual=display_bad_value,
        )

    return preprocess(**valmap(_expect_dtype, named))
dataset/ETHPy150Open quantopian/zipline/zipline/utils/input_validation.py/expect_dtypes/swapped operands of `not in`