repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
Erotemic/utool
utool/util_dict.py
dict_stack
def dict_stack(dict_list, key_prefix=''): r""" stacks values from two dicts into a new dict where the values are list of the input values. the keys are the same. DEPRICATE in favor of dict_stack2 Args: dict_list (list): list of dicts with similar keys Returns: dict dict_stacke...
python
def dict_stack(dict_list, key_prefix=''): r""" stacks values from two dicts into a new dict where the values are list of the input values. the keys are the same. DEPRICATE in favor of dict_stack2 Args: dict_list (list): list of dicts with similar keys Returns: dict dict_stacke...
[ "def", "dict_stack", "(", "dict_list", ",", "key_prefix", "=", "''", ")", ":", "r", "dict_stacked_", "=", "defaultdict", "(", "list", ")", "for", "dict_", "in", "dict_list", ":", "for", "key", ",", "val", "in", "six", ".", "iteritems", "(", "dict_", ")...
r""" stacks values from two dicts into a new dict where the values are list of the input values. the keys are the same. DEPRICATE in favor of dict_stack2 Args: dict_list (list): list of dicts with similar keys Returns: dict dict_stacked CommandLine: python -m utool.ut...
[ "r", "stacks", "values", "from", "two", "dicts", "into", "a", "new", "dict", "where", "the", "values", "are", "list", "of", "the", "input", "values", ".", "the", "keys", "are", "the", "same", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L332-L379
train
Erotemic/utool
utool/util_dict.py
dict_stack2
def dict_stack2(dict_list, key_suffix=None, default=None): """ Stacks vals from a list of dicts into a dict of lists. Inserts Nones in place of empty items to preserve order. Args: dict_list (list): list of dicts key_suffix (str): (default = None) Returns: dict: stacked_dic...
python
def dict_stack2(dict_list, key_suffix=None, default=None): """ Stacks vals from a list of dicts into a dict of lists. Inserts Nones in place of empty items to preserve order. Args: dict_list (list): list of dicts key_suffix (str): (default = None) Returns: dict: stacked_dic...
[ "def", "dict_stack2", "(", "dict_list", ",", "key_suffix", "=", "None", ",", "default", "=", "None", ")", ":", "if", "len", "(", "dict_list", ")", ">", "0", ":", "dict_list_", "=", "[", "map_dict_vals", "(", "lambda", "x", ":", "[", "x", "]", ",", ...
Stacks vals from a list of dicts into a dict of lists. Inserts Nones in place of empty items to preserve order. Args: dict_list (list): list of dicts key_suffix (str): (default = None) Returns: dict: stacked_dict Example: >>> # ENABLE_DOCTEST >>> # Usual case: ...
[ "Stacks", "vals", "from", "a", "list", "of", "dicts", "into", "a", "dict", "of", "lists", ".", "Inserts", "Nones", "in", "place", "of", "empty", "items", "to", "preserve", "order", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L382-L496
train
Erotemic/utool
utool/util_dict.py
invert_dict
def invert_dict(dict_, unique_vals=True): """ Reverses the keys and values in a dictionary. Set unique_vals to False if the values in the dict are not unique. Args: dict_ (dict_): dictionary unique_vals (bool): if False, inverted keys are returned in a list. Returns: dict: ...
python
def invert_dict(dict_, unique_vals=True): """ Reverses the keys and values in a dictionary. Set unique_vals to False if the values in the dict are not unique. Args: dict_ (dict_): dictionary unique_vals (bool): if False, inverted keys are returned in a list. Returns: dict: ...
[ "def", "invert_dict", "(", "dict_", ",", "unique_vals", "=", "True", ")", ":", "if", "unique_vals", ":", "inverted_items", "=", "[", "(", "val", ",", "key", ")", "for", "key", ",", "val", "in", "six", ".", "iteritems", "(", "dict_", ")", "]", "invert...
Reverses the keys and values in a dictionary. Set unique_vals to False if the values in the dict are not unique. Args: dict_ (dict_): dictionary unique_vals (bool): if False, inverted keys are returned in a list. Returns: dict: inverted_dict CommandLine: python -m utoo...
[ "Reverses", "the", "keys", "and", "values", "in", "a", "dictionary", ".", "Set", "unique_vals", "to", "False", "if", "the", "values", "in", "the", "dict", "are", "not", "unique", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L499-L550
train
Erotemic/utool
utool/util_dict.py
iter_all_dict_combinations_ordered
def iter_all_dict_combinations_ordered(varied_dict): """ Same as all_dict_combinations but preserves order """ tups_list = [[(key, val) for val in val_list] for (key, val_list) in six.iteritems(varied_dict)] dict_iter = (OrderedDict(tups) for tups in it.product(*tups_list)) retu...
python
def iter_all_dict_combinations_ordered(varied_dict): """ Same as all_dict_combinations but preserves order """ tups_list = [[(key, val) for val in val_list] for (key, val_list) in six.iteritems(varied_dict)] dict_iter = (OrderedDict(tups) for tups in it.product(*tups_list)) retu...
[ "def", "iter_all_dict_combinations_ordered", "(", "varied_dict", ")", ":", "tups_list", "=", "[", "[", "(", "key", ",", "val", ")", "for", "val", "in", "val_list", "]", "for", "(", "key", ",", "val_list", ")", "in", "six", ".", "iteritems", "(", "varied_...
Same as all_dict_combinations but preserves order
[ "Same", "as", "all_dict_combinations", "but", "preserves", "order" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L553-L560
train
Erotemic/utool
utool/util_dict.py
all_dict_combinations_lbls
def all_dict_combinations_lbls(varied_dict, remove_singles=True, allow_lone_singles=False): """ returns a label for each variation in a varydict. It tries to not be oververbose and returns only what parameters are varied in each label. CommandLine: python -m utool.util_dict --test-all_dict...
python
def all_dict_combinations_lbls(varied_dict, remove_singles=True, allow_lone_singles=False): """ returns a label for each variation in a varydict. It tries to not be oververbose and returns only what parameters are varied in each label. CommandLine: python -m utool.util_dict --test-all_dict...
[ "def", "all_dict_combinations_lbls", "(", "varied_dict", ",", "remove_singles", "=", "True", ",", "allow_lone_singles", "=", "False", ")", ":", "is_lone_single", "=", "all", "(", "[", "isinstance", "(", "val_list", ",", "(", "list", ",", "tuple", ")", ")", "...
returns a label for each variation in a varydict. It tries to not be oververbose and returns only what parameters are varied in each label. CommandLine: python -m utool.util_dict --test-all_dict_combinations_lbls python -m utool.util_dict --exec-all_dict_combinations_lbls:1 Example: ...
[ "returns", "a", "label", "for", "each", "variation", "in", "a", "varydict", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L617-L681
train
Erotemic/utool
utool/util_dict.py
build_conflict_dict
def build_conflict_dict(key_list, val_list): """ Builds dict where a list of values is associated with more than one key Args: key_list (list): val_list (list): Returns: dict: key_to_vals CommandLine: python -m utool.util_dict --test-build_conflict_dict Exampl...
python
def build_conflict_dict(key_list, val_list): """ Builds dict where a list of values is associated with more than one key Args: key_list (list): val_list (list): Returns: dict: key_to_vals CommandLine: python -m utool.util_dict --test-build_conflict_dict Exampl...
[ "def", "build_conflict_dict", "(", "key_list", ",", "val_list", ")", ":", "key_to_vals", "=", "defaultdict", "(", "list", ")", "for", "key", ",", "val", "in", "zip", "(", "key_list", ",", "val_list", ")", ":", "key_to_vals", "[", "key", "]", ".", "append...
Builds dict where a list of values is associated with more than one key Args: key_list (list): val_list (list): Returns: dict: key_to_vals CommandLine: python -m utool.util_dict --test-build_conflict_dict Example: >>> # ENABLE_DOCTEST >>> from utool.ut...
[ "Builds", "dict", "where", "a", "list", "of", "values", "is", "associated", "with", "more", "than", "one", "key" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L692-L724
train
Erotemic/utool
utool/util_dict.py
update_existing
def update_existing(dict1, dict2, copy=False, assert_exists=False, iswarning=False, alias_dict=None): r""" updates vals in dict1 using vals from dict2 only if the key is already in dict1. Args: dict1 (dict): dict2 (dict): copy (bool): if true modifies diction...
python
def update_existing(dict1, dict2, copy=False, assert_exists=False, iswarning=False, alias_dict=None): r""" updates vals in dict1 using vals from dict2 only if the key is already in dict1. Args: dict1 (dict): dict2 (dict): copy (bool): if true modifies diction...
[ "def", "update_existing", "(", "dict1", ",", "dict2", ",", "copy", "=", "False", ",", "assert_exists", "=", "False", ",", "iswarning", "=", "False", ",", "alias_dict", "=", "None", ")", ":", "r", "if", "assert_exists", ":", "try", ":", "assert_keys_are_sub...
r""" updates vals in dict1 using vals from dict2 only if the key is already in dict1. Args: dict1 (dict): dict2 (dict): copy (bool): if true modifies dictionary in place (default = False) assert_exists (bool): if True throws error if new key specified (default = False) ...
[ "r", "updates", "vals", "in", "dict1", "using", "vals", "from", "dict2", "only", "if", "the", "key", "is", "already", "in", "dict1", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L751-L796
train
Erotemic/utool
utool/util_dict.py
dict_update_newkeys
def dict_update_newkeys(dict_, dict2): """ Like dict.update, but does not overwrite items """ for key, val in six.iteritems(dict2): if key not in dict_: dict_[key] = val
python
def dict_update_newkeys(dict_, dict2): """ Like dict.update, but does not overwrite items """ for key, val in six.iteritems(dict2): if key not in dict_: dict_[key] = val
[ "def", "dict_update_newkeys", "(", "dict_", ",", "dict2", ")", ":", "for", "key", ",", "val", "in", "six", ".", "iteritems", "(", "dict2", ")", ":", "if", "key", "not", "in", "dict_", ":", "dict_", "[", "key", "]", "=", "val" ]
Like dict.update, but does not overwrite items
[ "Like", "dict", ".", "update", "but", "does", "not", "overwrite", "items" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L810-L814
train
Erotemic/utool
utool/util_dict.py
is_dicteq
def is_dicteq(dict1_, dict2_, almosteq_ok=True, verbose_err=True): """ Checks to see if dicts are the same. Performs recursion. Handles numpy """ import utool as ut assert len(dict1_) == len(dict2_), 'dicts are not of same length' try: for (key1, val1), (key2, val2) in zip(dict1_.items(), dict2_...
python
def is_dicteq(dict1_, dict2_, almosteq_ok=True, verbose_err=True): """ Checks to see if dicts are the same. Performs recursion. Handles numpy """ import utool as ut assert len(dict1_) == len(dict2_), 'dicts are not of same length' try: for (key1, val1), (key2, val2) in zip(dict1_.items(), dict2_...
[ "def", "is_dicteq", "(", "dict1_", ",", "dict2_", ",", "almosteq_ok", "=", "True", ",", "verbose_err", "=", "True", ")", ":", "import", "utool", "as", "ut", "assert", "len", "(", "dict1_", ")", "==", "len", "(", "dict2_", ")", ",", "'dicts are not of sam...
Checks to see if dicts are the same. Performs recursion. Handles numpy
[ "Checks", "to", "see", "if", "dicts", "are", "the", "same", ".", "Performs", "recursion", ".", "Handles", "numpy" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L817-L838
train
Erotemic/utool
utool/util_dict.py
dict_setdiff
def dict_setdiff(dict_, negative_keys): r""" returns a copy of dict_ without keys in the negative_keys list Args: dict_ (dict): negative_keys (list): """ keys = [key for key in six.iterkeys(dict_) if key not in set(negative_keys)] subdict_ = dict_subset(dict_, keys) ...
python
def dict_setdiff(dict_, negative_keys): r""" returns a copy of dict_ without keys in the negative_keys list Args: dict_ (dict): negative_keys (list): """ keys = [key for key in six.iterkeys(dict_) if key not in set(negative_keys)] subdict_ = dict_subset(dict_, keys) ...
[ "def", "dict_setdiff", "(", "dict_", ",", "negative_keys", ")", ":", "r", "keys", "=", "[", "key", "for", "key", "in", "six", ".", "iterkeys", "(", "dict_", ")", "if", "key", "not", "in", "set", "(", "negative_keys", ")", "]", "subdict_", "=", "dict_...
r""" returns a copy of dict_ without keys in the negative_keys list Args: dict_ (dict): negative_keys (list):
[ "r", "returns", "a", "copy", "of", "dict_", "without", "keys", "in", "the", "negative_keys", "list" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L877-L888
train
Erotemic/utool
utool/util_dict.py
delete_dict_keys
def delete_dict_keys(dict_, key_list): r""" Removes items from a dictionary inplace. Keys that do not exist are ignored. Args: dict_ (dict): dict like object with a __del__ attribute key_list (list): list of keys that specify the items to remove CommandLine: python -m utool...
python
def delete_dict_keys(dict_, key_list): r""" Removes items from a dictionary inplace. Keys that do not exist are ignored. Args: dict_ (dict): dict like object with a __del__ attribute key_list (list): list of keys that specify the items to remove CommandLine: python -m utool...
[ "def", "delete_dict_keys", "(", "dict_", ",", "key_list", ")", ":", "r", "invalid_keys", "=", "set", "(", "key_list", ")", "-", "set", "(", "dict_", ".", "keys", "(", ")", ")", "valid_keys", "=", "set", "(", "key_list", ")", "-", "invalid_keys", "for",...
r""" Removes items from a dictionary inplace. Keys that do not exist are ignored. Args: dict_ (dict): dict like object with a __del__ attribute key_list (list): list of keys that specify the items to remove CommandLine: python -m utool.util_dict --test-delete_dict_keys Exa...
[ "r", "Removes", "items", "from", "a", "dictionary", "inplace", ".", "Keys", "that", "do", "not", "exist", "are", "ignored", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L891-L919
train
Erotemic/utool
utool/util_dict.py
dict_take_gen
def dict_take_gen(dict_, keys, *d): r""" generate multiple values from a dictionary Args: dict_ (dict): keys (list): Varargs: d: if specified is default for key errors CommandLine: python -m utool.util_dict --test-dict_take_gen Example1: >>> # ENABLE_D...
python
def dict_take_gen(dict_, keys, *d): r""" generate multiple values from a dictionary Args: dict_ (dict): keys (list): Varargs: d: if specified is default for key errors CommandLine: python -m utool.util_dict --test-dict_take_gen Example1: >>> # ENABLE_D...
[ "def", "dict_take_gen", "(", "dict_", ",", "keys", ",", "*", "d", ")", ":", "r", "if", "isinstance", "(", "keys", ",", "six", ".", "string_types", ")", ":", "keys", "=", "keys", ".", "split", "(", "', '", ")", "if", "len", "(", "d", ")", "==", ...
r""" generate multiple values from a dictionary Args: dict_ (dict): keys (list): Varargs: d: if specified is default for key errors CommandLine: python -m utool.util_dict --test-dict_take_gen Example1: >>> # ENABLE_DOCTEST >>> from utool.util_dict ...
[ "r", "generate", "multiple", "values", "from", "a", "dictionary" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L925-L979
train
Erotemic/utool
utool/util_dict.py
dict_take
def dict_take(dict_, keys, *d): """ get multiple values from a dictionary """ try: return list(dict_take_gen(dict_, keys, *d)) except TypeError: return list(dict_take_gen(dict_, keys, *d))[0]
python
def dict_take(dict_, keys, *d): """ get multiple values from a dictionary """ try: return list(dict_take_gen(dict_, keys, *d)) except TypeError: return list(dict_take_gen(dict_, keys, *d))[0]
[ "def", "dict_take", "(", "dict_", ",", "keys", ",", "*", "d", ")", ":", "try", ":", "return", "list", "(", "dict_take_gen", "(", "dict_", ",", "keys", ",", "*", "d", ")", ")", "except", "TypeError", ":", "return", "list", "(", "dict_take_gen", "(", ...
get multiple values from a dictionary
[ "get", "multiple", "values", "from", "a", "dictionary" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L982-L987
train
Erotemic/utool
utool/util_dict.py
dict_take_pop
def dict_take_pop(dict_, keys, *d): """ like dict_take but pops values off CommandLine: python -m utool.util_dict --test-dict_take_pop Example1: >>> # ENABLE_DOCTEST >>> from utool.util_dict import * # NOQA >>> import utool as ut >>> dict_ = {1: 'a', 'other': None,...
python
def dict_take_pop(dict_, keys, *d): """ like dict_take but pops values off CommandLine: python -m utool.util_dict --test-dict_take_pop Example1: >>> # ENABLE_DOCTEST >>> from utool.util_dict import * # NOQA >>> import utool as ut >>> dict_ = {1: 'a', 'other': None,...
[ "def", "dict_take_pop", "(", "dict_", ",", "keys", ",", "*", "d", ")", ":", "if", "len", "(", "d", ")", "==", "0", ":", "return", "[", "dict_", ".", "pop", "(", "key", ")", "for", "key", "in", "keys", "]", "elif", "len", "(", "d", ")", "==", ...
like dict_take but pops values off CommandLine: python -m utool.util_dict --test-dict_take_pop Example1: >>> # ENABLE_DOCTEST >>> from utool.util_dict import * # NOQA >>> import utool as ut >>> dict_ = {1: 'a', 'other': None, 'another': 'foo', 2: 'b', 3: 'c'} >...
[ "like", "dict_take", "but", "pops", "values", "off" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1014-L1057
train
Erotemic/utool
utool/util_dict.py
dict_assign
def dict_assign(dict_, keys, vals): """ simple method for assigning or setting values with a similar interface to dict_take """ for key, val in zip(keys, vals): dict_[key] = val
python
def dict_assign(dict_, keys, vals): """ simple method for assigning or setting values with a similar interface to dict_take """ for key, val in zip(keys, vals): dict_[key] = val
[ "def", "dict_assign", "(", "dict_", ",", "keys", ",", "vals", ")", ":", "for", "key", ",", "val", "in", "zip", "(", "keys", ",", "vals", ")", ":", "dict_", "[", "key", "]", "=", "val" ]
simple method for assigning or setting values with a similar interface to dict_take
[ "simple", "method", "for", "assigning", "or", "setting", "values", "with", "a", "similar", "interface", "to", "dict_take" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1060-L1064
train
Erotemic/utool
utool/util_dict.py
dict_where_len0
def dict_where_len0(dict_): """ Accepts a dict of lists. Returns keys that have vals with no length """ keys = np.array(dict_.keys()) flags = np.array(list(map(len, dict_.values()))) == 0 indices = np.where(flags)[0] return keys[indices]
python
def dict_where_len0(dict_): """ Accepts a dict of lists. Returns keys that have vals with no length """ keys = np.array(dict_.keys()) flags = np.array(list(map(len, dict_.values()))) == 0 indices = np.where(flags)[0] return keys[indices]
[ "def", "dict_where_len0", "(", "dict_", ")", ":", "keys", "=", "np", ".", "array", "(", "dict_", ".", "keys", "(", ")", ")", "flags", "=", "np", ".", "array", "(", "list", "(", "map", "(", "len", ",", "dict_", ".", "values", "(", ")", ")", ")",...
Accepts a dict of lists. Returns keys that have vals with no length
[ "Accepts", "a", "dict", "of", "lists", ".", "Returns", "keys", "that", "have", "vals", "with", "no", "length" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1067-L1074
train
Erotemic/utool
utool/util_dict.py
dict_hist
def dict_hist(item_list, weight_list=None, ordered=False, labels=None): r""" Builds a histogram of items in item_list Args: item_list (list): list with hashable items (usually containing duplicates) Returns: dict : dictionary where the keys are items in item_list, and the values ...
python
def dict_hist(item_list, weight_list=None, ordered=False, labels=None): r""" Builds a histogram of items in item_list Args: item_list (list): list with hashable items (usually containing duplicates) Returns: dict : dictionary where the keys are items in item_list, and the values ...
[ "def", "dict_hist", "(", "item_list", ",", "weight_list", "=", "None", ",", "ordered", "=", "False", ",", "labels", "=", "None", ")", ":", "r", "if", "labels", "is", "None", ":", "hist_", "=", "defaultdict", "(", "int", ")", "else", ":", "hist_", "="...
r""" Builds a histogram of items in item_list Args: item_list (list): list with hashable items (usually containing duplicates) Returns: dict : dictionary where the keys are items in item_list, and the values are the number of times the item appears in item_list. CommandLine:...
[ "r", "Builds", "a", "histogram", "of", "items", "in", "item_list" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1236-L1279
train
Erotemic/utool
utool/util_dict.py
dict_isect_combine
def dict_isect_combine(dict1, dict2, combine_op=op.add): """ Intersection of dict keys and combination of dict values """ keys3 = set(dict1.keys()).intersection(set(dict2.keys())) dict3 = {key: combine_op(dict1[key], dict2[key]) for key in keys3} return dict3
python
def dict_isect_combine(dict1, dict2, combine_op=op.add): """ Intersection of dict keys and combination of dict values """ keys3 = set(dict1.keys()).intersection(set(dict2.keys())) dict3 = {key: combine_op(dict1[key], dict2[key]) for key in keys3} return dict3
[ "def", "dict_isect_combine", "(", "dict1", ",", "dict2", ",", "combine_op", "=", "op", ".", "add", ")", ":", "keys3", "=", "set", "(", "dict1", ".", "keys", "(", ")", ")", ".", "intersection", "(", "set", "(", "dict2", ".", "keys", "(", ")", ")", ...
Intersection of dict keys and combination of dict values
[ "Intersection", "of", "dict", "keys", "and", "combination", "of", "dict", "values" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1438-L1442
train
Erotemic/utool
utool/util_dict.py
dict_union_combine
def dict_union_combine(dict1, dict2, combine_op=op.add, default=util_const.NoParam, default2=util_const.NoParam): """ Combine of dict keys and uses dfault value when key does not exist CAREFUL WHEN USING THIS WITH REDUCE. Use dict_stack2 instead """ key...
python
def dict_union_combine(dict1, dict2, combine_op=op.add, default=util_const.NoParam, default2=util_const.NoParam): """ Combine of dict keys and uses dfault value when key does not exist CAREFUL WHEN USING THIS WITH REDUCE. Use dict_stack2 instead """ key...
[ "def", "dict_union_combine", "(", "dict1", ",", "dict2", ",", "combine_op", "=", "op", ".", "add", ",", "default", "=", "util_const", ".", "NoParam", ",", "default2", "=", "util_const", ".", "NoParam", ")", ":", "keys3", "=", "set", "(", "dict1", ".", ...
Combine of dict keys and uses dfault value when key does not exist CAREFUL WHEN USING THIS WITH REDUCE. Use dict_stack2 instead
[ "Combine", "of", "dict", "keys", "and", "uses", "dfault", "value", "when", "key", "does", "not", "exist" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1445-L1461
train
Erotemic/utool
utool/util_dict.py
dict_filter_nones
def dict_filter_nones(dict_): r""" Removes None values Args: dict_ (dict): a dictionary Returns: dict: CommandLine: python -m utool.util_dict --exec-dict_filter_nones Example: >>> # DISABLE_DOCTEST >>> # UNSTABLE_DOCTEST >>> # fails on python ...
python
def dict_filter_nones(dict_): r""" Removes None values Args: dict_ (dict): a dictionary Returns: dict: CommandLine: python -m utool.util_dict --exec-dict_filter_nones Example: >>> # DISABLE_DOCTEST >>> # UNSTABLE_DOCTEST >>> # fails on python ...
[ "def", "dict_filter_nones", "(", "dict_", ")", ":", "r", "dict2_", "=", "{", "key", ":", "val", "for", "key", ",", "val", "in", "six", ".", "iteritems", "(", "dict_", ")", "if", "val", "is", "not", "None", "}", "return", "dict2_" ]
r""" Removes None values Args: dict_ (dict): a dictionary Returns: dict: CommandLine: python -m utool.util_dict --exec-dict_filter_nones Example: >>> # DISABLE_DOCTEST >>> # UNSTABLE_DOCTEST >>> # fails on python 3 because of dict None order ...
[ "r", "Removes", "None", "values" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1474-L1504
train
Erotemic/utool
utool/util_dict.py
groupby_tags
def groupby_tags(item_list, tags_list): r""" case where an item can belong to multiple groups Args: item_list (list): tags_list (list): Returns: dict: groupid_to_items CommandLine: python -m utool.util_dict --test-groupby_tags Example: >>> # ENABLE_DOC...
python
def groupby_tags(item_list, tags_list): r""" case where an item can belong to multiple groups Args: item_list (list): tags_list (list): Returns: dict: groupid_to_items CommandLine: python -m utool.util_dict --test-groupby_tags Example: >>> # ENABLE_DOC...
[ "def", "groupby_tags", "(", "item_list", ",", "tags_list", ")", ":", "r", "groupid_to_items", "=", "defaultdict", "(", "list", ")", "for", "tags", ",", "item", "in", "zip", "(", "tags_list", ",", "item_list", ")", ":", "for", "tag", "in", "tags", ":", ...
r""" case where an item can belong to multiple groups Args: item_list (list): tags_list (list): Returns: dict: groupid_to_items CommandLine: python -m utool.util_dict --test-groupby_tags Example: >>> # ENABLE_DOCTEST >>> from utool.util_dict import...
[ "r", "case", "where", "an", "item", "can", "belong", "to", "multiple", "groups" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1507-L1552
train
Erotemic/utool
utool/util_dict.py
group_pairs
def group_pairs(pair_list): """ Groups a list of items using the first element in each pair as the item and the second element as the groupid. Args: pair_list (list): list of 2-tuples (item, groupid) Returns: dict: groupid_to_items: maps a groupid to a list of items SeeAlso: ...
python
def group_pairs(pair_list): """ Groups a list of items using the first element in each pair as the item and the second element as the groupid. Args: pair_list (list): list of 2-tuples (item, groupid) Returns: dict: groupid_to_items: maps a groupid to a list of items SeeAlso: ...
[ "def", "group_pairs", "(", "pair_list", ")", ":", "groupid_to_items", "=", "defaultdict", "(", "list", ")", "for", "item", ",", "groupid", "in", "pair_list", ":", "groupid_to_items", "[", "groupid", "]", ".", "append", "(", "item", ")", "return", "groupid_to...
Groups a list of items using the first element in each pair as the item and the second element as the groupid. Args: pair_list (list): list of 2-tuples (item, groupid) Returns: dict: groupid_to_items: maps a groupid to a list of items SeeAlso: group_items
[ "Groups", "a", "list", "of", "items", "using", "the", "first", "element", "in", "each", "pair", "as", "the", "item", "and", "the", "second", "element", "as", "the", "groupid", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1560-L1579
train
Erotemic/utool
utool/util_dict.py
group_items
def group_items(items, by=None, sorted_=True): """ Groups a list of items by group id. Args: items (list): a list of the values to be grouped. if `by` is None, then each item is assumed to be a (groupid, value) pair. by (list): a corresponding list to group items by....
python
def group_items(items, by=None, sorted_=True): """ Groups a list of items by group id. Args: items (list): a list of the values to be grouped. if `by` is None, then each item is assumed to be a (groupid, value) pair. by (list): a corresponding list to group items by....
[ "def", "group_items", "(", "items", ",", "by", "=", "None", ",", "sorted_", "=", "True", ")", ":", "if", "by", "is", "not", "None", ":", "pairs", "=", "list", "(", "zip", "(", "by", ",", "items", ")", ")", "if", "sorted_", ":", "try", ":", "pai...
Groups a list of items by group id. Args: items (list): a list of the values to be grouped. if `by` is None, then each item is assumed to be a (groupid, value) pair. by (list): a corresponding list to group items by. if specified, these are used as the keys to gr...
[ "Groups", "a", "list", "of", "items", "by", "group", "id", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1582-L1635
train
Erotemic/utool
utool/util_dict.py
hierarchical_group_items
def hierarchical_group_items(item_list, groupids_list): """ Generalization of group_item. Convert a flast list of ids into a heirarchical dictionary. TODO: move to util_dict Reference: http://stackoverflow.com/questions/10193235/python-translate-a-table-to-a-hierarchical-dictionary Args: ...
python
def hierarchical_group_items(item_list, groupids_list): """ Generalization of group_item. Convert a flast list of ids into a heirarchical dictionary. TODO: move to util_dict Reference: http://stackoverflow.com/questions/10193235/python-translate-a-table-to-a-hierarchical-dictionary Args: ...
[ "def", "hierarchical_group_items", "(", "item_list", ",", "groupids_list", ")", ":", "num_groups", "=", "len", "(", "groupids_list", ")", "leaf_type", "=", "partial", "(", "defaultdict", ",", "list", ")", "if", "num_groups", ">", "1", ":", "node_type", "=", ...
Generalization of group_item. Convert a flast list of ids into a heirarchical dictionary. TODO: move to util_dict Reference: http://stackoverflow.com/questions/10193235/python-translate-a-table-to-a-hierarchical-dictionary Args: item_list (list): groupids_list (list): Command...
[ "Generalization", "of", "group_item", ".", "Convert", "a", "flast", "list", "of", "ids", "into", "a", "heirarchical", "dictionary", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1638-L1719
train
Erotemic/utool
utool/util_dict.py
hierarchical_map_vals
def hierarchical_map_vals(func, node, max_depth=None, depth=0): """ node is a dict tree like structure with leaves of type list TODO: move to util_dict CommandLine: python -m utool.util_dict --exec-hierarchical_map_vals Example: >>> # ENABLE_DOCTEST >>> from utool.util_dic...
python
def hierarchical_map_vals(func, node, max_depth=None, depth=0): """ node is a dict tree like structure with leaves of type list TODO: move to util_dict CommandLine: python -m utool.util_dict --exec-hierarchical_map_vals Example: >>> # ENABLE_DOCTEST >>> from utool.util_dic...
[ "def", "hierarchical_map_vals", "(", "func", ",", "node", ",", "max_depth", "=", "None", ",", "depth", "=", "0", ")", ":", "if", "not", "hasattr", "(", "node", ",", "'items'", ")", ":", "return", "func", "(", "node", ")", "elif", "max_depth", "is", "...
node is a dict tree like structure with leaves of type list TODO: move to util_dict CommandLine: python -m utool.util_dict --exec-hierarchical_map_vals Example: >>> # ENABLE_DOCTEST >>> from utool.util_dict import * # NOQA >>> import utool as ut >>> item_list ...
[ "node", "is", "a", "dict", "tree", "like", "structure", "with", "leaves", "of", "type", "list" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1750-L1821
train
Erotemic/utool
utool/util_dict.py
sort_dict
def sort_dict(dict_, part='keys', key=None, reverse=False): """ sorts a dictionary by its values or its keys Args: dict_ (dict_): a dictionary part (str): specifies to sort by keys or values key (Optional[func]): a function that takes specified part and returns a sortab...
python
def sort_dict(dict_, part='keys', key=None, reverse=False): """ sorts a dictionary by its values or its keys Args: dict_ (dict_): a dictionary part (str): specifies to sort by keys or values key (Optional[func]): a function that takes specified part and returns a sortab...
[ "def", "sort_dict", "(", "dict_", ",", "part", "=", "'keys'", ",", "key", "=", "None", ",", "reverse", "=", "False", ")", ":", "if", "part", "==", "'keys'", ":", "index", "=", "0", "elif", "part", "in", "{", "'vals'", ",", "'values'", "}", ":", "...
sorts a dictionary by its values or its keys Args: dict_ (dict_): a dictionary part (str): specifies to sort by keys or values key (Optional[func]): a function that takes specified part and returns a sortable value reverse (bool): (Defaults to False) - True for descindi...
[ "sorts", "a", "dictionary", "by", "its", "values", "or", "its", "keys" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L1955-L2003
train
Erotemic/utool
utool/util_dict.py
order_dict_by
def order_dict_by(dict_, key_order): r""" Reorders items in a dictionary according to a custom key order Args: dict_ (dict_): a dictionary key_order (list): custom key order Returns: OrderedDict: sorted_dict CommandLine: python -m utool.util_dict --exec-order_dict...
python
def order_dict_by(dict_, key_order): r""" Reorders items in a dictionary according to a custom key order Args: dict_ (dict_): a dictionary key_order (list): custom key order Returns: OrderedDict: sorted_dict CommandLine: python -m utool.util_dict --exec-order_dict...
[ "def", "order_dict_by", "(", "dict_", ",", "key_order", ")", ":", "r", "dict_keys", "=", "set", "(", "dict_", ".", "keys", "(", ")", ")", "other_keys", "=", "dict_keys", "-", "set", "(", "key_order", ")", "key_order", "=", "it", ".", "chain", "(", "k...
r""" Reorders items in a dictionary according to a custom key order Args: dict_ (dict_): a dictionary key_order (list): custom key order Returns: OrderedDict: sorted_dict CommandLine: python -m utool.util_dict --exec-order_dict_by Example: >>> # ENABLE_DO...
[ "r", "Reorders", "items", "in", "a", "dictionary", "according", "to", "a", "custom", "key", "order" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L2006-L2038
train
Erotemic/utool
utool/util_dict.py
iteritems_sorted
def iteritems_sorted(dict_): """ change to iteritems ordered """ if isinstance(dict_, OrderedDict): return six.iteritems(dict_) else: return iter(sorted(six.iteritems(dict_)))
python
def iteritems_sorted(dict_): """ change to iteritems ordered """ if isinstance(dict_, OrderedDict): return six.iteritems(dict_) else: return iter(sorted(six.iteritems(dict_)))
[ "def", "iteritems_sorted", "(", "dict_", ")", ":", "if", "isinstance", "(", "dict_", ",", "OrderedDict", ")", ":", "return", "six", ".", "iteritems", "(", "dict_", ")", "else", ":", "return", "iter", "(", "sorted", "(", "six", ".", "iteritems", "(", "d...
change to iteritems ordered
[ "change", "to", "iteritems", "ordered" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L2041-L2046
train
Erotemic/utool
utool/util_dict.py
flatten_dict_vals
def flatten_dict_vals(dict_): """ Flattens only values in a heirarchical dictionary, keys are nested. """ if isinstance(dict_, dict): return dict([ ((key, augkey), augval) for key, val in dict_.items() for augkey, augval in flatten_dict_vals(val).items() ...
python
def flatten_dict_vals(dict_): """ Flattens only values in a heirarchical dictionary, keys are nested. """ if isinstance(dict_, dict): return dict([ ((key, augkey), augval) for key, val in dict_.items() for augkey, augval in flatten_dict_vals(val).items() ...
[ "def", "flatten_dict_vals", "(", "dict_", ")", ":", "if", "isinstance", "(", "dict_", ",", "dict", ")", ":", "return", "dict", "(", "[", "(", "(", "key", ",", "augkey", ")", ",", "augval", ")", "for", "key", ",", "val", "in", "dict_", ".", "items",...
Flattens only values in a heirarchical dictionary, keys are nested.
[ "Flattens", "only", "values", "in", "a", "heirarchical", "dictionary", "keys", "are", "nested", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L2054-L2065
train
Erotemic/utool
utool/util_dict.py
depth_atleast
def depth_atleast(list_, depth): r""" Returns if depth of list is at least ``depth`` Args: list_ (list): depth (int): Returns: bool: True CommandLine: python -m utool.util_dict --exec-depth_atleast --show Example: >>> # DISABLE_DOCTEST >>> from...
python
def depth_atleast(list_, depth): r""" Returns if depth of list is at least ``depth`` Args: list_ (list): depth (int): Returns: bool: True CommandLine: python -m utool.util_dict --exec-depth_atleast --show Example: >>> # DISABLE_DOCTEST >>> from...
[ "def", "depth_atleast", "(", "list_", ",", "depth", ")", ":", "r", "if", "depth", "==", "0", ":", "return", "True", "else", ":", "try", ":", "return", "all", "(", "[", "depth_atleast", "(", "item", ",", "depth", "-", "1", ")", "for", "item", "in", ...
r""" Returns if depth of list is at least ``depth`` Args: list_ (list): depth (int): Returns: bool: True CommandLine: python -m utool.util_dict --exec-depth_atleast --show Example: >>> # DISABLE_DOCTEST >>> from utool.util_dict import * # NOQA ...
[ "r", "Returns", "if", "depth", "of", "list", "is", "at", "least", "depth" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dict.py#L2096-L2125
train
glormph/msstitch
src/app/actions/mzidtsv/splitmerge.py
get_splitcolnr
def get_splitcolnr(header, bioset, splitcol): """Returns column nr on which to split PSM table. Chooses from flags given via bioset and splitcol""" if bioset: return header.index(mzidtsvdata.HEADER_SETNAME) elif splitcol is not None: return splitcol - 1 else: raise RuntimeErr...
python
def get_splitcolnr(header, bioset, splitcol): """Returns column nr on which to split PSM table. Chooses from flags given via bioset and splitcol""" if bioset: return header.index(mzidtsvdata.HEADER_SETNAME) elif splitcol is not None: return splitcol - 1 else: raise RuntimeErr...
[ "def", "get_splitcolnr", "(", "header", ",", "bioset", ",", "splitcol", ")", ":", "if", "bioset", ":", "return", "header", ".", "index", "(", "mzidtsvdata", ".", "HEADER_SETNAME", ")", "elif", "splitcol", "is", "not", "None", ":", "return", "splitcol", "-"...
Returns column nr on which to split PSM table. Chooses from flags given via bioset and splitcol
[ "Returns", "column", "nr", "on", "which", "to", "split", "PSM", "table", ".", "Chooses", "from", "flags", "given", "via", "bioset", "and", "splitcol" ]
ded7e5cbd813d7797dc9d42805778266e59ff042
https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/mzidtsv/splitmerge.py#L14-L22
train
glormph/msstitch
src/app/actions/mzidtsv/splitmerge.py
generate_psms_split
def generate_psms_split(fn, oldheader, bioset, splitcol): """Loops PSMs and outputs dictionaries passed to writer. Dictionaries contain the PSMs and info to which split pool the respective PSM belongs""" try: splitcolnr = get_splitcolnr(oldheader, bioset, splitcol) except IndexError: ...
python
def generate_psms_split(fn, oldheader, bioset, splitcol): """Loops PSMs and outputs dictionaries passed to writer. Dictionaries contain the PSMs and info to which split pool the respective PSM belongs""" try: splitcolnr = get_splitcolnr(oldheader, bioset, splitcol) except IndexError: ...
[ "def", "generate_psms_split", "(", "fn", ",", "oldheader", ",", "bioset", ",", "splitcol", ")", ":", "try", ":", "splitcolnr", "=", "get_splitcolnr", "(", "oldheader", ",", "bioset", ",", "splitcol", ")", "except", "IndexError", ":", "raise", "RuntimeError", ...
Loops PSMs and outputs dictionaries passed to writer. Dictionaries contain the PSMs and info to which split pool the respective PSM belongs
[ "Loops", "PSMs", "and", "outputs", "dictionaries", "passed", "to", "writer", ".", "Dictionaries", "contain", "the", "PSMs", "and", "info", "to", "which", "split", "pool", "the", "respective", "PSM", "belongs" ]
ded7e5cbd813d7797dc9d42805778266e59ff042
https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/mzidtsv/splitmerge.py#L25-L38
train
Erotemic/utool
utool/_internal/randomwrap.py
rnumlistwithoutreplacement
def rnumlistwithoutreplacement(min, max): """Returns a randomly ordered list of the integers between min and max""" if checkquota() < 1: raise Exception("Your www.random.org quota has already run out.") requestparam = build_request_parameterNR(min, max) request = urllib.request.Request(requestpa...
python
def rnumlistwithoutreplacement(min, max): """Returns a randomly ordered list of the integers between min and max""" if checkquota() < 1: raise Exception("Your www.random.org quota has already run out.") requestparam = build_request_parameterNR(min, max) request = urllib.request.Request(requestpa...
[ "def", "rnumlistwithoutreplacement", "(", "min", ",", "max", ")", ":", "if", "checkquota", "(", ")", "<", "1", ":", "raise", "Exception", "(", "\"Your www.random.org quota has already run out.\"", ")", "requestparam", "=", "build_request_parameterNR", "(", "min", ",...
Returns a randomly ordered list of the integers between min and max
[ "Returns", "a", "randomly", "ordered", "list", "of", "the", "integers", "between", "min", "and", "max" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/randomwrap.py#L54-L63
train
Erotemic/utool
utool/_internal/randomwrap.py
rnumlistwithreplacement
def rnumlistwithreplacement(howmany, max, min=0): """Returns a list of howmany integers with a maximum value = max. The minimum value defaults to zero.""" if checkquota() < 1: raise Exception("Your www.random.org quota has already run out.") requestparam = build_request_parameterWR(howmany, min,...
python
def rnumlistwithreplacement(howmany, max, min=0): """Returns a list of howmany integers with a maximum value = max. The minimum value defaults to zero.""" if checkquota() < 1: raise Exception("Your www.random.org quota has already run out.") requestparam = build_request_parameterWR(howmany, min,...
[ "def", "rnumlistwithreplacement", "(", "howmany", ",", "max", ",", "min", "=", "0", ")", ":", "if", "checkquota", "(", ")", "<", "1", ":", "raise", "Exception", "(", "\"Your www.random.org quota has already run out.\"", ")", "requestparam", "=", "build_request_par...
Returns a list of howmany integers with a maximum value = max. The minimum value defaults to zero.
[ "Returns", "a", "list", "of", "howmany", "integers", "with", "a", "maximum", "value", "=", "max", ".", "The", "minimum", "value", "defaults", "to", "zero", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/randomwrap.py#L75-L85
train
Erotemic/utool
utool/util_num.py
num_fmt
def num_fmt(num, max_digits=None): r""" Weird function. Not very well written. Very special case-y Args: num (int or float): max_digits (int): Returns: str: CommandLine: python -m utool.util_num --test-num_fmt Example: >>> # DISABLE_DOCTEST >>>...
python
def num_fmt(num, max_digits=None): r""" Weird function. Not very well written. Very special case-y Args: num (int or float): max_digits (int): Returns: str: CommandLine: python -m utool.util_num --test-num_fmt Example: >>> # DISABLE_DOCTEST >>>...
[ "def", "num_fmt", "(", "num", ",", "max_digits", "=", "None", ")", ":", "r", "if", "num", "is", "None", ":", "return", "'None'", "def", "num_in_mag", "(", "num", ",", "mag", ")", ":", "return", "mag", ">", "num", "and", "num", ">", "(", "-", "1",...
r""" Weird function. Not very well written. Very special case-y Args: num (int or float): max_digits (int): Returns: str: CommandLine: python -m utool.util_num --test-num_fmt Example: >>> # DISABLE_DOCTEST >>> from utool.util_num import * # NOQA ...
[ "r", "Weird", "function", ".", "Not", "very", "well", "written", ".", "Very", "special", "case", "-", "y" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_num.py#L82-L133
train
YuriyGuts/pygoose
pygoose/kg/project.py
Project.load_feature_lists
def load_feature_lists(self, feature_lists): """ Load pickled features for train and test sets, assuming they are saved in the `features` folder along with their column names. Args: feature_lists: A list containing the names of the feature lists to load. Returns: ...
python
def load_feature_lists(self, feature_lists): """ Load pickled features for train and test sets, assuming they are saved in the `features` folder along with their column names. Args: feature_lists: A list containing the names of the feature lists to load. Returns: ...
[ "def", "load_feature_lists", "(", "self", ",", "feature_lists", ")", ":", "column_names", "=", "[", "]", "feature_ranges", "=", "[", "]", "running_feature_count", "=", "0", "for", "list_id", "in", "feature_lists", ":", "feature_list_names", "=", "load_lines", "(...
Load pickled features for train and test sets, assuming they are saved in the `features` folder along with their column names. Args: feature_lists: A list containing the names of the feature lists to load. Returns: A tuple containing 3 items: train dataframe, test dataf...
[ "Load", "pickled", "features", "for", "train", "and", "test", "sets", "assuming", "they", "are", "saved", "in", "the", "features", "folder", "along", "with", "their", "column", "names", "." ]
4d9b8827c6d6c4b79949d1cd653393498c0bb3c2
https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/project.py#L89-L126
train
YuriyGuts/pygoose
pygoose/kg/project.py
Project.save_features
def save_features(self, train_features, test_features, feature_names, feature_list_id): """ Save features for the training and test sets to disk, along with their metadata. Args: train_features: A NumPy array of features for the training set. test_features: A NumPy array...
python
def save_features(self, train_features, test_features, feature_names, feature_list_id): """ Save features for the training and test sets to disk, along with their metadata. Args: train_features: A NumPy array of features for the training set. test_features: A NumPy array...
[ "def", "save_features", "(", "self", ",", "train_features", ",", "test_features", ",", "feature_names", ",", "feature_list_id", ")", ":", "self", ".", "save_feature_names", "(", "feature_names", ",", "feature_list_id", ")", "self", ".", "save_feature_list", "(", "...
Save features for the training and test sets to disk, along with their metadata. Args: train_features: A NumPy array of features for the training set. test_features: A NumPy array of features for the test set. feature_names: A list containing the names of the feature columns...
[ "Save", "features", "for", "the", "training", "and", "test", "sets", "to", "disk", "along", "with", "their", "metadata", "." ]
4d9b8827c6d6c4b79949d1cd653393498c0bb3c2
https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/project.py#L128-L141
train
YuriyGuts/pygoose
pygoose/kg/project.py
Project.discover
def discover(): """ Automatically discover the paths to various data folders in this project and compose a Project instance. Returns: A constructed Project object. Raises: ValueError: if the paths could not be figured out automatically. I...
python
def discover(): """ Automatically discover the paths to various data folders in this project and compose a Project instance. Returns: A constructed Project object. Raises: ValueError: if the paths could not be figured out automatically. I...
[ "def", "discover", "(", ")", ":", "candidate_path", "=", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "join", "(", "os", ".", "curdir", ",", "os", ".", "pardir", ",", "'data'", ")", ")", "if", "os", ".", "path", ".", "exists", ...
Automatically discover the paths to various data folders in this project and compose a Project instance. Returns: A constructed Project object. Raises: ValueError: if the paths could not be figured out automatically. In this case, you have to create a Pr...
[ "Automatically", "discover", "the", "paths", "to", "various", "data", "folders", "in", "this", "project", "and", "compose", "a", "Project", "instance", "." ]
4d9b8827c6d6c4b79949d1cd653393498c0bb3c2
https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/project.py#L170-L199
train
YuriyGuts/pygoose
pygoose/kg/project.py
Project.init
def init(): """ Creates the project infrastructure assuming the current directory is the project root. Typically used as a command-line entry point called by `pygoose init`. """ project = Project(os.path.abspath(os.getcwd())) paths_to_create = [ project.data_...
python
def init(): """ Creates the project infrastructure assuming the current directory is the project root. Typically used as a command-line entry point called by `pygoose init`. """ project = Project(os.path.abspath(os.getcwd())) paths_to_create = [ project.data_...
[ "def", "init", "(", ")", ":", "project", "=", "Project", "(", "os", ".", "path", ".", "abspath", "(", "os", ".", "getcwd", "(", ")", ")", ")", "paths_to_create", "=", "[", "project", ".", "data_dir", ",", "project", ".", "notebooks_dir", ",", "projec...
Creates the project infrastructure assuming the current directory is the project root. Typically used as a command-line entry point called by `pygoose init`.
[ "Creates", "the", "project", "infrastructure", "assuming", "the", "current", "directory", "is", "the", "project", "root", ".", "Typically", "used", "as", "a", "command", "-", "line", "entry", "point", "called", "by", "pygoose", "init", "." ]
4d9b8827c6d6c4b79949d1cd653393498c0bb3c2
https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/project.py#L202-L221
train
tmr232/awesomelib
awesome/iterator.py
unique_justseen
def unique_justseen(iterable, key=None): "List unique elements, preserving order. Remember only the element just seen." # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B # unique_justseen('ABBCcAD', str.lower) --> A B C A D return imap(next, imap(operator.itemgetter(1), groupby(iterable, key)))
python
def unique_justseen(iterable, key=None): "List unique elements, preserving order. Remember only the element just seen." # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B # unique_justseen('ABBCcAD', str.lower) --> A B C A D return imap(next, imap(operator.itemgetter(1), groupby(iterable, key)))
[ "def", "unique_justseen", "(", "iterable", ",", "key", "=", "None", ")", ":", "\"List unique elements, preserving order. Remember only the element just seen.\"", "return", "imap", "(", "next", ",", "imap", "(", "operator", ".", "itemgetter", "(", "1", ")", ",", "gro...
List unique elements, preserving order. Remember only the element just seen.
[ "List", "unique", "elements", "preserving", "order", ".", "Remember", "only", "the", "element", "just", "seen", "." ]
69a63466a63679f9e2abac8a719853a5e527219c
https://github.com/tmr232/awesomelib/blob/69a63466a63679f9e2abac8a719853a5e527219c/awesome/iterator.py#L122-L126
train
Erotemic/utool
utool/util_inject.py
_get_module
def _get_module(module_name=None, module=None, register=True): """ finds module in sys.modules based on module name unless the module has already been found and is passed in """ if module is None and module_name is not None: try: module = sys.modules[module_name] except KeyError ...
python
def _get_module(module_name=None, module=None, register=True): """ finds module in sys.modules based on module name unless the module has already been found and is passed in """ if module is None and module_name is not None: try: module = sys.modules[module_name] except KeyError ...
[ "def", "_get_module", "(", "module_name", "=", "None", ",", "module", "=", "None", ",", "register", "=", "True", ")", ":", "if", "module", "is", "None", "and", "module_name", "is", "not", "None", ":", "try", ":", "module", "=", "sys", ".", "modules", ...
finds module in sys.modules based on module name unless the module has already been found and is passed in
[ "finds", "module", "in", "sys", ".", "modules", "based", "on", "module", "name", "unless", "the", "module", "has", "already", "been", "found", "and", "is", "passed", "in" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L86-L102
train
Erotemic/utool
utool/util_inject.py
inject_colored_exceptions
def inject_colored_exceptions(): """ Causes exceptions to be colored if not already Hooks into sys.excepthook CommandLine: python -m utool.util_inject --test-inject_colored_exceptions Example: >>> # DISABLE_DOCTEST >>> from utool.util_inject import * # NOQA >>> pr...
python
def inject_colored_exceptions(): """ Causes exceptions to be colored if not already Hooks into sys.excepthook CommandLine: python -m utool.util_inject --test-inject_colored_exceptions Example: >>> # DISABLE_DOCTEST >>> from utool.util_inject import * # NOQA >>> pr...
[ "def", "inject_colored_exceptions", "(", ")", ":", "if", "VERBOSE", ":", "print", "(", "'[inject] injecting colored exceptions'", ")", "if", "not", "sys", ".", "platform", ".", "startswith", "(", "'win32'", ")", ":", "if", "VERYVERBOSE", ":", "print", "(", "'[...
Causes exceptions to be colored if not already Hooks into sys.excepthook CommandLine: python -m utool.util_inject --test-inject_colored_exceptions Example: >>> # DISABLE_DOCTEST >>> from utool.util_inject import * # NOQA >>> print('sys.excepthook = %r ' % (sys.excepthook,...
[ "Causes", "exceptions", "to", "be", "colored", "if", "not", "already" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L135-L166
train
Erotemic/utool
utool/util_inject.py
inject_print_functions
def inject_print_functions(module_name=None, module_prefix='[???]', DEBUG=False, module=None): """ makes print functions to be injected into the module """ module = _get_module(module_name, module) if SILENT: def print(*args): """ silent builtins.print ...
python
def inject_print_functions(module_name=None, module_prefix='[???]', DEBUG=False, module=None): """ makes print functions to be injected into the module """ module = _get_module(module_name, module) if SILENT: def print(*args): """ silent builtins.print ...
[ "def", "inject_print_functions", "(", "module_name", "=", "None", ",", "module_prefix", "=", "'[???]'", ",", "DEBUG", "=", "False", ",", "module", "=", "None", ")", ":", "module", "=", "_get_module", "(", "module_name", ",", "module", ")", "if", "SILENT", ...
makes print functions to be injected into the module
[ "makes", "print", "functions", "to", "be", "injected", "into", "the", "module" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L207-L272
train
Erotemic/utool
utool/util_inject.py
make_module_reload_func
def make_module_reload_func(module_name=None, module_prefix='[???]', module=None): """ Injects dynamic module reloading """ module = _get_module(module_name, module, register=False) if module_name is None: module_name = str(module.__name__) def rrr(verbose=True): """ Dynamic module reloa...
python
def make_module_reload_func(module_name=None, module_prefix='[???]', module=None): """ Injects dynamic module reloading """ module = _get_module(module_name, module, register=False) if module_name is None: module_name = str(module.__name__) def rrr(verbose=True): """ Dynamic module reloa...
[ "def", "make_module_reload_func", "(", "module_name", "=", "None", ",", "module_prefix", "=", "'[???]'", ",", "module", "=", "None", ")", ":", "module", "=", "_get_module", "(", "module_name", ",", "module", ",", "register", "=", "False", ")", "if", "module_...
Injects dynamic module reloading
[ "Injects", "dynamic", "module", "reloading" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L298-L318
train
Erotemic/utool
utool/util_inject.py
noinject
def noinject(module_name=None, module_prefix='[???]', DEBUG=False, module=None, N=0, via=None): """ Use in modules that do not have inject in them Does not inject anything into the module. Just lets utool know that a module is being imported so the import order can be debuged """ if PRINT_INJEC...
python
def noinject(module_name=None, module_prefix='[???]', DEBUG=False, module=None, N=0, via=None): """ Use in modules that do not have inject in them Does not inject anything into the module. Just lets utool know that a module is being imported so the import order can be debuged """ if PRINT_INJEC...
[ "def", "noinject", "(", "module_name", "=", "None", ",", "module_prefix", "=", "'[???]'", ",", "DEBUG", "=", "False", ",", "module", "=", "None", ",", "N", "=", "0", ",", "via", "=", "None", ")", ":", "if", "PRINT_INJECT_ORDER", ":", "from", "utool", ...
Use in modules that do not have inject in them Does not inject anything into the module. Just lets utool know that a module is being imported so the import order can be debuged
[ "Use", "in", "modules", "that", "do", "not", "have", "inject", "in", "them" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L441-L470
train
Erotemic/utool
utool/util_inject.py
inject
def inject(module_name=None, module_prefix='[???]', DEBUG=False, module=None, N=1): """ Injects your module with utool magic Utool magic is not actually magic. It just turns your ``print`` statments into logging statments, allows for your module to be used with the utool.Indent context manager and ...
python
def inject(module_name=None, module_prefix='[???]', DEBUG=False, module=None, N=1): """ Injects your module with utool magic Utool magic is not actually magic. It just turns your ``print`` statments into logging statments, allows for your module to be used with the utool.Indent context manager and ...
[ "def", "inject", "(", "module_name", "=", "None", ",", "module_prefix", "=", "'[???]'", ",", "DEBUG", "=", "False", ",", "module", "=", "None", ",", "N", "=", "1", ")", ":", "noinject", "(", "module_name", ",", "module_prefix", ",", "DEBUG", ",", "modu...
Injects your module with utool magic Utool magic is not actually magic. It just turns your ``print`` statments into logging statments, allows for your module to be used with the utool.Indent context manager and the and utool.indent_func decorator. ``printDBG`` will soon be deprecated as will ``print_``...
[ "Injects", "your", "module", "with", "utool", "magic" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L473-L508
train
Erotemic/utool
utool/util_inject.py
inject2
def inject2(module_name=None, module_prefix=None, DEBUG=False, module=None, N=1): """ wrapper that depricates print_ and printDBG """ if module_prefix is None: module_prefix = '[%s]' % (module_name,) noinject(module_name, module_prefix, DEBUG, module, N=N) module = _get_module(module_name, modul...
python
def inject2(module_name=None, module_prefix=None, DEBUG=False, module=None, N=1): """ wrapper that depricates print_ and printDBG """ if module_prefix is None: module_prefix = '[%s]' % (module_name,) noinject(module_name, module_prefix, DEBUG, module, N=N) module = _get_module(module_name, modul...
[ "def", "inject2", "(", "module_name", "=", "None", ",", "module_prefix", "=", "None", ",", "DEBUG", "=", "False", ",", "module", "=", "None", ",", "N", "=", "1", ")", ":", "if", "module_prefix", "is", "None", ":", "module_prefix", "=", "'[%s]'", "%", ...
wrapper that depricates print_ and printDBG
[ "wrapper", "that", "depricates", "print_", "and", "printDBG" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L511-L520
train
Erotemic/utool
utool/util_inject.py
inject_python_code2
def inject_python_code2(fpath, patch_code, tag): """ Does autogeneration stuff """ import utool as ut text = ut.readfrom(fpath) start_tag = '# <%s>' % tag end_tag = '# </%s>' % tag new_text = ut.replace_between_tags(text, patch_code, start_tag, end_tag) ut.writeto(fpath, new_text)
python
def inject_python_code2(fpath, patch_code, tag): """ Does autogeneration stuff """ import utool as ut text = ut.readfrom(fpath) start_tag = '# <%s>' % tag end_tag = '# </%s>' % tag new_text = ut.replace_between_tags(text, patch_code, start_tag, end_tag) ut.writeto(fpath, new_text)
[ "def", "inject_python_code2", "(", "fpath", ",", "patch_code", ",", "tag", ")", ":", "import", "utool", "as", "ut", "text", "=", "ut", ".", "readfrom", "(", "fpath", ")", "start_tag", "=", "'# <%s>'", "%", "tag", "end_tag", "=", "'# </%s>'", "%", "tag", ...
Does autogeneration stuff
[ "Does", "autogeneration", "stuff" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L561-L568
train
Erotemic/utool
utool/util_inject.py
inject_python_code
def inject_python_code(fpath, patch_code, tag=None, inject_location='after_imports'): """ DEPRICATE puts code into files on disk """ import utool as ut assert tag is not None, 'TAG MUST BE SPECIFIED IN INJECTED CODETEXT' text = ut.read_from(fpath) comment_start_tag...
python
def inject_python_code(fpath, patch_code, tag=None, inject_location='after_imports'): """ DEPRICATE puts code into files on disk """ import utool as ut assert tag is not None, 'TAG MUST BE SPECIFIED IN INJECTED CODETEXT' text = ut.read_from(fpath) comment_start_tag...
[ "def", "inject_python_code", "(", "fpath", ",", "patch_code", ",", "tag", "=", "None", ",", "inject_location", "=", "'after_imports'", ")", ":", "import", "utool", "as", "ut", "assert", "tag", "is", "not", "None", ",", "'TAG MUST BE SPECIFIED IN INJECTED CODETEXT'...
DEPRICATE puts code into files on disk
[ "DEPRICATE", "puts", "code", "into", "files", "on", "disk" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_inject.py#L571-L622
train
Erotemic/utool
utool/Printable.py
printableType
def printableType(val, name=None, parent=None): """ Tries to make a nice type string for a value. Can also pass in a Printable parent object """ import numpy as np if parent is not None and hasattr(parent, 'customPrintableType'): # Hack for non - trivial preference types _typestr...
python
def printableType(val, name=None, parent=None): """ Tries to make a nice type string for a value. Can also pass in a Printable parent object """ import numpy as np if parent is not None and hasattr(parent, 'customPrintableType'): # Hack for non - trivial preference types _typestr...
[ "def", "printableType", "(", "val", ",", "name", "=", "None", ",", "parent", "=", "None", ")", ":", "import", "numpy", "as", "np", "if", "parent", "is", "not", "None", "and", "hasattr", "(", "parent", ",", "'customPrintableType'", ")", ":", "_typestr", ...
Tries to make a nice type string for a value. Can also pass in a Printable parent object
[ "Tries", "to", "make", "a", "nice", "type", "string", "for", "a", "value", ".", "Can", "also", "pass", "in", "a", "Printable", "parent", "object" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/Printable.py#L96-L118
train
Erotemic/utool
utool/Printable.py
printableVal
def printableVal(val, type_bit=True, justlength=False): """ Very old way of doing pretty printing. Need to update and refactor. DEPRICATE """ from utool import util_dev # Move to util_dev # NUMPY ARRAY import numpy as np if type(val) is np.ndarray: info = npArrInfo(val) ...
python
def printableVal(val, type_bit=True, justlength=False): """ Very old way of doing pretty printing. Need to update and refactor. DEPRICATE """ from utool import util_dev # Move to util_dev # NUMPY ARRAY import numpy as np if type(val) is np.ndarray: info = npArrInfo(val) ...
[ "def", "printableVal", "(", "val", ",", "type_bit", "=", "True", ",", "justlength", "=", "False", ")", ":", "from", "utool", "import", "util_dev", "import", "numpy", "as", "np", "if", "type", "(", "val", ")", "is", "np", ".", "ndarray", ":", "info", ...
Very old way of doing pretty printing. Need to update and refactor. DEPRICATE
[ "Very", "old", "way", "of", "doing", "pretty", "printing", ".", "Need", "to", "update", "and", "refactor", ".", "DEPRICATE" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/Printable.py#L121-L163
train
Erotemic/utool
utool/Printable.py
npArrInfo
def npArrInfo(arr): """ OLD update and refactor """ from utool.DynamicStruct import DynStruct info = DynStruct() info.shapestr = '[' + ' x '.join([str(x) for x in arr.shape]) + ']' info.dtypestr = str(arr.dtype) if info.dtypestr == 'bool': info.bittotal = 'T=%d, F=%d' % (sum(ar...
python
def npArrInfo(arr): """ OLD update and refactor """ from utool.DynamicStruct import DynStruct info = DynStruct() info.shapestr = '[' + ' x '.join([str(x) for x in arr.shape]) + ']' info.dtypestr = str(arr.dtype) if info.dtypestr == 'bool': info.bittotal = 'T=%d, F=%d' % (sum(ar...
[ "def", "npArrInfo", "(", "arr", ")", ":", "from", "utool", ".", "DynamicStruct", "import", "DynStruct", "info", "=", "DynStruct", "(", ")", "info", ".", "shapestr", "=", "'['", "+", "' x '", ".", "join", "(", "[", "str", "(", "x", ")", "for", "x", ...
OLD update and refactor
[ "OLD", "update", "and", "refactor" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/Printable.py#L166-L185
train
glormph/msstitch
src/app/actions/mzidtsv/isonormalize.py
get_isobaric_ratios
def get_isobaric_ratios(psmfn, psmheader, channels, denom_channels, min_int, targetfn, accessioncol, normalize, normratiofn): """Main function to calculate ratios for PSMs, peptides, proteins, genes. Can do simple ratios, median-of-ratios and median-centering normalization.""" ps...
python
def get_isobaric_ratios(psmfn, psmheader, channels, denom_channels, min_int, targetfn, accessioncol, normalize, normratiofn): """Main function to calculate ratios for PSMs, peptides, proteins, genes. Can do simple ratios, median-of-ratios and median-centering normalization.""" ps...
[ "def", "get_isobaric_ratios", "(", "psmfn", ",", "psmheader", ",", "channels", ",", "denom_channels", ",", "min_int", ",", "targetfn", ",", "accessioncol", ",", "normalize", ",", "normratiofn", ")", ":", "psm_or_feat_ratios", "=", "get_psmratios", "(", "psmfn", ...
Main function to calculate ratios for PSMs, peptides, proteins, genes. Can do simple ratios, median-of-ratios and median-centering normalization.
[ "Main", "function", "to", "calculate", "ratios", "for", "PSMs", "peptides", "proteins", "genes", ".", "Can", "do", "simple", "ratios", "median", "-", "of", "-", "ratios", "and", "median", "-", "centering", "normalization", "." ]
ded7e5cbd813d7797dc9d42805778266e59ff042
https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/mzidtsv/isonormalize.py#L13-L45
train
timedata-org/loady
loady/files.py
sanitize
def sanitize(value): """Strips all undesirable characters out of potential file paths.""" value = unicodedata.normalize('NFKD', value) value = value.strip() value = re.sub('[^./\w\s-]', '', value) value = re.sub('[-\s]+', '-', value) return value
python
def sanitize(value): """Strips all undesirable characters out of potential file paths.""" value = unicodedata.normalize('NFKD', value) value = value.strip() value = re.sub('[^./\w\s-]', '', value) value = re.sub('[-\s]+', '-', value) return value
[ "def", "sanitize", "(", "value", ")", ":", "value", "=", "unicodedata", ".", "normalize", "(", "'NFKD'", ",", "value", ")", "value", "=", "value", ".", "strip", "(", ")", "value", "=", "re", ".", "sub", "(", "'[^./\\w\\s-]'", ",", "''", ",", "value",...
Strips all undesirable characters out of potential file paths.
[ "Strips", "all", "undesirable", "characters", "out", "of", "potential", "file", "paths", "." ]
94ffcdb92f15a28f3c85f77bd293a9cb59de4cad
https://github.com/timedata-org/loady/blob/94ffcdb92f15a28f3c85f77bd293a9cb59de4cad/loady/files.py#L10-L18
train
timedata-org/loady
loady/files.py
remove_on_exception
def remove_on_exception(dirname, remove=True): """Creates a directory, yields to the caller, and removes that directory if an exception is thrown.""" os.makedirs(dirname) try: yield except: if remove: shutil.rmtree(dirname, ignore_errors=True) raise
python
def remove_on_exception(dirname, remove=True): """Creates a directory, yields to the caller, and removes that directory if an exception is thrown.""" os.makedirs(dirname) try: yield except: if remove: shutil.rmtree(dirname, ignore_errors=True) raise
[ "def", "remove_on_exception", "(", "dirname", ",", "remove", "=", "True", ")", ":", "os", ".", "makedirs", "(", "dirname", ")", "try", ":", "yield", "except", ":", "if", "remove", ":", "shutil", ".", "rmtree", "(", "dirname", ",", "ignore_errors", "=", ...
Creates a directory, yields to the caller, and removes that directory if an exception is thrown.
[ "Creates", "a", "directory", "yields", "to", "the", "caller", "and", "removes", "that", "directory", "if", "an", "exception", "is", "thrown", "." ]
94ffcdb92f15a28f3c85f77bd293a9cb59de4cad
https://github.com/timedata-org/loady/blob/94ffcdb92f15a28f3c85f77bd293a9cb59de4cad/loady/files.py#L22-L31
train
glormph/msstitch
src/app/actions/mzidtsv/percolator.py
add_percolator_to_mzidtsv
def add_percolator_to_mzidtsv(mzidfn, tsvfn, multipsm, oldheader): """Takes a MSGF+ tsv and corresponding mzId, adds percolatordata to tsv lines. Generator yields the lines. Multiple PSMs per scan can be delivered, in which case rank is also reported. """ namespace = readers.get_mzid_namespace(mzidf...
python
def add_percolator_to_mzidtsv(mzidfn, tsvfn, multipsm, oldheader): """Takes a MSGF+ tsv and corresponding mzId, adds percolatordata to tsv lines. Generator yields the lines. Multiple PSMs per scan can be delivered, in which case rank is also reported. """ namespace = readers.get_mzid_namespace(mzidf...
[ "def", "add_percolator_to_mzidtsv", "(", "mzidfn", ",", "tsvfn", ",", "multipsm", ",", "oldheader", ")", ":", "namespace", "=", "readers", ".", "get_mzid_namespace", "(", "mzidfn", ")", "try", ":", "xmlns", "=", "'{%s}'", "%", "namespace", "[", "'xmlns'", "]...
Takes a MSGF+ tsv and corresponding mzId, adds percolatordata to tsv lines. Generator yields the lines. Multiple PSMs per scan can be delivered, in which case rank is also reported.
[ "Takes", "a", "MSGF", "+", "tsv", "and", "corresponding", "mzId", "adds", "percolatordata", "to", "tsv", "lines", ".", "Generator", "yields", "the", "lines", ".", "Multiple", "PSMs", "per", "scan", "can", "be", "delivered", "in", "which", "case", "rank", "...
ded7e5cbd813d7797dc9d42805778266e59ff042
https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/mzidtsv/percolator.py#L6-L39
train
Erotemic/utool
utool/util_profile.py
parse_rawprofile_blocks
def parse_rawprofile_blocks(text): """ Split the file into blocks along delimters and and put delimeters back in the list """ # The total time reported in the raw output is from pystone not kernprof # The pystone total time is actually the average time spent in the function delim = 'Total ti...
python
def parse_rawprofile_blocks(text): """ Split the file into blocks along delimters and and put delimeters back in the list """ # The total time reported in the raw output is from pystone not kernprof # The pystone total time is actually the average time spent in the function delim = 'Total ti...
[ "def", "parse_rawprofile_blocks", "(", "text", ")", ":", "delim", "=", "'Total time: '", "delim2", "=", "'Pystone time: '", "profile_block_list", "=", "ut", ".", "regex_split", "(", "'^'", "+", "delim", ",", "text", ")", "for", "ix", "in", "range", "(", "1",...
Split the file into blocks along delimters and and put delimeters back in the list
[ "Split", "the", "file", "into", "blocks", "along", "delimters", "and", "and", "put", "delimeters", "back", "in", "the", "list" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_profile.py#L78-L91
train
Erotemic/utool
utool/util_profile.py
parse_timemap_from_blocks
def parse_timemap_from_blocks(profile_block_list): """ Build a map from times to line_profile blocks """ prefix_list = [] timemap = ut.ddict(list) for ix in range(len(profile_block_list)): block = profile_block_list[ix] total_time = get_block_totaltime(block) # Blocks wit...
python
def parse_timemap_from_blocks(profile_block_list): """ Build a map from times to line_profile blocks """ prefix_list = [] timemap = ut.ddict(list) for ix in range(len(profile_block_list)): block = profile_block_list[ix] total_time = get_block_totaltime(block) # Blocks wit...
[ "def", "parse_timemap_from_blocks", "(", "profile_block_list", ")", ":", "prefix_list", "=", "[", "]", "timemap", "=", "ut", ".", "ddict", "(", "list", ")", "for", "ix", "in", "range", "(", "len", "(", "profile_block_list", ")", ")", ":", "block", "=", "...
Build a map from times to line_profile blocks
[ "Build", "a", "map", "from", "times", "to", "line_profile", "blocks" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_profile.py#L123-L138
train
Erotemic/utool
utool/util_profile.py
clean_line_profile_text
def clean_line_profile_text(text): """ Sorts the output from line profile by execution time Removes entries which were not run """ # profile_block_list = parse_rawprofile_blocks(text) #profile_block_list = fix_rawprofile_blocks(profile_block_list) #--- # FIXME can be written much nic...
python
def clean_line_profile_text(text): """ Sorts the output from line profile by execution time Removes entries which were not run """ # profile_block_list = parse_rawprofile_blocks(text) #profile_block_list = fix_rawprofile_blocks(profile_block_list) #--- # FIXME can be written much nic...
[ "def", "clean_line_profile_text", "(", "text", ")", ":", "profile_block_list", "=", "parse_rawprofile_blocks", "(", "text", ")", "prefix_list", ",", "timemap", "=", "parse_timemap_from_blocks", "(", "profile_block_list", ")", "sorted_lists", "=", "sorted", "(", "six",...
Sorts the output from line profile by execution time Removes entries which were not run
[ "Sorts", "the", "output", "from", "line", "profile", "by", "execution", "time", "Removes", "entries", "which", "were", "not", "run" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_profile.py#L191-L213
train
Erotemic/utool
utool/util_profile.py
clean_lprof_file
def clean_lprof_file(input_fname, output_fname=None): """ Reads a .lprof file and cleans it """ # Read the raw .lprof text dump text = ut.read_from(input_fname) # Sort and clean the text output_text = clean_line_profile_text(text) return output_text
python
def clean_lprof_file(input_fname, output_fname=None): """ Reads a .lprof file and cleans it """ # Read the raw .lprof text dump text = ut.read_from(input_fname) # Sort and clean the text output_text = clean_line_profile_text(text) return output_text
[ "def", "clean_lprof_file", "(", "input_fname", ",", "output_fname", "=", "None", ")", ":", "text", "=", "ut", ".", "read_from", "(", "input_fname", ")", "output_text", "=", "clean_line_profile_text", "(", "text", ")", "return", "output_text" ]
Reads a .lprof file and cleans it
[ "Reads", "a", ".", "lprof", "file", "and", "cleans", "it" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_profile.py#L216-L222
train
YuriyGuts/pygoose
pygoose/kg/keras.py
get_class_weights
def get_class_weights(y, smooth_factor=0): """ Returns the weights for each class based on the frequencies of the samples. Args: y: A list of true labels (the labels must be hashable). smooth_factor: A factor that smooths extremely uneven weights. Returns: A dictionary with the...
python
def get_class_weights(y, smooth_factor=0): """ Returns the weights for each class based on the frequencies of the samples. Args: y: A list of true labels (the labels must be hashable). smooth_factor: A factor that smooths extremely uneven weights. Returns: A dictionary with the...
[ "def", "get_class_weights", "(", "y", ",", "smooth_factor", "=", "0", ")", ":", "from", "collections", "import", "Counter", "counter", "=", "Counter", "(", "y", ")", "if", "smooth_factor", ">", "0", ":", "p", "=", "max", "(", "counter", ".", "values", ...
Returns the weights for each class based on the frequencies of the samples. Args: y: A list of true labels (the labels must be hashable). smooth_factor: A factor that smooths extremely uneven weights. Returns: A dictionary with the weight for each class.
[ "Returns", "the", "weights", "for", "each", "class", "based", "on", "the", "frequencies", "of", "the", "samples", "." ]
4d9b8827c6d6c4b79949d1cd653393498c0bb3c2
https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/keras.py#L4-L26
train
YuriyGuts/pygoose
pygoose/kg/keras.py
plot_loss_history
def plot_loss_history(history, figsize=(15, 8)): """ Plots the learning history for a Keras model, assuming the validation data was provided to the 'fit' function. Args: history: The return value from the 'fit' function. figsize: The size of the plot. """ plt.figure(figsize=fig...
python
def plot_loss_history(history, figsize=(15, 8)): """ Plots the learning history for a Keras model, assuming the validation data was provided to the 'fit' function. Args: history: The return value from the 'fit' function. figsize: The size of the plot. """ plt.figure(figsize=fig...
[ "def", "plot_loss_history", "(", "history", ",", "figsize", "=", "(", "15", ",", "8", ")", ")", ":", "plt", ".", "figure", "(", "figsize", "=", "figsize", ")", "plt", ".", "plot", "(", "history", ".", "history", "[", "\"loss\"", "]", ")", "plt", "....
Plots the learning history for a Keras model, assuming the validation data was provided to the 'fit' function. Args: history: The return value from the 'fit' function. figsize: The size of the plot.
[ "Plots", "the", "learning", "history", "for", "a", "Keras", "model", "assuming", "the", "validation", "data", "was", "provided", "to", "the", "fit", "function", "." ]
4d9b8827c6d6c4b79949d1cd653393498c0bb3c2
https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/keras.py#L29-L49
train
Erotemic/utool
utool/util_iter.py
iter_window
def iter_window(iterable, size=2, step=1, wrap=False): r""" iterates through iterable with a window size generalizeation of itertwo Args: iterable (iter): an iterable sequence size (int): window size (default = 2) wrap (bool): wraparound (default = False) Returns: i...
python
def iter_window(iterable, size=2, step=1, wrap=False): r""" iterates through iterable with a window size generalizeation of itertwo Args: iterable (iter): an iterable sequence size (int): window size (default = 2) wrap (bool): wraparound (default = False) Returns: i...
[ "def", "iter_window", "(", "iterable", ",", "size", "=", "2", ",", "step", "=", "1", ",", "wrap", "=", "False", ")", ":", "r", "iter_list", "=", "it", ".", "tee", "(", "iterable", ",", "size", ")", "if", "wrap", ":", "iter_list", "=", "[", "iter_...
r""" iterates through iterable with a window size generalizeation of itertwo Args: iterable (iter): an iterable sequence size (int): window size (default = 2) wrap (bool): wraparound (default = False) Returns: iter: returns windows in a sequence CommandLine: ...
[ "r", "iterates", "through", "iterable", "with", "a", "window", "size", "generalizeation", "of", "itertwo" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L89-L143
train
Erotemic/utool
utool/util_iter.py
iter_compress
def iter_compress(item_iter, flag_iter): """ iter_compress - like numpy compress Args: item_iter (list): flag_iter (list): of bools Returns: list: true_items Example: >>> # ENABLE_DOCTEST >>> from utool.util_iter import * # NOQA >>> item_iter = [1,...
python
def iter_compress(item_iter, flag_iter): """ iter_compress - like numpy compress Args: item_iter (list): flag_iter (list): of bools Returns: list: true_items Example: >>> # ENABLE_DOCTEST >>> from utool.util_iter import * # NOQA >>> item_iter = [1,...
[ "def", "iter_compress", "(", "item_iter", ",", "flag_iter", ")", ":", "true_items", "=", "(", "item", "for", "(", "item", ",", "flag", ")", "in", "zip", "(", "item_iter", ",", "flag_iter", ")", "if", "flag", ")", "return", "true_items" ]
iter_compress - like numpy compress Args: item_iter (list): flag_iter (list): of bools Returns: list: true_items Example: >>> # ENABLE_DOCTEST >>> from utool.util_iter import * # NOQA >>> item_iter = [1, 2, 3, 4, 5] >>> flag_iter = [False, True, Tr...
[ "iter_compress", "-", "like", "numpy", "compress" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L232-L255
train
Erotemic/utool
utool/util_iter.py
ichunks
def ichunks(iterable, chunksize, bordermode=None): r""" generates successive n-sized chunks from ``iterable``. Args: iterable (list): input to iterate over chunksize (int): size of sublist to return bordermode (str): None, 'cycle', or 'replicate' References: http://stac...
python
def ichunks(iterable, chunksize, bordermode=None): r""" generates successive n-sized chunks from ``iterable``. Args: iterable (list): input to iterate over chunksize (int): size of sublist to return bordermode (str): None, 'cycle', or 'replicate' References: http://stac...
[ "def", "ichunks", "(", "iterable", ",", "chunksize", ",", "bordermode", "=", "None", ")", ":", "r", "if", "bordermode", "is", "None", ":", "return", "ichunks_noborder", "(", "iterable", ",", "chunksize", ")", "elif", "bordermode", "==", "'cycle'", ":", "re...
r""" generates successive n-sized chunks from ``iterable``. Args: iterable (list): input to iterate over chunksize (int): size of sublist to return bordermode (str): None, 'cycle', or 'replicate' References: http://stackoverflow.com/questions/434287/iterate-over-a-list-in-c...
[ "r", "generates", "successive", "n", "-", "sized", "chunks", "from", "iterable", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L340-L411
train
Erotemic/utool
utool/util_iter.py
ichunks_list
def ichunks_list(list_, chunksize): """ input must be a list. SeeAlso: ichunks References: http://stackoverflow.com/questions/434287/iterate-over-a-list-in-chunks """ return (list_[ix:ix + chunksize] for ix in range(0, len(list_), chunksize))
python
def ichunks_list(list_, chunksize): """ input must be a list. SeeAlso: ichunks References: http://stackoverflow.com/questions/434287/iterate-over-a-list-in-chunks """ return (list_[ix:ix + chunksize] for ix in range(0, len(list_), chunksize))
[ "def", "ichunks_list", "(", "list_", ",", "chunksize", ")", ":", "return", "(", "list_", "[", "ix", ":", "ix", "+", "chunksize", "]", "for", "ix", "in", "range", "(", "0", ",", "len", "(", "list_", ")", ",", "chunksize", ")", ")" ]
input must be a list. SeeAlso: ichunks References: http://stackoverflow.com/questions/434287/iterate-over-a-list-in-chunks
[ "input", "must", "be", "a", "list", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L458-L468
train
Erotemic/utool
utool/util_iter.py
interleave
def interleave(args): r""" zip followed by flatten Args: args (tuple): tuple of lists to interleave SeeAlso: You may actually be better off doing something like this: a, b, = args ut.flatten(ut.bzip(a, b)) ut.flatten(ut.bzip([1, 2, 3], ['-'])) ...
python
def interleave(args): r""" zip followed by flatten Args: args (tuple): tuple of lists to interleave SeeAlso: You may actually be better off doing something like this: a, b, = args ut.flatten(ut.bzip(a, b)) ut.flatten(ut.bzip([1, 2, 3], ['-'])) ...
[ "def", "interleave", "(", "args", ")", ":", "r", "arg_iters", "=", "list", "(", "map", "(", "iter", ",", "args", ")", ")", "cycle_iter", "=", "it", ".", "cycle", "(", "arg_iters", ")", "for", "iter_", "in", "cycle_iter", ":", "yield", "six", ".", "...
r""" zip followed by flatten Args: args (tuple): tuple of lists to interleave SeeAlso: You may actually be better off doing something like this: a, b, = args ut.flatten(ut.bzip(a, b)) ut.flatten(ut.bzip([1, 2, 3], ['-'])) [1, '-', 2, '-', 3,...
[ "r", "zip", "followed", "by", "flatten" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L477-L505
train
Erotemic/utool
utool/util_iter.py
random_product
def random_product(items, num=None, rng=None): """ Yields `num` items from the cartesian product of items in a random order. Args: items (list of sequences): items to get caresian product of packed in a list or tuple. (note this deviates from api of it.product) Example:...
python
def random_product(items, num=None, rng=None): """ Yields `num` items from the cartesian product of items in a random order. Args: items (list of sequences): items to get caresian product of packed in a list or tuple. (note this deviates from api of it.product) Example:...
[ "def", "random_product", "(", "items", ",", "num", "=", "None", ",", "rng", "=", "None", ")", ":", "import", "utool", "as", "ut", "rng", "=", "ut", ".", "ensure_rng", "(", "rng", ",", "'python'", ")", "seen", "=", "set", "(", ")", "items", "=", "...
Yields `num` items from the cartesian product of items in a random order. Args: items (list of sequences): items to get caresian product of packed in a list or tuple. (note this deviates from api of it.product) Example: import utool as ut items = [(1, 2, 3), (4,...
[ "Yields", "num", "items", "from", "the", "cartesian", "product", "of", "items", "in", "a", "random", "order", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L512-L549
train
Erotemic/utool
utool/util_iter.py
random_combinations
def random_combinations(items, size, num=None, rng=None): """ Yields `num` combinations of length `size` from items in random order Args: items (?): size (?): num (None): (default = None) rng (RandomState): random number generator(default = None) Yields: tuple:...
python
def random_combinations(items, size, num=None, rng=None): """ Yields `num` combinations of length `size` from items in random order Args: items (?): size (?): num (None): (default = None) rng (RandomState): random number generator(default = None) Yields: tuple:...
[ "def", "random_combinations", "(", "items", ",", "size", ",", "num", "=", "None", ",", "rng", "=", "None", ")", ":", "import", "scipy", ".", "misc", "import", "numpy", "as", "np", "import", "utool", "as", "ut", "rng", "=", "ut", ".", "ensure_rng", "(...
Yields `num` combinations of length `size` from items in random order Args: items (?): size (?): num (None): (default = None) rng (RandomState): random number generator(default = None) Yields: tuple: combo CommandLine: python -m utool.util_iter random_comb...
[ "Yields", "num", "combinations", "of", "length", "size", "from", "items", "in", "random", "order" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L552-L616
train
chriso/gauged
gauged/drivers/__init__.py
parse_dsn
def parse_dsn(dsn_string): """Parse a connection string and return the associated driver""" dsn = urlparse(dsn_string) scheme = dsn.scheme.split('+')[0] username = password = host = port = None host = dsn.netloc if '@' in host: username, host = host.split('@') if ':' in username:...
python
def parse_dsn(dsn_string): """Parse a connection string and return the associated driver""" dsn = urlparse(dsn_string) scheme = dsn.scheme.split('+')[0] username = password = host = port = None host = dsn.netloc if '@' in host: username, host = host.split('@') if ':' in username:...
[ "def", "parse_dsn", "(", "dsn_string", ")", ":", "dsn", "=", "urlparse", "(", "dsn_string", ")", "scheme", "=", "dsn", ".", "scheme", ".", "split", "(", "'+'", ")", "[", "0", "]", "username", "=", "password", "=", "host", "=", "port", "=", "None", ...
Parse a connection string and return the associated driver
[ "Parse", "a", "connection", "string", "and", "return", "the", "associated", "driver" ]
cda3bba2f3e92ce2fb4aa92132dcc0e689bf7976
https://github.com/chriso/gauged/blob/cda3bba2f3e92ce2fb4aa92132dcc0e689bf7976/gauged/drivers/__init__.py#L14-L57
train
Thermondo/django-heroku-connect
heroku_connect/db/router.py
HerokuConnectRouter.db_for_write
def db_for_write(self, model, **hints): """ Prevent write actions on read-only tables. Raises: WriteNotSupportedError: If models.sf_access is ``read_only``. """ try: if model.sf_access == READ_ONLY: raise WriteNotSupportedError("%r is a r...
python
def db_for_write(self, model, **hints): """ Prevent write actions on read-only tables. Raises: WriteNotSupportedError: If models.sf_access is ``read_only``. """ try: if model.sf_access == READ_ONLY: raise WriteNotSupportedError("%r is a r...
[ "def", "db_for_write", "(", "self", ",", "model", ",", "**", "hints", ")", ":", "try", ":", "if", "model", ".", "sf_access", "==", "READ_ONLY", ":", "raise", "WriteNotSupportedError", "(", "\"%r is a read-only model.\"", "%", "model", ")", "except", "Attribute...
Prevent write actions on read-only tables. Raises: WriteNotSupportedError: If models.sf_access is ``read_only``.
[ "Prevent", "write", "actions", "on", "read", "-", "only", "tables", "." ]
f390e0fbf256ee79b30bb88f9a8c9576c6c8d9b5
https://github.com/Thermondo/django-heroku-connect/blob/f390e0fbf256ee79b30bb88f9a8c9576c6c8d9b5/heroku_connect/db/router.py#L26-L39
train
product-definition-center/pdc-client
pdc_client/runner.py
Runner.run_hook
def run_hook(self, hook, *args, **kwargs): """ Loop over all plugins and invoke function `hook` with `args` and `kwargs` in each of them. If the plugin does not have the function, it is skipped. """ for plugin in self.raw_plugins: if hasattr(plugin, hook): ...
python
def run_hook(self, hook, *args, **kwargs): """ Loop over all plugins and invoke function `hook` with `args` and `kwargs` in each of them. If the plugin does not have the function, it is skipped. """ for plugin in self.raw_plugins: if hasattr(plugin, hook): ...
[ "def", "run_hook", "(", "self", ",", "hook", ",", "*", "args", ",", "**", "kwargs", ")", ":", "for", "plugin", "in", "self", ".", "raw_plugins", ":", "if", "hasattr", "(", "plugin", ",", "hook", ")", ":", "self", ".", "logger", ".", "debug", "(", ...
Loop over all plugins and invoke function `hook` with `args` and `kwargs` in each of them. If the plugin does not have the function, it is skipped.
[ "Loop", "over", "all", "plugins", "and", "invoke", "function", "hook", "with", "args", "and", "kwargs", "in", "each", "of", "them", ".", "If", "the", "plugin", "does", "not", "have", "the", "function", "it", "is", "skipped", "." ]
7236fd8b72e675ebb321bbe337289d9fbeb6119f
https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/runner.py#L134-L143
train
glormph/msstitch
src/app/writers/tsv.py
write_tsv
def write_tsv(headerfields, features, outfn): """Writes header and generator of lines to tab separated file. headerfields - list of field names in header in correct order features - generates 1 list per line that belong to header outfn - filename to output to. Overwritten if exists """ with ope...
python
def write_tsv(headerfields, features, outfn): """Writes header and generator of lines to tab separated file. headerfields - list of field names in header in correct order features - generates 1 list per line that belong to header outfn - filename to output to. Overwritten if exists """ with ope...
[ "def", "write_tsv", "(", "headerfields", ",", "features", ",", "outfn", ")", ":", "with", "open", "(", "outfn", ",", "'w'", ")", "as", "fp", ":", "write_tsv_line_from_list", "(", "headerfields", ",", "fp", ")", "for", "line", "in", "features", ":", "writ...
Writes header and generator of lines to tab separated file. headerfields - list of field names in header in correct order features - generates 1 list per line that belong to header outfn - filename to output to. Overwritten if exists
[ "Writes", "header", "and", "generator", "of", "lines", "to", "tab", "separated", "file", "." ]
ded7e5cbd813d7797dc9d42805778266e59ff042
https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/writers/tsv.py#L1-L12
train
glormph/msstitch
src/app/writers/tsv.py
write_tsv_line_from_list
def write_tsv_line_from_list(linelist, outfp): """Utility method to convert list to tsv line with carriage return""" line = '\t'.join(linelist) outfp.write(line) outfp.write('\n')
python
def write_tsv_line_from_list(linelist, outfp): """Utility method to convert list to tsv line with carriage return""" line = '\t'.join(linelist) outfp.write(line) outfp.write('\n')
[ "def", "write_tsv_line_from_list", "(", "linelist", ",", "outfp", ")", ":", "line", "=", "'\\t'", ".", "join", "(", "linelist", ")", "outfp", ".", "write", "(", "line", ")", "outfp", ".", "write", "(", "'\\n'", ")" ]
Utility method to convert list to tsv line with carriage return
[ "Utility", "method", "to", "convert", "list", "to", "tsv", "line", "with", "carriage", "return" ]
ded7e5cbd813d7797dc9d42805778266e59ff042
https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/writers/tsv.py#L15-L19
train
Erotemic/utool
utool/util_str.py
replace_between_tags
def replace_between_tags(text, repl_, start_tag, end_tag=None): r""" Replaces text between sentinal lines in a block of text. Args: text (str): repl_ (str): start_tag (str): end_tag (str): (default=None) Returns: str: new_text CommandLine: python -m...
python
def replace_between_tags(text, repl_, start_tag, end_tag=None): r""" Replaces text between sentinal lines in a block of text. Args: text (str): repl_ (str): start_tag (str): end_tag (str): (default=None) Returns: str: new_text CommandLine: python -m...
[ "def", "replace_between_tags", "(", "text", ",", "repl_", ",", "start_tag", ",", "end_tag", "=", "None", ")", ":", "r", "new_lines", "=", "[", "]", "editing", "=", "False", "lines", "=", "text", ".", "split", "(", "'\\n'", ")", "for", "line", "in", "...
r""" Replaces text between sentinal lines in a block of text. Args: text (str): repl_ (str): start_tag (str): end_tag (str): (default=None) Returns: str: new_text CommandLine: python -m utool.util_str --exec-replace_between_tags Example: >>...
[ "r", "Replaces", "text", "between", "sentinal", "lines", "in", "a", "block", "of", "text", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L75-L128
train
Erotemic/utool
utool/util_str.py
theta_str
def theta_str(theta, taustr=TAUSTR, fmtstr='{coeff:,.1f}{taustr}'): r""" Format theta so it is interpretable in base 10 Args: theta (float) angle in radians taustr (str): default 2pi Returns: str : theta_str - the angle in tau units Example1: >>> # ENABLE_DOCTEST ...
python
def theta_str(theta, taustr=TAUSTR, fmtstr='{coeff:,.1f}{taustr}'): r""" Format theta so it is interpretable in base 10 Args: theta (float) angle in radians taustr (str): default 2pi Returns: str : theta_str - the angle in tau units Example1: >>> # ENABLE_DOCTEST ...
[ "def", "theta_str", "(", "theta", ",", "taustr", "=", "TAUSTR", ",", "fmtstr", "=", "'{coeff:,.1f}{taustr}'", ")", ":", "r", "coeff", "=", "theta", "/", "TAU", "theta_str", "=", "fmtstr", ".", "format", "(", "coeff", "=", "coeff", ",", "taustr", "=", "...
r""" Format theta so it is interpretable in base 10 Args: theta (float) angle in radians taustr (str): default 2pi Returns: str : theta_str - the angle in tau units Example1: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> theta = 3.14...
[ "r", "Format", "theta", "so", "it", "is", "interpretable", "in", "base", "10" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L131-L161
train
Erotemic/utool
utool/util_str.py
bbox_str
def bbox_str(bbox, pad=4, sep=', '): r""" makes a string from an integer bounding box """ if bbox is None: return 'None' fmtstr = sep.join(['%' + six.text_type(pad) + 'd'] * 4) return '(' + fmtstr % tuple(bbox) + ')'
python
def bbox_str(bbox, pad=4, sep=', '): r""" makes a string from an integer bounding box """ if bbox is None: return 'None' fmtstr = sep.join(['%' + six.text_type(pad) + 'd'] * 4) return '(' + fmtstr % tuple(bbox) + ')'
[ "def", "bbox_str", "(", "bbox", ",", "pad", "=", "4", ",", "sep", "=", "', '", ")", ":", "r", "if", "bbox", "is", "None", ":", "return", "'None'", "fmtstr", "=", "sep", ".", "join", "(", "[", "'%'", "+", "six", ".", "text_type", "(", "pad", ")"...
r""" makes a string from an integer bounding box
[ "r", "makes", "a", "string", "from", "an", "integer", "bounding", "box" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L164-L169
train
Erotemic/utool
utool/util_str.py
verts_str
def verts_str(verts, pad=1): r""" makes a string from a list of integer verticies """ if verts is None: return 'None' fmtstr = ', '.join(['%' + six.text_type(pad) + 'd' + ', %' + six.text_type(pad) + 'd'] * 1) return ', '.join(['(' + fmtstr % vert + ')' for vert in verts]...
python
def verts_str(verts, pad=1): r""" makes a string from a list of integer verticies """ if verts is None: return 'None' fmtstr = ', '.join(['%' + six.text_type(pad) + 'd' + ', %' + six.text_type(pad) + 'd'] * 1) return ', '.join(['(' + fmtstr % vert + ')' for vert in verts]...
[ "def", "verts_str", "(", "verts", ",", "pad", "=", "1", ")", ":", "r", "if", "verts", "is", "None", ":", "return", "'None'", "fmtstr", "=", "', '", ".", "join", "(", "[", "'%'", "+", "six", ".", "text_type", "(", "pad", ")", "+", "'d'", "+", "'...
r""" makes a string from a list of integer verticies
[ "r", "makes", "a", "string", "from", "a", "list", "of", "integer", "verticies" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L172-L178
train
Erotemic/utool
utool/util_str.py
remove_chars
def remove_chars(str_, char_list): """ removes all chars in char_list from str_ Args: str_ (str): char_list (list): Returns: str: outstr Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> str_ = '1, 2, 3, 4' >>> char_...
python
def remove_chars(str_, char_list): """ removes all chars in char_list from str_ Args: str_ (str): char_list (list): Returns: str: outstr Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> str_ = '1, 2, 3, 4' >>> char_...
[ "def", "remove_chars", "(", "str_", ",", "char_list", ")", ":", "outstr", "=", "str_", "[", ":", "]", "for", "char", "in", "char_list", ":", "outstr", "=", "outstr", ".", "replace", "(", "char", ",", "''", ")", "return", "outstr" ]
removes all chars in char_list from str_ Args: str_ (str): char_list (list): Returns: str: outstr Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> str_ = '1, 2, 3, 4' >>> char_list = [','] >>> result = remove_chars(...
[ "removes", "all", "chars", "in", "char_list", "from", "str_" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L195-L218
train
Erotemic/utool
utool/util_str.py
get_minimum_indentation
def get_minimum_indentation(text): r""" returns the number of preceding spaces Args: text (str): unicode text Returns: int: indentation CommandLine: python -m utool.util_str --exec-get_minimum_indentation --show Example: >>> # ENABLE_DOCTEST >>> from u...
python
def get_minimum_indentation(text): r""" returns the number of preceding spaces Args: text (str): unicode text Returns: int: indentation CommandLine: python -m utool.util_str --exec-get_minimum_indentation --show Example: >>> # ENABLE_DOCTEST >>> from u...
[ "def", "get_minimum_indentation", "(", "text", ")", ":", "r", "lines", "=", "text", ".", "split", "(", "'\\n'", ")", "indentations", "=", "[", "get_indentation", "(", "line_", ")", "for", "line_", "in", "lines", "if", "len", "(", "line_", ".", "strip", ...
r""" returns the number of preceding spaces Args: text (str): unicode text Returns: int: indentation CommandLine: python -m utool.util_str --exec-get_minimum_indentation --show Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA ...
[ "r", "returns", "the", "number", "of", "preceding", "spaces" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L228-L255
train
Erotemic/utool
utool/util_str.py
indentjoin
def indentjoin(strlist, indent='\n ', suffix=''): r""" Convineince indentjoin similar to '\n '.join(strlist) but indent is also prefixed Args: strlist (?): indent (str): suffix (str): Returns: str: joined list """ indent_ = indent strlist = list...
python
def indentjoin(strlist, indent='\n ', suffix=''): r""" Convineince indentjoin similar to '\n '.join(strlist) but indent is also prefixed Args: strlist (?): indent (str): suffix (str): Returns: str: joined list """ indent_ = indent strlist = list...
[ "def", "indentjoin", "(", "strlist", ",", "indent", "=", "'\\n '", ",", "suffix", "=", "''", ")", ":", "r", "indent_", "=", "indent", "strlist", "=", "list", "(", "strlist", ")", "if", "len", "(", "strlist", ")", "==", "0", ":", "return", "''", ...
r""" Convineince indentjoin similar to '\n '.join(strlist) but indent is also prefixed Args: strlist (?): indent (str): suffix (str): Returns: str: joined list
[ "r", "Convineince", "indentjoin" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L357-L376
train
Erotemic/utool
utool/util_str.py
truncate_str
def truncate_str(str_, maxlen=110, truncmsg=' ~~~TRUNCATED~~~ '): """ Removes the middle part of any string over maxlen characters. """ if NO_TRUNCATE: return str_ if maxlen is None or maxlen == -1 or len(str_) < maxlen: return str_ else: maxlen_ = maxlen - len(truncmsg) ...
python
def truncate_str(str_, maxlen=110, truncmsg=' ~~~TRUNCATED~~~ '): """ Removes the middle part of any string over maxlen characters. """ if NO_TRUNCATE: return str_ if maxlen is None or maxlen == -1 or len(str_) < maxlen: return str_ else: maxlen_ = maxlen - len(truncmsg) ...
[ "def", "truncate_str", "(", "str_", ",", "maxlen", "=", "110", ",", "truncmsg", "=", "' ~~~TRUNCATED~~~ '", ")", ":", "if", "NO_TRUNCATE", ":", "return", "str_", "if", "maxlen", "is", "None", "or", "maxlen", "==", "-", "1", "or", "len", "(", "str_", ")...
Removes the middle part of any string over maxlen characters.
[ "Removes", "the", "middle", "part", "of", "any", "string", "over", "maxlen", "characters", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L379-L392
train
Erotemic/utool
utool/util_str.py
packstr
def packstr(instr, textwidth=160, breakchars=' ', break_words=True, newline_prefix='', indentation='', nlprefix=None, wordsep=' ', remove_newlines=True): """ alias for pack_into. has more up to date kwargs """ if not isinstance(instr, six.string_types): instr = repr(instr) if...
python
def packstr(instr, textwidth=160, breakchars=' ', break_words=True, newline_prefix='', indentation='', nlprefix=None, wordsep=' ', remove_newlines=True): """ alias for pack_into. has more up to date kwargs """ if not isinstance(instr, six.string_types): instr = repr(instr) if...
[ "def", "packstr", "(", "instr", ",", "textwidth", "=", "160", ",", "breakchars", "=", "' '", ",", "break_words", "=", "True", ",", "newline_prefix", "=", "''", ",", "indentation", "=", "''", ",", "nlprefix", "=", "None", ",", "wordsep", "=", "' '", ","...
alias for pack_into. has more up to date kwargs
[ "alias", "for", "pack_into", ".", "has", "more", "up", "to", "date", "kwargs" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L468-L480
train
Erotemic/utool
utool/util_str.py
byte_str
def byte_str(nBytes, unit='bytes', precision=2): """ representing the number of bytes with the chosen unit Returns: str """ #return (nBytes * ureg.byte).to(unit.upper()) if unit.lower().startswith('b'): nUnit = nBytes elif unit.lower().startswith('k'): nUnit = nByte...
python
def byte_str(nBytes, unit='bytes', precision=2): """ representing the number of bytes with the chosen unit Returns: str """ #return (nBytes * ureg.byte).to(unit.upper()) if unit.lower().startswith('b'): nUnit = nBytes elif unit.lower().startswith('k'): nUnit = nByte...
[ "def", "byte_str", "(", "nBytes", ",", "unit", "=", "'bytes'", ",", "precision", "=", "2", ")", ":", "if", "unit", ".", "lower", "(", ")", ".", "startswith", "(", "'b'", ")", ":", "nUnit", "=", "nBytes", "elif", "unit", ".", "lower", "(", ")", "....
representing the number of bytes with the chosen unit Returns: str
[ "representing", "the", "number", "of", "bytes", "with", "the", "chosen", "unit" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L671-L691
train
Erotemic/utool
utool/util_str.py
func_str
def func_str(func, args=[], kwargs={}, type_aliases=[], packed=False, packkw=None, truncate=False): """ string representation of function definition Returns: str: a representation of func with args, kwargs, and type_aliases Args: func (function): args (list): argum...
python
def func_str(func, args=[], kwargs={}, type_aliases=[], packed=False, packkw=None, truncate=False): """ string representation of function definition Returns: str: a representation of func with args, kwargs, and type_aliases Args: func (function): args (list): argum...
[ "def", "func_str", "(", "func", ",", "args", "=", "[", "]", ",", "kwargs", "=", "{", "}", ",", "type_aliases", "=", "[", "]", ",", "packed", "=", "False", ",", "packkw", "=", "None", ",", "truncate", "=", "False", ")", ":", "import", "utool", "as...
string representation of function definition Returns: str: a representation of func with args, kwargs, and type_aliases Args: func (function): args (list): argument values (default = []) kwargs (dict): kwargs values (default = {}) type_aliases (list): (default = []) ...
[ "string", "representation", "of", "function", "definition" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L720-L778
train
Erotemic/utool
utool/util_str.py
func_defsig
def func_defsig(func, with_name=True): """ String of function definition signature Args: func (function): live python function Returns: str: defsig CommandLine: python -m utool.util_str --exec-func_defsig Example: >>> # ENABLE_DOCTEST >>> from utool.ut...
python
def func_defsig(func, with_name=True): """ String of function definition signature Args: func (function): live python function Returns: str: defsig CommandLine: python -m utool.util_str --exec-func_defsig Example: >>> # ENABLE_DOCTEST >>> from utool.ut...
[ "def", "func_defsig", "(", "func", ",", "with_name", "=", "True", ")", ":", "import", "inspect", "argspec", "=", "inspect", ".", "getargspec", "(", "func", ")", "(", "args", ",", "varargs", ",", "varkw", ",", "defaults", ")", "=", "argspec", "defsig", ...
String of function definition signature Args: func (function): live python function Returns: str: defsig CommandLine: python -m utool.util_str --exec-func_defsig Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> func = func_str...
[ "String", "of", "function", "definition", "signature" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L781-L809
train
Erotemic/utool
utool/util_str.py
func_callsig
def func_callsig(func, with_name=True): """ String of function call signature Args: func (function): live python function Returns: str: callsig CommandLine: python -m utool.util_str --exec-func_callsig Example: >>> # ENABLE_DOCTEST >>> from utool.util_...
python
def func_callsig(func, with_name=True): """ String of function call signature Args: func (function): live python function Returns: str: callsig CommandLine: python -m utool.util_str --exec-func_callsig Example: >>> # ENABLE_DOCTEST >>> from utool.util_...
[ "def", "func_callsig", "(", "func", ",", "with_name", "=", "True", ")", ":", "import", "inspect", "argspec", "=", "inspect", ".", "getargspec", "(", "func", ")", "(", "args", ",", "varargs", ",", "varkw", ",", "defaults", ")", "=", "argspec", "callsig", ...
String of function call signature Args: func (function): live python function Returns: str: callsig CommandLine: python -m utool.util_str --exec-func_callsig Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> func = func_str ...
[ "String", "of", "function", "call", "signature" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L812-L840
train
Erotemic/utool
utool/util_str.py
numpy_str
def numpy_str(arr, strvals=False, precision=None, pr=None, force_dtype=False, with_dtype=None, suppress_small=None, max_line_width=None, threshold=None, **kwargs): """ suppress_small = False turns off scientific representation """ # strvals = kwargs.get('strvals...
python
def numpy_str(arr, strvals=False, precision=None, pr=None, force_dtype=False, with_dtype=None, suppress_small=None, max_line_width=None, threshold=None, **kwargs): """ suppress_small = False turns off scientific representation """ # strvals = kwargs.get('strvals...
[ "def", "numpy_str", "(", "arr", ",", "strvals", "=", "False", ",", "precision", "=", "None", ",", "pr", "=", "None", ",", "force_dtype", "=", "False", ",", "with_dtype", "=", "None", ",", "suppress_small", "=", "None", ",", "max_line_width", "=", "None",...
suppress_small = False turns off scientific representation
[ "suppress_small", "=", "False", "turns", "off", "scientific", "representation" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1112-L1170
train
Erotemic/utool
utool/util_str.py
list_str_summarized
def list_str_summarized(list_, list_name, maxlen=5): """ prints the list members when the list is small and the length when it is large """ if len(list_) > maxlen: return 'len(%s)=%d' % (list_name, len(list_)) else: return '%s=%r' % (list_name, list_)
python
def list_str_summarized(list_, list_name, maxlen=5): """ prints the list members when the list is small and the length when it is large """ if len(list_) > maxlen: return 'len(%s)=%d' % (list_name, len(list_)) else: return '%s=%r' % (list_name, list_)
[ "def", "list_str_summarized", "(", "list_", ",", "list_name", ",", "maxlen", "=", "5", ")", ":", "if", "len", "(", "list_", ")", ">", "maxlen", ":", "return", "'len(%s)=%d'", "%", "(", "list_name", ",", "len", "(", "list_", ")", ")", "else", ":", "re...
prints the list members when the list is small and the length when it is large
[ "prints", "the", "list", "members", "when", "the", "list", "is", "small", "and", "the", "length", "when", "it", "is", "large" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1251-L1259
train
Erotemic/utool
utool/util_str.py
_rectify_countdown_or_bool
def _rectify_countdown_or_bool(count_or_bool): """ used by recrusive functions to specify which level to turn a bool on in counting down yeilds True, True, ..., False conting up yeilds False, False, False, ... True Args: count_or_bool (bool or int): if positive will count down, if negative ...
python
def _rectify_countdown_or_bool(count_or_bool): """ used by recrusive functions to specify which level to turn a bool on in counting down yeilds True, True, ..., False conting up yeilds False, False, False, ... True Args: count_or_bool (bool or int): if positive will count down, if negative ...
[ "def", "_rectify_countdown_or_bool", "(", "count_or_bool", ")", ":", "if", "count_or_bool", "is", "True", "or", "count_or_bool", "is", "False", ":", "count_or_bool_", "=", "count_or_bool", "elif", "isinstance", "(", "count_or_bool", ",", "int", ")", ":", "if", "...
used by recrusive functions to specify which level to turn a bool on in counting down yeilds True, True, ..., False conting up yeilds False, False, False, ... True Args: count_or_bool (bool or int): if positive will count down, if negative will count up, if bool will remain same Re...
[ "used", "by", "recrusive", "functions", "to", "specify", "which", "level", "to", "turn", "a", "bool", "on", "in", "counting", "down", "yeilds", "True", "True", "...", "False", "conting", "up", "yeilds", "False", "False", "False", "...", "True" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1266-L1310
train
Erotemic/utool
utool/util_str.py
repr2
def repr2(obj_, **kwargs): """ Attempt to replace repr more configurable pretty version that works the same in both 2 and 3 """ kwargs['nl'] = kwargs.pop('nl', kwargs.pop('newlines', False)) val_str = _make_valstr(**kwargs) return val_str(obj_)
python
def repr2(obj_, **kwargs): """ Attempt to replace repr more configurable pretty version that works the same in both 2 and 3 """ kwargs['nl'] = kwargs.pop('nl', kwargs.pop('newlines', False)) val_str = _make_valstr(**kwargs) return val_str(obj_)
[ "def", "repr2", "(", "obj_", ",", "**", "kwargs", ")", ":", "kwargs", "[", "'nl'", "]", "=", "kwargs", ".", "pop", "(", "'nl'", ",", "kwargs", ".", "pop", "(", "'newlines'", ",", "False", ")", ")", "val_str", "=", "_make_valstr", "(", "**", "kwargs...
Attempt to replace repr more configurable pretty version that works the same in both 2 and 3
[ "Attempt", "to", "replace", "repr", "more", "configurable", "pretty", "version", "that", "works", "the", "same", "in", "both", "2", "and", "3" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1317-L1324
train
Erotemic/utool
utool/util_str.py
repr2_json
def repr2_json(obj_, **kwargs): """ hack for json reprs """ import utool as ut kwargs['trailing_sep'] = False json_str = ut.repr2(obj_, **kwargs) json_str = str(json_str.replace('\'', '"')) json_str = json_str.replace('(', '[') json_str = json_str.replace(')', ']') json_str = json_str.re...
python
def repr2_json(obj_, **kwargs): """ hack for json reprs """ import utool as ut kwargs['trailing_sep'] = False json_str = ut.repr2(obj_, **kwargs) json_str = str(json_str.replace('\'', '"')) json_str = json_str.replace('(', '[') json_str = json_str.replace(')', ']') json_str = json_str.re...
[ "def", "repr2_json", "(", "obj_", ",", "**", "kwargs", ")", ":", "import", "utool", "as", "ut", "kwargs", "[", "'trailing_sep'", "]", "=", "False", "json_str", "=", "ut", ".", "repr2", "(", "obj_", ",", "**", "kwargs", ")", "json_str", "=", "str", "(...
hack for json reprs
[ "hack", "for", "json", "reprs" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1327-L1336
train
Erotemic/utool
utool/util_str.py
list_str
def list_str(list_, **listkw): r""" Makes a pretty list string Args: list_ (list): input list **listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep, trailing_sep, truncatekw, strvals, recursive, indent_, precision, use_numpy, with_dtype, force...
python
def list_str(list_, **listkw): r""" Makes a pretty list string Args: list_ (list): input list **listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep, trailing_sep, truncatekw, strvals, recursive, indent_, precision, use_numpy, with_dtype, force...
[ "def", "list_str", "(", "list_", ",", "**", "listkw", ")", ":", "r", "import", "utool", "as", "ut", "newlines", "=", "listkw", ".", "pop", "(", "'nl'", ",", "listkw", ".", "pop", "(", "'newlines'", ",", "1", ")", ")", "packed", "=", "listkw", ".", ...
r""" Makes a pretty list string Args: list_ (list): input list **listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep, trailing_sep, truncatekw, strvals, recursive, indent_, precision, use_numpy, with_dtype, force_dtype, stritems,...
[ "r", "Makes", "a", "pretty", "list", "string" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1582-L1694
train
Erotemic/utool
utool/util_str.py
horiz_string
def horiz_string(*args, **kwargs): """ Horizontally concatenates strings reprs preserving indentation Concats a list of objects ensuring that the next item in the list is all the way to the right of any previous items. Args: *args: list of strings to concat **kwargs: precision, sep...
python
def horiz_string(*args, **kwargs): """ Horizontally concatenates strings reprs preserving indentation Concats a list of objects ensuring that the next item in the list is all the way to the right of any previous items. Args: *args: list of strings to concat **kwargs: precision, sep...
[ "def", "horiz_string", "(", "*", "args", ",", "**", "kwargs", ")", ":", "import", "unicodedata", "precision", "=", "kwargs", ".", "get", "(", "'precision'", ",", "None", ")", "sep", "=", "kwargs", ".", "get", "(", "'sep'", ",", "''", ")", "if", "len"...
Horizontally concatenates strings reprs preserving indentation Concats a list of objects ensuring that the next item in the list is all the way to the right of any previous items. Args: *args: list of strings to concat **kwargs: precision, sep CommandLine: python -m utool.util...
[ "Horizontally", "concatenates", "strings", "reprs", "preserving", "indentation" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1795-L1879
train
Erotemic/utool
utool/util_str.py
str_between
def str_between(str_, startstr, endstr): r""" gets substring between two sentianl strings Example: >>> # DISABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> import utool as ut >>> str_ = '\n INSERT INTO vsone(\n' >>> startstr = 'INSERT' >>> en...
python
def str_between(str_, startstr, endstr): r""" gets substring between two sentianl strings Example: >>> # DISABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> import utool as ut >>> str_ = '\n INSERT INTO vsone(\n' >>> startstr = 'INSERT' >>> en...
[ "def", "str_between", "(", "str_", ",", "startstr", ",", "endstr", ")", ":", "r", "if", "startstr", "is", "None", ":", "startpos", "=", "0", "else", ":", "startpos", "=", "str_", ".", "find", "(", "startstr", ")", "+", "len", "(", "startstr", ")", ...
r""" gets substring between two sentianl strings Example: >>> # DISABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> import utool as ut >>> str_ = '\n INSERT INTO vsone(\n' >>> startstr = 'INSERT' >>> endstr = '(' >>> result = str_between(s...
[ "r", "gets", "substring", "between", "two", "sentianl", "strings" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1885-L1910
train
Erotemic/utool
utool/util_str.py
get_callable_name
def get_callable_name(func): """ Works on must functionlike objects including str, which has no func_name Args: func (function): Returns: str: CommandLine: python -m utool.util_str --exec-get_callable_name Example: >>> # ENABLE_DOCTEST >>> from utool.util_...
python
def get_callable_name(func): """ Works on must functionlike objects including str, which has no func_name Args: func (function): Returns: str: CommandLine: python -m utool.util_str --exec-get_callable_name Example: >>> # ENABLE_DOCTEST >>> from utool.util_...
[ "def", "get_callable_name", "(", "func", ")", ":", "try", ":", "return", "meta_util_six", ".", "get_funcname", "(", "func", ")", "except", "AttributeError", ":", "if", "isinstance", "(", "func", ",", "type", ")", ":", "return", "repr", "(", "func", ")", ...
Works on must functionlike objects including str, which has no func_name Args: func (function): Returns: str: CommandLine: python -m utool.util_str --exec-get_callable_name Example: >>> # ENABLE_DOCTEST >>> from utool.util_str import * # NOQA >>> func...
[ "Works", "on", "must", "functionlike", "objects", "including", "str", "which", "has", "no", "func_name" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1913-L1942
train
Erotemic/utool
utool/util_str.py
multi_replace
def multi_replace(str_, search_list, repl_list): r""" Performs multiple replace functions foreach item in search_list and repl_list. Args: str_ (str): string to search search_list (list): list of search strings repl_list (list or str): one or multiple replace strings Return...
python
def multi_replace(str_, search_list, repl_list): r""" Performs multiple replace functions foreach item in search_list and repl_list. Args: str_ (str): string to search search_list (list): list of search strings repl_list (list or str): one or multiple replace strings Return...
[ "def", "multi_replace", "(", "str_", ",", "search_list", ",", "repl_list", ")", ":", "r", "if", "isinstance", "(", "repl_list", ",", "six", ".", "string_types", ")", ":", "repl_list_", "=", "[", "repl_list", "]", "*", "len", "(", "search_list", ")", "els...
r""" Performs multiple replace functions foreach item in search_list and repl_list. Args: str_ (str): string to search search_list (list): list of search strings repl_list (list or str): one or multiple replace strings Returns: str: str_ CommandLine: python...
[ "r", "Performs", "multiple", "replace", "functions", "foreach", "item", "in", "search_list", "and", "repl_list", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2213-L2248
train
Erotemic/utool
utool/util_str.py
pluralize
def pluralize(wordtext, num=2, plural_suffix='s'): r""" Heuristically changes a word to its plural form if `num` is not 1 Args: wordtext (str): word in singular form num (int): a length of an associated list if applicable (default = 2) plural_suffix (str): heurstic plural form (defa...
python
def pluralize(wordtext, num=2, plural_suffix='s'): r""" Heuristically changes a word to its plural form if `num` is not 1 Args: wordtext (str): word in singular form num (int): a length of an associated list if applicable (default = 2) plural_suffix (str): heurstic plural form (defa...
[ "def", "pluralize", "(", "wordtext", ",", "num", "=", "2", ",", "plural_suffix", "=", "'s'", ")", ":", "r", "if", "num", "==", "1", ":", "return", "wordtext", "else", ":", "if", "wordtext", ".", "endswith", "(", "'\\'s'", ")", ":", "return", "wordtex...
r""" Heuristically changes a word to its plural form if `num` is not 1 Args: wordtext (str): word in singular form num (int): a length of an associated list if applicable (default = 2) plural_suffix (str): heurstic plural form (default = 's') Returns: str: pluralized form. ...
[ "r", "Heuristically", "changes", "a", "word", "to", "its", "plural", "form", "if", "num", "is", "not", "1" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2251-L2281
train
Erotemic/utool
utool/util_str.py
quantstr
def quantstr(typestr, num, plural_suffix='s'): r""" Heuristically generates an english phrase relating to the quantity of something. This is useful for writing user messages. Args: typestr (str): singular form of the word num (int): quanity of the type plural_suffix (str): heur...
python
def quantstr(typestr, num, plural_suffix='s'): r""" Heuristically generates an english phrase relating to the quantity of something. This is useful for writing user messages. Args: typestr (str): singular form of the word num (int): quanity of the type plural_suffix (str): heur...
[ "def", "quantstr", "(", "typestr", ",", "num", ",", "plural_suffix", "=", "'s'", ")", ":", "r", "return", "six", ".", "text_type", "(", "num", ")", "+", "' '", "+", "pluralize", "(", "typestr", ",", "num", ",", "plural_suffix", ")" ]
r""" Heuristically generates an english phrase relating to the quantity of something. This is useful for writing user messages. Args: typestr (str): singular form of the word num (int): quanity of the type plural_suffix (str): heurstic plural form (default = 's') Returns: ...
[ "r", "Heuristically", "generates", "an", "english", "phrase", "relating", "to", "the", "quantity", "of", "something", ".", "This", "is", "useful", "for", "writing", "user", "messages", "." ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2284-L2314
train
Erotemic/utool
utool/util_str.py
msgblock
def msgblock(key, text, side='|'): """ puts text inside a visual ascii block """ blocked_text = ''.join( [' + --- ', key, ' ---\n'] + [' ' + side + ' ' + line + '\n' for line in text.split('\n')] + [' L ___ ', key, ' ___\n'] ) return blocked_text
python
def msgblock(key, text, side='|'): """ puts text inside a visual ascii block """ blocked_text = ''.join( [' + --- ', key, ' ---\n'] + [' ' + side + ' ' + line + '\n' for line in text.split('\n')] + [' L ___ ', key, ' ___\n'] ) return blocked_text
[ "def", "msgblock", "(", "key", ",", "text", ",", "side", "=", "'|'", ")", ":", "blocked_text", "=", "''", ".", "join", "(", "[", "' + --- '", ",", "key", ",", "' ---\\n'", "]", "+", "[", "' '", "+", "side", "+", "' '", "+", "line", "+", "'\\n'", ...
puts text inside a visual ascii block
[ "puts", "text", "inside", "a", "visual", "ascii", "block" ]
3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2317-L2324
train