def pp_options_list(keys, width=80, _print=False): """ Builds a concise listing of available options, grouped by prefix """ from textwrap import wrap from itertools import groupby def pp(name, ks): pfx = (name + '.[' if name else '') ls = wrap(', '.join(ks), width, initial_indent=pfx, subsequent_indent=' ' * len(pfx), break_long_words=False) if ls and ls[-1] and name: ls[-1] = ls[-1] + ']' return ls ls = [] singles = [x for x in sorted(keys) if x.find('.') < 0] if singles: ls += pp('', singles) keys = [x for x in keys if x.find('.') >= 0] for k, g in groupby(sorted(keys), lambda x: x[:x.rfind('.')]): ks = [x[len(k) + 1:] for x in list(g)] ls += pp(k, ks) s = '\n'.join(ls) if _print: print(s) else: return s
def pp_options_list(keys, width=80, _print=False): """ Builds a concise listing of available options, grouped by prefix """ from textwrap import wrap from itertools import groupby def pp(name, ks): pfx = (name + '.[' if name else '') ls = wrap(', '.join(ks), width, initial_indent=pfx, subsequent_indent=' ' * len(pfx), break_long_words=False) if ls and ls[-1] and name: ls[-1] = ls[-1] + ']' return ls ls = [] singles = [x for x in sorted(keys) if x.find('.') < 0] if singles: ls += pp('', singles) keys = [x for x in keys if x.find('.') >= 0] for k, g in groupby(sorted(keys), lambda x: x[:x.rfind('.')]): ks = [x[len(k) + 1:] for x in list(g)] ls += pp(k, ks) s = '\n'.join(ls) if _print: print s else: return s
def inner(x): if isinstance(_type,(tuple,list)) : if not any([isinstance(x,t) for t in _type]): from pandas.core.common import pprint_thing as pp pp_values = list(map(pp, _type)) raise ValueError("Value must be an instance of %s" % pp("|".join(pp_values))) elif not isinstance(x, _type): raise ValueError("Value must be an instance of '%s'" % str(_type))
def inner(x): if isinstance(_type,(tuple,list)) : if not any([isinstance(x,t) for t in _type]): from pandas.core.common import pprint_thing as pp pp_values = map(pp, _type) raise ValueError("Value must be an instance of %s" % pp("|".join(pp_values))) elif not isinstance(x, _type): raise ValueError("Value must be an instance of '%s'" % str(_type))
def inner(x): from pandas.core.common import pprint_thing as pp if x not in legal_values: if not any([c(x) for c in callables]): pp_values = pp("|".join(lmap(pp, legal_values))) msg = "Value must be one of {0}".format(pp_values) if len(callables): msg += " or a callable" raise ValueError(msg)
def inner(x): from pandas.core.common import pprint_thing as pp if not x in legal_values: pp_values = map(pp, legal_values) raise ValueError("Value must be one of %s" % pp("|".join(pp_values)))
def inner(x): from pandas.core.common import pprint_thing as pp if not x in legal_values: pp_values = lmap(pp, legal_values) raise ValueError("Value must be one of %s" % pp("|".join(pp_values)))