sequence stringlengths 492 15.9k | code stringlengths 75 8.58k |
|---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:slug; 6, block; 6, 7; 6, 16; 6, 21; 6, 29; 6, 42; 6, 55; 6, 68; 6, 81; 6, 94; 6, 107; 6, 115; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:kb; 10, cal... | def get(self, slug):
kb = api.get_kb_by_slug(slug)
check_knowledge_access(kb)
parser = reqparse.RequestParser()
parser.add_argument(
'from', type=str,
help="Return only entries where 'from' matches this.")
parser.add_argument(
'to', type=str,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:pretty; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 95; 6, expression_statement; 6, 7; 7, string:"sort values and format output for viewing and comparing in test scenarios"; 8, expression_statement; 8, 9; 9, assignm... | def pretty(self):
"sort values and format output for viewing and comparing in test scenarios"
pretty_obj = OrderedDict()
for key, value in sorted(iteritems(self.__dict__)):
if value is None:
pretty_obj[key] = None
elif is_str_or_unicode(value):
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 1, 17; 2, function_name:import_directory; 3, parameters; 3, 4; 3, 8; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:module_basename; 6, type; 6, 7; 7, identifier:str; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:directory; 10, type; 10, 11; 11, identif... | def import_directory(module_basename: str, directory: str, sort_key = None) -> None:
'''Load all python modules in directory and directory's children.
Parameters
----------
:``module_basename``: module name prefix for loaded modules
:``directory``: directory to load python modules from
:``... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:read; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:given_file; 6, block; 6, 7; 6, 25; 6, 36; 6, 50; 6, 108; 6, 119; 6, 136; 7, if_statement; 7, 8; 7, 19; 8, boolean_operator:and; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9,... | def read(self, given_file):
if self.unique is not False and self.unique is not True:
raise AttributeError("Attribute 'unique' is not True or False.")
self.filename = str.strip(given_file)
self.log('Read-only opening {0}'.format(self.filename))
with open(self.filename, 'r') as... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:force_clear_lock; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, string:'''Kick out whoever currently owns the namespace global lock.
This is intended as purely a last-resort tool. If a... | def force_clear_lock(self):
'''Kick out whoever currently owns the namespace global lock.
This is intended as purely a last-resort tool. If another
process has managed to get the global lock for a very long time,
or if it requested the lock with a long expiration and then
crashe... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prettyprint; 3, parameters; 3, 4; 4, identifier:d; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:print; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:json; 1... | def prettyprint(d):
print(json.dumps(d, sort_keys=True,
indent=4, separators=("," , ": "))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_is_iterable; 3, parameters; 3, 4; 4, identifier:val; 5, block; 5, 6; 6, try_statement; 6, 7; 6, 13; 6, 20; 7, block; 7, 8; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:iter; 11, argument_list; 11, 12; 12, identifier:val... | def _is_iterable(val):
try:
iter(val)
except (ValueError, TypeError):
return False
else:
return not isinstance(val, basestring) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:square_off; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:series; 5, default_parameter; 5, 6; 5, 7; 6, identifier:time_delta; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:transition_seconds; 10, integer:1; 11, block; 11, 12; 11, ... | def square_off(series, time_delta=None, transition_seconds=1):
if time_delta:
if isinstance(time_delta, (int, float)):
time_delta = datetime.timedelta(0, time_delta)
new_times = series.index + time_delta
else:
diff = np.diff(series.index)
time_delta = np.append(diff, ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sortframe; 3, parameters; 3, 4; 4, identifier:frame; 5, block; 5, 6; 5, 8; 5, 14; 5, 32; 5, 38; 5, 44; 6, expression_statement; 6, 7; 7, string:'''
sorts particles for a frame
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9,... | def sortframe(frame):
'''
sorts particles for a frame
'''
d = frame['data'];
sortedargs = np.lexsort([d['xi'],d['yi'],d['zi']])
d = d[sortedargs];
frame['data']=d;
return frame; |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_release_id; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:version; 6, None; 7, block; 7, 8; 7, 21; 7, 28; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ts; 11, call; 11, 12; 11, 19; 12, at... | def get_release_id(version=None):
ts = datetime.utcnow().strftime(RELEASE_DATE_FMT)
if version is None:
return ts
return '{0}-{1}'.format(ts, version) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:group_objects_by; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:self; 5, identifier:list; 6, identifier:attr; 7, default_parameter; 7, 8; 7, 9; 8, identifier:valueLabel; 9, string:"value"; 10, default_parameter; 10, 11; 10, 12; 1... | def group_objects_by(self, list, attr, valueLabel="value", childrenLabel="children"):
groups = []
for obj in list:
val = obj.get(attr)
if not val:
pass
newGroup = {"attribute": attr, valueLabel: val, childrenLabel: [obj]}
found = False
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorts_query; 3, parameters; 3, 4; 4, identifier:sortables; 5, block; 5, 6; 5, 10; 5, 49; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:stmts; 9, list:[]; 10, for_statement; 10, 11; 10, 12; 10, 13; 11, identifier:sortab... | def sorts_query(sortables):
stmts = []
for sortable in sortables:
if sortable.desc:
stmts.append('{} DESC'.format(sortable.field))
else:
stmts.append('{} ASC'.format(sortable.field))
return ' ORDER BY {}'.format(', '.join(stmts)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:rtype; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 16; 8, 20; 8, 34; 8, 57; 8, 78; 8, 88; 8, 99; 8, 117; 8, 128; 8, 148; 8, 152; 8, 156; ... | def search(self, rtype, **kwargs):
model = rtype_to_model(rtype)
param = {}
pages = self.pages_query(kwargs.get('pages'))
sorts = self.sorts_query(kwargs.get(
'sorts', [Sortable(goldman.config.SORT)]
))
query =
query = query.format(
cols=se... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:force_seek; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:fd; 5, identifier:offset; 6, default_parameter; 6, 7; 6, 8; 7, identifier:chunk; 8, identifier:CHUNK; 9, block; 9, 10; 10, try_statement; 10, 11; 10, 19; 11, block; 11, 12; 12, expressi... | def force_seek(fd, offset, chunk=CHUNK):
try:
fd.seek(offset)
except (AttributeError, io.UnsupportedOperation):
emulate_seek(fd, offset, chunk) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:append; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:hcont; 6, identifier:value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:score; 9, None; 10, block; 10, 11; 10, 25; 10, 44; 11, assert_statement; 11, 12; 12, c... | def append(self, hcont, value, score = None):
assert (score is None) != (self.field.sort_field is None)
if score is None:
score = getattr(value, self.field.sort_field.name)
ContainerFieldWriter.append(self, hcont, value, score) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:raise_errors_on_nested_writes; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:method_name; 5, identifier:serializer; 6, identifier:validated_data; 7, block; 7, 8; 7, 71; 8, assert_statement; 8, 9; 8, 44; 9, not_operator; 9, 10; 10, call; 10, 11... | def raise_errors_on_nested_writes(method_name, serializer, validated_data):
assert not any(
isinstance(field, BaseSerializer) and
(key in validated_data) and
isinstance(validated_data[key], (list, dict))
for key, field in serializer.fields.items()
), (
'The `.{method_name... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:threenum; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:h5file; 5, identifier:var; 6, default_parameter; 6, 7; 6, 8; 7, identifier:post_col; 8, string:'mult'; 9, block; 9, 10; 9, 20; 9, 26; 9, 32; 9, 40; 9, 48; 9, 60; 9, 71; 9, 75; 9, 79; 9, 2... | def threenum(h5file, var, post_col='mult'):
f = h5py.File(h5file, 'r')
d = f[var]
w = f[post_col]
s = d.chunks[0]
n = d.shape[0]
maxval = -np.abs(d[0])
minval = np.abs(d[0])
total = 0
wsum = 0
for x in range(0, n, s):
aN = ~np.logical_or(np.isnan(d[x:x+s]), np.isinf(d[x:x... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_filter_keys; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:content_id; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:prefix; 10, None; 11, default_parameter; 11, 12; 11... | def _filter_keys(self, content_id=None, prefix=None, subtopic_id=None):
'''Filter out-of-order labels by key tuple.
:class:`Label` always sorts by `(cid1,cid2,sid1,sid2)`, but
for efficient lookups on `cid2` this class also stores in
order `(cid2,cid1,sid2,sid1)`. Filter out things that... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:topological_sorting; 3, parameters; 3, 4; 3, 5; 4, identifier:nodes; 5, identifier:relations; 6, block; 6, 7; 6, 9; 6, 13; 6, 25; 6, 32; 6, 39; 6, 47; 6, 110; 6, 135; 7, expression_statement; 7, 8; 8, string:'''An implementation of Kahn's algor... | def topological_sorting(nodes, relations):
'''An implementation of Kahn's algorithm.
'''
ret = []
nodes = set(nodes) | _nodes(relations)
inc = _incoming(relations)
out = _outgoing(relations)
free = _free_nodes(nodes, inc)
while free:
n = free.pop()
ret.append(n)
o... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:solve_resource; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:value; 6, identifier:resource; 7, block; 7, 8; 7, 31; 8, for_statement; 8, 9; 8, 10; 8, 16; 9, identifier:solver; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12... | def solve_resource(self, value, resource):
for solver in self.get_resource_solvers(resource):
try:
return solver.solve(value, resource)
except CannotSolve:
continue
raise SolveFailure(self, resource, value) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:incrementName; 3, parameters; 3, 4; 3, 5; 4, identifier:nameList; 5, identifier:name; 6, block; 6, 7; 6, 14; 6, 23; 6, 67; 7, if_statement; 7, 8; 7, 11; 8, comparison_operator:not; 8, 9; 8, 10; 9, identifier:name; 10, identifier:nameList; 11, b... | def incrementName(nameList, name):
if name not in nameList:
return name
newName = name + str(1)
for n in range(1, len(nameList) + 2):
found = False
for b in nameList:
newName = name + str(n)
if b == newName:
found = True
if not found:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:polylines; 5, block; 5, 6; 6, for_statement; 6, 7; 6, 10; 6, 14; 7, pattern_list; 7, 8; 7, 9; 8, identifier:n; 9, identifier:c; 10, call; 10, 11; 10, 12; 11, identifier:enumerate; 12, argument_list; 12, ... | def sort(polylines):
for n, c in enumerate(polylines):
l = len(c)
if l > 2:
mid = c.mean(axis=0)
distV = (c - mid)
dists = norm(distV, axis=-1)
firstI = np.argmax(dists)
sign = np.sign(distV[firstI])
dd = np.logical_or(np.sign(d... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_queryset; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 34; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:queryset; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, call; 11, 12; 11, 1... | def get_queryset(self):
queryset = super(MostVotedManager, self).get_queryset()
sql =
messages = queryset.extra(
select={
'vote_count': sql,
}
)
return messages.order_by('-vote_count', 'received_time') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:deleteByOrigIndex; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:index; 6, block; 6, 7; 6, 11; 6, 15; 6, 53; 6, 59; 6, 65; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, list:[]; 11, expressi... | def deleteByOrigIndex(self, index):
result = []
result_tracker = []
for counter, row in enumerate(self.table):
if self.index_track[counter] != index:
result.append(row)
result_tracker.append(self.index_track[counter])
self.table = result
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:deleteByOrigIndexList; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:indexList; 6, block; 6, 7; 6, 11; 6, 15; 6, 19; 6, 53; 6, 59; 6, 65; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, list:[... | def deleteByOrigIndexList(self, indexList):
result = []
result_tracker = []
counter = 0
for row in self.table:
if not counter in indexList:
result.append(row)
result_tracker.append(self.index_track[counter])
counter += 1
sel... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:none_greater; 11, False; 12, block; 12, 1... | def sort(self, key, reverse=False, none_greater=False):
'''Sort the list in the order of the dictionary key.
Example of use:
>>> test = [
... {"name": "Jim", "age": 18, "income": 93000, "wigs": 68 },
... {"name": "Larry", "age": 18, "wigs": [3, 2, 9... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:returnIndexList; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, False; 8, block; 8, 9; 8, 11; 8, 20; 8, 24; 8, 52; 9, expression_statement; 9, 10; 10, string:'''Return a list of integers... | def returnIndexList(self, limit=False):
'''Return a list of integers that are list-index references to the
original list of dictionaries."
Example of use:
>>> test = [
... {"name": "Jim", "age": 18, "income": 93000, "order": 2},
... {"name": "Larry", "age": 18, ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:returnValue; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:last; 8, False; 9, block; 9, 10; 9, 12; 9, 23; 9, 29; 9, 38; 10, expression_statement; 10, 11; 11, string:'''Re... | def returnValue(self, key, last=False):
'''Return the key's value for the first entry in the current list.
If 'last=True', then the last entry is referenced."
Returns None is the list is empty or the key is missing.
Example of use:
>>> test = [
... {"name": "Jim", "a... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:returnValueList; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key_list; 6, default_parameter; 6, 7; 6, 8; 7, identifier:last; 8, False; 9, block; 9, 10; 9, 12; 9, 16; 9, 27; 9, 33; 9, 42; 9, 59; 10, expression_statement; 1... | def returnValueList(self, key_list, last=False):
'''Return a list of key values for the first entry in the current list.
If 'last=True', then the last entry is referenced."
Returns None is the list is empty. If a key is missing, then
that entry in the list is None.
Example of use... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_seq_records; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:seq_records; 6, block; 6, 7; 6, 25; 6, 38; 6, 45; 6, 61; 6, 74; 6, 81; 6, 97; 6, 101; 6, 138; 7, for_statement; 7, 8; 7, 9; 7, 10; 8, identifier:seq_record; 9, ident... | def sort_seq_records(self, seq_records):
for seq_record in seq_records:
seq_record.voucher_code = seq_record.voucher_code.replace("-", "_")
unsorted_gene_codes = set([i.gene_code for i in seq_records])
sorted_gene_codes = list(unsorted_gene_codes)
sorted_gene_codes.sort(key=l... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:extractFromSQLFile; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:filePointer; 6, default_parameter; 6, 7; 6, 8; 7, identifier:delimiter; 8, string:";"; 9, block; 9, 10; 9, 18; 9, 22; 9, 26; 9, 80; 9, 84; 9, 88; 9, 164; 10,... | def extractFromSQLFile(self, filePointer, delimiter=";"):
data = filePointer.read()
dataLines = []
dataLinesIndex = 0
for c in data:
if len(dataLines) - 1 < dataLinesIndex:
dataLines.append("")
if c == "\r\n" or c == "\r" or c == "\n":
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort_data; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:data; 6, identifier:sort_key; 7, default_parameter; 7, 8; 7, 9; 8, identifier:reverse; 9, False; 10, block; 10, 11; 10, 15; 10, 33; 10, 44; 11, expression_stat... | async def sort_data(self, data, sort_key, reverse=False):
sorted_data = []
lines = sorted(data, key=lambda k: k[sort_key], reverse=reverse)
for line in lines:
sorted_data.append(line)
return sorted_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 11; 2, function_name:get_ceiling; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:clouds; 6, type; 6, 7; 7, list:[Cloud]; 7, 8; 8, identifier:Cloud; 9, type; 9, 10; 10, identifier:Cloud; 11, block; 11, 12; 11, 32; 12, for_statement; 12, 13... | def get_ceiling(clouds: [Cloud]) -> Cloud:
for cloud in clouds:
if cloud.altitude and cloud.type in ('OVC', 'BKN', 'VV'):
return cloud
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_finish_filter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:lst; 6, identifier:key; 7, identifier:include_self; 8, identifier:exclusive; 9, identifier:biggest_first; 10, block; 10, 11; 10, 20; 10, 30; 1... | def _finish_filter(self, lst, key, include_self, exclusive, biggest_first):
key = self._actual_key(key)
locations = [x[0] for x in lst]
if not include_self and key in locations:
lst.pop(locations.index(key))
lst.sort(key=lambda x: x[1], reverse=biggest_first)
lst = [x... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:intersects; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:include_self; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:exclusive; 11, F... | def intersects(self, key, include_self=False, exclusive=False, biggest_first=True, only=None):
possibles = self.topology if only is None else {k: self[k] for k in only}
if key == 'RoW' and 'RoW' not in self:
return ['RoW'] if 'RoW' in possibles else []
faces = self[key]
lst =... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:group_by_key_func; 3, parameters; 3, 4; 3, 5; 4, identifier:iterable; 5, identifier:key_func; 6, block; 6, 7; 6, 14; 6, 30; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:result; 10, call; 10, 11; 10, 12; 11, identifie... | def group_by_key_func(iterable, key_func):
result = defaultdict(list)
for item in iterable:
result[key_func(item)].append(item)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:line; 5, block; 5, 6; 5, 14; 5, 18; 5, 51; 5, 60; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 13; 8, pattern_list; 8, 9; 8, 10; 8, 11; 8, 12; 9, identifier:x0; 10, identifier:y0; 11, identifie... | def sort(line):
x0, y0, x1, y1 = line
turn = False
if abs(x1 - x0) > abs(y1 - y0):
if x1 < x0:
turn = True
elif y1 < y0:
turn = True
if turn:
return (x1, y1, x0, y0)
return line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:vectorizable_features; 3, parameters; 3, 4; 4, identifier:fcs; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, string:'''Discovers the ordered set of vectorizable features in ``fcs``.
Returns a list of feature names, sorted l... | def vectorizable_features(fcs):
'''Discovers the ordered set of vectorizable features in ``fcs``.
Returns a list of feature names, sorted lexicographically.
Feature names are only included if the corresponding
features are vectorizable (i.e., they are an instance of
:class:`collections.Mapping`).
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:extension_sort_key; 3, parameters; 3, 4; 4, identifier:extension; 5, block; 5, 6; 5, 12; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:name; 9, attribute; 9, 10; 9, 11; 10, identifier:extension; 11, identifier:n... | def extension_sort_key(extension):
name = extension.name
category = name.split('_', 2)[1]
return (0, name) if category in ('ARB', 'KHR', 'OES') else (1, name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:estimate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 11; 6, 23; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:val; 10, integer:0; 11, for_statement; 11, 12; 11, 13; 11, 1... | def estimate(self, upgrades):
val = 0
for u in upgrades:
val += u.estimate()
return val |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:human_estimate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 16; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:val; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13;... | def human_estimate(self, upgrades):
val = self.estimate(upgrades)
if val < 60:
return "less than 1 minute"
elif val < 300:
return "less than 5 minutes"
elif val < 600:
return "less than 10 minutes"
elif val < 1800:
return "less than... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:pre_upgrade_checks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 11; 6, 53; 6, 95; 6, 101; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:errors; 10, list:[]; 11, for_statem... | def pre_upgrade_checks(self, upgrades):
errors = []
for check in self.global_pre_upgrade:
self._setup_log_prefix(plugin_id=check.__name__)
try:
check()
except RuntimeError as e:
errors.append((check.__name__, e.args))
for u in u... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:post_upgrade_checks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:upgrades; 6, block; 6, 7; 6, 11; 6, 53; 6, 95; 6, 101; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:errors; 10, list:[]; 11, for_state... | def post_upgrade_checks(self, upgrades):
errors = []
for u in upgrades:
self._setup_log_prefix(plugin_id=u.name)
try:
u.post_upgrade()
except RuntimeError as e:
errors.append((u.name, e.args))
for check in self.global_post_upgra... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:order_upgrades; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:upgrades; 6, default_parameter; 6, 7; 6, 8; 7, identifier:history; 8, None; 9, block; 9, 10; 9, 16; 9, 28; 9, 131; 9, 162; 9, 184; 9, 188; 9, 241; 9, 264; 10, ex... | def order_upgrades(self, upgrades, history=None):
history = history or {}
graph_incoming, graph_outgoing = self._create_graph(upgrades, history)
for node_id in six.iterkeys(history):
start_nodes = [node_id, ]
while start_nodes:
node = start_nodes.pop()
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_validate_field; 3, parameters; 3, 4; 3, 5; 4, identifier:param; 5, identifier:fields; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:not; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:param; 11, identifier:field... | def _validate_field(param, fields):
if param.field not in fields:
raise InvalidQueryParams(**{
'detail': 'The sort query param value of "%s" is '
'invalid. That field does not exist on the '
'resource being requested.' % param.raw_field,
'l... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_validate_no_rels; 3, parameters; 3, 4; 3, 5; 4, identifier:param; 5, identifier:rels; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 13; 8, comparison_operator:in; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:param; 11, identifier:field;... | def _validate_no_rels(param, rels):
if param.field in rels:
raise InvalidQueryParams(**{
'detail': 'The sort query param value of "%s" is not '
'supported. Sorting on relationships is not '
'currently supported' % param.raw_field,
'links': ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:init; 3, parameters; 3, 4; 3, 5; 4, identifier:req; 5, identifier:model; 6, block; 6, 7; 6, 13; 6, 19; 6, 35; 6, 50; 6, 66; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:rels; 10, attribute; 10, 11; 10, 12; 11, identi... | def init(req, model):
rels = model.relationships
fields = model.all_fields
params = req.get_param_as_list('sort') or [goldman.config.SORT]
params = [Sortable(param.lower()) for param in params]
for param in params:
_validate_no_rels(param, rels)
_validate_field(param, fields)
ret... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_allposts; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 27; 5, 48; 5, 57; 5, 61; 5, 65; 5, 225; 5, 240; 6, expression_statement; 6, 7; 7, string:''' Return all posts in blog sorted by date
'''; 8, expression_statement;... | def get_allposts(self):
''' Return all posts in blog sorted by date
'''
result = self.client.posts(self.blog, offset = 0, limit = 1)
try:
total_posts = result['total_posts']
except:
raise phasetumblr_errors.TumblrBlogException(result['meta']['msg'])
delta = (total_posts / 10) + 1
all_posts = []
p... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_dict_by_key; 3, parameters; 3, 4; 4, identifier:obj; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sort_func; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:x; 12, su... | def sort_dict_by_key(obj):
sort_func = lambda x: x[0]
return OrderedDict(sorted(obj.items(), key=sort_func)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sortBy; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 16; 7, 45; 8, expression_statement; 8, 9; 9, string:'''sort results by given criteria'''; 10, expression_statement... | def sortBy(self, *args):
'''sort results by given criteria'''
criteria = ['seeds', 'size']
for k in args:
if k in criteria:
self.results = sorted(
self.results, key=attrgetter(k), reverse=True)
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rate_limited; 3, parameters; 3, 4; 4, identifier:max_per_second; 5, block; 5, 6; 5, 9; 5, 20; 5, 25; 5, 129; 6, import_statement; 6, 7; 7, dotted_name; 7, 8; 8, identifier:datetime; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12... | def rate_limited(max_per_second):
import datetime
min_request_time = datetime.timedelta(seconds=max_per_second)
last_time_called = [None]
def decorate(func):
def rate_limited_function(*args, **kwargs):
if last_time_called[0]:
delta = datetime.datetime.now() - last_tim... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:monotony; 3, parameters; 3, 4; 4, identifier:seq; 5, block; 5, 6; 6, if_statement; 6, 7; 6, 13; 6, 16; 6, 33; 7, comparison_operator:==; 7, 8; 7, 9; 8, identifier:seq; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12,... | def monotony(seq):
if seq == sorted(seq):
return 1
elif seq == list(reversed(sorted(seq))):
return -1
else:
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:variables; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator... | def variables(self):
p = lambda o: isinstance(o, Variable) and self._docfilter(o)
return sorted(filter(p, self.doc.values())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:classes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator:a... | def classes(self):
p = lambda o: isinstance(o, Class) and self._docfilter(o)
return sorted(filter(p, self.doc.values())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:functions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operator... | def functions(self):
p = lambda o: isinstance(o, Function) and self._docfilter(o)
return sorted(filter(p, self.doc.values())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:submodules; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 24; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_operato... | def submodules(self):
p = lambda o: isinstance(o, Module) and self._docfilter(o)
return sorted(filter(p, self.doc.values())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:class_variables; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 26; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:p; 9, lambda; 9, 10; 9, 12; 10, lambda_parameters; 10, 11; 11, identifier:o; 12, boolean_op... | def class_variables(self):
p = lambda o: isinstance(o, Variable) and self.module._docfilter(o)
return filter(p, self.doc.values()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:BEDIterator; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:filehandle; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sortedby; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:verbose; 10, False; 11, default_parameter... | def BEDIterator(filehandle, sortedby=None, verbose=False, scoreType=int,
dropAfter=None):
chromsSeen = set()
prev = None
if type(filehandle).__name__ == "str":
filehandle = open(filehandle)
if verbose:
try:
pind = ProgressIndicator(totalToDo=os.path.getsize(filehandle.name),
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:compress_and_sort_index; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 40; 5, 50; 5, 63; 5, 69; 5, 80; 5, 88; 5, 100; 5, 107; 5, 118; 5, 129; 5, 135; 5, 154; 5, 161; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9;... | def compress_and_sort_index(self):
idx_fname = '{name}.{date}.mbox.csv'.format(**self.__dict__)
try:
reader = csv.reader(open(idx_fname), dialect='excel-tab')
except IOError:
return False
index = [x for x in reader if x]
sorted_index = sorted(index, key=it... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:versions; 11, call; 11, 12; 11, 13; 12, identifier:OrderedD... | def _sort(self):
self.versions = OrderedDict(sorted(self.versions.items(), key=lambda v: v[0])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_workspace_activities; 3, parameters; 3, 4; 3, 5; 4, identifier:brain; 5, default_parameter; 5, 6; 5, 7; 6, identifier:limit; 7, integer:1; 8, block; 8, 9; 8, 16; 8, 32; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, ide... | def get_workspace_activities(brain, limit=1):
mb = queryUtility(IMicroblogTool)
items = mb.context_values(brain.getObject(), limit=limit)
return [
{
'subject': item.creator,
'verb': 'published',
'object': item.text,
'time': {
'datetime'... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_by; 3, parameters; 3, 4; 3, 5; 4, identifier:items; 5, identifier:attr; 6, block; 6, 7; 6, 38; 7, function_definition; 7, 8; 7, 9; 7, 11; 8, function_name:key_func; 9, parameters; 9, 10; 10, identifier:item; 11, block; 11, 12; 12, try_stat... | def sort_by(items, attr):
def key_func(item):
try:
return getattr(item, attr)
except AttributeError:
try:
return item[attr]
except TypeError:
getattr(item, attr)
return sorted(items, key=key_func) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sorted_migrations; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 35; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:_sorted_migrations; 11, block; 11, 12; 12, exp... | def sorted_migrations(self):
if not self._sorted_migrations:
self._sorted_migrations = sorted(
self.migration_registry.items(),
key=lambda migration_tuple: migration_tuple[0])
return self._sorted_migrations |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sorter; 3, parameters; 3, 4; 4, identifier:generated; 5, block; 5, 6; 5, 36; 5, 42; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:pairs; 9, list_comprehension; 9, 10; 9, 27; 10, tuple; 10, 11; 10, 19; 11, call; 11, 12... | def _sorter(generated):
pairs = [(os.path.dirname(f), os.path.basename(f))
for f in set(list(generated))]
pairs.sort()
return [os.path.join(pair[0], pair[1]) for pair in pairs] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:regionsIntersection; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:s1; 5, identifier:s2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:collapse; 8, True; 9, block; 9, 10; 9, 14; 9, 21; 9, 28; 9, 45; 9, 49; 9, 53; 9, 346; 10, expression_state... | def regionsIntersection(s1, s2, collapse=True):
debug = False
s1_c = collapseRegions(s1)
s2_c = collapseRegions(s2)
if len(s1_c) == 0 or len(s2_c) == 0:
return []
res = []
j = 0
for i in range(0, len(s1_c)):
if debug:
sys.stderr.write("processing from s1_c : " + str(s1_c[i]) + "\n")
if d... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:bucketIterator; 3, parameters; 3, 4; 3, 5; 4, identifier:elements; 5, identifier:buckets; 6, block; 6, 7; 6, 66; 6, 200; 6, 204; 6, 208; 6, 216; 7, function_definition; 7, 8; 7, 9; 7, 12; 8, function_name:check_sorted; 9, parameters; 9, 10; 9, ... | def bucketIterator(elements, buckets):
def check_sorted(current, previous):
if (previous is not None) and \
((previous.chrom > current.chrom) or
((previous.chrom == current.chrom) and
(previous.start > current.start))):
raise GenomicIntervalError("elements not sorted. Saw " +
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_ordered; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:generator; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 28; 9, 45; 9, 51; 9, 63; 10, expression_statement;... | def _ordered(generator, *args, **kwargs):
unordered_dict = {k: v for k, v in generator(*args, **kwargs)}
keys = sorted(list(dict(unordered_dict).keys()))
result = OrderedDict()
for key in keys:
result[key] = unordered_dict[key]
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:str2dict_keys; 3, parameters; 3, 4; 4, identifier:str_in; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 6, expression_statement; 6, 7; 7, string:'''
Extracts the keys from a string that represents a dict and returns them
sorted by key.
Args:
... | def str2dict_keys(str_in):
'''
Extracts the keys from a string that represents a dict and returns them
sorted by key.
Args:
str_in (string) that contains python dict
Returns:
(list) with keys or None if no valid dict was found
Raises:
-
'''
tmp_dict = str2dict(str... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:str2dict_values; 3, parameters; 3, 4; 4, identifier:str_in; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 6, expression_statement; 6, 7; 7, string:'''
Extracts the values from a string that represents a dict and returns them
sorted by key.
Ar... | def str2dict_values(str_in):
'''
Extracts the values from a string that represents a dict and returns them
sorted by key.
Args:
str_in (string) that contains python dict
Returns:
(list) with values or None if no valid dict was found
Raises:
-
'''
tmp_dict = str2di... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:to_json; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, keyword_separator; 6, default_parameter; 6, 7; 6, 8; 7, identifier:include_keys; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:exclude_keys; 11,... | def to_json(self, *, include_keys=None, exclude_keys=None, use_default_excludes=True,
pretty=False):
return to_json(
self.to_dict(
include_keys=include_keys,
exclude_keys=exclude_keys,
use_default_excludes=use_default_excludes),
pretty=pretty) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 34; 2, function_name:get_annotations; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 4, identifier:cls; 5, identifier:target; 6, default_parameter; 6, 7; 6, 8; 7, identifier:exclude; 8, None; 9, default_parameter; 9, 10; 9, 11; 10... | def get_annotations(
cls, target,
exclude=None, ctx=None, select=lambda *p: True,
mindepth=0, maxdepth=0, followannotated=True, public=True,
_history=None
):
result = []
if mindepth <= 0:
try:
annotations_by_ctx = get_proper... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_filenames; 3, parameters; 3, 4; 4, identifier:dirname; 5, block; 5, 6; 5, 20; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:filenames; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:glob; 12, ... | def get_filenames(dirname):
filenames = glob.glob('{}/*.pkl'.format(dirname))
return sorted(filenames, key=_f_to_i) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_states; 3, parameters; 3, 4; 3, 5; 4, identifier:states; 5, identifier:sort_list; 6, block; 6, 7; 6, 15; 6, 73; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:sorted_states; 10, call; 10, 11; 10, 14; 11, attribute... | def sort_states(states, sort_list):
sorted_states= states.copy()
for sort_pair in reversed( _convert_list_of_dict_to_tuple(sort_list) ):
if sort_pair[0].lstrip('-') in ['data','measure','meta']:
sorted_states= _state_value_sort(sorted_states, sort_pair, _state_key_function)
elif sort... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 11; 3, 14; 3, 19; 4, identifier:self; 5, identifier:terms; 6, default_parameter; 6, 7; 6, 8; 7, identifier:category; 8, attribute; 8, 9; 8, 10; 9, identifier:Category; 10, identifier:all_categories; ... | def search(self, terms, category=Category.all_categories, page=1,
sort_key=SearchSortKey.date,
order_key=SearchOrderKey.descending):
params = {
'page': 'search',
'term': terms,
'cats': category.value,
'sort': sort_key.value,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:partition; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:mapped_values; 6, block; 6, 7; 6, 16; 6, 31; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:partitioned_data; 10, call; 10, 11; 10, 14; 11, attrib... | def partition(self, mapped_values):
partitioned_data = collections.defaultdict(list)
for key, value in mapped_values:
partitioned_data[key].append(value)
return partitioned_data.items() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:cond_int; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:conkey; 6, block; 6, 7; 6, 19; 6, 25; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:m; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12... | def cond_int(self, conkey):
m = re.match(self.numrx, conkey)
if not m:
return conkey
return int(m.group(1)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sorted_conkeys; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:prefix; 7, None; 8, block; 8, 9; 8, 13; 8, 42; 8, 48; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:... | def sorted_conkeys(self, prefix=None):
conkeys = []
for cond in _COND_PREFIXES:
conkeys += sorted([key for key in self.conditions
if key.startswith(cond)], key=self.cond_int)
if not prefix:
return conkeys
return [key for key in conke... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:isordinal; 3, parameters; 3, 4; 4, identifier:x; 5, block; 5, 6; 5, 11; 5, 34; 5, 69; 6, import_statement; 6, 7; 7, aliased_import; 7, 8; 7, 10; 8, dotted_name; 8, 9; 9, identifier:numpy; 10, identifier:np; 11, if_statement; 11, 12; 11, 26; 12,... | def isordinal(x):
import numpy as np
if len(x) == len(np.unique(x)):
return False, ("number of observations equals the "
"number of unique values.")
if not isinstance(x[0], str):
if not np.all(np.equal(np.mod(x, 1), 0)):
return False, "elements are not inte... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:sort; 7, block; 7, 8; 7, 30; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifie... | def sort(self, *sort):
self.add_get_param('sort', FILTER_DELIMITER.join(
[ELEMENT_DELIMITER.join(elements) for elements in sort]))
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:to_json; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:drop_null; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:camel; 10, False; 11, default_parameter; 11, 12; 1... | def to_json(self, drop_null=True, camel=False, indent=None, sort_keys=False):
return json.dumps(self.to_dict(drop_null, camel), indent=indent,
sort_keys=sort_keys) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by_name; 3, parameters; 3, 4; 4, identifier:names; 5, block; 5, 6; 5, 61; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:last_name_key; 8, parameters; 8, 9; 9, identifier:full_name; 10, block; 10, 11; 10, 20; 10, 34; 10, 55; 1... | def sort_by_name(names):
def last_name_key(full_name):
parts = full_name.split(' ')
if len(parts) == 1:
return full_name.upper()
last_first = parts[-1] + ' ' + ' '.join(parts[:-1])
return last_first.upper()
return sorted(set(names), key=last_name_key) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 47; 5, 67; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:users; 9, list:[]; 10, for_statement; 10, 11; 10, 14; 10, 31; 11, pattern_list; 11, 12; ... | def sort(self):
users = []
for _, group in itertools.groupby(sorted(self.commits),
operator.attrgetter('author_mail')):
if group:
users.append(self.merge_user_commits(group))
self.sorted_commits = sorted(users,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 22; 5, 33; 5, 39; 5, 45; 5, 107; 5, 121; 5, 130; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:s... | def sort(self):
self.sorted_commits = []
if not self.commits:
return self.sorted_commits
prev_commit = self.commits.pop(0)
prev_line = prev_commit.line_number
prev_uuid = prev_commit.uuid
for commit in self.commits:
if (commit.uuid != prev_uuid or
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:truncate_most_common; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:truncation_length; 6, block; 6, 7; 6, 9; 6, 26; 7, expression_statement; 7, 8; 8, string:'''
Sorts the counter and keeps only the most common items up to... | def truncate_most_common(self, truncation_length):
'''
Sorts the counter and keeps only the most common items up to
``truncation_length`` in place.
:type truncation_length: int
'''
keep_keys = set(v[0] for v in self.most_common(truncation_length))
for key in self.... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_ordered_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:keypath; 6, identifier:distance_from; 7, default_parameter; 7, 8; 7, 9; 8, identifier:open_interval; 9, True; 10, block; 10, 11; 10, 15; 10, 30; 10, 7... | def get_ordered_values(self, keypath, distance_from, open_interval=True):
values = []
if keypath[0] == 'target':
keypath = keypath[1:]
for _, instance in self.iter_singleton_referents():
value = instance.get_value_from_path(keypath)
if hasattr(value, 'low') an... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:gp_datdir; 3, parameters; 3, 4; 3, 5; 4, identifier:initial; 5, identifier:topN; 6, block; 6, 7; 6, 15; 6, 23; 6, 35; 6, 50; 6, 56; 6, 138; 6, 145; 6, 179; 6, 201; 6, 208; 6, 270; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pa... | def gp_datdir(initial, topN):
inDir, outDir = getWorkDirs()
initial = initial.capitalize()
inDir = os.path.join(inDir, initial)
if not os.path.exists(inDir):
return "initial %s doesn't exist" % initial
data = OrderedDict()
for file in os.listdir(inDir):
country = os.path.splitext(file)[0]
file_u... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:rankingEval; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 19; 5, 30; 5, 61; 5, 69; 5, 91; 5, 99; 5, 110; 5, 114; 5, 161; 5, 167; 5, 173; 6, expression_statement; 6, 7; 7, string:'''
Sorting the pop. base on the fitnessEva... | def rankingEval(self):
'''
Sorting the pop. base on the fitnessEval result
'''
fitnessAll = numpy.zeros(self.length)
fitnessNorm = numpy.zeros(self.length)
for i in range(self.length):
self.Ind[i].fitnessEval()
fitnessAll[i] = self.Ind[i].fitness
maxFitness = fitnessAll.max()
for i in range(self.l... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sortedbyAge; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 19; 5, 40; 5, 48; 6, expression_statement; 6, 7; 7, string:'''
Sorting the pop. base of the age
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; ... | def sortedbyAge(self):
'''
Sorting the pop. base of the age
'''
ageAll = numpy.zeros(self.length)
for i in range(self.length):
ageAll[i] = self.Ind[i].age
ageSorted = ageAll.argsort()
return ageSorted[::-1] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:upcoming_releases; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:product; 6, block; 6, 7; 6, 11; 6, 19; 6, 36; 6, 42; 6, 52; 6, 59; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:url; 10, string:'api/v6/... | def upcoming_releases(self, product):
url = 'api/v6/releases/'
url = url + '?product__shortname=' + product
url = url + '&ga_date__gte=' + date.today().strftime('%Y-%m-%d')
url = url + '&ordering=shortname_sort'
releases = yield self._get(url)
result = munchify(releases)
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:es_field_sort; 3, parameters; 3, 4; 4, identifier:fld_name; 5, block; 5, 6; 5, 15; 5, 35; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:parts; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:fld_na... | def es_field_sort(fld_name):
parts = fld_name.split(".")
if "_" not in parts[-1]:
parts[-1] = "_" + parts[-1]
return ".".join(parts) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_get_vars; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 5, 40; 5, 44; 5, 106; 5, 129; 5, 337; 5, 349; 5, 356; 6, expression_statement; 6, 7; 7, string:''' load the vars section from a play, accounting for all sorts of v... | def _get_vars(self):
''' load the vars section from a play, accounting for all sorts of variable features
including loading from yaml files, prompting, and conditional includes of the first
file found in a list. '''
if self.vars is None:
self.vars = {}
if type(self.va... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:list_refs; 3, parameters; 3, 4; 3, 5; 4, identifier:profile; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ref_type; 7, None; 8, block; 8, 9; 8, 13; 8, 22; 8, 32; 8, 43; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, iden... | def list_refs(profile, ref_type=None):
resource = "/refs"
if ref_type:
resource += "/" + ref_type
data = api.get_request(profile, resource)
result = [prepare(x) for x in data]
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 12; 3, 15; 4, identifier:self; 5, identifier:fieldname; 6, default_parameter; 6, 7; 6, 8; 7, identifier:key; 8, lambda; 8, 9; 8, 11; 9, lambda_parameters; 9, 10; 10, identifier:x; 11, identifier:x; 12,... | def sort(self, fieldname, key=lambda x: x, desc=False, inplace=False):
try:
field_index = tuple(self.fields).index(fieldname)
except ValueError:
raise ValueError("Sorting on a field that doesn't exist: `%s`" %
fieldname)
data_cols = izip(*sort... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:intersectingIntervalIterator; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:start; 6, identifier:end; 7, block; 7, 8; 7, 18; 7, 32; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:items; 11, call;... | def intersectingIntervalIterator(self, start, end):
items = self.intersectingInterval(start, end)
items.sort(key=lambda x: x.start)
for item in items:
yield item |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sanitize_usecols; 3, parameters; 3, 4; 4, identifier:usecols; 5, block; 5, 6; 5, 13; 5, 63; 5, 67; 5, 128; 5, 138; 5, 144; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:usecols; 9, None; 10, block; 10, 11; ... | def _sanitize_usecols(usecols):
if usecols is None:
return None
try:
pats = usecols.split(',')
pats = [p.strip() for p in pats if p]
except AttributeError:
usecols = [int(c) for c in usecols]
usecols.sort()
return tuple(usecols)
cols = []
for pat in pa... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:binary_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:data; 5, identifier:target; 6, default_parameter; 6, 7; 6, 8; 7, identifier:lo; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:hi; 11, None; 12, block; 12, 1... | def binary_search(data, target, lo=0, hi=None):
hi = hi if hi is not None else len(data)
mid = (lo + hi) // 2
if hi < 2 or hi > len(data) or target > data[-1] or target < data[0]:
return -1
if data[mid] > target:
return binary_search(data, target, lo=lo, hi=mid)
elif data[mid] < targ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:repr_feature; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:feature; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_keys; 7, integer:100; 8, default_parameter; 8, 9; 8, 10; 9, identifier:indent; 10, integer:8; 11, default_paramete... | def repr_feature(feature, max_keys=100, indent=8, lexigraphic=False):
'''
generate a pretty-printed string for a feature
Currently implemented:
* StringCounter
@max_keys: truncate long counters
@indent: indent multi-line displays by this many spaces
@lexigraphic: instead of sorting counter... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_getkey; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:args; 6, identifier:kwargs; 7, block; 7, 8; 7, 15; 7, 25; 7, 40; 7, 50; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:values; 11, call; 11,... | def _getkey(self, args, kwargs):
values = list(args)
keys = sorted(list(kwargs))
for key in keys:
values.append((key, kwargs[key]))
result = hash(tuple(values))
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:iterator; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 143; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:results; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, call; 11, 12; 11, 13; 1... | def iterator(self):
results = super(SearchableQuerySet, self).iterator()
if self._search_terms and not self._search_ordered:
results = list(results)
for i, result in enumerate(results):
count = 0
related_weights = []
for (field, wei... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:save_as_json; 3, parameters; 3, 4; 3, 8; 3, 11; 3, 16; 3, 19; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:total; 6, type; 6, 7; 7, identifier:list; 8, default_parameter; 8, 9; 8, 10; 9, identifier:name; 10, string:'data.json'; 11, typed_defa... | def save_as_json(total: list,
name='data.json',
sort_by: str = None,
no_duplicate=False,
order='asc'):
if sort_by:
reverse = order == 'desc'
total = sorted(total, key=itemgetter(sort_by), reverse=reverse)
if no_duplicate:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.