Module ImportFrom alias ImportFrom alias alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias alias alias ImportFrom alias alias alias Import alias identifier ImportFrom alias FunctionDef arguments args NameParam defaults body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Return IfExp CompareIs NameLoad NameLoad NameLoad Call NameLoad NameLoad NameLoad NameLoad decorator_list Call NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body If Call NameLoad NameLoad NameLoad body Return Call AttributeLoad NameLoad attr orelse Raise Call NameLoad Call AttributeLoad Str attr AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str TryExcept body Return Call NameLoad NameLoad handlers ExceptHandler type NameLoad body Raise Call NameLoad Call AttributeLoad Str attr keyword Call NameLoad NameLoad keyword NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If Call NameLoad NameLoad NameLoad body Return NameLoad If Call NameLoad NameLoad NameLoad body Return Call NameLoad NameLoad Raise Call NameLoad Call AttributeLoad Str attr keyword Call NameLoad NameLoad keyword NameLoad keyword NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str If NameLoad body Raise Call NameLoad Str For TupleStore NameStore NameStore Call NameLoad NameLoad body If UnaryOpNot Call NameLoad NameLoad TupleLoad NameLoad NameLoad body Raise Call NameLoad Call AttributeLoad Str attr keyword NameLoad keyword NameLoad FunctionDef arguments args NameParam defaults body Expr Str If Call NameLoad NameLoad NameLoad body Assign NameStore NameLoad orelse Assign NameStore TupleLoad NameLoad Assign NameStore Call AttributeLoad Str attr keyword Call AttributeLoad Str attr GeneratorExp Call NameLoad AttributeLoad NameLoad attr comprehension NameStore NameLoad FunctionDef arguments args NameParam defaults body Return CompareNotIn Call NameLoad NameLoad Str NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body TryExcept body Return AttributeLoad AttributeLoad NameLoad attr attr handlers ExceptHandler type NameLoad body Return NameLoad decorator_list Return Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad decorator_list Return Call NameLoad Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str If NameLoad body Raise Call NameLoad Str For TupleStore NameStore NameStore Call NameLoad NameLoad body If UnaryOpNot Call NameLoad NameLoad TupleLoad NameLoad NameLoad body Raise Call NameLoad Call AttributeLoad Str attr keyword NameLoad keyword NameLoad FunctionDef arguments args NameParam defaults body Assign NameStore Str If Call NameLoad NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr keyword Call AttributeLoad Str attr Call NameLoad NameLoad NameLoad orelse Assign NameStore Call AttributeLoad NameLoad attr keyword Call NameLoad NameLoad Return Call NameLoad NameLoad NameLoad Lambda arguments args NameParam defaults UnaryOpNot Call NameLoad NameLoad NameLoad Call NameLoad NameLoad NameLoad decorator_list Return Call NameLoad Call NameLoad NameLoad NameLoad decorator_list If NameLoad body Assign NameStore Call NameLoad Str orelse FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore AttributeLoad NameLoad attr If CompareIn NameLoad TupleLoad Str Str Str body Return AttributeLoad NameLoad attr Return Call AttributeLoad Str attr ListLoad NameLoad AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body If Call NameLoad NameLoad body Raise Call NameLoad BinOpMod NameLoad Dict Str Str Str Call NameLoad NameLoad NameLoad Call NameLoad NameLoad Return NameLoad decorator_list Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return TupleLoad NameLoad Call NameLoad NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str If NameLoad body Raise Call NameLoad Str FunctionDef arguments args NameParam defaults body Assign NameStore Call AttributeLoad Str attr keyword NameLoad Return Call NameLoad NameLoad NameLoad Call NameLoad Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list Return Call NameLoad Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args defaults kwarg body Expr Str FunctionDef arguments args NameParam defaults body FunctionDef arguments args NameParam NameParam NameParam defaults body Assign NameStore Call NameLoad NameLoad Assign NameStore AttributeLoad NameLoad attr If CompareNotEq NameLoad NameLoad body If CompareEq NameLoad Num body Assign NameStore Str orelse Assign NameStore BinOpMod Str NameLoad Raise Call NameLoad Call AttributeLoad Str attr keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Return NameLoad decorator_list Return NameLoad decorator_list Return Call NameLoad Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults kwarg body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body If Call NameLoad NameLoad NameLoad body Return Call NameLoad NameLoad NameLoad Return NameLoad decorator_list Return NameLoad decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults vararg kwarg body Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body FunctionDef arguments args defaults vararg kwarg body For TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr body If CompareIn NameLoad NameLoad body Raise Call NameLoad NameLoad Return Call NameLoad NameLoad NameLoad decorator_list Return NameLoad decorator_list decorator_list Assign NameStore Call NameLoad NameLoad NameLoad
N/A datetime tzinfo functools partial wraps operator attrgetter numpy dtype pytz timezone six iteritems string_types PY3 toolz valmap complement compose N/A toolz.curried.operator op zipline.utils.preprocess preprocess optionally N/A N/A preprocessor N/A N/A N/A Modify a preprocessor to explicitly allow `None`.

    Parameters
    ----------
    preprocessor : callable[callable, str, any -> any]
        A preprocessor to delegate to when `arg is not None`.

    Returns
    -------
    optional_preprocessor : callable[callable, str, any -> any]
        A preprocessor that delegates to `preprocessor` when `arg is not None`.

    Usage
    -----
    >>> def preprocessor(func, argname, arg):
    ...     if not isinstance(arg, int):
    ...         raise TypeError('arg must be int')
    ...     return arg
    ...
    >>> @preprocess(a=optionally(preprocessor))
    ... def f(a):
    ...     return a
    ...
    >>> f(1)  # call with int
    1
    >>> f('a')  # call with not int
    Traceback (most recent call last):
       ...
    TypeError: arg must be int
    >>> f(None) is None  # call with explicit None
    True
     wrapper N/A N/A func argname arg N/A N/A N/A N/A N/A arg None arg N/A preprocessor func argname arg N/A N/A wraps preprocessor N/A wrapper N/A ensure_upper_case N/A N/A func argname arg N/A N/A N/A N/A isinstance arg string_types N/A N/A N/A N/A arg upper N/A N/A N/A TypeError N/A N/A {0}() expected argument '{1}' to be a string, but got {2} instead. format N/A func __name__ argname arg N/A ensure_dtype N/A N/A func argname arg N/A N/A N/A 
    Argument preprocessor that converts the input into a numpy dtype.

    Usage
    -----
    >>> import numpy as np
    >>> from zipline.utils.preprocess import preprocess
    >>> @preprocess(dtype=ensure_dtype)
    ... def foo(dtype):
    ...     return dtype
    ...
    >>> foo(float)
    dtype('float64')
     N/A N/A N/A N/A dtype arg N/A N/A N/A TypeError N/A N/A N/A TypeError N/A N/A {func}() couldn't convert argument {argname}={arg!r} to a numpy dtype. format func N/A _qualified_name func argname argname arg arg N/A ensure_timezone N/A N/A func argname arg N/A N/A N/A Argument preprocessor that converts the input into a tzinfo object.

    Usage
    -----
    >>> from zipline.utils.preprocess import preprocess
    >>> @preprocess(tz=ensure_timezone)
    ... def foo(tz):
    ...     return tz
    >>> foo('utc')
    <UTC>
     N/A N/A isinstance arg tzinfo N/A N/A arg N/A N/A isinstance arg string_types N/A N/A N/A timezone arg N/A N/A TypeError N/A N/A {func}() couldn't convert argument {argname}={arg!r} to a timezone. format func N/A _qualified_name func argname argname arg arg N/A expect_dtypes N/A N/A N/A _pos named N/A N/A 
    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
     N/A _pos N/A N/A N/A TypeError expect_dtypes() only takes keyword arguments. N/A N/A name type_ N/A iteritems named N/A N/A N/A N/A isinstance type_ N/A dtype tuple N/A N/A N/A TypeError N/A N/A expect_dtypes() expected a numpy dtype or tuple of dtypes for argument {name!r}, but got {dtype} instead. format name name dtype dtype _expect_dtype N/A N/A _dtype_or_dtype_tuple N/A N/A N/A 
        Factory for dtype-checking functions that work the @preprocess
        decorator.
         N/A N/A isinstance _dtype_or_dtype_tuple tuple N/A N/A allowed_dtypes _dtype_or_dtype_tuple N/A N/A allowed_dtypes N/A _dtype_or_dtype_tuple N/A template N/A N/A %(funcname)s() expected a value with dtype {dtype_str} for argument '%(argname)s', but got %(actual)r instead. format dtype_str N/A N/A  or  join N/A N/A repr N/A d name N/A d allowed_dtypes check_dtype N/A N/A value N/A N/A N/A N/A N/A getattr value dtype None allowed_dtypes N/A display_bad_value N/A N/A value N/A N/A N/A N/A N/A N/A N/A value dtype name N/A N/A N/A AttributeError N/A N/A value N/A N/A N/A make_check exc_type TypeError template template pred check_dtype actual display_bad_value N/A N/A N/A preprocess N/A valmap _expect_dtype named N/A expect_types N/A N/A N/A _pos named N/A N/A 
    Preprocessing decorator that verifies inputs have expected types.

    Usage
    -----
    >>> @expect_types(x=int, y=str)
    ... def foo(x, y):
    ...    return x, y
    ...
    >>> foo(2, '3')
    (2, '3')
    >>> foo(2.0, '3')
    Traceback (most recent call last):
       ...
    TypeError: foo() expected an argument of type 'int' for argument 'x', but got float instead.  # noqa
     N/A _pos N/A N/A N/A TypeError expect_types() only takes keyword arguments. N/A N/A name type_ N/A iteritems named N/A N/A N/A N/A isinstance type_ N/A type tuple N/A N/A N/A TypeError N/A N/A expect_types() expected a type or tuple of types for argument '{name}', but got {type_} instead. format name name type_ type_ _expect_type N/A N/A type_ N/A N/A N/A _template %(funcname)s() expected a value of type {type_or_types} for argument '%(argname)s', but got %(actual)s instead. N/A N/A isinstance type_ tuple N/A N/A template N/A N/A _template format type_or_types N/A N/A  or  join N/A map _qualified_name type_ N/A N/A template N/A N/A _template format type_or_types N/A _qualified_name type_ N/A N/A make_check TypeError template N/A N/A N/A v N/A N/A N/A isinstance v type_ N/A compose _qualified_name type N/A N/A N/A preprocess N/A valmap _expect_type named N/A N/A PY3 N/A N/A _qualified_name N/A attrgetter __qualname__ N/A _qualified_name N/A N/A obj N/A N/A N/A 
        Return the fully-qualified name (ignoring inner classes) of a type.
         N/A module N/A obj __module__ N/A N/A module N/A __builtin__ __main__ builtins N/A N/A N/A obj __name__ N/A N/A N/A . join N/A module N/A obj __name__ N/A make_check N/A N/A exc_type template pred actual N/A N/A N/A 
    Factory for making preprocessing functions that check a predicate on the
    input value.

    Parameters
    ----------
    exc_type : Exception
        The exception type to raise if the predicate fails.
    template : str
        A template string to use to create error messages.
        Should have %-style named template parameters for 'funcname',
        'argname', and 'actual'.
    pred : function[object -> bool]
        A function to call on the argument being preprocessed.  If the
        predicate returns `True`, we raise an instance of `exc_type`.
    actual : function[object -> object]
        A function to call on bad values to produce the value to display in the
        error message.
     _check N/A N/A func argname argvalue N/A N/A N/A N/A pred argvalue N/A N/A N/A exc_type N/A template N/A funcname argname actual N/A _qualified_name func argname N/A actual argvalue N/A argvalue N/A N/A _check N/A optional N/A N/A type_ N/A N/A N/A 
    Helper for use with `expect_types` when an input can be `type_` or `None`.

    Returns an object such that both `None` and instances of `type_` pass
    checks of the form `isinstance(obj, optional(type_))`.

    Parameters
    ----------
    type_ : type
       Type for which to produce an option.

    Examples
    --------
    >>> isinstance({}, optional(dict))
    True
    >>> isinstance(None, optional(dict))
    True
    >>> isinstance(1, optional(dict))
    False
     N/A N/A type_ N/A type None N/A expect_element N/A N/A N/A _pos named N/A N/A 
    Preprocessing decorator that verifies inputs are elements of some
    expected collection.

    Usage
    -----
    >>> @expect_element(x=('a', 'b'))
    ... def foo(x):
    ...    return x.upper()
    ...
    >>> foo('a')
    'A'
    >>> foo('b')
    'B'
    >>> foo('c')
    Traceback (most recent call last):
       ...
    ValueError: foo() expected a value in ('a', 'b') for argument 'x', but got 'c' instead.  # noqa

    Notes
    -----
    This uses the `in` operator (__contains__) to make the containment check.
    This allows us to use any custom container as long as the object supports
    the container protocol.
     N/A _pos N/A N/A N/A TypeError expect_element() only takes keyword arguments. _expect_element N/A N/A collection N/A N/A N/A template N/A N/A %(funcname)s() expected a value in {collection} for argument '%(argname)s', but got %(actual)s instead. format collection collection N/A N/A make_check ValueError template N/A complement N/A N/A op contains collection repr N/A N/A N/A preprocess N/A valmap _expect_element named N/A expect_dimensions N/A N/A N/A dimensions N/A N/A 
    Preprocessing decorator that verifies inputs are numpy arrays with a
    specific dimensionality.

    Usage
    -----
    >>> from numpy import array
    >>> @expect_dimensions(x=1, y=2)
    ... def foo(x, y):
    ...    return x[0] + y[0, 0]
    ...
    >>> foo(array([1, 1]), array([[1, 1], [2, 2]]))
    2
    >>> foo(array([1, 1], array([1, 1])))
    Traceback (most recent call last):
       ...
    TypeError: foo() expected a 2-D array for argument 'y', but got a 1-D array instead.  # noqa
     _expect_dimension N/A N/A expected_ndim N/A N/A _check N/A N/A func argname argvalue N/A N/A N/A funcname N/A _qualified_name func N/A actual_ndim N/A argvalue ndim N/A N/A actual_ndim expected_ndim N/A N/A N/A actual_ndim 0 N/A N/A actual_repr scalar N/A N/A actual_repr N/A %d-D array actual_ndim N/A N/A ValueError N/A N/A {func}() expected a {expected:d}-D array for argument {argname!r}, but got a {actual} instead. format func funcname expected expected_ndim argname argname actual actual_repr N/A argvalue N/A N/A _check N/A N/A N/A preprocess N/A valmap _expect_dimension dimensions N/A coerce N/A N/A from_ to N/A to_kwargs N/A N/A 
    A preprocessing decorator that coerces inputs of a given type by passing
    them to a callable.

    Parameters
    ----------
    from : type or tuple or types
        Inputs types on which to call ``to``.
    to : function
        Coercion function to call on inputs.
    **to_kwargs
        Additional keywords to forward to every call to ``to``.

    Usage
    -----
    >>> @preprocess(x=coerce(float, int), y=coerce(float, int))
    ... def floordiff(x, y):
    ...     return x - y
    ...
    >>> floordiff(3.2, 2.5)
    1

    >>> @preprocess(x=coerce(str, int, base=2), y=coerce(str, int, base=2))
    ... def add_binary_strings(x, y):
    ...     return bin(x + y)[2:]
    ...
    >>> add_binary_strings('101', '001')
    '110'
     preprocessor N/A N/A func argname arg N/A N/A N/A N/A isinstance arg from_ N/A N/A N/A to arg to_kwargs N/A arg N/A N/A preprocessor N/A error_keywords N/A object N/A __init__ N/A N/A self N/A args kwargs N/A N/A N/A self messages kwargs N/A __call__ N/A N/A self func N/A N/A assert_keywords_and_call N/A N/A N/A args kwargs N/A N/A N/A field message N/A iteritems N/A self messages N/A N/A N/A field kwargs N/A N/A N/A TypeError message N/A N/A func args kwargs N/A N/A assert_keywords_and_call N/A N/A N/A coerce_string N/A partial coerce string_types