repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Erotemic/utool | utool/util_list.py | iflag_unique_items | def iflag_unique_items(list_):
"""
Returns a list of flags corresponding to the first time an item is seen
Args:
list_ (list): list of items
Returns:
flag_iter
"""
seen = set()
def unseen(item):
if item in seen:
return False
seen.add(item)
... | python | def iflag_unique_items(list_):
"""
Returns a list of flags corresponding to the first time an item is seen
Args:
list_ (list): list of items
Returns:
flag_iter
"""
seen = set()
def unseen(item):
if item in seen:
return False
seen.add(item)
... | [
"def",
"iflag_unique_items",
"(",
"list_",
")",
":",
"seen",
"=",
"set",
"(",
")",
"def",
"unseen",
"(",
"item",
")",
":",
"if",
"item",
"in",
"seen",
":",
"return",
"False",
"seen",
".",
"add",
"(",
"item",
")",
"return",
"True",
"flag_iter",
"=",
... | Returns a list of flags corresponding to the first time an item is seen
Args:
list_ (list): list of items
Returns:
flag_iter | [
"Returns",
"a",
"list",
"of",
"flags",
"corresponding",
"to",
"the",
"first",
"time",
"an",
"item",
"is",
"seen"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1332-L1349 | train | Returns a list of flags corresponding to the first time an item is seen |
Erotemic/utool | utool/util_list.py | unique_ordered | def unique_ordered(list_):
"""
Returns unique items in ``list_`` in the order they were seen.
Args:
list_ (list):
Returns:
list: unique_list - unique list which maintains order
CommandLine:
python -m utool.util_list --exec-unique_ordered
Example:
>>> # ENABLE_... | python | def unique_ordered(list_):
"""
Returns unique items in ``list_`` in the order they were seen.
Args:
list_ (list):
Returns:
list: unique_list - unique list which maintains order
CommandLine:
python -m utool.util_list --exec-unique_ordered
Example:
>>> # ENABLE_... | [
"def",
"unique_ordered",
"(",
"list_",
")",
":",
"list_",
"=",
"list",
"(",
"list_",
")",
"flag_list",
"=",
"flag_unique_items",
"(",
"list_",
")",
"unique_list",
"=",
"compress",
"(",
"list_",
",",
"flag_list",
")",
"return",
"unique_list"
] | Returns unique items in ``list_`` in the order they were seen.
Args:
list_ (list):
Returns:
list: unique_list - unique list which maintains order
CommandLine:
python -m utool.util_list --exec-unique_ordered
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_lis... | [
"Returns",
"unique",
"items",
"in",
"list_",
"in",
"the",
"order",
"they",
"were",
"seen",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1352-L1377 | train | Returns unique items in list_ in the order they were seen. |
Erotemic/utool | utool/util_list.py | setdiff | def setdiff(list1, list2):
"""
returns list1 elements that are not in list2. preserves order of list1
Args:
list1 (list):
list2 (list):
Returns:
list: new_list
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool ... | python | def setdiff(list1, list2):
"""
returns list1 elements that are not in list2. preserves order of list1
Args:
list1 (list):
list2 (list):
Returns:
list: new_list
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool ... | [
"def",
"setdiff",
"(",
"list1",
",",
"list2",
")",
":",
"set2",
"=",
"set",
"(",
"list2",
")",
"return",
"[",
"item",
"for",
"item",
"in",
"list1",
"if",
"item",
"not",
"in",
"set2",
"]"
] | returns list1 elements that are not in list2. preserves order of list1
Args:
list1 (list):
list2 (list):
Returns:
list: new_list
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool as ut
>>> list1 = ['featweight_... | [
"returns",
"list1",
"elements",
"that",
"are",
"not",
"in",
"list2",
".",
"preserves",
"order",
"of",
"list1"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1407-L1430 | train | returns list1 elements that are not in list2. preserves order of list1
|
Erotemic/utool | utool/util_list.py | isetdiff_flags | def isetdiff_flags(list1, list2):
"""
move to util_iter
"""
set2 = set(list2)
return (item not in set2 for item in list1) | python | def isetdiff_flags(list1, list2):
"""
move to util_iter
"""
set2 = set(list2)
return (item not in set2 for item in list1) | [
"def",
"isetdiff_flags",
"(",
"list1",
",",
"list2",
")",
":",
"set2",
"=",
"set",
"(",
"list2",
")",
"return",
"(",
"item",
"not",
"in",
"set2",
"for",
"item",
"in",
"list1",
")"
] | move to util_iter | [
"move",
"to",
"util_iter"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1437-L1442 | train | returns True if list1 and list2 are not in list1 |
Erotemic/utool | utool/util_list.py | sortedby | def sortedby(item_list, key_list, reverse=False):
""" sorts ``item_list`` using key_list
Args:
list_ (list): list to sort
key_list (list): list to sort by
reverse (bool): sort order is descending (largest first)
if reverse is True else acscending (smallest first)... | python | def sortedby(item_list, key_list, reverse=False):
""" sorts ``item_list`` using key_list
Args:
list_ (list): list to sort
key_list (list): list to sort by
reverse (bool): sort order is descending (largest first)
if reverse is True else acscending (smallest first)... | [
"def",
"sortedby",
"(",
"item_list",
",",
"key_list",
",",
"reverse",
"=",
"False",
")",
":",
"assert",
"len",
"(",
"item_list",
")",
"==",
"len",
"(",
"key_list",
")",
",",
"(",
"'Expected same len. Got: %r != %r'",
"%",
"(",
"len",
"(",
"item_list",
")",... | sorts ``item_list`` using key_list
Args:
list_ (list): list to sort
key_list (list): list to sort by
reverse (bool): sort order is descending (largest first)
if reverse is True else acscending (smallest first)
Returns:
list : ``list_`` sorted by the valu... | [
"sorts",
"item_list",
"using",
"key_list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1477-L1507 | train | Sort the list by the values of one list using key_list |
Erotemic/utool | utool/util_list.py | sortedby2 | def sortedby2(item_list, *args, **kwargs):
""" sorts ``item_list`` using key_list
Args:
item_list (list): list to sort
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending
Returns:
list : ``list_`` sorted by... | python | def sortedby2(item_list, *args, **kwargs):
""" sorts ``item_list`` using key_list
Args:
item_list (list): list to sort
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending
Returns:
list : ``list_`` sorted by... | [
"def",
"sortedby2",
"(",
"item_list",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"assert",
"all",
"(",
"[",
"len",
"(",
"item_list",
")",
"==",
"len_",
"for",
"len_",
"in",
"map",
"(",
"len",
",",
"args",
")",
"]",
")",
"reverse",
"=",
... | sorts ``item_list`` using key_list
Args:
item_list (list): list to sort
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending
Returns:
list : ``list_`` sorted by the values of another ``list``. defaults to
... | [
"sorts",
"item_list",
"using",
"key_list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1510-L1565 | train | This function sorts the items of a list using key_list
VIRTUAL_DOMAINS |
Erotemic/utool | utool/util_list.py | unflat_take | def unflat_take(items_list, unflat_index_list):
r"""
Returns nested subset of items_list
Args:
items_list (list):
unflat_index_list (list): nested list of indices
CommandLine:
python -m utool.util_list --exec-unflat_take
SeeAlso:
ut.take
Example:
>>> #... | python | def unflat_take(items_list, unflat_index_list):
r"""
Returns nested subset of items_list
Args:
items_list (list):
unflat_index_list (list): nested list of indices
CommandLine:
python -m utool.util_list --exec-unflat_take
SeeAlso:
ut.take
Example:
>>> #... | [
"def",
"unflat_take",
"(",
"items_list",
",",
"unflat_index_list",
")",
":",
"return",
"[",
"unflat_take",
"(",
"items_list",
",",
"xs",
")",
"if",
"isinstance",
"(",
"xs",
",",
"list",
")",
"else",
"take",
"(",
"items_list",
",",
"xs",
")",
"for",
"xs",... | r"""
Returns nested subset of items_list
Args:
items_list (list):
unflat_index_list (list): nested list of indices
CommandLine:
python -m utool.util_list --exec-unflat_take
SeeAlso:
ut.take
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list im... | [
"r",
"Returns",
"nested",
"subset",
"of",
"items_list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1568-L1594 | train | r Returns nested subset of items_list |
Erotemic/utool | utool/util_list.py | argsort | def argsort(*args, **kwargs):
"""
like np.argsort but for lists
Args:
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending
CommandLine:
python -m utool.util_list argsort
Example:
>>> # DISABLE_DOCTE... | python | def argsort(*args, **kwargs):
"""
like np.argsort but for lists
Args:
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending
CommandLine:
python -m utool.util_list argsort
Example:
>>> # DISABLE_DOCTE... | [
"def",
"argsort",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"isinstance",
"(",
"args",
"[",
"0",
"]",
",",
"dict",
")",
":",
"dict_",
"=",
"args",
"[",
"0",
"]",
"index_list",
"=",
"... | like np.argsort but for lists
Args:
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending
CommandLine:
python -m utool.util_list argsort
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list import... | [
"like",
"np",
".",
"argsort",
"but",
"for",
"lists"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1597-L1622 | train | Like np. argsort but for lists
AttributeNames |
Erotemic/utool | utool/util_list.py | argsort2 | def argsort2(indexable, key=None, reverse=False):
"""
Returns the indices that would sort a indexable object.
This is similar to np.argsort, but it is written in pure python and works
on both lists and dictionaries.
Args:
indexable (list or dict): indexable to sort by
Returns:
... | python | def argsort2(indexable, key=None, reverse=False):
"""
Returns the indices that would sort a indexable object.
This is similar to np.argsort, but it is written in pure python and works
on both lists and dictionaries.
Args:
indexable (list or dict): indexable to sort by
Returns:
... | [
"def",
"argsort2",
"(",
"indexable",
",",
"key",
"=",
"None",
",",
"reverse",
"=",
"False",
")",
":",
"# Create an iterator of value/key pairs",
"if",
"isinstance",
"(",
"indexable",
",",
"dict",
")",
":",
"vk_iter",
"=",
"(",
"(",
"v",
",",
"k",
")",
"f... | Returns the indices that would sort a indexable object.
This is similar to np.argsort, but it is written in pure python and works
on both lists and dictionaries.
Args:
indexable (list or dict): indexable to sort by
Returns:
list: indices: list of indices such that sorts the indexable
... | [
"Returns",
"the",
"indices",
"that",
"would",
"sort",
"a",
"indexable",
"object",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1625-L1665 | train | Returns the indices that would sort a indexable object. |
Erotemic/utool | utool/util_list.py | argmax | def argmax(input_, multi=False):
"""
Returns index / key of the item with the largest value.
Args:
input_ (dict or list):
References:
http://stackoverflow.com/questions/16945518/python-argmin-argmax
Ignore:
list_ = np.random.rand(10000).tolist()
%timeit list_.index... | python | def argmax(input_, multi=False):
"""
Returns index / key of the item with the largest value.
Args:
input_ (dict or list):
References:
http://stackoverflow.com/questions/16945518/python-argmin-argmax
Ignore:
list_ = np.random.rand(10000).tolist()
%timeit list_.index... | [
"def",
"argmax",
"(",
"input_",
",",
"multi",
"=",
"False",
")",
":",
"if",
"multi",
":",
"if",
"isinstance",
"(",
"input_",
",",
"dict",
")",
":",
"keys",
"=",
"list",
"(",
"input_",
".",
"keys",
"(",
")",
")",
"values",
"=",
"list",
"(",
"input... | Returns index / key of the item with the largest value.
Args:
input_ (dict or list):
References:
http://stackoverflow.com/questions/16945518/python-argmin-argmax
Ignore:
list_ = np.random.rand(10000).tolist()
%timeit list_.index(max(list_))
%timeit max(enumerate(li... | [
"Returns",
"index",
"/",
"key",
"of",
"the",
"item",
"with",
"the",
"largest",
"value",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1668-L1715 | train | Returns index of the item with the largest value. |
Erotemic/utool | utool/util_list.py | argmin | def argmin(input_, key=None):
"""
Returns index / key of the item with the smallest value.
Args:
input_ (dict or list):
Note:
a[argmin(a, key=key)] == min(a, key=key)
"""
# if isinstance(input_, dict):
# return list(input_.keys())[argmin(list(input_.values()))]
# el... | python | def argmin(input_, key=None):
"""
Returns index / key of the item with the smallest value.
Args:
input_ (dict or list):
Note:
a[argmin(a, key=key)] == min(a, key=key)
"""
# if isinstance(input_, dict):
# return list(input_.keys())[argmin(list(input_.values()))]
# el... | [
"def",
"argmin",
"(",
"input_",
",",
"key",
"=",
"None",
")",
":",
"# if isinstance(input_, dict):",
"# return list(input_.keys())[argmin(list(input_.values()))]",
"# elif hasattr(input_, 'index'):",
"# return input_.index(min(input_))",
"# else:",
"# return min(enumerate(i... | Returns index / key of the item with the smallest value.
Args:
input_ (dict or list):
Note:
a[argmin(a, key=key)] == min(a, key=key) | [
"Returns",
"index",
"/",
"key",
"of",
"the",
"item",
"with",
"the",
"smallest",
"value",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1718-L1743 | train | Returns index of the item with the smallest value. |
Erotemic/utool | utool/util_list.py | index_complement | def index_complement(index_list, len_=None):
"""
Returns the other indicies in a list of length ``len_``
"""
mask1 = index_to_boolmask(index_list, len_)
mask2 = not_list(mask1)
index_list_bar = list_where(mask2)
return index_list_bar | python | def index_complement(index_list, len_=None):
"""
Returns the other indicies in a list of length ``len_``
"""
mask1 = index_to_boolmask(index_list, len_)
mask2 = not_list(mask1)
index_list_bar = list_where(mask2)
return index_list_bar | [
"def",
"index_complement",
"(",
"index_list",
",",
"len_",
"=",
"None",
")",
":",
"mask1",
"=",
"index_to_boolmask",
"(",
"index_list",
",",
"len_",
")",
"mask2",
"=",
"not_list",
"(",
"mask1",
")",
"index_list_bar",
"=",
"list_where",
"(",
"mask2",
")",
"... | Returns the other indicies in a list of length ``len_`` | [
"Returns",
"the",
"other",
"indicies",
"in",
"a",
"list",
"of",
"length",
"len_"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1746-L1753 | train | Returns the other indicies in a list of length len_. |
Erotemic/utool | utool/util_list.py | take_complement | def take_complement(list_, index_list):
""" Returns items in ``list_`` not indexed by index_list """
mask = not_list(index_to_boolmask(index_list, len(list_)))
return compress(list_, mask) | python | def take_complement(list_, index_list):
""" Returns items in ``list_`` not indexed by index_list """
mask = not_list(index_to_boolmask(index_list, len(list_)))
return compress(list_, mask) | [
"def",
"take_complement",
"(",
"list_",
",",
"index_list",
")",
":",
"mask",
"=",
"not_list",
"(",
"index_to_boolmask",
"(",
"index_list",
",",
"len",
"(",
"list_",
")",
")",
")",
"return",
"compress",
"(",
"list_",
",",
"mask",
")"
] | Returns items in ``list_`` not indexed by index_list | [
"Returns",
"items",
"in",
"list_",
"not",
"indexed",
"by",
"index_list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1756-L1759 | train | Returns items in list_ not indexed by index_list |
Erotemic/utool | utool/util_list.py | take | def take(list_, index_list):
"""
Selects a subset of a list based on a list of indices.
This is similar to np.take, but pure python.
Args:
list_ (list): some indexable object
index_list (list, slice, int): some indexing object
Returns:
list or scalar: subset of the list
... | python | def take(list_, index_list):
"""
Selects a subset of a list based on a list of indices.
This is similar to np.take, but pure python.
Args:
list_ (list): some indexable object
index_list (list, slice, int): some indexing object
Returns:
list or scalar: subset of the list
... | [
"def",
"take",
"(",
"list_",
",",
"index_list",
")",
":",
"try",
":",
"return",
"[",
"list_",
"[",
"index",
"]",
"for",
"index",
"in",
"index_list",
"]",
"except",
"TypeError",
":",
"return",
"list_",
"[",
"index_list",
"]"
] | Selects a subset of a list based on a list of indices.
This is similar to np.take, but pure python.
Args:
list_ (list): some indexable object
index_list (list, slice, int): some indexing object
Returns:
list or scalar: subset of the list
CommandLine:
python -m utool.ut... | [
"Selects",
"a",
"subset",
"of",
"a",
"list",
"based",
"on",
"a",
"list",
"of",
"indices",
".",
"This",
"is",
"similar",
"to",
"np",
".",
"take",
"but",
"pure",
"python",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1772-L1823 | train | Takes a subset of a list based on a list of indices |
Erotemic/utool | utool/util_list.py | take_percentile | def take_percentile(arr, percent):
""" take the top `percent` items in a list rounding up """
size = len(arr)
stop = min(int(size * percent), len(arr))
return arr[0:stop] | python | def take_percentile(arr, percent):
""" take the top `percent` items in a list rounding up """
size = len(arr)
stop = min(int(size * percent), len(arr))
return arr[0:stop] | [
"def",
"take_percentile",
"(",
"arr",
",",
"percent",
")",
":",
"size",
"=",
"len",
"(",
"arr",
")",
"stop",
"=",
"min",
"(",
"int",
"(",
"size",
"*",
"percent",
")",
",",
"len",
"(",
"arr",
")",
")",
"return",
"arr",
"[",
"0",
":",
"stop",
"]"... | take the top `percent` items in a list rounding up | [
"take",
"the",
"top",
"percent",
"items",
"in",
"a",
"list",
"rounding",
"up"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1834-L1838 | train | take the top percent items in a list rounding up |
Erotemic/utool | utool/util_list.py | snapped_slice | def snapped_slice(size, frac, n):
r"""
Creates a slice spanning `n` items in a list of length `size` at position
`frac`.
Args:
size (int): length of the list
frac (float): position in the range [0, 1]
n (int): number of items in the slice
Returns:
slice: slice objec... | python | def snapped_slice(size, frac, n):
r"""
Creates a slice spanning `n` items in a list of length `size` at position
`frac`.
Args:
size (int): length of the list
frac (float): position in the range [0, 1]
n (int): number of items in the slice
Returns:
slice: slice objec... | [
"def",
"snapped_slice",
"(",
"size",
",",
"frac",
",",
"n",
")",
":",
"if",
"size",
"<",
"n",
":",
"n",
"=",
"size",
"start",
"=",
"int",
"(",
"size",
"*",
"frac",
"-",
"ceil",
"(",
"n",
"/",
"2",
")",
")",
"+",
"1",
"stop",
"=",
"int",
"("... | r"""
Creates a slice spanning `n` items in a list of length `size` at position
`frac`.
Args:
size (int): length of the list
frac (float): position in the range [0, 1]
n (int): number of items in the slice
Returns:
slice: slice object that best fits the criteria
See... | [
"r",
"Creates",
"a",
"slice",
"spanning",
"n",
"items",
"in",
"a",
"list",
"of",
"length",
"size",
"at",
"position",
"frac",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1841-L1884 | train | r Returns a slice that spanning n items in a list at position size at position frac. |
Erotemic/utool | utool/util_list.py | take_percentile_parts | def take_percentile_parts(arr, front=None, mid=None, back=None):
r"""
Take parts from front, back, or middle of a list
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool as ut
>>> arr = list(range(20))
>>> front = 3
>>> m... | python | def take_percentile_parts(arr, front=None, mid=None, back=None):
r"""
Take parts from front, back, or middle of a list
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool as ut
>>> arr = list(range(20))
>>> front = 3
>>> m... | [
"def",
"take_percentile_parts",
"(",
"arr",
",",
"front",
"=",
"None",
",",
"mid",
"=",
"None",
",",
"back",
"=",
"None",
")",
":",
"slices",
"=",
"[",
"]",
"if",
"front",
":",
"slices",
"+=",
"[",
"snapped_slice",
"(",
"len",
"(",
"arr",
")",
",",... | r"""
Take parts from front, back, or middle of a list
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool as ut
>>> arr = list(range(20))
>>> front = 3
>>> mid = 3
>>> back = 3
>>> result = take_percentile_part... | [
"r",
"Take",
"parts",
"from",
"front",
"back",
"or",
"middle",
"of",
"a",
"list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1907-L1931 | train | r Take parts from front back or middle of a list
|
Erotemic/utool | utool/util_list.py | list_inverse_take | def list_inverse_take(list_, index_list):
r"""
Args:
list_ (list): list in sorted domain
index_list (list): index list of the unsorted domain
Note:
Seems to be logically equivalent to
ut.take(list_, ut.argsort(index_list)), but faster
Returns:
list: output_list_... | python | def list_inverse_take(list_, index_list):
r"""
Args:
list_ (list): list in sorted domain
index_list (list): index list of the unsorted domain
Note:
Seems to be logically equivalent to
ut.take(list_, ut.argsort(index_list)), but faster
Returns:
list: output_list_... | [
"def",
"list_inverse_take",
"(",
"list_",
",",
"index_list",
")",
":",
"output_list_",
"=",
"[",
"None",
"]",
"*",
"len",
"(",
"index_list",
")",
"for",
"item",
",",
"index",
"in",
"zip",
"(",
"list_",
",",
"index_list",
")",
":",
"output_list_",
"[",
... | r"""
Args:
list_ (list): list in sorted domain
index_list (list): index list of the unsorted domain
Note:
Seems to be logically equivalent to
ut.take(list_, ut.argsort(index_list)), but faster
Returns:
list: output_list_ - the input list in the unsorted domain
... | [
"r",
"Args",
":",
"list_",
"(",
"list",
")",
":",
"list",
"in",
"sorted",
"domain",
"index_list",
"(",
"list",
")",
":",
"index",
"list",
"of",
"the",
"unsorted",
"domain"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1934-L1976 | train | r This function takes a list of items from the unsorted domain and returns the list of items in the unsorted domain. |
Erotemic/utool | utool/util_list.py | broadcast_zip | def broadcast_zip(list1, list2):
r"""
Zips elementwise pairs between list1 and list2. Broadcasts
the first dimension if a single list is of length 1.
Aliased as bzip
Args:
list1 (list):
list2 (list):
Returns:
list: list of pairs
SeeAlso:
util_dict.dzip
... | python | def broadcast_zip(list1, list2):
r"""
Zips elementwise pairs between list1 and list2. Broadcasts
the first dimension if a single list is of length 1.
Aliased as bzip
Args:
list1 (list):
list2 (list):
Returns:
list: list of pairs
SeeAlso:
util_dict.dzip
... | [
"def",
"broadcast_zip",
"(",
"list1",
",",
"list2",
")",
":",
"try",
":",
"len",
"(",
"list1",
")",
"except",
"TypeError",
":",
"list1",
"=",
"list",
"(",
"list1",
")",
"try",
":",
"len",
"(",
"list2",
")",
"except",
"TypeError",
":",
"list2",
"=",
... | r"""
Zips elementwise pairs between list1 and list2. Broadcasts
the first dimension if a single list is of length 1.
Aliased as bzip
Args:
list1 (list):
list2 (list):
Returns:
list: list of pairs
SeeAlso:
util_dict.dzip
Raises:
ValueError: if the ... | [
"r",
"Zips",
"elementwise",
"pairs",
"between",
"list1",
"and",
"list2",
".",
"Broadcasts",
"the",
"first",
"dimension",
"if",
"a",
"single",
"list",
"is",
"of",
"length",
"1",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L1979-L2031 | train | r Returns a new list of elementwise pairs between list1 and list2. |
Erotemic/utool | utool/util_list.py | equal | def equal(list1, list2):
""" takes flags returns indexes of True values """
return [item1 == item2 for item1, item2 in broadcast_zip(list1, list2)] | python | def equal(list1, list2):
""" takes flags returns indexes of True values """
return [item1 == item2 for item1, item2 in broadcast_zip(list1, list2)] | [
"def",
"equal",
"(",
"list1",
",",
"list2",
")",
":",
"return",
"[",
"item1",
"==",
"item2",
"for",
"item1",
",",
"item2",
"in",
"broadcast_zip",
"(",
"list1",
",",
"list2",
")",
"]"
] | takes flags returns indexes of True values | [
"takes",
"flags",
"returns",
"indexes",
"of",
"True",
"values"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2039-L2041 | train | returns indexes of True values in list1 and list2 |
Erotemic/utool | utool/util_list.py | scalar_input_map | def scalar_input_map(func, input_):
"""
Map like function
Args:
func: function to apply
input_ : either an iterable or scalar value
Returns:
If ``input_`` is iterable this function behaves like map
otherwise applies func to ``input_``
"""
if util_iter.isiterable... | python | def scalar_input_map(func, input_):
"""
Map like function
Args:
func: function to apply
input_ : either an iterable or scalar value
Returns:
If ``input_`` is iterable this function behaves like map
otherwise applies func to ``input_``
"""
if util_iter.isiterable... | [
"def",
"scalar_input_map",
"(",
"func",
",",
"input_",
")",
":",
"if",
"util_iter",
".",
"isiterable",
"(",
"input_",
")",
":",
"return",
"list",
"(",
"map",
"(",
"func",
",",
"input_",
")",
")",
"else",
":",
"return",
"func",
"(",
"input_",
")"
] | Map like function
Args:
func: function to apply
input_ : either an iterable or scalar value
Returns:
If ``input_`` is iterable this function behaves like map
otherwise applies func to ``input_`` | [
"Map",
"like",
"function"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2061-L2076 | train | Map like function
|
Erotemic/utool | utool/util_list.py | partial_imap_1to1 | def partial_imap_1to1(func, si_func):
""" a bit messy
DEPRICATE
"""
@functools.wraps(si_func)
def wrapper(input_):
if not util_iter.isiterable(input_):
return func(si_func(input_))
else:
return list(map(func, si_func(input_)))
set_funcname(wrapper, util_s... | python | def partial_imap_1to1(func, si_func):
""" a bit messy
DEPRICATE
"""
@functools.wraps(si_func)
def wrapper(input_):
if not util_iter.isiterable(input_):
return func(si_func(input_))
else:
return list(map(func, si_func(input_)))
set_funcname(wrapper, util_s... | [
"def",
"partial_imap_1to1",
"(",
"func",
",",
"si_func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"si_func",
")",
"def",
"wrapper",
"(",
"input_",
")",
":",
"if",
"not",
"util_iter",
".",
"isiterable",
"(",
"input_",
")",
":",
"return",
"func",
"... | a bit messy
DEPRICATE | [
"a",
"bit",
"messy"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2079-L2091 | train | a bit messy
DEPRICATE
|
Erotemic/utool | utool/util_list.py | sample_zip | def sample_zip(items_list, num_samples, allow_overflow=False, per_bin=1):
""" Helper for sampling
Given a list of lists, samples one item for each list and bins them into
num_samples bins. If all sublists are of equal size this is equivilent to a
zip, but otherewise consecutive bins will have monotonic... | python | def sample_zip(items_list, num_samples, allow_overflow=False, per_bin=1):
""" Helper for sampling
Given a list of lists, samples one item for each list and bins them into
num_samples bins. If all sublists are of equal size this is equivilent to a
zip, but otherewise consecutive bins will have monotonic... | [
"def",
"sample_zip",
"(",
"items_list",
",",
"num_samples",
",",
"allow_overflow",
"=",
"False",
",",
"per_bin",
"=",
"1",
")",
":",
"# Prealloc a list of lists",
"samples_list",
"=",
"[",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"num_samples",
")",
"]",
... | Helper for sampling
Given a list of lists, samples one item for each list and bins them into
num_samples bins. If all sublists are of equal size this is equivilent to a
zip, but otherewise consecutive bins will have monotonically less
elemements
# Doctest doesn't work with assertionerror
#util... | [
"Helper",
"for",
"sampling"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2094-L2152 | train | Samples a list of items into a new base directory tree structure |
Erotemic/utool | utool/util_list.py | sample_lists | def sample_lists(items_list, num=1, seed=None):
r"""
Args:
items_list (list):
num (int): (default = 1)
seed (None): (default = None)
Returns:
list: samples_list
CommandLine:
python -m utool.util_list --exec-sample_lists
Example:
>>> # DISABLE_DOCTES... | python | def sample_lists(items_list, num=1, seed=None):
r"""
Args:
items_list (list):
num (int): (default = 1)
seed (None): (default = None)
Returns:
list: samples_list
CommandLine:
python -m utool.util_list --exec-sample_lists
Example:
>>> # DISABLE_DOCTES... | [
"def",
"sample_lists",
"(",
"items_list",
",",
"num",
"=",
"1",
",",
"seed",
"=",
"None",
")",
":",
"if",
"seed",
"is",
"not",
"None",
":",
"rng",
"=",
"np",
".",
"random",
".",
"RandomState",
"(",
"seed",
")",
"else",
":",
"rng",
"=",
"np",
".",... | r"""
Args:
items_list (list):
num (int): (default = 1)
seed (None): (default = None)
Returns:
list: samples_list
CommandLine:
python -m utool.util_list --exec-sample_lists
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list import * # NOQA
... | [
"r",
"Args",
":",
"items_list",
"(",
"list",
")",
":",
"num",
"(",
"int",
")",
":",
"(",
"default",
"=",
"1",
")",
"seed",
"(",
"None",
")",
":",
"(",
"default",
"=",
"None",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2155-L2189 | train | r Sample a list of items from the items_list |
Erotemic/utool | utool/util_list.py | issorted | def issorted(list_, op=operator.le):
"""
Determines if a list is sorted
Args:
list_ (list):
op (func): sorted operation (default=operator.le)
Returns:
bool : True if the list is sorted
"""
return all(op(list_[ix], list_[ix + 1]) for ix in range(len(list_) - 1)) | python | def issorted(list_, op=operator.le):
"""
Determines if a list is sorted
Args:
list_ (list):
op (func): sorted operation (default=operator.le)
Returns:
bool : True if the list is sorted
"""
return all(op(list_[ix], list_[ix + 1]) for ix in range(len(list_) - 1)) | [
"def",
"issorted",
"(",
"list_",
",",
"op",
"=",
"operator",
".",
"le",
")",
":",
"return",
"all",
"(",
"op",
"(",
"list_",
"[",
"ix",
"]",
",",
"list_",
"[",
"ix",
"+",
"1",
"]",
")",
"for",
"ix",
"in",
"range",
"(",
"len",
"(",
"list_",
")"... | Determines if a list is sorted
Args:
list_ (list):
op (func): sorted operation (default=operator.le)
Returns:
bool : True if the list is sorted | [
"Determines",
"if",
"a",
"list",
"is",
"sorted"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2213-L2224 | train | Determines if a list is sorted by a given operation |
Erotemic/utool | utool/util_list.py | find_nonconsec_values | def find_nonconsec_values(values, min_=None, max_=None):
"""
Determines if a list of values is consecutive (ascending)
Args:
values (list): list of values, sorted and unique
min_(int): minimum value in range defaults min(values)
max_(int): maximum value in range defaults max(values)... | python | def find_nonconsec_values(values, min_=None, max_=None):
"""
Determines if a list of values is consecutive (ascending)
Args:
values (list): list of values, sorted and unique
min_(int): minimum value in range defaults min(values)
max_(int): maximum value in range defaults max(values)... | [
"def",
"find_nonconsec_values",
"(",
"values",
",",
"min_",
"=",
"None",
",",
"max_",
"=",
"None",
")",
":",
"# values = sorted(set(values))",
"if",
"min_",
"is",
"None",
":",
"min_",
"=",
"values",
"[",
"0",
"]",
"if",
"max_",
"is",
"None",
":",
"max_",... | Determines if a list of values is consecutive (ascending)
Args:
values (list): list of values, sorted and unique
min_(int): minimum value in range defaults min(values)
max_(int): maximum value in range defaults max(values)
Returns:
missing_values: missing values that would make... | [
"Determines",
"if",
"a",
"list",
"of",
"values",
"is",
"consecutive",
"(",
"ascending",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2227-L2263 | train | Determines if a list of values is consecutive |
Erotemic/utool | utool/util_list.py | group_consecutives | def group_consecutives(data, stepsize=1):
"""
Return list of consecutive lists of numbers from data (number list).
References:
http://stackoverflow.com/questions/7352684/how-to-find-the-groups-of-consecutive-elements-from-an-array-in-numpy
"""
run = []
result = [run]
expect = None
... | python | def group_consecutives(data, stepsize=1):
"""
Return list of consecutive lists of numbers from data (number list).
References:
http://stackoverflow.com/questions/7352684/how-to-find-the-groups-of-consecutive-elements-from-an-array-in-numpy
"""
run = []
result = [run]
expect = None
... | [
"def",
"group_consecutives",
"(",
"data",
",",
"stepsize",
"=",
"1",
")",
":",
"run",
"=",
"[",
"]",
"result",
"=",
"[",
"run",
"]",
"expect",
"=",
"None",
"for",
"item",
"in",
"data",
":",
"if",
"(",
"item",
"==",
"expect",
")",
"or",
"(",
"expe... | Return list of consecutive lists of numbers from data (number list).
References:
http://stackoverflow.com/questions/7352684/how-to-find-the-groups-of-consecutive-elements-from-an-array-in-numpy | [
"Return",
"list",
"of",
"consecutive",
"lists",
"of",
"numbers",
"from",
"data",
"(",
"number",
"list",
")",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2266-L2283 | train | Return list of consecutive lists of numbers from data. |
Erotemic/utool | utool/util_list.py | debug_consec_list | def debug_consec_list(list_):
"""
Returns:
tuple of (missing_items, missing_indices, duplicate_items)
"""
if not issorted(list_):
print('warning list is not sorted. indices will not match')
sortedlist = sorted(list_)
start = sortedlist[0]
last = start - 1
missing_vals = [... | python | def debug_consec_list(list_):
"""
Returns:
tuple of (missing_items, missing_indices, duplicate_items)
"""
if not issorted(list_):
print('warning list is not sorted. indices will not match')
sortedlist = sorted(list_)
start = sortedlist[0]
last = start - 1
missing_vals = [... | [
"def",
"debug_consec_list",
"(",
"list_",
")",
":",
"if",
"not",
"issorted",
"(",
"list_",
")",
":",
"print",
"(",
"'warning list is not sorted. indices will not match'",
")",
"sortedlist",
"=",
"sorted",
"(",
"list_",
")",
"start",
"=",
"sortedlist",
"[",
"0",
... | Returns:
tuple of (missing_items, missing_indices, duplicate_items) | [
"Returns",
":",
"tuple",
"of",
"(",
"missing_items",
"missing_indices",
"duplicate_items",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2322-L2349 | train | Returns a tuple of missing items missing indices duplicate items |
Erotemic/utool | utool/util_list.py | find_duplicate_items | def find_duplicate_items(items, k=2):
r"""
Args:
items (list):
Returns:
dict: duplicate_map of indexes
CommandLine:
python -m utool.util_list --test-find_duplicate_items
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> it... | python | def find_duplicate_items(items, k=2):
r"""
Args:
items (list):
Returns:
dict: duplicate_map of indexes
CommandLine:
python -m utool.util_list --test-find_duplicate_items
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> it... | [
"def",
"find_duplicate_items",
"(",
"items",
",",
"k",
"=",
"2",
")",
":",
"import",
"utool",
"as",
"ut",
"# Build item histogram",
"duplicate_map",
"=",
"ut",
".",
"ddict",
"(",
"list",
")",
"for",
"count",
",",
"item",
"in",
"enumerate",
"(",
"items",
... | r"""
Args:
items (list):
Returns:
dict: duplicate_map of indexes
CommandLine:
python -m utool.util_list --test-find_duplicate_items
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> items = [0, 1, 2, 3, 3, 0, 12, 2, 9]
... | [
"r",
"Args",
":",
"items",
"(",
"list",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2352-L2384 | train | r Find duplicate items in a list |
Erotemic/utool | utool/util_list.py | list_depth | def list_depth(list_, func=max, _depth=0):
"""
Returns the deepest level of nesting within a list of lists
Args:
list_ : a nested listlike object
func : depth aggregation strategy (defaults to max)
_depth : internal var
Example:
>>> # ENABLE_DOCTEST
>>> from uto... | python | def list_depth(list_, func=max, _depth=0):
"""
Returns the deepest level of nesting within a list of lists
Args:
list_ : a nested listlike object
func : depth aggregation strategy (defaults to max)
_depth : internal var
Example:
>>> # ENABLE_DOCTEST
>>> from uto... | [
"def",
"list_depth",
"(",
"list_",
",",
"func",
"=",
"max",
",",
"_depth",
"=",
"0",
")",
":",
"depth_list",
"=",
"[",
"list_depth",
"(",
"item",
",",
"func",
"=",
"func",
",",
"_depth",
"=",
"_depth",
"+",
"1",
")",
"for",
"item",
"in",
"list_",
... | Returns the deepest level of nesting within a list of lists
Args:
list_ : a nested listlike object
func : depth aggregation strategy (defaults to max)
_depth : internal var
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> list_ = [[[[[... | [
"Returns",
"the",
"deepest",
"level",
"of",
"nesting",
"within",
"a",
"list",
"of",
"lists"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2434-L2456 | train | Returns the deepest level of nesting within a list of lists |
Erotemic/utool | utool/util_list.py | depth | def depth(sequence, func=max, _depth=0):
"""
Find the nesting depth of a nested sequence
"""
if isinstance(sequence, dict):
sequence = list(sequence.values())
depth_list = [depth(item, func=func, _depth=_depth + 1)
for item in sequence if (isinstance(item, dict) or util_typ... | python | def depth(sequence, func=max, _depth=0):
"""
Find the nesting depth of a nested sequence
"""
if isinstance(sequence, dict):
sequence = list(sequence.values())
depth_list = [depth(item, func=func, _depth=_depth + 1)
for item in sequence if (isinstance(item, dict) or util_typ... | [
"def",
"depth",
"(",
"sequence",
",",
"func",
"=",
"max",
",",
"_depth",
"=",
"0",
")",
":",
"if",
"isinstance",
"(",
"sequence",
",",
"dict",
")",
":",
"sequence",
"=",
"list",
"(",
"sequence",
".",
"values",
"(",
")",
")",
"depth_list",
"=",
"[",... | Find the nesting depth of a nested sequence | [
"Find",
"the",
"nesting",
"depth",
"of",
"a",
"nested",
"sequence"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2459-L2470 | train | Find the nesting depth of a nested sequence |
Erotemic/utool | utool/util_list.py | list_deep_types | def list_deep_types(list_):
"""
Returns all types in a deep list
"""
type_list = []
for item in list_:
if util_type.is_listlike(item):
type_list.extend(list_deep_types(item))
else:
type_list.append(type(item))
return type_list | python | def list_deep_types(list_):
"""
Returns all types in a deep list
"""
type_list = []
for item in list_:
if util_type.is_listlike(item):
type_list.extend(list_deep_types(item))
else:
type_list.append(type(item))
return type_list | [
"def",
"list_deep_types",
"(",
"list_",
")",
":",
"type_list",
"=",
"[",
"]",
"for",
"item",
"in",
"list_",
":",
"if",
"util_type",
".",
"is_listlike",
"(",
"item",
")",
":",
"type_list",
".",
"extend",
"(",
"list_deep_types",
"(",
"item",
")",
")",
"e... | Returns all types in a deep list | [
"Returns",
"all",
"types",
"in",
"a",
"deep",
"list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2473-L2483 | train | Returns all types in a deep list |
Erotemic/utool | utool/util_list.py | depth_profile | def depth_profile(list_, max_depth=None, compress_homogenous=True, compress_consecutive=False, new_depth=False):
r"""
Returns a nested list corresponding the shape of the nested structures
lists represent depth, tuples represent shape. The values of the items do
not matter. only the lengths.
Args:
... | python | def depth_profile(list_, max_depth=None, compress_homogenous=True, compress_consecutive=False, new_depth=False):
r"""
Returns a nested list corresponding the shape of the nested structures
lists represent depth, tuples represent shape. The values of the items do
not matter. only the lengths.
Args:
... | [
"def",
"depth_profile",
"(",
"list_",
",",
"max_depth",
"=",
"None",
",",
"compress_homogenous",
"=",
"True",
",",
"compress_consecutive",
"=",
"False",
",",
"new_depth",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"list_",
",",
"dict",
")",
":",
"lis... | r"""
Returns a nested list corresponding the shape of the nested structures
lists represent depth, tuples represent shape. The values of the items do
not matter. only the lengths.
Args:
list_ (list):
max_depth (None):
compress_homogenous (bool):
compress_consecutive (boo... | [
"r",
"Returns",
"a",
"nested",
"list",
"corresponding",
"the",
"shape",
"of",
"the",
"nested",
"structures",
"lists",
"represent",
"depth",
"tuples",
"represent",
"shape",
".",
"The",
"values",
"of",
"the",
"items",
"do",
"not",
"matter",
".",
"only",
"the",... | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2486-L2665 | train | r Returns a nested list corresponding to the shape of the nested structures
lists represent depth tuples. |
Erotemic/utool | utool/util_list.py | list_type_profile | def list_type_profile(sequence, compress_homogenous=True, with_dtype=True):
"""
similar to depth_profile but reports types
Args:
sequence (?):
compress_homogenous (bool): (default = True)
Returns:
str: level_type_str
CommandLine:
python -m utool.util_list --test-li... | python | def list_type_profile(sequence, compress_homogenous=True, with_dtype=True):
"""
similar to depth_profile but reports types
Args:
sequence (?):
compress_homogenous (bool): (default = True)
Returns:
str: level_type_str
CommandLine:
python -m utool.util_list --test-li... | [
"def",
"list_type_profile",
"(",
"sequence",
",",
"compress_homogenous",
"=",
"True",
",",
"with_dtype",
"=",
"True",
")",
":",
"# For a pure bottom level list return the length",
"#if not any(map(util_type.is_listlike, sequence)) or (isinstance(sequence, np.ndarray) and sequence.dtype... | similar to depth_profile but reports types
Args:
sequence (?):
compress_homogenous (bool): (default = True)
Returns:
str: level_type_str
CommandLine:
python -m utool.util_list --test-list_type_profile
python3 -m utool.util_list --test-list_type_profile
Example... | [
"similar",
"to",
"depth_profile",
"but",
"reports",
"types"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2676-L2734 | train | This function returns the type of the elements in the given sequence |
Erotemic/utool | utool/util_list.py | type_profile2 | def type_profile2(sequence, TypedSequence=None):
"""
similar to depth_profile but reports types
Args:
sequence (?):
compress_homogenous (bool): (default = True)
Returns:
str: level_type_str
CommandLine:
python -m utool.util_list --exec-type_profile2
Example:
... | python | def type_profile2(sequence, TypedSequence=None):
"""
similar to depth_profile but reports types
Args:
sequence (?):
compress_homogenous (bool): (default = True)
Returns:
str: level_type_str
CommandLine:
python -m utool.util_list --exec-type_profile2
Example:
... | [
"def",
"type_profile2",
"(",
"sequence",
",",
"TypedSequence",
"=",
"None",
")",
":",
"if",
"TypedSequence",
"is",
"None",
":",
"TypedSequence",
"=",
"type_sequence_factory",
"(",
")",
"# For a pure bottom level list return the length",
"#if not any(map(util_type.is_listlik... | similar to depth_profile but reports types
Args:
sequence (?):
compress_homogenous (bool): (default = True)
Returns:
str: level_type_str
CommandLine:
python -m utool.util_list --exec-type_profile2
Example:
>>> # DISABLE_DOCTEST
>>> sequence = []
... | [
"similar",
"to",
"depth_profile",
"but",
"reports",
"types"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2737-L2779 | train | This function returns a type_profile that uses the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level_type_str of the level... |
Erotemic/utool | utool/util_list.py | list_cover | def list_cover(list1, list2):
r"""
returns boolean for each position in list1 if it is in list2
Args:
list1 (list):
list2 (list):
Returns:
list: incover_list - true where list1 intersects list2
CommandLine:
python -m utool.util_list --test-list_cover
Example:
... | python | def list_cover(list1, list2):
r"""
returns boolean for each position in list1 if it is in list2
Args:
list1 (list):
list2 (list):
Returns:
list: incover_list - true where list1 intersects list2
CommandLine:
python -m utool.util_list --test-list_cover
Example:
... | [
"def",
"list_cover",
"(",
"list1",
",",
"list2",
")",
":",
"set2",
"=",
"set",
"(",
"list2",
")",
"incover_list",
"=",
"[",
"item1",
"in",
"set2",
"for",
"item1",
"in",
"list1",
"]",
"return",
"incover_list"
] | r"""
returns boolean for each position in list1 if it is in list2
Args:
list1 (list):
list2 (list):
Returns:
list: incover_list - true where list1 intersects list2
CommandLine:
python -m utool.util_list --test-list_cover
Example:
>>> # DISABLE_DOCTEST
... | [
"r",
"returns",
"boolean",
"for",
"each",
"position",
"in",
"list1",
"if",
"it",
"is",
"in",
"list2"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2846-L2875 | train | r Tests if list1 intersects list2 |
Erotemic/utool | utool/util_list.py | list_argmaxima | def list_argmaxima(list_):
r"""
Args:
list_ (list):
Returns:
list: argmaxima
CommandLine:
python -m utool.util_list --exec-list_argmaxima
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> list_ = np.array([1, 2, 3, 3, 3, 2,... | python | def list_argmaxima(list_):
r"""
Args:
list_ (list):
Returns:
list: argmaxima
CommandLine:
python -m utool.util_list --exec-list_argmaxima
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> list_ = np.array([1, 2, 3, 3, 3, 2,... | [
"def",
"list_argmaxima",
"(",
"list_",
")",
":",
"argmax",
"=",
"list_argmax",
"(",
"list_",
")",
"maxval",
"=",
"list_",
"[",
"argmax",
"]",
"argmaxima",
"=",
"np",
".",
"where",
"(",
"(",
"np",
".",
"isclose",
"(",
"maxval",
",",
"list_",
")",
")",... | r"""
Args:
list_ (list):
Returns:
list: argmaxima
CommandLine:
python -m utool.util_list --exec-list_argmaxima
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> list_ = np.array([1, 2, 3, 3, 3, 2, 1])
>>> argmaxima = li... | [
"r",
"Args",
":",
"list_",
"(",
"list",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2957-L2980 | train | r List the argmaxima of a set of items in a set of items |
Erotemic/utool | utool/util_list.py | make_index_lookup | def make_index_lookup(list_, dict_factory=dict):
r"""
Args:
list_ (list): assumed to have unique items
Returns:
dict: mapping from item to index
CommandLine:
python -m utool.util_list --exec-make_index_lookup
Example:
>>> # ENABLE_DOCTEST
>>> from utool.uti... | python | def make_index_lookup(list_, dict_factory=dict):
r"""
Args:
list_ (list): assumed to have unique items
Returns:
dict: mapping from item to index
CommandLine:
python -m utool.util_list --exec-make_index_lookup
Example:
>>> # ENABLE_DOCTEST
>>> from utool.uti... | [
"def",
"make_index_lookup",
"(",
"list_",
",",
"dict_factory",
"=",
"dict",
")",
":",
"return",
"dict_factory",
"(",
"zip",
"(",
"list_",
",",
"range",
"(",
"len",
"(",
"list_",
")",
")",
")",
")"
] | r"""
Args:
list_ (list): assumed to have unique items
Returns:
dict: mapping from item to index
CommandLine:
python -m utool.util_list --exec-make_index_lookup
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> import utool as u... | [
"r",
"Args",
":",
"list_",
"(",
"list",
")",
":",
"assumed",
"to",
"have",
"unique",
"items"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L2983-L3005 | train | r This function will make a dictionary mapping from item to index. |
Erotemic/utool | utool/util_list.py | list_alignment | def list_alignment(list1, list2, missing=False):
"""
Assumes list items are unique
Args:
list1 (list): a list of unique items to be aligned
list2 (list): a list of unique items in a desired ordering
missing (bool): True if list2 can contain items not in list1
Returns:
l... | python | def list_alignment(list1, list2, missing=False):
"""
Assumes list items are unique
Args:
list1 (list): a list of unique items to be aligned
list2 (list): a list of unique items in a desired ordering
missing (bool): True if list2 can contain items not in list1
Returns:
l... | [
"def",
"list_alignment",
"(",
"list1",
",",
"list2",
",",
"missing",
"=",
"False",
")",
":",
"import",
"utool",
"as",
"ut",
"item1_to_idx",
"=",
"make_index_lookup",
"(",
"list1",
")",
"if",
"missing",
":",
"sortx",
"=",
"ut",
".",
"dict_take",
"(",
"ite... | Assumes list items are unique
Args:
list1 (list): a list of unique items to be aligned
list2 (list): a list of unique items in a desired ordering
missing (bool): True if list2 can contain items not in list1
Returns:
list: sorting that will map list1 onto list2
CommandLine:... | [
"Assumes",
"list",
"items",
"are",
"unique"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3008-L3052 | train | Returns a list of unique items that are aligned to list2 |
Erotemic/utool | utool/util_list.py | unique_inverse | def unique_inverse(item_list):
"""
Like np.unique(item_list, return_inverse=True)
"""
import utool as ut
unique_items = ut.unique(item_list)
inverse = list_alignment(unique_items, item_list)
return unique_items, inverse | python | def unique_inverse(item_list):
"""
Like np.unique(item_list, return_inverse=True)
"""
import utool as ut
unique_items = ut.unique(item_list)
inverse = list_alignment(unique_items, item_list)
return unique_items, inverse | [
"def",
"unique_inverse",
"(",
"item_list",
")",
":",
"import",
"utool",
"as",
"ut",
"unique_items",
"=",
"ut",
".",
"unique",
"(",
"item_list",
")",
"inverse",
"=",
"list_alignment",
"(",
"unique_items",
",",
"item_list",
")",
"return",
"unique_items",
",",
... | Like np.unique(item_list, return_inverse=True) | [
"Like",
"np",
".",
"unique",
"(",
"item_list",
"return_inverse",
"=",
"True",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3055-L3062 | train | Returns unique items and inverse of item_list |
Erotemic/utool | utool/util_list.py | list_transpose | def list_transpose(list_, shape=None):
r"""
Swaps rows and columns.
nCols should be specified if the initial list is empty.
Args:
list_ (list):
Returns:
list:
CommandLine:
python -m utool.util_list --test-list_transpose
Example:
>>> # ENABLE_DOCTEST
... | python | def list_transpose(list_, shape=None):
r"""
Swaps rows and columns.
nCols should be specified if the initial list is empty.
Args:
list_ (list):
Returns:
list:
CommandLine:
python -m utool.util_list --test-list_transpose
Example:
>>> # ENABLE_DOCTEST
... | [
"def",
"list_transpose",
"(",
"list_",
",",
"shape",
"=",
"None",
")",
":",
"num_cols_set",
"=",
"unique",
"(",
"[",
"len",
"(",
"x",
")",
"for",
"x",
"in",
"list_",
"]",
")",
"if",
"shape",
"is",
"None",
":",
"if",
"len",
"(",
"num_cols_set",
")",... | r"""
Swaps rows and columns.
nCols should be specified if the initial list is empty.
Args:
list_ (list):
Returns:
list:
CommandLine:
python -m utool.util_list --test-list_transpose
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA... | [
"r",
"Swaps",
"rows",
"and",
"columns",
".",
"nCols",
"should",
"be",
"specified",
"if",
"the",
"initial",
"list",
"is",
"empty",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3065-L3122 | train | r Transposes the list of tables and columns. |
Erotemic/utool | utool/util_list.py | delete_items_by_index | def delete_items_by_index(list_, index_list, copy=False):
"""
Remove items from ``list_`` at positions specified in ``index_list``
The original ``list_`` is preserved if ``copy`` is True
Args:
list_ (list):
index_list (list):
copy (bool): preserves original list if True
Exa... | python | def delete_items_by_index(list_, index_list, copy=False):
"""
Remove items from ``list_`` at positions specified in ``index_list``
The original ``list_`` is preserved if ``copy`` is True
Args:
list_ (list):
index_list (list):
copy (bool): preserves original list if True
Exa... | [
"def",
"delete_items_by_index",
"(",
"list_",
",",
"index_list",
",",
"copy",
"=",
"False",
")",
":",
"if",
"copy",
":",
"list_",
"=",
"list_",
"[",
":",
"]",
"# Rectify negative indicies",
"index_list_",
"=",
"[",
"(",
"len",
"(",
"list_",
")",
"+",
"x"... | Remove items from ``list_`` at positions specified in ``index_list``
The original ``list_`` is preserved if ``copy`` is True
Args:
list_ (list):
index_list (list):
copy (bool): preserves original list if True
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list im... | [
"Remove",
"items",
"from",
"list_",
"at",
"positions",
"specified",
"in",
"index_list",
"The",
"original",
"list_",
"is",
"preserved",
"if",
"copy",
"is",
"True"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3128-L3155 | train | Removes items from list_ at positions specified in index_list |
Erotemic/utool | utool/util_list.py | delete_list_items | def delete_list_items(list_, item_list, copy=False):
r"""
Remove items in ``item_list`` from ``list_``.
The original ``list_`` is preserved if ``copy`` is True
"""
if copy:
list_ = list_[:]
for item in item_list:
list_.remove(item)
return list_ | python | def delete_list_items(list_, item_list, copy=False):
r"""
Remove items in ``item_list`` from ``list_``.
The original ``list_`` is preserved if ``copy`` is True
"""
if copy:
list_ = list_[:]
for item in item_list:
list_.remove(item)
return list_ | [
"def",
"delete_list_items",
"(",
"list_",
",",
"item_list",
",",
"copy",
"=",
"False",
")",
":",
"if",
"copy",
":",
"list_",
"=",
"list_",
"[",
":",
"]",
"for",
"item",
"in",
"item_list",
":",
"list_",
".",
"remove",
"(",
"item",
")",
"return",
"list... | r"""
Remove items in ``item_list`` from ``list_``.
The original ``list_`` is preserved if ``copy`` is True | [
"r",
"Remove",
"items",
"in",
"item_list",
"from",
"list_",
".",
"The",
"original",
"list_",
"is",
"preserved",
"if",
"copy",
"is",
"True"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3158-L3167 | train | r Remove items in item_list from list_. |
Erotemic/utool | utool/util_list.py | unflat_map | def unflat_map(func, unflat_items, vectorized=False, **kwargs):
r"""
Uses an ibeis lookup function with a non-flat rowid list.
In essence this is equivilent to [list(map(func, _items)) for _items in unflat_items].
The utility of this function is that it only calls method once.
This is more efficient... | python | def unflat_map(func, unflat_items, vectorized=False, **kwargs):
r"""
Uses an ibeis lookup function with a non-flat rowid list.
In essence this is equivilent to [list(map(func, _items)) for _items in unflat_items].
The utility of this function is that it only calls method once.
This is more efficient... | [
"def",
"unflat_map",
"(",
"func",
",",
"unflat_items",
",",
"vectorized",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"utool",
"as",
"ut",
"# First flatten the list, and remember the original dimensions",
"flat_items",
",",
"reverse_list",
"=",
"ut",
... | r"""
Uses an ibeis lookup function with a non-flat rowid list.
In essence this is equivilent to [list(map(func, _items)) for _items in unflat_items].
The utility of this function is that it only calls method once.
This is more efficient for calls that can take a list of inputs
Args:
func (f... | [
"r",
"Uses",
"an",
"ibeis",
"lookup",
"function",
"with",
"a",
"non",
"-",
"flat",
"rowid",
"list",
".",
"In",
"essence",
"this",
"is",
"equivilent",
"to",
"[",
"list",
"(",
"map",
"(",
"func",
"_items",
"))",
"for",
"_items",
"in",
"unflat_items",
"]"... | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3170-L3219 | train | r Uses an ibeis lookup function with a non - flat rowid list. |
Erotemic/utool | utool/util_list.py | list_reshape | def list_reshape(list_, new_shape, trail=False):
r"""
reshapes leaving trailing dimnsions in front if prod(new_shape) != len(list_)
Args:
list_ (list):
new_shape (tuple):
Returns:
list: list_
CommandLine:
python -m utool.util_list --exec-list_reshape --show
Ex... | python | def list_reshape(list_, new_shape, trail=False):
r"""
reshapes leaving trailing dimnsions in front if prod(new_shape) != len(list_)
Args:
list_ (list):
new_shape (tuple):
Returns:
list: list_
CommandLine:
python -m utool.util_list --exec-list_reshape --show
Ex... | [
"def",
"list_reshape",
"(",
"list_",
",",
"new_shape",
",",
"trail",
"=",
"False",
")",
":",
"if",
"not",
"trail",
":",
"total",
"=",
"reduce",
"(",
"operator",
".",
"mul",
",",
"new_shape",
")",
"assert",
"total",
"==",
"len",
"(",
"list_",
")",
"ne... | r"""
reshapes leaving trailing dimnsions in front if prod(new_shape) != len(list_)
Args:
list_ (list):
new_shape (tuple):
Returns:
list: list_
CommandLine:
python -m utool.util_list --exec-list_reshape --show
Example:
>>> # ENABLE_DOCTEST
>>> from ... | [
"r",
"reshapes",
"leaving",
"trailing",
"dimnsions",
"in",
"front",
"if",
"prod",
"(",
"new_shape",
")",
"!",
"=",
"len",
"(",
"list_",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3246-L3284 | train | r Reshapes the list_ to new_shape leaving trailing dimnsions in front |
Erotemic/utool | utool/util_list.py | list_strip | def list_strip(list_, to_strip, left=True, right=True):
"""
list_ = [1, 2, 1, 3, 1, 1]
to_strip = 1
stripped_list = ut.list_strip(list_, to_strip)
"""
import utool as ut
flags = [item != to_strip for item in list_]
flag_lists = []
if right:
rstrip_flags = ut.cumsum(flags[::-1... | python | def list_strip(list_, to_strip, left=True, right=True):
"""
list_ = [1, 2, 1, 3, 1, 1]
to_strip = 1
stripped_list = ut.list_strip(list_, to_strip)
"""
import utool as ut
flags = [item != to_strip for item in list_]
flag_lists = []
if right:
rstrip_flags = ut.cumsum(flags[::-1... | [
"def",
"list_strip",
"(",
"list_",
",",
"to_strip",
",",
"left",
"=",
"True",
",",
"right",
"=",
"True",
")",
":",
"import",
"utool",
"as",
"ut",
"flags",
"=",
"[",
"item",
"!=",
"to_strip",
"for",
"item",
"in",
"list_",
"]",
"flag_lists",
"=",
"[",
... | list_ = [1, 2, 1, 3, 1, 1]
to_strip = 1
stripped_list = ut.list_strip(list_, to_strip) | [
"list_",
"=",
"[",
"1",
"2",
"1",
"3",
"1",
"1",
"]",
"to_strip",
"=",
"1",
"stripped_list",
"=",
"ut",
".",
"list_strip",
"(",
"list_",
"to_strip",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3333-L3350 | train | strips the specified items from the list |
Erotemic/utool | utool/util_list.py | aslist | def aslist(sequence):
r"""
Ensures that the sequence object is a Python list.
Handles, numpy arrays, and python sequences (e.g. tuples, and iterables).
Args:
sequence (sequence): a list-like object
Returns:
list: list_ - `sequence` as a Python list
Example:
>>> # DISAB... | python | def aslist(sequence):
r"""
Ensures that the sequence object is a Python list.
Handles, numpy arrays, and python sequences (e.g. tuples, and iterables).
Args:
sequence (sequence): a list-like object
Returns:
list: list_ - `sequence` as a Python list
Example:
>>> # DISAB... | [
"def",
"aslist",
"(",
"sequence",
")",
":",
"if",
"isinstance",
"(",
"sequence",
",",
"list",
")",
":",
"return",
"sequence",
"elif",
"util_type",
".",
"HAVE_NUMPY",
"and",
"isinstance",
"(",
"sequence",
",",
"np",
".",
"ndarray",
")",
":",
"list_",
"=",... | r"""
Ensures that the sequence object is a Python list.
Handles, numpy arrays, and python sequences (e.g. tuples, and iterables).
Args:
sequence (sequence): a list-like object
Returns:
list: list_ - `sequence` as a Python list
Example:
>>> # DISABLE_DOCTEST
>>> fro... | [
"r",
"Ensures",
"that",
"the",
"sequence",
"object",
"is",
"a",
"Python",
"list",
".",
"Handles",
"numpy",
"arrays",
"and",
"python",
"sequences",
"(",
"e",
".",
"g",
".",
"tuples",
"and",
"iterables",
")",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3366-L3395 | train | r Converts a Python list into a list. |
Erotemic/utool | utool/util_list.py | length_hint | def length_hint(obj, default=0):
"""
Return an estimate of the number of items in obj.
This is the PEP 424 implementation.
If the object supports len(), the result will be
exact. Otherwise, it may over- or under-estimate by an
arbitrary amount. The result will be an integer >= 0.
"""
tr... | python | def length_hint(obj, default=0):
"""
Return an estimate of the number of items in obj.
This is the PEP 424 implementation.
If the object supports len(), the result will be
exact. Otherwise, it may over- or under-estimate by an
arbitrary amount. The result will be an integer >= 0.
"""
tr... | [
"def",
"length_hint",
"(",
"obj",
",",
"default",
"=",
"0",
")",
":",
"try",
":",
"return",
"len",
"(",
"obj",
")",
"except",
"TypeError",
":",
"try",
":",
"get_hint",
"=",
"type",
"(",
"obj",
")",
".",
"__length_hint__",
"except",
"AttributeError",
":... | Return an estimate of the number of items in obj.
This is the PEP 424 implementation.
If the object supports len(), the result will be
exact. Otherwise, it may over- or under-estimate by an
arbitrary amount. The result will be an integer >= 0. | [
"Return",
"an",
"estimate",
"of",
"the",
"number",
"of",
"items",
"in",
"obj",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_list.py#L3459-L3486 | train | Return an estimate of the number of items in the object. |
product-definition-center/pdc-client | pdc_client/plugin_helpers.py | add_parser_arguments | def add_parser_arguments(parser, args, group=None, prefix=DATA_PREFIX):
"""
Helper method that populates parser arguments. The argument values can
be later retrieved with `extract_arguments` method.
The `args` argument to this method should be a dict with strings as
keys and dicts as values. The ke... | python | def add_parser_arguments(parser, args, group=None, prefix=DATA_PREFIX):
"""
Helper method that populates parser arguments. The argument values can
be later retrieved with `extract_arguments` method.
The `args` argument to this method should be a dict with strings as
keys and dicts as values. The ke... | [
"def",
"add_parser_arguments",
"(",
"parser",
",",
"args",
",",
"group",
"=",
"None",
",",
"prefix",
"=",
"DATA_PREFIX",
")",
":",
"if",
"group",
":",
"parser",
"=",
"parser",
".",
"add_argument_group",
"(",
"group",
")",
"for",
"arg",
",",
"kwargs",
"in... | Helper method that populates parser arguments. The argument values can
be later retrieved with `extract_arguments` method.
The `args` argument to this method should be a dict with strings as
keys and dicts as values. The keys will be used as keys in returned
data. Their values will be passed as kwargs ... | [
"Helper",
"method",
"that",
"populates",
"parser",
"arguments",
".",
"The",
"argument",
"values",
"can",
"be",
"later",
"retrieved",
"with",
"extract_arguments",
"method",
"."
] | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/plugin_helpers.py#L102-L125 | train | Helper method that populates the parser arguments. |
product-definition-center/pdc-client | pdc_client/plugin_helpers.py | add_mutually_exclusive_args | def add_mutually_exclusive_args(parser, args, required=False, prefix=DATA_PREFIX):
"""
Helper method that populates mutually exclusive arguments. The argument values can
be later retrieved with `extract_arguments` method.
The `args` argument to this method should be a dict with strings as
keys and ... | python | def add_mutually_exclusive_args(parser, args, required=False, prefix=DATA_PREFIX):
"""
Helper method that populates mutually exclusive arguments. The argument values can
be later retrieved with `extract_arguments` method.
The `args` argument to this method should be a dict with strings as
keys and ... | [
"def",
"add_mutually_exclusive_args",
"(",
"parser",
",",
"args",
",",
"required",
"=",
"False",
",",
"prefix",
"=",
"DATA_PREFIX",
")",
":",
"parser",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
"required",
"=",
"required",
")",
"for",
"arg",
","... | Helper method that populates mutually exclusive arguments. The argument values can
be later retrieved with `extract_arguments` method.
The `args` argument to this method should be a dict with strings as
keys and dicts as values. The keys will be used as keys in returned
data. Their values will be passe... | [
"Helper",
"method",
"that",
"populates",
"mutually",
"exclusive",
"arguments",
".",
"The",
"argument",
"values",
"can",
"be",
"later",
"retrieved",
"with",
"extract_arguments",
"method",
"."
] | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/plugin_helpers.py#L128-L147 | train | Helper method that populates the parser with mutually exclusive arguments. |
product-definition-center/pdc-client | pdc_client/plugin_helpers.py | add_create_update_args | def add_create_update_args(parser, required_args, optional_args, create=False):
"""Wrapper around ``add_parser_arguments``.
If ``create`` is True, one argument group will be created for each of
``required_args`` and ``optional_args``. Each required argument will have
the ``required`` parameter set to T... | python | def add_create_update_args(parser, required_args, optional_args, create=False):
"""Wrapper around ``add_parser_arguments``.
If ``create`` is True, one argument group will be created for each of
``required_args`` and ``optional_args``. Each required argument will have
the ``required`` parameter set to T... | [
"def",
"add_create_update_args",
"(",
"parser",
",",
"required_args",
",",
"optional_args",
",",
"create",
"=",
"False",
")",
":",
"if",
"create",
":",
"for",
"key",
"in",
"required_args",
":",
"required_args",
"[",
"key",
"]",
"[",
"'required'",
"]",
"=",
... | Wrapper around ``add_parser_arguments``.
If ``create`` is True, one argument group will be created for each of
``required_args`` and ``optional_args``. Each required argument will have
the ``required`` parameter set to True automatically.
If ``create`` is False, only one group of optional arguments wi... | [
"Wrapper",
"around",
"add_parser_arguments",
"."
] | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/plugin_helpers.py#L150-L169 | train | Wrapper around add_parser_arguments that creates a new group of required_args and optional_args. |
product-definition-center/pdc-client | pdc_client/plugin_helpers.py | extract_arguments | def extract_arguments(args, prefix=DATA_PREFIX):
"""Return a dict of arguments created by `add_parser_arguments`.
If the key in `args` contains two underscores, a nested dictionary will be
created. Only keys starting with given prefix are examined. The prefix is
stripped away and does not appear in the... | python | def extract_arguments(args, prefix=DATA_PREFIX):
"""Return a dict of arguments created by `add_parser_arguments`.
If the key in `args` contains two underscores, a nested dictionary will be
created. Only keys starting with given prefix are examined. The prefix is
stripped away and does not appear in the... | [
"def",
"extract_arguments",
"(",
"args",
",",
"prefix",
"=",
"DATA_PREFIX",
")",
":",
"data",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"args",
".",
"__dict__",
")",
":",
"if",
"key",
".",
"startswith",
"(",
"prefix",
")",
"a... | Return a dict of arguments created by `add_parser_arguments`.
If the key in `args` contains two underscores, a nested dictionary will be
created. Only keys starting with given prefix are examined. The prefix is
stripped away and does not appear in the result. | [
"Return",
"a",
"dict",
"of",
"arguments",
"created",
"by",
"add_parser_arguments",
"."
] | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/plugin_helpers.py#L172-L194 | train | Extract arguments from the given arguments dictionary. |
glormph/msstitch | src/app/actions/mslookup/searchspace.py | create_searchspace | def create_searchspace(lookup, fastafn, proline_cut=False,
reverse_seqs=True, do_trypsinize=True):
"""Given a FASTA database, proteins are trypsinized and resulting peptides
stored in a database or dict for lookups"""
allpeps = []
for record in SeqIO.parse(fastafn, 'fasta'):
... | python | def create_searchspace(lookup, fastafn, proline_cut=False,
reverse_seqs=True, do_trypsinize=True):
"""Given a FASTA database, proteins are trypsinized and resulting peptides
stored in a database or dict for lookups"""
allpeps = []
for record in SeqIO.parse(fastafn, 'fasta'):
... | [
"def",
"create_searchspace",
"(",
"lookup",
",",
"fastafn",
",",
"proline_cut",
"=",
"False",
",",
"reverse_seqs",
"=",
"True",
",",
"do_trypsinize",
"=",
"True",
")",
":",
"allpeps",
"=",
"[",
"]",
"for",
"record",
"in",
"SeqIO",
".",
"parse",
"(",
"fas... | Given a FASTA database, proteins are trypsinized and resulting peptides
stored in a database or dict for lookups | [
"Given",
"a",
"FASTA",
"database",
"proteins",
"are",
"trypsinized",
"and",
"resulting",
"peptides",
"stored",
"in",
"a",
"database",
"or",
"dict",
"for",
"lookups"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/mslookup/searchspace.py#L24-L43 | train | Create a searchspace for the given database. |
glormph/msstitch | src/app/actions/mslookup/searchspace.py | trypsinize | def trypsinize(proseq, proline_cut=False):
# TODO add cysteine to non cut options, use enums
"""Trypsinize a protein sequence. Returns a list of peptides.
Peptides include both cut and non-cut when P is behind a tryptic
residue. Multiple consequent tryptic residues are treated as follows:
PEPKKKTIDE... | python | def trypsinize(proseq, proline_cut=False):
# TODO add cysteine to non cut options, use enums
"""Trypsinize a protein sequence. Returns a list of peptides.
Peptides include both cut and non-cut when P is behind a tryptic
residue. Multiple consequent tryptic residues are treated as follows:
PEPKKKTIDE... | [
"def",
"trypsinize",
"(",
"proseq",
",",
"proline_cut",
"=",
"False",
")",
":",
"# TODO add cysteine to non cut options, use enums",
"outpeps",
"=",
"[",
"]",
"currentpeps",
"=",
"[",
"''",
"]",
"trypres",
"=",
"set",
"(",
"[",
"'K'",
",",
"'R'",
"]",
")",
... | Trypsinize a protein sequence. Returns a list of peptides.
Peptides include both cut and non-cut when P is behind a tryptic
residue. Multiple consequent tryptic residues are treated as follows:
PEPKKKTIDE - [PEPK, PEPKK, PEPKKK, KKTIDE, KTIDE, TIDE, K, K, KK ] | [
"Trypsinize",
"a",
"protein",
"sequence",
".",
"Returns",
"a",
"list",
"of",
"peptides",
".",
"Peptides",
"include",
"both",
"cut",
"and",
"non",
"-",
"cut",
"when",
"P",
"is",
"behind",
"a",
"tryptic",
"residue",
".",
"Multiple",
"consequent",
"tryptic",
... | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/mslookup/searchspace.py#L46-L76 | train | Trypsinize a protein sequence. Returns a list of peptides.
Peptides include both cut and non - cut when P is behind a tryptic
residue. |
Erotemic/utool | utool/util_hash.py | make_hash | def make_hash(o):
r"""
Makes a hash from a dictionary, list, tuple or set to any level, that
contains only other hashable types (including any lists, tuples, sets, and
dictionaries). In the case where other kinds of objects (like classes) need
to be hashed, pass in a collection of object attributes ... | python | def make_hash(o):
r"""
Makes a hash from a dictionary, list, tuple or set to any level, that
contains only other hashable types (including any lists, tuples, sets, and
dictionaries). In the case where other kinds of objects (like classes) need
to be hashed, pass in a collection of object attributes ... | [
"def",
"make_hash",
"(",
"o",
")",
":",
"if",
"type",
"(",
"o",
")",
"==",
"DictProxyType",
":",
"o2",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"o",
".",
"items",
"(",
")",
":",
"if",
"not",
"k",
".",
"startswith",
"(",
"\"__\"",
")",
":",
... | r"""
Makes a hash from a dictionary, list, tuple or set to any level, that
contains only other hashable types (including any lists, tuples, sets, and
dictionaries). In the case where other kinds of objects (like classes) need
to be hashed, pass in a collection of object attributes that are pertinent.
... | [
"r",
"Makes",
"a",
"hash",
"from",
"a",
"dictionary",
"list",
"tuple",
"or",
"set",
"to",
"any",
"level",
"that",
"contains",
"only",
"other",
"hashable",
"types",
"(",
"including",
"any",
"lists",
"tuples",
"sets",
"and",
"dictionaries",
")",
".",
"In",
... | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L65-L95 | train | r Returns a hash of the object o. |
Erotemic/utool | utool/util_hash.py | hashstr_arr | def hashstr_arr(arr, lbl='arr', pathsafe=False, **kwargs):
r"""
Args:
arr (ndarray):
lbl (str): (default = 'arr')
pathsafe (bool): (default = False)
Returns:
str: arr_hashstr
CommandLine:
python -m utool.util_hash --test-hashstr_arr
python -m utool.util_... | python | def hashstr_arr(arr, lbl='arr', pathsafe=False, **kwargs):
r"""
Args:
arr (ndarray):
lbl (str): (default = 'arr')
pathsafe (bool): (default = False)
Returns:
str: arr_hashstr
CommandLine:
python -m utool.util_hash --test-hashstr_arr
python -m utool.util_... | [
"def",
"hashstr_arr",
"(",
"arr",
",",
"lbl",
"=",
"'arr'",
",",
"pathsafe",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"arr",
",",
"list",
")",
":",
"arr",
"=",
"tuple",
"(",
"arr",
")",
"# force arrays into a tuple for ... | r"""
Args:
arr (ndarray):
lbl (str): (default = 'arr')
pathsafe (bool): (default = False)
Returns:
str: arr_hashstr
CommandLine:
python -m utool.util_hash --test-hashstr_arr
python -m utool.util_hash hashstr_arr:2
Example0:
>>> # ENABLE_DOCTEST
... | [
"r",
"Args",
":",
"arr",
"(",
"ndarray",
")",
":",
"lbl",
"(",
"str",
")",
":",
"(",
"default",
"=",
"arr",
")",
"pathsafe",
"(",
"bool",
")",
":",
"(",
"default",
"=",
"False",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L106-L160 | train | r This function is used to hash a numpy array into a single string |
Erotemic/utool | utool/util_hash.py | hashid_arr | def hashid_arr(arr, label='arr', hashlen=16):
""" newer version of hashstr_arr2 """
hashstr = hash_data(arr)[0:hashlen]
if isinstance(arr, (list, tuple)):
shapestr = len(arr)
else:
shapestr = ','.join(list(map(str, arr.shape)))
hashid = '{}-{}-{}'.format(label, shapestr, hashstr)
... | python | def hashid_arr(arr, label='arr', hashlen=16):
""" newer version of hashstr_arr2 """
hashstr = hash_data(arr)[0:hashlen]
if isinstance(arr, (list, tuple)):
shapestr = len(arr)
else:
shapestr = ','.join(list(map(str, arr.shape)))
hashid = '{}-{}-{}'.format(label, shapestr, hashstr)
... | [
"def",
"hashid_arr",
"(",
"arr",
",",
"label",
"=",
"'arr'",
",",
"hashlen",
"=",
"16",
")",
":",
"hashstr",
"=",
"hash_data",
"(",
"arr",
")",
"[",
"0",
":",
"hashlen",
"]",
"if",
"isinstance",
"(",
"arr",
",",
"(",
"list",
",",
"tuple",
")",
")... | newer version of hashstr_arr2 | [
"newer",
"version",
"of",
"hashstr_arr2"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L163-L171 | train | newer version of hashstr_arr2 |
Erotemic/utool | utool/util_hash.py | _covert_to_hashable | def _covert_to_hashable(data):
r"""
Args:
data (?):
Returns:
?:
CommandLine:
python -m utool.util_hash _covert_to_hashable
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_hash import * # NOQA
>>> from utool.util_hash import _covert_to_hashable ... | python | def _covert_to_hashable(data):
r"""
Args:
data (?):
Returns:
?:
CommandLine:
python -m utool.util_hash _covert_to_hashable
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_hash import * # NOQA
>>> from utool.util_hash import _covert_to_hashable ... | [
"def",
"_covert_to_hashable",
"(",
"data",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"six",
".",
"binary_type",
")",
":",
"hashable",
"=",
"data",
"prefix",
"=",
"b'TXT'",
"elif",
"util_type",
".",
"HAVE_NUMPY",
"and",
"isinstance",
"(",
"data",
",",... | r"""
Args:
data (?):
Returns:
?:
CommandLine:
python -m utool.util_hash _covert_to_hashable
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_hash import * # NOQA
>>> from utool.util_hash import _covert_to_hashable # NOQA
>>> import utool as ... | [
"r",
"Args",
":",
"data",
"(",
"?",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L179-L238 | train | r Converts a numpy array into a hashable object |
Erotemic/utool | utool/util_hash.py | _update_hasher | def _update_hasher(hasher, data):
"""
This is the clear winner over the generate version.
Used by hash_data
Ignore:
import utool
rng = np.random.RandomState(0)
# str1 = rng.rand(0).dumps()
str1 = b'SEP'
str2 = rng.rand(10000).dumps()
for timer in utool.Ti... | python | def _update_hasher(hasher, data):
"""
This is the clear winner over the generate version.
Used by hash_data
Ignore:
import utool
rng = np.random.RandomState(0)
# str1 = rng.rand(0).dumps()
str1 = b'SEP'
str2 = rng.rand(10000).dumps()
for timer in utool.Ti... | [
"def",
"_update_hasher",
"(",
"hasher",
",",
"data",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"(",
"tuple",
",",
"list",
",",
"zip",
")",
")",
":",
"needs_iteration",
"=",
"True",
"elif",
"(",
"util_type",
".",
"HAVE_NUMPY",
"and",
"isinstance",
... | This is the clear winner over the generate version.
Used by hash_data
Ignore:
import utool
rng = np.random.RandomState(0)
# str1 = rng.rand(0).dumps()
str1 = b'SEP'
str2 = rng.rand(10000).dumps()
for timer in utool.Timerit(100, label='twocall'):
hashe... | [
"This",
"is",
"the",
"clear",
"winner",
"over",
"the",
"generate",
"version",
".",
"Used",
"by",
"hash_data"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L241-L358 | train | Update the hasher with the data |
Erotemic/utool | utool/util_hash.py | combine_hashes | def combine_hashes(bytes_list, hasher=None):
"""
Only works on bytes
Example:
>>> # DISABLE_DOCTEST
>>> x = [b('1111'), b('2222')]
>>> y = [b('11'), b('11'), b('22'), b('22')]
>>> bytes_list = y
>>> out1 = ut.combine_hashes(x, hashlib.sha1())
>>> hasher = has... | python | def combine_hashes(bytes_list, hasher=None):
"""
Only works on bytes
Example:
>>> # DISABLE_DOCTEST
>>> x = [b('1111'), b('2222')]
>>> y = [b('11'), b('11'), b('22'), b('22')]
>>> bytes_list = y
>>> out1 = ut.combine_hashes(x, hashlib.sha1())
>>> hasher = has... | [
"def",
"combine_hashes",
"(",
"bytes_list",
",",
"hasher",
"=",
"None",
")",
":",
"if",
"hasher",
"is",
"None",
":",
"hasher",
"=",
"hashlib",
".",
"sha256",
"(",
")",
"for",
"b",
"in",
"bytes_list",
":",
"hasher",
".",
"update",
"(",
"b",
")",
"hash... | Only works on bytes
Example:
>>> # DISABLE_DOCTEST
>>> x = [b('1111'), b('2222')]
>>> y = [b('11'), b('11'), b('22'), b('22')]
>>> bytes_list = y
>>> out1 = ut.combine_hashes(x, hashlib.sha1())
>>> hasher = hashlib.sha1()
>>> out2 = ut.combine_hashes(y, hashe... | [
"Only",
"works",
"on",
"bytes"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L410-L434 | train | Combine the list of bytes into a single base64 - encoded version of the current base64 - encoded version of the current base64 - encoded version. |
Erotemic/utool | utool/util_hash.py | hash_data | def hash_data(data, hashlen=None, alphabet=None):
r"""
Get a unique hash depending on the state of the data.
Args:
data (object): any sort of loosely organized data
hashlen (None): (default = None)
alphabet (None): (default = None)
Returns:
str: text - hash string
... | python | def hash_data(data, hashlen=None, alphabet=None):
r"""
Get a unique hash depending on the state of the data.
Args:
data (object): any sort of loosely organized data
hashlen (None): (default = None)
alphabet (None): (default = None)
Returns:
str: text - hash string
... | [
"def",
"hash_data",
"(",
"data",
",",
"hashlen",
"=",
"None",
",",
"alphabet",
"=",
"None",
")",
":",
"if",
"alphabet",
"is",
"None",
":",
"alphabet",
"=",
"ALPHABET_27",
"if",
"hashlen",
"is",
"None",
":",
"hashlen",
"=",
"HASH_LEN2",
"if",
"isinstance"... | r"""
Get a unique hash depending on the state of the data.
Args:
data (object): any sort of loosely organized data
hashlen (None): (default = None)
alphabet (None): (default = None)
Returns:
str: text - hash string
CommandLine:
python -m utool.util_hash hash_d... | [
"r",
"Get",
"a",
"unique",
"hash",
"depending",
"on",
"the",
"state",
"of",
"the",
"data",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L438-L498 | train | r This function calculates a unique hash of the given data. |
Erotemic/utool | utool/util_hash.py | hashstr | def hashstr(data, hashlen=HASH_LEN, alphabet=ALPHABET):
"""
python -c "import utool as ut; print(ut.hashstr('abcd'))"
Args:
data (hashable):
hashlen (int): (default = 16)
alphabet (list): list of characters:
Returns:
str: hashstr
CommandLine:
python -m utoo... | python | def hashstr(data, hashlen=HASH_LEN, alphabet=ALPHABET):
"""
python -c "import utool as ut; print(ut.hashstr('abcd'))"
Args:
data (hashable):
hashlen (int): (default = 16)
alphabet (list): list of characters:
Returns:
str: hashstr
CommandLine:
python -m utoo... | [
"def",
"hashstr",
"(",
"data",
",",
"hashlen",
"=",
"HASH_LEN",
",",
"alphabet",
"=",
"ALPHABET",
")",
":",
"if",
"util_type",
".",
"HAVE_NUMPY",
"and",
"isinstance",
"(",
"data",
",",
"np",
".",
"ndarray",
")",
":",
"if",
"data",
".",
"dtype",
".",
... | python -c "import utool as ut; print(ut.hashstr('abcd'))"
Args:
data (hashable):
hashlen (int): (default = 16)
alphabet (list): list of characters:
Returns:
str: hashstr
CommandLine:
python -m utool.util_hash --test-hashstr
python3 -m utool.util_hash --test... | [
"python",
"-",
"c",
"import",
"utool",
"as",
"ut",
";",
"print",
"(",
"ut",
".",
"hashstr",
"(",
"abcd",
"))"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L511-L655 | train | hashstr - hash a string |
Erotemic/utool | utool/util_hash.py | convert_bytes_to_bigbase | def convert_bytes_to_bigbase(bytes_, alphabet=ALPHABET_27):
r"""
Args:
bytes_ (bytes):
Returns:
str:
Ignore:
CommandLine:
python -m utool.util_hash convert_bytes_to_bigbase
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_hash import * # NOQA
... | python | def convert_bytes_to_bigbase(bytes_, alphabet=ALPHABET_27):
r"""
Args:
bytes_ (bytes):
Returns:
str:
Ignore:
CommandLine:
python -m utool.util_hash convert_bytes_to_bigbase
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_hash import * # NOQA
... | [
"def",
"convert_bytes_to_bigbase",
"(",
"bytes_",
",",
"alphabet",
"=",
"ALPHABET_27",
")",
":",
"x",
"=",
"_bytes_to_int",
"(",
"bytes_",
")",
"if",
"x",
"==",
"0",
":",
"return",
"'0'",
"sign",
"=",
"1",
"if",
"x",
">",
"0",
"else",
"-",
"1",
"x",
... | r"""
Args:
bytes_ (bytes):
Returns:
str:
Ignore:
CommandLine:
python -m utool.util_hash convert_bytes_to_bigbase
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_hash import * # NOQA
>>> import utool as ut
>>> bytes_ = b('999999999999999... | [
"r",
"Args",
":",
"bytes_",
"(",
"bytes",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L726-L763 | train | r Converts a byte string to a bigbase string. |
Erotemic/utool | utool/util_hash.py | convert_hexstr_to_bigbase | def convert_hexstr_to_bigbase(hexstr, alphabet=ALPHABET, bigbase=BIGBASE):
r"""
Packs a long hexstr into a shorter length string with a larger base
Ignore:
# Determine the length savings with lossless conversion
import sympy as sy
consts = dict(hexbase=16, hexlen=256, bigbase=27)
... | python | def convert_hexstr_to_bigbase(hexstr, alphabet=ALPHABET, bigbase=BIGBASE):
r"""
Packs a long hexstr into a shorter length string with a larger base
Ignore:
# Determine the length savings with lossless conversion
import sympy as sy
consts = dict(hexbase=16, hexlen=256, bigbase=27)
... | [
"def",
"convert_hexstr_to_bigbase",
"(",
"hexstr",
",",
"alphabet",
"=",
"ALPHABET",
",",
"bigbase",
"=",
"BIGBASE",
")",
":",
"x",
"=",
"int",
"(",
"hexstr",
",",
"16",
")",
"# first convert to base 16",
"if",
"x",
"==",
"0",
":",
"return",
"'0'",
"sign",... | r"""
Packs a long hexstr into a shorter length string with a larger base
Ignore:
# Determine the length savings with lossless conversion
import sympy as sy
consts = dict(hexbase=16, hexlen=256, bigbase=27)
symbols = sy.symbols('hexbase, hexlen, bigbase, newlen')
haexbase... | [
"r",
"Packs",
"a",
"long",
"hexstr",
"into",
"a",
"shorter",
"length",
"string",
"with",
"a",
"larger",
"base"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L766-L806 | train | r Convert a long hexstr into a shorter length string with a larger base |
Erotemic/utool | utool/util_hash.py | get_file_hash | def get_file_hash(fpath, blocksize=65536, hasher=None, stride=1,
hexdigest=False):
r"""
For better hashes use hasher=hashlib.sha256, and keep stride=1
Args:
fpath (str): file path string
blocksize (int): 2 ** 16. Affects speed of reading file
hasher (None): defau... | python | def get_file_hash(fpath, blocksize=65536, hasher=None, stride=1,
hexdigest=False):
r"""
For better hashes use hasher=hashlib.sha256, and keep stride=1
Args:
fpath (str): file path string
blocksize (int): 2 ** 16. Affects speed of reading file
hasher (None): defau... | [
"def",
"get_file_hash",
"(",
"fpath",
",",
"blocksize",
"=",
"65536",
",",
"hasher",
"=",
"None",
",",
"stride",
"=",
"1",
",",
"hexdigest",
"=",
"False",
")",
":",
"if",
"hasher",
"is",
"None",
":",
"hasher",
"=",
"hashlib",
".",
"sha1",
"(",
")",
... | r"""
For better hashes use hasher=hashlib.sha256, and keep stride=1
Args:
fpath (str): file path string
blocksize (int): 2 ** 16. Affects speed of reading file
hasher (None): defaults to sha1 for fast (but insecure) hashing
stride (int): strides > 1 skip data to hash, useful f... | [
"r",
"For",
"better",
"hashes",
"use",
"hasher",
"=",
"hashlib",
".",
"sha256",
"and",
"keep",
"stride",
"=",
"1"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L829-L897 | train | r Returns the hash of the given file |
Erotemic/utool | utool/util_hash.py | write_hash_file | def write_hash_file(fpath, hash_tag='md5', recompute=False):
r""" Creates a hash file for each file in a path
CommandLine:
python -m utool.util_hash --test-write_hash_file
Example:
>>> # DISABLE_DOCTEST
>>> import utool as ut
>>> from utool.util_hash import * # NOQA
... | python | def write_hash_file(fpath, hash_tag='md5', recompute=False):
r""" Creates a hash file for each file in a path
CommandLine:
python -m utool.util_hash --test-write_hash_file
Example:
>>> # DISABLE_DOCTEST
>>> import utool as ut
>>> from utool.util_hash import * # NOQA
... | [
"def",
"write_hash_file",
"(",
"fpath",
",",
"hash_tag",
"=",
"'md5'",
",",
"recompute",
"=",
"False",
")",
":",
"hash_dict",
"=",
"{",
"'md5'",
":",
"hashlib",
".",
"md5",
"(",
")",
",",
"'sha1'",
":",
"hashlib",
".",
"sha1",
"(",
")",
",",
"'sha256... | r""" Creates a hash file for each file in a path
CommandLine:
python -m utool.util_hash --test-write_hash_file
Example:
>>> # DISABLE_DOCTEST
>>> import utool as ut
>>> from utool.util_hash import * # NOQA
>>> fpath = ut.grab_test_imgpath('patsy.jpg')
>>> write... | [
"r",
"Creates",
"a",
"hash",
"file",
"for",
"each",
"file",
"in",
"a",
"path"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L900-L936 | train | r Write a hash file for each file in a path |
Erotemic/utool | utool/util_hash.py | write_hash_file_for_path | def write_hash_file_for_path(path, recompute=False):
r""" Creates a hash file for each file in a path
CommandLine:
python -m utool.util_hash --test-write_hash_file_for_path
Example:
>>> # DISABLE_DOCTEST
>>> import os
>>> import utool as ut
>>> from utool.util_hash ... | python | def write_hash_file_for_path(path, recompute=False):
r""" Creates a hash file for each file in a path
CommandLine:
python -m utool.util_hash --test-write_hash_file_for_path
Example:
>>> # DISABLE_DOCTEST
>>> import os
>>> import utool as ut
>>> from utool.util_hash ... | [
"def",
"write_hash_file_for_path",
"(",
"path",
",",
"recompute",
"=",
"False",
")",
":",
"hash_fpath_list",
"=",
"[",
"]",
"for",
"root",
",",
"dname_list",
",",
"fname_list",
"in",
"os",
".",
"walk",
"(",
"path",
")",
":",
"for",
"fname",
"in",
"sorted... | r""" Creates a hash file for each file in a path
CommandLine:
python -m utool.util_hash --test-write_hash_file_for_path
Example:
>>> # DISABLE_DOCTEST
>>> import os
>>> import utool as ut
>>> from utool.util_hash import * # NOQA
>>> fpath = ut.grab_test_imgpath... | [
"r",
"Creates",
"a",
"hash",
"file",
"for",
"each",
"file",
"in",
"a",
"path"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L939-L965 | train | r Creates a hash file for each file in a path |
Erotemic/utool | utool/util_hash.py | get_file_uuid | def get_file_uuid(fpath, hasher=None, stride=1):
""" Creates a uuid from the hash of a file
"""
if hasher is None:
hasher = hashlib.sha1() # 20 bytes of output
#hasher = hashlib.sha256() # 32 bytes of output
# sha1 produces a 20 byte hash
hashbytes_20 = get_file_hash(fpath, hasher=... | python | def get_file_uuid(fpath, hasher=None, stride=1):
""" Creates a uuid from the hash of a file
"""
if hasher is None:
hasher = hashlib.sha1() # 20 bytes of output
#hasher = hashlib.sha256() # 32 bytes of output
# sha1 produces a 20 byte hash
hashbytes_20 = get_file_hash(fpath, hasher=... | [
"def",
"get_file_uuid",
"(",
"fpath",
",",
"hasher",
"=",
"None",
",",
"stride",
"=",
"1",
")",
":",
"if",
"hasher",
"is",
"None",
":",
"hasher",
"=",
"hashlib",
".",
"sha1",
"(",
")",
"# 20 bytes of output",
"#hasher = hashlib.sha256() # 32 bytes of output",
... | Creates a uuid from the hash of a file | [
"Creates",
"a",
"uuid",
"from",
"the",
"hash",
"of",
"a",
"file"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L968-L979 | train | Creates a uuid from the hash of a file |
Erotemic/utool | utool/util_hash.py | image_uuid | def image_uuid(pil_img):
"""
UNSAFE: DEPRICATE: JPEG IS NOT GAURENTEED TO PRODUCE CONSITENT VALUES ON
MULTIPLE MACHINES image global unique id
References:
http://stackoverflow.com/questions/23565889/jpeg-images-have-different-pixel-values-across-multiple-devices
"""
print('WARNING DO N... | python | def image_uuid(pil_img):
"""
UNSAFE: DEPRICATE: JPEG IS NOT GAURENTEED TO PRODUCE CONSITENT VALUES ON
MULTIPLE MACHINES image global unique id
References:
http://stackoverflow.com/questions/23565889/jpeg-images-have-different-pixel-values-across-multiple-devices
"""
print('WARNING DO N... | [
"def",
"image_uuid",
"(",
"pil_img",
")",
":",
"print",
"(",
"'WARNING DO NOT USE utool.util_hash.image_uuid UNSAFE AND DEPRICATED'",
")",
"# Get the bytes of the image",
"img_bytes_",
"=",
"pil_img",
".",
"tobytes",
"(",
")",
"uuid_",
"=",
"hashable_to_uuid",
"(",
"img_b... | UNSAFE: DEPRICATE: JPEG IS NOT GAURENTEED TO PRODUCE CONSITENT VALUES ON
MULTIPLE MACHINES image global unique id
References:
http://stackoverflow.com/questions/23565889/jpeg-images-have-different-pixel-values-across-multiple-devices | [
"UNSAFE",
":",
"DEPRICATE",
":",
"JPEG",
"IS",
"NOT",
"GAURENTEED",
"TO",
"PRODUCE",
"CONSITENT",
"VALUES",
"ON"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L982-L995 | train | Returns uuid of image |
Erotemic/utool | utool/util_hash.py | hashable_to_uuid | def hashable_to_uuid(hashable_):
"""
TODO: ensure that python2 and python3 agree on hashes of the same
information
Args:
hashable_ (hashable): hashables are bytes-like objects
An object that supports the Buffer Protocol, like bytes, bytearray
or memoryview. Bytes-like obje... | python | def hashable_to_uuid(hashable_):
"""
TODO: ensure that python2 and python3 agree on hashes of the same
information
Args:
hashable_ (hashable): hashables are bytes-like objects
An object that supports the Buffer Protocol, like bytes, bytearray
or memoryview. Bytes-like obje... | [
"def",
"hashable_to_uuid",
"(",
"hashable_",
")",
":",
"bytes_",
"=",
"_ensure_hashable_bytes",
"(",
"hashable_",
")",
"try",
":",
"bytes_sha1",
"=",
"hashlib",
".",
"sha1",
"(",
"bytes_",
")",
"except",
"TypeError",
":",
"print",
"(",
"'hashable_ = %r'",
"%",... | TODO: ensure that python2 and python3 agree on hashes of the same
information
Args:
hashable_ (hashable): hashables are bytes-like objects
An object that supports the Buffer Protocol, like bytes, bytearray
or memoryview. Bytes-like objects can be used for various operations
... | [
"TODO",
":",
"ensure",
"that",
"python2",
"and",
"python3",
"agree",
"on",
"hashes",
"of",
"the",
"same",
"information"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L1120-L1173 | train | This function will convert a list of hashables to a UUID. |
Erotemic/utool | utool/util_hash.py | random_nonce | def random_nonce(length=64, alphabet=None):
"""
returns a random string of len=<length> from <alphabet>
I have no idea why this is named random_nonce
"""
assert length > 0
if alphabet is None:
alphabet = ALPHABET_16
return ''.join( [alphabet[random.randint(0, len(alphabet) - 1)] for ... | python | def random_nonce(length=64, alphabet=None):
"""
returns a random string of len=<length> from <alphabet>
I have no idea why this is named random_nonce
"""
assert length > 0
if alphabet is None:
alphabet = ALPHABET_16
return ''.join( [alphabet[random.randint(0, len(alphabet) - 1)] for ... | [
"def",
"random_nonce",
"(",
"length",
"=",
"64",
",",
"alphabet",
"=",
"None",
")",
":",
"assert",
"length",
">",
"0",
"if",
"alphabet",
"is",
"None",
":",
"alphabet",
"=",
"ALPHABET_16",
"return",
"''",
".",
"join",
"(",
"[",
"alphabet",
"[",
"random"... | returns a random string of len=<length> from <alphabet>
I have no idea why this is named random_nonce | [
"returns",
"a",
"random",
"string",
"of",
"len",
"=",
"<length",
">",
"from",
"<alphabet",
">",
"I",
"have",
"no",
"idea",
"why",
"this",
"is",
"named",
"random_nonce"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_hash.py#L1180-L1188 | train | returns a random string of length = length from alphabet |
dsoprea/NsqSpinner | nsq/master.py | Master.__start_connection | def __start_connection(self, context, node, ccallbacks=None):
"""Start a new connection, and manage it from a new greenlet."""
_logger.debug("Creating connection object: CONTEXT=[%s] NODE=[%s]",
context, node)
c = nsq.connection.Connection(
context,
... | python | def __start_connection(self, context, node, ccallbacks=None):
"""Start a new connection, and manage it from a new greenlet."""
_logger.debug("Creating connection object: CONTEXT=[%s] NODE=[%s]",
context, node)
c = nsq.connection.Connection(
context,
... | [
"def",
"__start_connection",
"(",
"self",
",",
"context",
",",
"node",
",",
"ccallbacks",
"=",
"None",
")",
":",
"_logger",
".",
"debug",
"(",
"\"Creating connection object: CONTEXT=[%s] NODE=[%s]\"",
",",
"context",
",",
"node",
")",
"c",
"=",
"nsq",
".",
"co... | Start a new connection, and manage it from a new greenlet. | [
"Start",
"a",
"new",
"connection",
"and",
"manage",
"it",
"from",
"a",
"new",
"greenlet",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L44-L76 | train | Start a new connection and manage it from a new greenlet. |
dsoprea/NsqSpinner | nsq/master.py | Master.__wait_for_one_server_connection | def __wait_for_one_server_connection(self):
"""Wait until at least one server is connected. Since quitting relies
on a bunch of loops terminating, attempting to quit [cleanly]
immediately will still have to wait for the connections to finish
starting.
"""
_logger.info... | python | def __wait_for_one_server_connection(self):
"""Wait until at least one server is connected. Since quitting relies
on a bunch of loops terminating, attempting to quit [cleanly]
immediately will still have to wait for the connections to finish
starting.
"""
_logger.info... | [
"def",
"__wait_for_one_server_connection",
"(",
"self",
")",
":",
"_logger",
".",
"info",
"(",
"\"Waiting for first connection.\"",
")",
"while",
"1",
":",
"is_connected_to_one",
"=",
"False",
"for",
"(",
"n",
",",
"c",
",",
"g",
")",
"in",
"self",
".",
"__c... | Wait until at least one server is connected. Since quitting relies
on a bunch of loops terminating, attempting to quit [cleanly]
immediately will still have to wait for the connections to finish
starting. | [
"Wait",
"until",
"at",
"least",
"one",
"server",
"is",
"connected",
".",
"Since",
"quitting",
"relies",
"on",
"a",
"bunch",
"of",
"loops",
"terminating",
"attempting",
"to",
"quit",
"[",
"cleanly",
"]",
"immediately",
"will",
"still",
"have",
"to",
"wait",
... | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L78-L109 | train | Wait until at least one server is connected. |
dsoprea/NsqSpinner | nsq/master.py | Master.__audit_connections | def __audit_connections(self, ccallbacks):
"""Monitor state of all connections, and utility of all servers."""
while self.__quit_ev.is_set() is False:
# Remove any connections that are dead.
self.__connections = filter(
lambda (n, c, g): not g... | python | def __audit_connections(self, ccallbacks):
"""Monitor state of all connections, and utility of all servers."""
while self.__quit_ev.is_set() is False:
# Remove any connections that are dead.
self.__connections = filter(
lambda (n, c, g): not g... | [
"def",
"__audit_connections",
"(",
"self",
",",
"ccallbacks",
")",
":",
"while",
"self",
".",
"__quit_ev",
".",
"is_set",
"(",
")",
"is",
"False",
":",
"# Remove any connections that are dead.",
"self",
".",
"__connections",
"=",
"filter",
"(",
"lambda",
"(",
... | Monitor state of all connections, and utility of all servers. | [
"Monitor",
"state",
"of",
"all",
"connections",
"and",
"utility",
"of",
"all",
"servers",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L111-L170 | train | Monitor state of all connections and utility of all servers. |
dsoprea/NsqSpinner | nsq/master.py | Master.__join_connections | def __join_connections(self):
"""Wait for all connections to close. There are no side-effects here.
We just want to try and leave -after- everything has closed, in
general.
"""
interval_s = nsq.config.client.CONNECTION_CLOSE_AUDIT_WAIT_S
graceful_wait_s = nsq.config.cl... | python | def __join_connections(self):
"""Wait for all connections to close. There are no side-effects here.
We just want to try and leave -after- everything has closed, in
general.
"""
interval_s = nsq.config.client.CONNECTION_CLOSE_AUDIT_WAIT_S
graceful_wait_s = nsq.config.cl... | [
"def",
"__join_connections",
"(",
"self",
")",
":",
"interval_s",
"=",
"nsq",
".",
"config",
".",
"client",
".",
"CONNECTION_CLOSE_AUDIT_WAIT_S",
"graceful_wait_s",
"=",
"nsq",
".",
"config",
".",
"client",
".",
"CONNECTION_QUIT_CLOSE_TIMEOUT_S",
"graceful",
"=",
... | Wait for all connections to close. There are no side-effects here.
We just want to try and leave -after- everything has closed, in
general. | [
"Wait",
"for",
"all",
"connections",
"to",
"close",
".",
"There",
"are",
"no",
"side",
"-",
"effects",
"here",
".",
"We",
"just",
"want",
"to",
"try",
"and",
"leave",
"-",
"after",
"-",
"everything",
"has",
"closed",
"in",
"general",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L172-L200 | train | Wait for all connections to close. |
dsoprea/NsqSpinner | nsq/master.py | Master.__manage_connections | def __manage_connections(self, ccallbacks=None):
"""This runs as the main connection management greenlet."""
_logger.info("Running client.")
# Create message-handler.
if self.__message_handler_cls is not None:
# TODO(dustin): Move this to another thread if we can mix multithreading wi... | python | def __manage_connections(self, ccallbacks=None):
"""This runs as the main connection management greenlet."""
_logger.info("Running client.")
# Create message-handler.
if self.__message_handler_cls is not None:
# TODO(dustin): Move this to another thread if we can mix multithreading wi... | [
"def",
"__manage_connections",
"(",
"self",
",",
"ccallbacks",
"=",
"None",
")",
":",
"_logger",
".",
"info",
"(",
"\"Running client.\"",
")",
"# Create message-handler.",
"if",
"self",
".",
"__message_handler_cls",
"is",
"not",
"None",
":",
"# TODO(dustin): Move th... | This runs as the main connection management greenlet. | [
"This",
"runs",
"as",
"the",
"main",
"connection",
"management",
"greenlet",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L202-L237 | train | This greenlet is responsible for handling the connection management. |
dsoprea/NsqSpinner | nsq/master.py | Master.set_servers | def set_servers(self, node_couplets):
"""Set the current collection of servers. The entries are 2-tuples of
contexts and nodes.
"""
node_couplets_s = set(node_couplets)
if node_couplets_s != self.__node_couplets_s:
_logger.info("Servers have changed. NEW: %s REMOVE... | python | def set_servers(self, node_couplets):
"""Set the current collection of servers. The entries are 2-tuples of
contexts and nodes.
"""
node_couplets_s = set(node_couplets)
if node_couplets_s != self.__node_couplets_s:
_logger.info("Servers have changed. NEW: %s REMOVE... | [
"def",
"set_servers",
"(",
"self",
",",
"node_couplets",
")",
":",
"node_couplets_s",
"=",
"set",
"(",
"node_couplets",
")",
"if",
"node_couplets_s",
"!=",
"self",
".",
"__node_couplets_s",
":",
"_logger",
".",
"info",
"(",
"\"Servers have changed. NEW: %s REMOVED: ... | Set the current collection of servers. The entries are 2-tuples of
contexts and nodes. | [
"Set",
"the",
"current",
"collection",
"of",
"servers",
".",
"The",
"entries",
"are",
"2",
"-",
"tuples",
"of",
"contexts",
"and",
"nodes",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L239-L257 | train | Set the current collection of servers. |
dsoprea/NsqSpinner | nsq/master.py | Master.start | def start(self, ccallbacks=None):
"""Establish and maintain connections."""
self.__manage_g = gevent.spawn(self.__manage_connections, ccallbacks)
self.__ready_ev.wait() | python | def start(self, ccallbacks=None):
"""Establish and maintain connections."""
self.__manage_g = gevent.spawn(self.__manage_connections, ccallbacks)
self.__ready_ev.wait() | [
"def",
"start",
"(",
"self",
",",
"ccallbacks",
"=",
"None",
")",
":",
"self",
".",
"__manage_g",
"=",
"gevent",
".",
"spawn",
"(",
"self",
".",
"__manage_connections",
",",
"ccallbacks",
")",
"self",
".",
"__ready_ev",
".",
"wait",
"(",
")"
] | Establish and maintain connections. | [
"Establish",
"and",
"maintain",
"connections",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L268-L272 | train | Establish and maintain connections. |
dsoprea/NsqSpinner | nsq/master.py | Master.stop | def stop(self):
"""Stop all of the connections."""
_logger.debug("Emitting quit signal for connections.")
self.__quit_ev.set()
_logger.info("Waiting for connection manager to stop.")
self.__manage_g.join() | python | def stop(self):
"""Stop all of the connections."""
_logger.debug("Emitting quit signal for connections.")
self.__quit_ev.set()
_logger.info("Waiting for connection manager to stop.")
self.__manage_g.join() | [
"def",
"stop",
"(",
"self",
")",
":",
"_logger",
".",
"debug",
"(",
"\"Emitting quit signal for connections.\"",
")",
"self",
".",
"__quit_ev",
".",
"set",
"(",
")",
"_logger",
".",
"info",
"(",
"\"Waiting for connection manager to stop.\"",
")",
"self",
".",
"_... | Stop all of the connections. | [
"Stop",
"all",
"of",
"the",
"connections",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/master.py#L274-L281 | train | Stop all of the connections. |
LEMS/pylems | lems/run.py | process_args | def process_args():
"""
Parse command-line arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument('-I', type=str,
metavar='<Include directory>',
action='append',
help='Directory to be searched for included files... | python | def process_args():
"""
Parse command-line arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument('-I', type=str,
metavar='<Include directory>',
action='append',
help='Directory to be searched for included files... | [
"def",
"process_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'-I'",
",",
"type",
"=",
"str",
",",
"metavar",
"=",
"'<Include directory>'",
",",
"action",
"=",
"'append'",
",",
"help"... | Parse command-line arguments. | [
"Parse",
"command",
"-",
"line",
"arguments",
"."
] | 4eeb719d2f23650fe16c38626663b69b5c83818b | https://github.com/LEMS/pylems/blob/4eeb719d2f23650fe16c38626663b69b5c83818b/lems/run.py#L19-L42 | train | Parse command - line arguments. |
LEMS/pylems | lems/run.py | run | def run(file_path,include_dirs=[],dlems=False,nogui=False):
"""
Function for running from a script or shell.
"""
import argparse
args = argparse.Namespace()
args.lems_file = file_path
args.I = include_dirs
args.dlems = dlems
args.nogui = nogui
main(args=args) | python | def run(file_path,include_dirs=[],dlems=False,nogui=False):
"""
Function for running from a script or shell.
"""
import argparse
args = argparse.Namespace()
args.lems_file = file_path
args.I = include_dirs
args.dlems = dlems
args.nogui = nogui
main(args=args) | [
"def",
"run",
"(",
"file_path",
",",
"include_dirs",
"=",
"[",
"]",
",",
"dlems",
"=",
"False",
",",
"nogui",
"=",
"False",
")",
":",
"import",
"argparse",
"args",
"=",
"argparse",
".",
"Namespace",
"(",
")",
"args",
".",
"lems_file",
"=",
"file_path",... | Function for running from a script or shell. | [
"Function",
"for",
"running",
"from",
"a",
"script",
"or",
"shell",
"."
] | 4eeb719d2f23650fe16c38626663b69b5c83818b | https://github.com/LEMS/pylems/blob/4eeb719d2f23650fe16c38626663b69b5c83818b/lems/run.py#L44-L54 | train | Function for running from a script or shell. |
LEMS/pylems | lems/run.py | main | def main(args=None):
"""
Program entry point.
"""
if args is None:
args = process_args()
print('Parsing and resolving model: '+args.lems_file)
model = Model()
if args.I is not None:
for dir in args.I:
model.add_include_directory(dir)
model.import_fro... | python | def main(args=None):
"""
Program entry point.
"""
if args is None:
args = process_args()
print('Parsing and resolving model: '+args.lems_file)
model = Model()
if args.I is not None:
for dir in args.I:
model.add_include_directory(dir)
model.import_fro... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"process_args",
"(",
")",
"print",
"(",
"'Parsing and resolving model: '",
"+",
"args",
".",
"lems_file",
")",
"model",
"=",
"Model",
"(",
")",
"if",
"args... | Program entry point. | [
"Program",
"entry",
"point",
"."
] | 4eeb719d2f23650fe16c38626663b69b5c83818b | https://github.com/LEMS/pylems/blob/4eeb719d2f23650fe16c38626663b69b5c83818b/lems/run.py#L56-L109 | train | Main function of the simulation. |
dsoprea/NsqSpinner | nsq/node.py | DiscoveredNode.connect | def connect(self, nice_quit_ev):
"""Connect the server. We expect this to implement backoff and all
connection logistics for servers that were discovered via a lookup
node.
"""
_logger.debug("Connecting to discovered node: [%s]", self.server_host)
stop_epoch = time.t... | python | def connect(self, nice_quit_ev):
"""Connect the server. We expect this to implement backoff and all
connection logistics for servers that were discovered via a lookup
node.
"""
_logger.debug("Connecting to discovered node: [%s]", self.server_host)
stop_epoch = time.t... | [
"def",
"connect",
"(",
"self",
",",
"nice_quit_ev",
")",
":",
"_logger",
".",
"debug",
"(",
"\"Connecting to discovered node: [%s]\"",
",",
"self",
".",
"server_host",
")",
"stop_epoch",
"=",
"time",
".",
"time",
"(",
")",
"+",
"nsq",
".",
"config",
".",
"... | Connect the server. We expect this to implement backoff and all
connection logistics for servers that were discovered via a lookup
node. | [
"Connect",
"the",
"server",
".",
"We",
"expect",
"this",
"to",
"implement",
"backoff",
"and",
"all",
"connection",
"logistics",
"for",
"servers",
"that",
"were",
"discovered",
"via",
"a",
"lookup",
"node",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/node.py#L62-L98 | train | Connect to the nsqlookupd server. |
dsoprea/NsqSpinner | nsq/node.py | ServerNode.connect | def connect(self, nice_quit_ev):
"""Connect the server. We expect this to implement connection logistics
for servers that were explicitly prescribed to us.
"""
_logger.debug("Connecting to explicit server node: [%s]",
self.server_host)
# According to th... | python | def connect(self, nice_quit_ev):
"""Connect the server. We expect this to implement connection logistics
for servers that were explicitly prescribed to us.
"""
_logger.debug("Connecting to explicit server node: [%s]",
self.server_host)
# According to th... | [
"def",
"connect",
"(",
"self",
",",
"nice_quit_ev",
")",
":",
"_logger",
".",
"debug",
"(",
"\"Connecting to explicit server node: [%s]\"",
",",
"self",
".",
"server_host",
")",
"# According to the docs, a nsqlookupd-discovered server should fall-out ",
"# of the lineup immedia... | Connect the server. We expect this to implement connection logistics
for servers that were explicitly prescribed to us. | [
"Connect",
"the",
"server",
".",
"We",
"expect",
"this",
"to",
"implement",
"connection",
"logistics",
"for",
"servers",
"that",
"were",
"explicitly",
"prescribed",
"to",
"us",
"."
] | 972237b8ddce737983bfed001fde52e5236be695 | https://github.com/dsoprea/NsqSpinner/blob/972237b8ddce737983bfed001fde52e5236be695/nsq/node.py#L107-L130 | train | Connect to the explicit server. |
glormph/msstitch | src/app/drivers/prottable/fdr.py | ProttableFDRDriver.prepare | def prepare(self):
"""No percolator XML for protein tables"""
self.target = self.fn
self.targetheader = reader.get_tsv_header(self.target)
self.decoyheader = reader.get_tsv_header(self.decoyfn) | python | def prepare(self):
"""No percolator XML for protein tables"""
self.target = self.fn
self.targetheader = reader.get_tsv_header(self.target)
self.decoyheader = reader.get_tsv_header(self.decoyfn) | [
"def",
"prepare",
"(",
"self",
")",
":",
"self",
".",
"target",
"=",
"self",
".",
"fn",
"self",
".",
"targetheader",
"=",
"reader",
".",
"get_tsv_header",
"(",
"self",
".",
"target",
")",
"self",
".",
"decoyheader",
"=",
"reader",
".",
"get_tsv_header",
... | No percolator XML for protein tables | [
"No",
"percolator",
"XML",
"for",
"protein",
"tables"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/drivers/prottable/fdr.py#L32-L36 | train | Prepare the protein tables for the protein table |
product-definition-center/pdc-client | pdc_client/__init__.py | PDCClient.obtain_token | def obtain_token(self):
"""
Try to obtain token from all end-points that were ever used to serve the
token. If the request returns 404 NOT FOUND, retry with older version of
the URL.
"""
token_end_points = ('token/obtain',
'obtain-token',
... | python | def obtain_token(self):
"""
Try to obtain token from all end-points that were ever used to serve the
token. If the request returns 404 NOT FOUND, retry with older version of
the URL.
"""
token_end_points = ('token/obtain',
'obtain-token',
... | [
"def",
"obtain_token",
"(",
"self",
")",
":",
"token_end_points",
"=",
"(",
"'token/obtain'",
",",
"'obtain-token'",
",",
"'obtain_token'",
")",
"for",
"end_point",
"in",
"token_end_points",
":",
"try",
":",
"return",
"self",
".",
"auth",
"[",
"end_point",
"]"... | Try to obtain token from all end-points that were ever used to serve the
token. If the request returns 404 NOT FOUND, retry with older version of
the URL. | [
"Try",
"to",
"obtain",
"token",
"from",
"all",
"end",
"-",
"points",
"that",
"were",
"ever",
"used",
"to",
"serve",
"the",
"token",
".",
"If",
"the",
"request",
"returns",
"404",
"NOT",
"FOUND",
"retry",
"with",
"older",
"version",
"of",
"the",
"URL",
... | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/__init__.py#L195-L210 | train | Try to obtain a token from all end - points that were ever used to serve the token. |
product-definition-center/pdc-client | pdc_client/__init__.py | PDCClient.get_paged | def get_paged(self, res, **kwargs):
"""
This call is equivalent to ``res(**kwargs)``, only it retrieves all pages
and returns the results joined into a single iterable. The advantage over
retrieving everything at once is that the result can be consumed immediately.
:param res: ... | python | def get_paged(self, res, **kwargs):
"""
This call is equivalent to ``res(**kwargs)``, only it retrieves all pages
and returns the results joined into a single iterable. The advantage over
retrieving everything at once is that the result can be consumed immediately.
:param res: ... | [
"def",
"get_paged",
"(",
"self",
",",
"res",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"page_size",
"is",
"not",
"None",
":",
"kwargs",
"[",
"'page_size'",
"]",
"=",
"self",
".",
"page_size",
"if",
"self",
".",
"page_size",
"<=",
"0",
"... | This call is equivalent to ``res(**kwargs)``, only it retrieves all pages
and returns the results joined into a single iterable. The advantage over
retrieving everything at once is that the result can be consumed immediately.
:param res: what resource to connect to
:param kwargs: f... | [
"This",
"call",
"is",
"equivalent",
"to",
"res",
"(",
"**",
"kwargs",
")",
"only",
"it",
"retrieves",
"all",
"pages",
"and",
"returns",
"the",
"results",
"joined",
"into",
"a",
"single",
"iterable",
".",
"The",
"advantage",
"over",
"retrieving",
"everything"... | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/__init__.py#L212-L244 | train | This method returns all pages and returns the results as a single iterable. |
product-definition-center/pdc-client | pdc_client/__init__.py | _BeanBagWrapper.results | def results(self, *args, **kwargs):
"""
Return an iterator with all pages of data.
Return NoResultsError with response if there is unexpected data.
"""
def worker():
kwargs['page'] = 1
while True:
response = self.client(*args, **kwarg... | python | def results(self, *args, **kwargs):
"""
Return an iterator with all pages of data.
Return NoResultsError with response if there is unexpected data.
"""
def worker():
kwargs['page'] = 1
while True:
response = self.client(*args, **kwarg... | [
"def",
"results",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"worker",
"(",
")",
":",
"kwargs",
"[",
"'page'",
"]",
"=",
"1",
"while",
"True",
":",
"response",
"=",
"self",
".",
"client",
"(",
"*",
"args",
",",
"*"... | Return an iterator with all pages of data.
Return NoResultsError with response if there is unexpected data. | [
"Return",
"an",
"iterator",
"with",
"all",
"pages",
"of",
"data",
".",
"Return",
"NoResultsError",
"with",
"response",
"if",
"there",
"is",
"unexpected",
"data",
"."
] | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/__init__.py#L331-L352 | train | Return an iterator with all pages of data. |
moluwole/Bast | bast/validator/rules.py | is_required.run | def run(self, value):
""" Determines if value value is empty.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if not value:
return False
return True | python | def run(self, value):
""" Determines if value value is empty.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if not value:
return False
return True | [
"def",
"run",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"pass_",
"and",
"not",
"value",
".",
"strip",
"(",
")",
":",
"return",
"True",
"if",
"not",
"value",
":",
"return",
"False",
"return",
"True"
] | Determines if value value is empty.
Keyword arguments:
value str -- the value of the associated field to compare | [
"Determines",
"if",
"value",
"value",
"is",
"empty",
".",
"Keyword",
"arguments",
":",
"value",
"str",
"--",
"the",
"value",
"of",
"the",
"associated",
"field",
"to",
"compare"
] | eecf55ae72e6f24af7c101549be0422cd2c1c95a | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/validator/rules.py#L128-L138 | train | Determines if value is empty. |
moluwole/Bast | bast/validator/rules.py | required_length.run | def run(self, value):
""" Determines if value character length equal self.length.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if len((value.strip() if self.strip else value)... | python | def run(self, value):
""" Determines if value character length equal self.length.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if len((value.strip() if self.strip else value)... | [
"def",
"run",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"pass_",
"and",
"not",
"value",
".",
"strip",
"(",
")",
":",
"return",
"True",
"if",
"len",
"(",
"(",
"value",
".",
"strip",
"(",
")",
"if",
"self",
".",
"strip",
"else",
"va... | Determines if value character length equal self.length.
Keyword arguments:
value str -- the value of the associated field to compare | [
"Determines",
"if",
"value",
"character",
"length",
"equal",
"self",
".",
"length",
".",
"Keyword",
"arguments",
":",
"value",
"str",
"--",
"the",
"value",
"of",
"the",
"associated",
"field",
"to",
"compare"
] | eecf55ae72e6f24af7c101549be0422cd2c1c95a | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/validator/rules.py#L159-L170 | train | Determines if value character length equal self. length. |
moluwole/Bast | bast/validator/rules.py | length_between.run | def run(self, value):
""" Determines if value character length is between self.minimum and self.maximum.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if self.minimum <= len((... | python | def run(self, value):
""" Determines if value character length is between self.minimum and self.maximum.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if self.minimum <= len((... | [
"def",
"run",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"pass_",
"and",
"not",
"value",
".",
"strip",
"(",
")",
":",
"return",
"True",
"if",
"self",
".",
"minimum",
"<=",
"len",
"(",
"(",
"value",
".",
"strip",
"(",
")",
"if",
"se... | Determines if value character length is between self.minimum and self.maximum.
Keyword arguments:
value str -- the value of the associated field to compare | [
"Determines",
"if",
"value",
"character",
"length",
"is",
"between",
"self",
".",
"minimum",
"and",
"self",
".",
"maximum",
".",
"Keyword",
"arguments",
":",
"value",
"str",
"--",
"the",
"value",
"of",
"the",
"associated",
"field",
"to",
"compare"
] | eecf55ae72e6f24af7c101549be0422cd2c1c95a | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/validator/rules.py#L193-L205 | train | Determines if value character length is between self. minimum and self. maximum. |
moluwole/Bast | bast/validator/rules.py | in_list.run | def run(self, value):
""" Checks if value is included within self.given_list.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if (value.strip() if self.strip else value) not in ... | python | def run(self, value):
""" Checks if value is included within self.given_list.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if (value.strip() if self.strip else value) not in ... | [
"def",
"run",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"pass_",
"and",
"not",
"value",
".",
"strip",
"(",
")",
":",
"return",
"True",
"if",
"(",
"value",
".",
"strip",
"(",
")",
"if",
"self",
".",
"strip",
"else",
"value",
")",
"... | Checks if value is included within self.given_list.
Keyword arguments:
value str -- the value of the associated field to compare | [
"Checks",
"if",
"value",
"is",
"included",
"within",
"self",
".",
"given_list",
".",
"Keyword",
"arguments",
":",
"value",
"str",
"--",
"the",
"value",
"of",
"the",
"associated",
"field",
"to",
"compare"
] | eecf55ae72e6f24af7c101549be0422cd2c1c95a | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/validator/rules.py#L225-L236 | train | Checks if value is included within self. given_list. |
moluwole/Bast | bast/validator/rules.py | is_type.run | def run(self, value):
""" Compares value against self.asserted_type.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if not isinstance(value, type(self.asserted_type)):
... | python | def run(self, value):
""" Compares value against self.asserted_type.
Keyword arguments:
value str -- the value of the associated field to compare
"""
if self.pass_ and not value.strip():
return True
if not isinstance(value, type(self.asserted_type)):
... | [
"def",
"run",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"pass_",
"and",
"not",
"value",
".",
"strip",
"(",
")",
":",
"return",
"True",
"if",
"not",
"isinstance",
"(",
"value",
",",
"type",
"(",
"self",
".",
"asserted_type",
")",
")",
... | Compares value against self.asserted_type.
Keyword arguments:
value str -- the value of the associated field to compare | [
"Compares",
"value",
"against",
"self",
".",
"asserted_type",
".",
"Keyword",
"arguments",
":",
"value",
"str",
"--",
"the",
"value",
"of",
"the",
"associated",
"field",
"to",
"compare"
] | eecf55ae72e6f24af7c101549be0422cd2c1c95a | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/validator/rules.py#L254-L265 | train | Checks the value of the associated field against the asserted_type. |
glormph/msstitch | src/app/actions/headers/base.py | generate_general_header | def generate_general_header(headerfields, fieldtypes, firstfield, oldheader,
group_by_field):
"""From headerfield object, this generates a full header as a list, ready
to write to a TSV file
E.g:
headerfield = {precusroquant: {HEADER_AREA: OD([(set1, set1_HEAD), (set2,
se... | python | def generate_general_header(headerfields, fieldtypes, firstfield, oldheader,
group_by_field):
"""From headerfield object, this generates a full header as a list, ready
to write to a TSV file
E.g:
headerfield = {precusroquant: {HEADER_AREA: OD([(set1, set1_HEAD), (set2,
se... | [
"def",
"generate_general_header",
"(",
"headerfields",
",",
"fieldtypes",
",",
"firstfield",
",",
"oldheader",
",",
"group_by_field",
")",
":",
"if",
"not",
"oldheader",
":",
"header",
"=",
"[",
"firstfield",
"]",
"else",
":",
"header",
"=",
"[",
"firstfield",... | From headerfield object, this generates a full header as a list, ready
to write to a TSV file
E.g:
headerfield = {precusroquant: {HEADER_AREA: OD([(set1, set1_HEAD), (set2,
set2_HEAD), etc])}} | [
"From",
"headerfield",
"object",
"this",
"generates",
"a",
"full",
"header",
"as",
"a",
"list",
"ready",
"to",
"write",
"to",
"a",
"TSV",
"file",
"E",
".",
"g",
":",
"headerfield",
"=",
"{",
"precusroquant",
":",
"{",
"HEADER_AREA",
":",
"OD",
"(",
"["... | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/headers/base.py#L7-L47 | train | This function generates a full header for a TSV file. |
glormph/msstitch | src/app/actions/headers/base.py | generate_headerfields | def generate_headerfields(headertypes, allfield_defs, poolnames, db=False, genecentric=False):
"""Returns a headerfields object (dict) which contains information on
fields of the header, including optional pool names"""
hfields = {}
for fieldtype in headertypes:
if fieldtype == 'isoquant':
... | python | def generate_headerfields(headertypes, allfield_defs, poolnames, db=False, genecentric=False):
"""Returns a headerfields object (dict) which contains information on
fields of the header, including optional pool names"""
hfields = {}
for fieldtype in headertypes:
if fieldtype == 'isoquant':
... | [
"def",
"generate_headerfields",
"(",
"headertypes",
",",
"allfield_defs",
",",
"poolnames",
",",
"db",
"=",
"False",
",",
"genecentric",
"=",
"False",
")",
":",
"hfields",
"=",
"{",
"}",
"for",
"fieldtype",
"in",
"headertypes",
":",
"if",
"fieldtype",
"==",
... | Returns a headerfields object (dict) which contains information on
fields of the header, including optional pool names | [
"Returns",
"a",
"headerfields",
"object",
"(",
"dict",
")",
"which",
"contains",
"information",
"on",
"fields",
"of",
"the",
"header",
"including",
"optional",
"pool",
"names"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/headers/base.py#L50-L72 | train | Generates a headerfields object which contains information on the header fields of the header |
glormph/msstitch | src/app/actions/headers/base.py | get_isoquant_fields | def get_isoquant_fields(pqdb=False, poolnames=False):
"""Returns a headerfield dict for isobaric quant channels. Channels are
taken from DB and there isn't a pool-independent version of this yet"""
# FIXME when is a None database passed?
if pqdb is None:
return {}
try:
channels_psms ... | python | def get_isoquant_fields(pqdb=False, poolnames=False):
"""Returns a headerfield dict for isobaric quant channels. Channels are
taken from DB and there isn't a pool-independent version of this yet"""
# FIXME when is a None database passed?
if pqdb is None:
return {}
try:
channels_psms ... | [
"def",
"get_isoquant_fields",
"(",
"pqdb",
"=",
"False",
",",
"poolnames",
"=",
"False",
")",
":",
"# FIXME when is a None database passed?",
"if",
"pqdb",
"is",
"None",
":",
"return",
"{",
"}",
"try",
":",
"channels_psms",
"=",
"pqdb",
".",
"get_isoquant_amount... | Returns a headerfield dict for isobaric quant channels. Channels are
taken from DB and there isn't a pool-independent version of this yet | [
"Returns",
"a",
"headerfield",
"dict",
"for",
"isobaric",
"quant",
"channels",
".",
"Channels",
"are",
"taken",
"from",
"DB",
"and",
"there",
"isn",
"t",
"a",
"pool",
"-",
"independent",
"version",
"of",
"this",
"yet"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/headers/base.py#L83-L100 | train | Returns a headerfield dict for isobaric quant channels. Channels are
taken from DB and poolnames are ignored. |
trendels/gevent_inotifyx | example.py | watch_for_events | def watch_for_events():
"""Wait for events and print them to stdout."""
fd = inotify.init()
try:
wd = inotify.add_watch(fd, '/tmp', inotify.IN_CLOSE_WRITE)
while True:
for event in inotify.get_events(fd):
print("event:", event.name, event.get_mask_description())
... | python | def watch_for_events():
"""Wait for events and print them to stdout."""
fd = inotify.init()
try:
wd = inotify.add_watch(fd, '/tmp', inotify.IN_CLOSE_WRITE)
while True:
for event in inotify.get_events(fd):
print("event:", event.name, event.get_mask_description())
... | [
"def",
"watch_for_events",
"(",
")",
":",
"fd",
"=",
"inotify",
".",
"init",
"(",
")",
"try",
":",
"wd",
"=",
"inotify",
".",
"add_watch",
"(",
"fd",
",",
"'/tmp'",
",",
"inotify",
".",
"IN_CLOSE_WRITE",
")",
"while",
"True",
":",
"for",
"event",
"in... | Wait for events and print them to stdout. | [
"Wait",
"for",
"events",
"and",
"print",
"them",
"to",
"stdout",
"."
] | b1e531616d150e86b13aeca450a61c66f9bbc855 | https://github.com/trendels/gevent_inotifyx/blob/b1e531616d150e86b13aeca450a61c66f9bbc855/example.py#L16-L25 | train | Wait for events and print them to stdout. |
ColinDuquesnoy/QCrash | qcrash/formatters/markdown.py | MardownFormatter.format_body | def format_body(self, description, sys_info=None, traceback=None):
"""
Formats the body using markdown.
:param description: Description of the issue, written by the user.
:param sys_info: Optional system information string
:param log: Optional application log
:param trac... | python | def format_body(self, description, sys_info=None, traceback=None):
"""
Formats the body using markdown.
:param description: Description of the issue, written by the user.
:param sys_info: Optional system information string
:param log: Optional application log
:param trac... | [
"def",
"format_body",
"(",
"self",
",",
"description",
",",
"sys_info",
"=",
"None",
",",
"traceback",
"=",
"None",
")",
":",
"body",
"=",
"BODY_ITEM_TEMPLATE",
"%",
"{",
"'name'",
":",
"'Description'",
",",
"'value'",
":",
"description",
"}",
"if",
"trace... | Formats the body using markdown.
:param description: Description of the issue, written by the user.
:param sys_info: Optional system information string
:param log: Optional application log
:param traceback: Optional traceback. | [
"Formats",
"the",
"body",
"using",
"markdown",
"."
] | 775e1b15764e2041a8f9a08bea938e4d6ce817c7 | https://github.com/ColinDuquesnoy/QCrash/blob/775e1b15764e2041a8f9a08bea938e4d6ce817c7/qcrash/formatters/markdown.py#L21-L43 | train | Formats the issue s body using markdown. |
moluwole/Bast | bast/bast.py | Bast.run | def run(self):
"""
Function to Run the server. Server runs on host: 127.0.0.1 and port: 2000 by default. Debug is also set to false
by default
Can be overriden by using the config.ini file
"""
define("port", default=self.port, help="Run on given port", type=int)
... | python | def run(self):
"""
Function to Run the server. Server runs on host: 127.0.0.1 and port: 2000 by default. Debug is also set to false
by default
Can be overriden by using the config.ini file
"""
define("port", default=self.port, help="Run on given port", type=int)
... | [
"def",
"run",
"(",
"self",
")",
":",
"define",
"(",
"\"port\"",
",",
"default",
"=",
"self",
".",
"port",
",",
"help",
"=",
"\"Run on given port\"",
",",
"type",
"=",
"int",
")",
"define",
"(",
"\"host\"",
",",
"default",
"=",
"self",
".",
"host",
",... | Function to Run the server. Server runs on host: 127.0.0.1 and port: 2000 by default. Debug is also set to false
by default
Can be overriden by using the config.ini file | [
"Function",
"to",
"Run",
"the",
"server",
".",
"Server",
"runs",
"on",
"host",
":",
"127",
".",
"0",
".",
"0",
".",
"1",
"and",
"port",
":",
"2000",
"by",
"default",
".",
"Debug",
"is",
"also",
"set",
"to",
"false",
"by",
"default"
] | eecf55ae72e6f24af7c101549be0422cd2c1c95a | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/bast.py#L69-L88 | train | Function to Run the server |
garethr/cloth | src/cloth/tasks.py | list | def list():
"List EC2 name and public and private ip address"
for node in env.nodes:
print "%s (%s, %s)" % (node.tags["Name"], node.ip_address,
node.private_ip_address) | python | def list():
"List EC2 name and public and private ip address"
for node in env.nodes:
print "%s (%s, %s)" % (node.tags["Name"], node.ip_address,
node.private_ip_address) | [
"def",
"list",
"(",
")",
":",
"for",
"node",
"in",
"env",
".",
"nodes",
":",
"print",
"\"%s (%s, %s)\"",
"%",
"(",
"node",
".",
"tags",
"[",
"\"Name\"",
"]",
",",
"node",
".",
"ip_address",
",",
"node",
".",
"private_ip_address",
")"
] | List EC2 name and public and private ip address | [
"List",
"EC2",
"name",
"and",
"public",
"and",
"private",
"ip",
"address"
] | b50c7cd6b03f49a931ee55ec94212760c50694a9 | https://github.com/garethr/cloth/blob/b50c7cd6b03f49a931ee55ec94212760c50694a9/src/cloth/tasks.py#L40-L44 | train | List EC2 name and public and private ip address |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.