Ejemplo n.º 1
0
 def wrp_asi(self, input_, *args, **kwargs):
     #if HAVE_PANDAS:
     #    if isinstance(input_, (pd.DataFrame, pd.Series)):
     #        input_ = input_.values
     if util_iter.isiterable(input_):
         # If input is already iterable do default behavior
         return func(self, input_, *args, **kwargs)
     else:
         # If input is scalar, wrap input, execute, and unpack result
         ret = func(self, (input_,), *args, **kwargs)
         if ret is not None:
             return ret[0]
Ejemplo n.º 2
0
 def wrp_asi2(self, *args, **kwargs):
     # Hack in case wrapping a function with varargs
     argx_list_ = [argx for argx in argx_list if argx < len(args)]
     __assert_param_consistency(args, argx_list_)
     if all([util_iter.isiterable(args[ix]) for ix in argx_list_]):
         # If input is already iterable do default behavior
         return func(self, *args, **kwargs)
     else:
         # If input is scalar, wrap input, execute, and unpack result
         args_wrapped = [(arg,) if ix in argx_list_ else arg
                         for ix, arg in enumerate(args)]
         ret = func(self, *args_wrapped, **kwargs)
         if ret is not None:
             return ret[0]
Ejemplo n.º 3
0
 def wrp_asivo(self, input_, *args, **kwargs):
     #import utool
     #if utool.DEBUG:
     #    print('[IN SIVO] args=%r' % (args,))
     #    print('[IN SIVO] kwargs=%r' % (kwargs,))
     if util_iter.isiterable(input_):
         # If input is already iterable do default behavior
         return func(self, input_, *args, **kwargs)
     else:
         # If input is scalar, wrap input, execute, and unpack result
         result = func(self, (input_,), *args, **kwargs)
         # The output length could be 0 on a scalar input
         if len(result) == 0:
             return []
         else:
             assert len(result) == 1, 'error in asivo'
             return result[0]
Ejemplo n.º 4
0
def __assert_param_consistency(args, argx_list_):
    """
    debugging function for accepts_scalar_input2
    checks to make sure all the iterable inputs are of the same length
    """
    if util_arg.NO_ASSERTS:
        return
    if len(argx_list_) == 0:
        return True
    argx_flags = [util_iter.isiterable(args[argx]) for argx in argx_list_]
    try:
        assert all([argx_flags[0] == flag for flag in argx_flags]), (
            'invalid mixing of iterable and scalar inputs')
    except AssertionError as ex:
        print('!!! ASSERTION ERROR IN UTIL_DECOR !!!')
        for argx in argx_list_:
            print('args[%d] = %r' % (argx, args[argx]))
        raise ex
Ejemplo n.º 5
0
def assert_scalar_list(list_):
    if util_arg.NO_ASSERTS:
        return
    for count, item in enumerate(list_):
        assert not util_iter.isiterable(item), 'count=%r, item=%r is iterable!' % (count, item)
Ejemplo n.º 6
0
def assert_scalar_list(list_):
    if util_arg.NO_ASSERTS:
        return
    for count, item in enumerate(list_):
        assert not util_iter.isiterable(
            item), 'count=%r, item=%r is iterable!' % (count, item)