sequence stringlengths 492 15.9k | code stringlengths 75 8.58k |
|---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:serialize_to_normalized_pretty_json; 3, parameters; 3, 4; 4, identifier:py_obj; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:json; 10, identifier:dumps; 11, argument_list; 11, 12; 11,... | def serialize_to_normalized_pretty_json(py_obj):
return json.dumps(py_obj, sort_keys=True, indent=2, cls=ToJsonCompatibleTypes) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:serialize_to_normalized_compact_json; 3, parameters; 3, 4; 4, identifier:py_obj; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:json; 10, identifier:dumps; 11, argument_list; 11, 12; 11... | def serialize_to_normalized_compact_json(py_obj):
return json.dumps(
py_obj, sort_keys=True, separators=(',', ':'), cls=ToJsonCompatibleTypes
) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:topological_sort; 3, parameters; 3, 4; 4, identifier:unsorted_dict; 5, block; 5, 6; 5, 10; 5, 16; 5, 20; 5, 28; 5, 79; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sorted_list; 9, list:[]; 10, expression_statement; 10... | def topological_sort(unsorted_dict):
sorted_list = []
sorted_set = set()
found = True
unconnected_dict = unsorted_dict.copy()
while found:
found = False
for pid, obsoletes_pid in list(unconnected_dict.items()):
if obsoletes_pid is None or obsoletes_pid in sorted_set:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_elements_by_child_values; 3, parameters; 3, 4; 3, 5; 4, identifier:obj_pyxb; 5, identifier:child_name_list; 6, block; 6, 7; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:obj_pyxb; 11, ident... | def sort_elements_by_child_values(obj_pyxb, child_name_list):
obj_pyxb.sort(key=lambda x: [get_auto(getattr(x, n)) for n in child_name_list]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_field_values; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 10; 3, 13; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:maxvalues; 8, unary_operator:-; 8, 9; 9, integer:1; 10, default_parameter; 10, 11; 10, 12;... | def get_field_values(self, name, maxvalues=-1, sort=True, **query_dict):
param_dict = query_dict.copy()
param_dict.update(
{
'rows': '0',
'facet': 'true',
'facet.field': name,
'facet.limit': str(maxvalues),
'face... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:bin; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:x; 5, identifier:bins; 6, default_parameter; 6, 7; 6, 8; 7, identifier:maxX; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:minX; 11, None; 12, block; 12, 13; 12, 15; 12, 2... | def bin(x, bins, maxX=None, minX=None):
'''
bin signal x using 'binsN' bin. If minX, maxX are None, they default to the full
range of the signal. If they are not None, everything above maxX gets assigned to
binsN-1 and everything below minX gets assigned to 0, this is effectively the same
as clippin... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:update_item; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, identifier:self; 5, identifier:table_name; 6, identifier:key_dict; 7, default_parameter; 7, 8; 7, 9; 8, identifier:condition_expression; 9, None; ... | def update_item(self, table_name, key_dict,
condition_expression=None,
update_expression=None,
expression_attribute_names=None,
expression_attribute_values=None,
return_consumed_capacity=None,
return_... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 42; 2, function_name:query; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 3, 36; 3, 39; 4, identifier:self; 5, identifier:table_name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:index_name; 8, None; 9, default_p... | def query(self, table_name,
index_name=None,
consistent_read=None,
key_condition_expression=None,
filter_expression=None,
expression_attribute_names=None,
expression_attribute_values=None,
projection_expression=None,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_gae_versions; 3, parameters; 4, block; 4, 5; 4, 14; 4, 20; 4, 34; 4, 38; 4, 80; 5, expression_statement; 5, 6; 6, assignment; 6, 7; 6, 8; 7, identifier:r; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:requests; 11, identi... | def get_gae_versions():
r = requests.get(SDK_RELEASES_URL)
r.raise_for_status()
releases = r.json().get('items', {})
versions_and_urls = []
for release in releases:
match = PYTHON_RELEASE_RE.match(release['name'])
if not match:
continue
versions_and_urls.append(
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 20; 2, function_name:_parse_options; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:options; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:str; 12, type; 12, 13... | def _parse_options(options: List[str]) -> Dict[str, str]:
try:
return dict(i.split('=', maxsplit=1) for i in options)
except ValueError:
raise ArgumentError(
f'Option must be in format <key>=<value>, got: {options}') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:collapse; 3, parameters; 3, 4; 3, 5; 4, identifier:l; 5, identifier:raw; 6, block; 6, 7; 6, 14; 6, 18; 6, 22; 6, 211; 6, 218; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:logger_ts; 11, identif... | def collapse(l, raw):
logger_ts.info("enter collapse")
_master = {}
_dsn = ""
try:
_pc = l[0]["mode"]
for entry in l:
dsn = entry['dataSetName']
_dsn = dsn
_current = entry
if dsn not in _master:
logger_ts.info("collapsing: ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:collapseTs; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:ts; 6, None; 7, block; 7, 8; 7, 10; 7, 14; 7, 94; 8, global_statement; 8, 9; 9, identifier:_timeseries_data; 10, expression_statement; 10, 11; 11, assignment; 11, ... | def collapseTs(ts=None):
global _timeseries_data
_d = {}
if not ts:
print("Error: Time series data not provided. Pass time series into the function.")
else:
try:
_raw = _timeseries_data[ts[0]["time_id"]]
print(mode_ts("collapse", mode="", ts=ts))
_d = ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:display_results; 3, parameters; 3, 4; 3, 5; 4, identifier:results; 5, default_parameter; 5, 6; 5, 7; 6, identifier:detailed; 7, False; 8, block; 8, 9; 8, 18; 8, 92; 9, if_statement; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:detaile... | def display_results(results, detailed=False):
if not detailed:
print('FILENAME......................................... STATUS..........')
for entry in results:
try:
if detailed:
print("\n{}".format(entry["filename"]))
print(create_detailed_results(ent... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:call_validator_api; 3, parameters; 3, 4; 3, 5; 4, identifier:dsn; 5, identifier:api_data; 6, block; 6, 7; 6, 13; 6, 241; 6, 261; 6, 267; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:_filename; 10, binary_operator:+; ... | def call_validator_api(dsn, api_data):
_filename = dsn + ".lpd"
try:
api_data = json.dumps(api_data)
payload = {'json_payload': api_data, 'apikey': 'lipd_linked'}
response = requests.post('http://www.lipd.net/api/validator', data=payload)
if response.status_code == 413:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:create_back_links; 3, parameters; 3, 4; 4, identifier:env; 5, block; 5, 6; 5, 14; 5, 20; 5, 148; 6, if_statement; 6, 7; 6, 12; 7, subscript; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:env; 10, identifier:needs_workflow; 11, string:'b... | def create_back_links(env):
if env.needs_workflow['backlink_creation']:
return
needs = env.needs_all_needs
for key, need in needs.items():
for link in need["links"]:
link_main = link.split('.')[0]
try:
link_part = link.split('.')[1]
except ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:CaseGroups; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:unicode_dir; 6, identifier:_UNICODE_DIR; 7, block; 7, 8; 7, 12; 7, 55; 7, 64; 7, 72; 7, 82; 7, 88; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, ... | def CaseGroups(unicode_dir=_UNICODE_DIR):
togroup = {}
def DoLine(codes, fields):
(_, foldtype, lower, _) = fields
if foldtype not in ("C", "S"):
return
lower = _UInt(lower)
togroup.setdefault(lower, [lower]).extend(codes)
ReadUnicodeTable(unicode_dir+"/CaseFolding.txt", 4, DoLine)
groups ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:naturalsortkey; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 6, return_statement; 6, 7; 7, list_comprehension; 7, 8; 7, 19; 8, conditional_expression:if; 8, 9; 8, 13; 8, 18; 9, call; 9, 10; 9, 11; 10, identifier:int; 11, argument_list;... | def naturalsortkey(s):
return [int(part) if part.isdigit() else part
for part in re.split('([0-9]+)', s)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:max_variance_genes; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:nbins; 7, integer:5; 8, default_parameter; 8, 9; 8, 10; 9, identifier:frac; 10, float:0.2; 11, block; 11, 12; 11, 16; 11, ... | def max_variance_genes(data, nbins=5, frac=0.2):
indices = []
if sparse.issparse(data):
means, var = sparse_mean_var(data)
else:
means = data.mean(1)
var = data.var(1)
mean_indices = means.argsort()
n_elements = int(data.shape[0]/nbins)
frac_elements = int(n_elements*frac... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:unique; 3, parameters; 3, 4; 4, identifier:ar; 5, block; 5, 6; 5, 8; 5, 14; 5, 32; 6, expression_statement; 6, 7; 7, identifier:r; 8, import_statement; 8, 9; 9, aliased_import; 9, 10; 9, 13; 10, dotted_name; 10, 11; 10, 12; 11, identifier:dask;... | def unique(ar):
r
import dask.array as da
if isinstance(ar, da.core.Array):
return da.unique(ar)
return _unique(ar) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:polls_get; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 14; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, subscript; 10, 11; 10, 12; 11, identifier:... | def polls_get(self, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('callback'):
return self.polls_get_with_http_info(**kwargs)
else:
(data) = self.polls_get_with_http_info(**kwargs)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sorted_actions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 35; 5, 63; 6, for_statement; 6, 7; 6, 8; 6, 31; 7, identifier:a; 8, call; 8, 9; 8, 10; 9, identifier:filter; 10, argument_list; 10, 11; 10, 28; 11, lambda; 11, 12; 11,... | def _sorted_actions(self):
for a in filter(lambda _: not _.last and \
not self.is_action(_, 'parsers'), self._actions):
yield a
for a in filter(lambda _: _.last and \
not self.is_action(_, 'parsers'), self._actions):
yield a
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:eigendecomp; 3, parameters; 3, 4; 3, 5; 4, identifier:G; 5, identifier:d; 6, block; 6, 7; 6, 15; 6, 28; 6, 37; 6, 52; 6, 58; 6, 82; 6, 90; 6, 105; 6, 124; 6, 132; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:N; 10, s... | def eigendecomp(G, d):
N = G.shape[0]
lamda, u = np.linalg.eig(G)
lamda = np.real(lamda)
indices = np.argsort(lamda)[::-1]
lamda_sorted = lamda[indices]
assert (lamda_sorted[
:d] > -1e-10).all(), "{} not all positive!".format(lamda_sorted[:d])
u = u[:, indices]
factor = np.em... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_astrom; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:official; 6, string:'%'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:provisional; 9, string:'%'; 10, block; 10, 11; 10, 15; 10, 19; 10, 36; 10, 43; 10, ... | def get_astrom(official='%',provisional='%'):
sql= "SELECT m.* FROM measure m "
sql+="LEFT JOIN object o ON m.provisional LIKE o.provisional "
if not official:
sql+="WHERE o.official IS NULL"
else:
sql+="WHERE o.official LIKE '%s' " % ( official, )
sql+=" AND m.provisional LIKE '%s... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sorted_by_field; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:issues; 5, default_parameter; 5, 6; 5, 7; 6, identifier:field; 7, string:'closed_at'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 12, r... | def sorted_by_field(issues, field='closed_at', reverse=False):
return sorted(issues, key = lambda i:i[field], reverse=reverse) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:order_by; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_selector; 7, identifier:identity; 8, block; 8, 9; 8, 11; 8, 25; 8, 49; 9, expression_statement; 9, 10; 10, string:'''Sorts by a key in ... | def order_by(self, key_selector=identity):
'''Sorts by a key in ascending order.
Introduces a primary sorting order to the sequence. Additional sort
criteria should be specified by subsequent calls to then_by() and
then_by_descending(). Calling order_by() or order_by_descending() on
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:then_by; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_selector; 7, identifier:identity; 8, block; 8, 9; 8, 11; 8, 25; 8, 49; 8, 61; 9, expression_statement; 9, 10; 10, string:'''Introduce su... | def then_by(self, key_selector=identity):
'''Introduce subsequent ordering to the sequence with an optional key.
The returned sequence will be sorted in ascending order by the
selected key.
Note: This method uses deferred execution.
Args:
key_selector: A unary functio... |
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, call; 7, 8; 7, 13; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:_matches; 12, identifier:sort_values;... | def sort(self):
self._matches.sort_values(
by=[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME,
constants.COUNT_FIELDNAME, constants.LABEL_FIELDNAME,
constants.WORK_FIELDNAME, constants.SIGLUM_FIELDNAME],
ascending=[False, True, False, True, True, True... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_set_labels; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:catalogue; 6, block; 6, 7; 6, 94; 7, with_statement; 7, 8; 7, 13; 8, with_clause; 8, 9; 9, with_item; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, ident... | def _set_labels(self, catalogue):
with self._conn:
self._conn.execute(constants.UPDATE_LABELS_SQL, [''])
labels = {}
for work, label in catalogue.items():
self._conn.execute(constants.UPDATE_LABEL_SQL, [label, work])
cursor = self._conn.execute... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_fn_args; 3, parameters; 3, 4; 3, 5; 3, 9; 4, identifier:fn; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:kwargs; 7, type; 7, 8; 8, identifier:dict; 9, typed_default_parameter; 9, 10; 9, 11; 9, 13; 10, identifier:prefix; 11, type; 11, 12; ... | def get_fn_args(fn, kwargs: dict, prefix: str = None):
all_args = get_all_args(fn)
required_args = get_required_args(fn)
fn_kwargs = pick_kwargs(kwargs, all_args, prefix)
missing_args = [arg for arg in required_args if arg not in fn_kwargs]
if missing_args:
raise ValueError(
'The... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:pick_kwargs; 3, parameters; 3, 4; 3, 8; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:kwargs; 6, type; 6, 7; 7, identifier:dict; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:required_args; 10, type; 10, 11; 11, identifier:list; 12, ty... | def pick_kwargs(kwargs: dict, required_args: list, prefix: str = None):
picked = {k: v for k, v in kwargs.items() if k in required_args}
prefixed = {}
if prefix:
prefix = prefix + '__'
prefixed = {
_remove_prefix(k, prefix): v
for k, v in kwargs.items()
if... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 4, identifier:query; 5, default_parameter; 5, 6; 5, 7; 6, identifier:query_type; 7, identifier:DEFAULT_QUERY_TYPE; 8, block; 8, 9; 8, 18; 8, 34; 8, 72; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 1... | def search(query, query_type=DEFAULT_QUERY_TYPE):
statement, arguments = _build_search(query)
if statement is None and arguments is None:
return QueryResults([], [], 'AND')
with db_connect() as db_connection:
with db_connection.cursor() as cursor:
cursor.execute(statement, argume... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_tdms_files; 3, parameters; 3, 4; 4, identifier:directory; 5, block; 5, 6; 5, 19; 5, 38; 5, 56; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:path; 9, call; 9, 10; 9, 18; 10, attribute; 10, 11; 10, 17; 11, call; 11,... | def get_tdms_files(directory):
path = pathlib.Path(directory).resolve()
tdmslist = [r for r in path.rglob("*.tdms") if r.is_file()]
tdmslist = [r for r in tdmslist if not r.name.endswith("_traces.tdms")]
return sorted(tdmslist) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:footrule_dist; 3, parameters; 3, 4; 3, 5; 4, identifier:params1; 5, default_parameter; 5, 6; 5, 7; 6, identifier:params2; 7, None; 8, block; 8, 9; 8, 11; 8, 25; 8, 35; 8, 70; 9, expression_statement; 9, 10; 10, identifier:r; 11, assert_statemen... | def footrule_dist(params1, params2=None):
r
assert params2 is None or len(params1) == len(params2)
ranks1 = rankdata(params1, method="average")
if params2 is None:
ranks2 = np.arange(1, len(params1) + 1, dtype=float)
else:
ranks2 = rankdata(params2, method="average")
return np.su... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:kendalltau_dist; 3, parameters; 3, 4; 3, 5; 4, identifier:params1; 5, default_parameter; 5, 6; 5, 7; 6, identifier:params2; 7, None; 8, block; 8, 9; 8, 11; 8, 25; 8, 35; 8, 70; 8, 80; 8, 87; 8, 98; 9, expression_statement; 9, 10; 10, identifier... | def kendalltau_dist(params1, params2=None):
r
assert params2 is None or len(params1) == len(params2)
ranks1 = rankdata(params1, method="ordinal")
if params2 is None:
ranks2 = np.arange(1, len(params1) + 1, dtype=float)
else:
ranks2 = rankdata(params2, method="ordinal")
tau, _ = k... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_sort_string; 3, parameters; 3, 4; 4, identifier:sort; 5, block; 5, 6; 5, 14; 5, 23; 5, 27; 5, 100; 5, 107; 6, if_statement; 6, 7; 6, 10; 7, comparison_operator:is; 7, 8; 7, 9; 8, identifier:sort; 9, None; 10, block; 10, 11; 11, return_sta... | def parse_sort_string(sort):
if sort is None:
return ['_score']
l = sort.rsplit(',')
sortlist = []
for se in l:
se = se.strip()
order = 'desc' if se[0:1] == '-' else 'asc'
field = se[1:] if se[0:1] in ['-', '+'] else se
field = field.strip()
sortlist.appen... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_config_dir; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pattern; 7, string:"*.config"; 8, default_parameter; 8, 9; 8, 10; 9, identifier:configspec; 10, None; 11, default_param... | def get_config_dir(path, pattern="*.config", configspec=None, allow_errors=False):
logger = logging.getLogger(__name__)
logger.debug("Loading all files matching {0} in {1}".format(pattern, path))
files = Globber(path, include=[pattern], recursive=False).glob()
files = sorted(files)
config = ConfigObj()
for filena... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:is_first_instance_aws; 3, parameters; 4, block; 4, 5; 4, 51; 4, 114; 4, 174; 5, try_statement; 5, 6; 5, 35; 6, block; 6, 7; 6, 23; 6, 29; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:instance_details; 10, call; 10, 1... | def is_first_instance_aws():
try:
instance_details = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document',
timeout=5).json()
instance_id = instance_details['instanceId']
instance_region = instance_details['region']
except... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:creation_ordered; 3, parameters; 3, 4; 4, identifier:class_to_decorate; 5, block; 5, 6; 5, 20; 5, 26; 5, 67; 5, 74; 5, 88; 5, 95; 5, 104; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:next_index; 9, call; 9, 10; 9, 13;... | def creation_ordered(class_to_decorate):
next_index = functools.partial(next, itertools.count())
__init__orig = class_to_decorate.__init__
@functools.wraps(__init__orig, assigned=['__doc__'])
def __init__(self, *args, **kwargs):
object.__setattr__(self, '_index', next_index())
__init__or... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:get_members; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:cls; 5, default_parameter; 5, 6; 5, 7; 6, identifier:member_class; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:is_member; 10, None; 11, default_parameter; ... | def get_members(cls, member_class=None, is_member=None, sort_key=None, _parameter=None):
if member_class is None and is_member is None:
raise TypeError("get_members either needs a member_class parameter or an is_member check function (or both)")
members = OrderedDict()
for base in cls.__bases__:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:sort_field; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:field_name; 6, identifier:direction; 7, default_parameter; 7, 8; 7, 9; 8, identifier:field_vals; 9, None; 10, block; 10, 11; 10, 20; 10, 51; 10, 70; 11, expre... | def sort_field(self, field_name, direction, field_vals=None):
field_name = self._normalize_field_name(field_name)
if direction > 0:
direction = 1
elif direction < 0:
direction = -1
else:
raise ValueError("direction {} is undefined".format(direction))
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:check_photometry_categorize; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:x; 5, identifier:y; 6, identifier:levels; 7, default_parameter; 7, 8; 7, 9; 8, identifier:tags; 9, None; 10, block; 10, 11; 10, 13; 10, 22; 10, 31; 10, 39; 10, 4... | def check_photometry_categorize(x, y, levels, tags=None):
'''Put every point in its category.
levels must be sorted.'''
x = numpy.asarray(x)
y = numpy.asarray(y)
ys = y.copy()
ys.sort()
m = ys[len(ys) // 2:].mean()
y /= m
m = 1.0
s = ys[len(ys) // 2:].std()
result = []
if... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_normalize_sort_SQL; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:field_name; 6, identifier:field_vals; 7, identifier:sort_dir_str; 8, block; 8, 9; 8, 13; 8, 45; 8, 60; 8, 64; 8, 92; 8, 99; 8, 108; 9, expression_stat... | def _normalize_sort_SQL(self, field_name, field_vals, sort_dir_str):
fvi = None
if sort_dir_str == 'ASC':
fvi = (t for t in enumerate(field_vals))
else:
fvi = (t for t in enumerate(reversed(field_vals)))
query_sort_str = [' CASE {}'.format(self._normalize_name(... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_process; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:segments; 6, block; 6, 7; 6, 19; 6, 30; 6, 49; 6, 58; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:mlh; 11, ident... | def _process(self, segments):
mlh, mlw = self.max_line_height, self.max_line_width
s = segments.astype(numpy.uint32)
order = mlw * (s[:, 1] // mlh) + s[:, 0]
sort_order = numpy.argsort(order)
return segments[sort_order] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:flatten; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:rho; 5, identifier:pval; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sortby; 8, string:"cor"; 9, block; 9, 10; 9, 18; 9, 30; 9, 63; 9, 80; 9, 133; 10, expression_statement; 10, 11; 11,... | def flatten(rho, pval, sortby="cor"):
n = rho.shape[0]
idx = np.triu_indices(n, k=1)
tab = pd.DataFrame(
columns=['i', 'j', 'cor', 'pval'],
data=np.c_[idx[0], idx[1], rho[idx], pval[idx]])
tab[['i', "j"]] = tab[['i', "j"]].astype(int)
if sortby == "cor":
tab['abscor'] = np.ab... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:has_code; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:state; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:incorrect_msg; 8, string:"The checker expected to find `{{text}}` in your command."; 9, default_parameter... | def has_code(state, text, incorrect_msg="The checker expected to find `{{text}}` in your command.", fixed=False):
stu_code = state.student_code
res = text in stu_code if fixed else re.search(text, stu_code)
if not res:
_msg = state.build_message(incorrect_msg, fmt_kwargs={ 'text': text })
st... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:topports; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:sort_by; 6, string:'records'; 7, default_parameter; 7, 8; 7, 9; 8, identifier:limit; 9, integer:10; 10, default_parameter; 10, 11; 10, 12; 11, i... | def topports(sort_by='records', limit=10, date=None, return_format=None):
uri = '/'.join(['topports', sort_by, str(limit)])
if date:
try:
uri = '/'.join([uri, date.strftime("%Y-%m-%d")])
except AttributeError:
uri = '/'.join([uri, date])
return _get(uri, return_format... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:all_nodes_that_receive; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:service; 5, default_parameter; 5, 6; 5, 7; 6, identifier:service_configuration; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:run_only; 10, False; 11, de... | def all_nodes_that_receive(service, service_configuration=None, run_only=False, deploy_to_only=False):
assert not (run_only and deploy_to_only)
if service_configuration is None:
service_configuration = read_services_configuration()
runs_on = service_configuration[service]['runs_on']
deployed_to ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_cuthill_mckee; 3, parameters; 3, 4; 3, 5; 4, identifier:vertices; 5, identifier:vertices_neighbours; 6, block; 6, 7; 6, 25; 6, 41; 6, 49; 6, 54; 6, 62; 6, 129; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:vertices_d... | def _cuthill_mckee(vertices, vertices_neighbours):
vertices_degrees = {v: sum(itervalues(vertices_neighbours[v]))
for v in vertices}
peripheral_vertex = min(vertices, key=(lambda v: vertices_degrees[v]))
visited = set([peripheral_vertex])
cm_order = [peripheral_vertex]
previo... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:write_csv; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:path; 7, None; 8, block; 8, 9; 8, 23; 8, 36; 8, 49; 8, 60; 8, 68; 8, 74; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, att... | def write_csv(self, path=None):
self.sort_sections(['Root', 'Contacts', 'Documentation', 'References', 'Resources', 'Citations', 'Schema'])
if self.description:
self.description = self.description
if self.abstract:
self.description = self.abstract
t = self['Root']... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:validate_functions; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:ast; 6, type; 6, 7; 7, identifier:BELAst; 8, identifier:bo; 9, block; 9, 10; 9, 99; 9, 118; 10, if_statement; 10, 11; 10, 16; 11, call; 11, 12; 11, 13;... | def validate_functions(ast: BELAst, bo):
if isinstance(ast, Function):
log.debug(f"Validating: {ast.name}, {ast.function_type}, {ast.args}")
function_signatures = bo.spec["functions"]["signatures"][ast.name]["signatures"]
function_name = ast.name
(valid_function, messages) = check_fu... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 1, 16; 2, function_name:hash_nanopub; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:nanopub; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Mapping; 9, type_parameter; 9, 10; 9, 12; 10, type; 10, 11; 11, identifier:str; 12, type... | def hash_nanopub(nanopub: Mapping[str, Any]) -> str:
hash_list = []
hash_list.append(nanopub["nanopub"]["type"].get("name", "").strip())
hash_list.append(nanopub["nanopub"]["type"].get("version", "").strip())
if nanopub["nanopub"]["citation"].get("database", False):
hash_list.append(
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:build_listing; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 97; 5, 117; 6, function_definition; 6, 7; 6, 8; 6, 11; 7, function_name:func_entry; 8, parameters; 8, 9; 8, 10; 9, identifier:name; 10, identifier:func; 11, block; 11, 1... | def build_listing(self):
def func_entry(name, func):
args, varargs, defaults = self._get_arg_spec(func)
params = [{'name': str(a), 'optional': a in defaults, 'vararg': False} for a in args if a != 'ctx']
if varargs:
params += [{'name': str(varargs), 'optional'... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_url_qsl; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:cls; 5, identifier:raw_url; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 16; 8, 25; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, ... | def sort_url_qsl(cls, raw_url, **kwargs):
parsed_url = urlparse(raw_url)
qsl = parse_qsl(parsed_url.query)
return cls._join_url(parsed_url, sorted(qsl, **kwargs)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:get_sorted_series_files; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:startpath; 7, string:""; 8, default_parameter; 8, 9; 8, 10; 9, identifier:series_number; ... | def get_sorted_series_files(self, startpath="", series_number=None, return_files_with_info=False,
sort_keys="SliceLocation", return_files=True, remove_doubled_slice_locations=True):
dcmdir = self.files_with_info[:]
if series_number is not None:
dcmdir = [
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:guess_interval; 3, parameters; 3, 4; 3, 5; 4, identifier:nums; 5, default_parameter; 5, 6; 5, 7; 6, identifier:accuracy; 7, integer:0; 8, block; 8, 9; 8, 15; 8, 29; 8, 41; 8, 65; 8, 77; 8, 84; 8, 95; 9, if_statement; 9, 10; 9, 12; 10, not_opera... | def guess_interval(nums, accuracy=0):
if not nums:
return 0
nums = sorted([int(i) for i in nums])
if len(nums) == 1:
return nums[0]
diffs = [nums[i + 1] - nums[i] for i in range(len(nums) - 1)]
diffs = [item for item in diffs if item >= accuracy]
sorted_diff = sorted(diffs)
r... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sort_list_of_dicts; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:lst_of_dct; 5, identifier:keys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, dictionary_splat_pattern; 9, 10; 10, identifier:sort_args; 11, block... | def sort_list_of_dicts(lst_of_dct, keys, reverse=False, **sort_args):
if type(keys) != list:
keys = [keys]
lst_of_dct.sort(key=lambda x: [((False, x[key]) if key in x else (True, 0)) for key in keys], reverse=reverse, **sort_args)
return lst_of_dct |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:parallel_deblur; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:inputs; 5, identifier:params; 6, identifier:pos_ref_db_fp; 7, identifier:neg_ref_dp_fp; 8, default_parameter; 8, 9; 8, 10; 9, identifier:jobs_to_start; 10, integer:1; ... | def parallel_deblur(inputs, params,
pos_ref_db_fp, neg_ref_dp_fp, jobs_to_start=1):
logger = logging.getLogger(__name__)
logger.info('parallel deblur started for %d inputs' % len(inputs))
remove_param_list = ['-O', '--jobs-to-start', '--seqs-fp',
'--pos-ref-db-fp... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:build_index_sortmerna; 3, parameters; 3, 4; 3, 5; 4, identifier:ref_fp; 5, identifier:working_dir; 6, block; 6, 7; 6, 16; 6, 29; 6, 33; 6, 164; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:logger; 10, call; 10, 11; 1... | def build_index_sortmerna(ref_fp, working_dir):
logger = logging.getLogger(__name__)
logger.info('build_index_sortmerna files %s to'
' dir %s' % (ref_fp, working_dir))
all_db = []
for db in ref_fp:
fasta_dir, fasta_filename = split(db)
index_basename = splitext(fasta_file... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:remove_artifacts_from_biom_table; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:table_filename; 5, identifier:fasta_filename; 6, identifier:ref_fp; 7, identifier:biom_table_dir; 8, identifier:ref_db_fp; ... | def remove_artifacts_from_biom_table(table_filename,
fasta_filename,
ref_fp,
biom_table_dir,
ref_db_fp,
threads=1,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:remove_artifacts_seqs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:seqs_fp; 5, identifier:ref_fp; 6, identifier:working_dir; 7, identifier:ref_db_fp; 8, default_parameter; 8, 9; 8, 10; 9, identifier:n... | def remove_artifacts_seqs(seqs_fp,
ref_fp,
working_dir,
ref_db_fp,
negate=False,
threads=1,
verbose=False,
sim_thresh=None,
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:launch_workflow; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 3, 14; 3, 15; 3, 18; 3, 21; 4, identifier:seqs_fp; 5, identifier:working_dir; 6, identifier:mean_error; 7, identifier:error_dist; 8, identifier:ind... | def launch_workflow(seqs_fp, working_dir, mean_error, error_dist,
indel_prob, indel_max, trim_length, left_trim_length,
min_size, ref_fp, ref_db_fp, threads_per_sample=1,
sim_thresh=None, coverage_thresh=None):
logger = logging.getLogger(__name__)
logg... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:logs; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 22; 5, 34; 5, 48; 6, if_statement; 6, 7; 6, 13; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:parent; 12, iden... | def logs(self):
if not self.parent.loaded: self.parent.load()
logs = self.parent.p.logs_dir.flat_directories
logs.sort(key=lambda x: x.mod_time)
return logs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_string_by_pairs; 3, parameters; 3, 4; 4, identifier:strings; 5, block; 5, 6; 5, 15; 5, 19; 5, 26; 5, 80; 6, assert_statement; 6, 7; 7, comparison_operator:==; 7, 8; 7, 14; 8, binary_operator:%; 8, 9; 8, 13; 9, call; 9, 10; 9, 11; 10, ident... | def sort_string_by_pairs(strings):
assert len(strings) % 2 == 0
pairs = []
strings = list(strings)
while strings:
template = strings.pop()
for i, candidate in enumerate(strings):
if count_string_diff(template, candidate) == 1:
pair = [template, strings.pop(i)]... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:natural_sort; 3, parameters; 3, 4; 4, identifier:item; 5, block; 5, 6; 5, 15; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:dre; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:re; 12, identifier:c... | def natural_sort(item):
dre = re.compile(r'(\d+)')
return [int(s) if s.isdigit() else s.lower() for s in re.split(dre, item)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_elementary_intervals; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:features; 6, block; 6, 7; 6, 11; 6, 61; 6, 71; 6, 77; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:coords; 10, list:[]; 11, try_s... | def get_elementary_intervals(self, features):
coords = []
try:
for interval in features:
if len(interval) != 3:
raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval))
coords.extend([... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:convtable2dict; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:convtable; 5, identifier:locale; 6, default_parameter; 6, 7; 6, 8; 7, identifier:update; 8, None; 9, block; 9, 10; 9, 21; 9, 100; 10, expression_statement; 10, 11; 11, assignment; 1... | def convtable2dict(convtable, locale, update=None):
rdict = update.copy() if update else {}
for r in convtable:
if ':uni' in r:
if locale in r:
rdict[r[':uni']] = r[locale]
elif locale[:-1] == 'zh-han':
if locale in r:
for word in r.values(... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:re_sort; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 17; 5, 21; 5, 38; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:keys; 9, call; 9, 10; 9, 11; 10, identifier:sorted; 11, argument_list; 11, 12; 12, ca... | def re_sort(data):
keys = sorted(data.keys())
new_data = {}
for number, key in enumerate(keys):
new_data[number] = data[key]
return new_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:natural_sorted; 3, parameters; 3, 4; 4, identifier:iterable; 5, block; 5, 6; 5, 34; 5, 43; 6, function_definition; 6, 7; 6, 8; 6, 10; 7, function_name:sortkey; 8, parameters; 8, 9; 9, identifier:x; 10, block; 10, 11; 11, return_statement; 11, 1... | def natural_sorted(iterable):
def sortkey(x):
return [(int(c) if c.isdigit() else c) for c in re.split(numbers, x)]
numbers = re.compile(r'(\d+)')
return sorted(iterable, key=sortkey) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:sort_keys; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:keys; 6, default_parameter; 6, 7; 6, 8; 7, identifier:order; 8, attribute; 8, 9; 8, 10; 9, identifier:QuerySet; 10, identifier:ASCENDING; 11, block; 11, 12; 11, 30; ... | def sort_keys(self, keys, order=QuerySet.ASCENDING):
missing_keys = [
key
for key in keys
if not len(self._reverse_index[key])
]
keys_and_values = [
(key, self._reverse_index[key][0])
for key in keys
if key not in missing_ke... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:options; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 18; 5, 27; 5, 38; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:keys; 9, call; 9, 10; 9, 17; 10, attribute; 10, 11; 10, 16; 11, attribute; 11, 12; 11... | def options(self):
keys = self.__class__.__dict__.copy()
keys.update(self.__dict__)
keys = sorted(keys.keys())
for opt in keys:
val = self.get(opt)
if val is not None:
yield opt, val |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 7; 2, function_name:_tidy; 3, parameters; 3, 4; 4, identifier:self; 5, type; 5, 6; 6, None; 7, block; 7, 8; 8, if_statement; 8, 9; 8, 12; 8, 22; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:no_overlap; 12, block; 12, 13; 13, expression_sta... | def _tidy(self) -> None:
if self.no_overlap:
self.remove_overlap(self.no_contiguous)
else:
self._sort() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 1, 35; 2, function_name:index_list_for_sort_order; 3, parameters; 3, 4; 3, 12; 3, 24; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:x; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:An... | def index_list_for_sort_order(x: List[Any], key: Callable[[Any], Any] = None,
reverse: bool = False) -> List[int]:
def key_with_user_func(idx_val: Tuple[int, Any]):
return key(idx_val[1])
if key:
sort_key = key_with_user_func
else:
sort_key = itemgetter(... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 1, 22; 2, function_name:sort_list_by_index_list; 3, parameters; 3, 4; 3, 12; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:x; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:Any; 12, ty... | def sort_list_by_index_list(x: List[Any], indexes: List[int]) -> None:
x[:] = [x[i] for i in indexes] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 18; 2, function_name:fetch_all_first_values; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:session; 6, type; 6, 7; 7, identifier:Session; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:select_statement; 10, type; 10, 11; 11, ident... | def fetch_all_first_values(session: Session,
select_statement: Select) -> List[Any]:
rows = session.execute(select_statement)
try:
return [row[0] for row in rows]
except ValueError as e:
raise MultipleResultsFound(str(e)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 16; 2, function_name:atoi; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:text; 6, type; 6, 7; 7, identifier:str; 8, type; 8, 9; 9, generic_type; 9, 10; 9, 11; 10, identifier:Union; 11, type_parameter; 11, 12; 11, 14; 12, type; 12, 13; 13... | def atoi(text: str) -> Union[int, str]:
return int(text) if text.isdigit() else text |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:reducer_metro; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:metro; 6, identifier:values; 7, block; 7, 8; 7, 17; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:lookup; 11, call; 11, 12; 11, 13; 1... | def reducer_metro(self, metro, values):
lookup = CachedLookup(precision=POI_GEOHASH_PRECISION)
for i, value in enumerate(values):
type_tag, lonlat, data = value
if type_tag == 1:
lookup.insert(i, dict(
geometry=dict(type='Point', coordinates=pr... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 1, 19; 2, function_name:list_file_extensions; 3, parameters; 3, 4; 3, 8; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:path; 6, type; 6, 7; 7, identifier:str; 8, typed_default_parameter; 8, 9; 8, 10; 8, 12; 9, identifier:reportevery; 10, type; 10, 11; 11, iden... | def list_file_extensions(path: str, reportevery: int = 1) -> List[str]:
extensions = set()
count = 0
for root, dirs, files in os.walk(path):
count += 1
if count % reportevery == 0:
log.debug("Walking directory {}: {!r}", count, root)
for file in files:
filenam... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_by_dependencies; 3, parameters; 3, 4; 3, 5; 4, identifier:exts; 5, default_parameter; 5, 6; 5, 7; 6, identifier:retry; 7, None; 8, block; 8, 9; 8, 19; 8, 29; 8, 43; 8, 161; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11... | def sort_by_dependencies(exts, retry=None):
sorted_ext, features_from_sorted = [], set()
pending = [(e, 0) for e in exts]
retry = len(exts) * 100 if retry is None else retry
while pending:
ext, cnt = pending.pop(0)
if not isinstance(ext, Extractor) and not issubclass(ext, Extractor):
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_sort_layers; 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:_layers; 11, call; 11, 12; 11, 13; 12, identifier:Or... | def _sort_layers(self):
self._layers = OrderedDict(sorted(self._layers.items(), key=lambda t: t[0])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_sections; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:order; 6, block; 6, 7; 6, 19; 6, 41; 6, 67; 6, 79; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:order_lc; 10, list_comprehension; 10, 11; 10... | def sort_sections(self, order):
order_lc = [e.lower() for e in order]
sections = OrderedDict( (k,self.sections[k]) for k in order_lc if k in self.sections)
sections.update( (k,self.sections[k]) for k in self.sections.keys() if k not in order_lc)
assert len(self.sections) == len(sections)... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:split_iterable_as_iterable; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:values; 6, block; 6, 7; 6, 17; 6, 23; 6, 64; 6, 75; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:values; 10, call; 10, 11; 10, ... | def split_iterable_as_iterable(self, values):
values = iter(enumerate(values))
cache = dict()
def get_value(ti):
try:
return cache.pop(ti)
except:
while True:
i, v = next(values)
if i==ti:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:as_index; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 3, 16; 4, identifier:keys; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, attribute; 7, 8; 7, 9; 8, identifier:semantics; 9, identifier:axis_default; 10, default_parameter; 10, 11; 1... | def as_index(keys, axis=semantics.axis_default, base=False, stable=True, lex_as_struct=False):
if isinstance(keys, Index):
if type(keys) is BaseIndex and base==False:
keys = keys.keys
else:
return keys
if isinstance(keys, tuple):
if lex_as_struct:
keys... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:axis_as_object; 3, parameters; 3, 4; 3, 5; 4, identifier:arr; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, unary_operator:-; 7, 8; 8, integer:1; 9, block; 9, 10; 9, 16; 9, 34; 9, 46; 9, 59; 10, expression_statement; 10, 11; 11, assi... | def axis_as_object(arr, axis=-1):
shape = arr.shape
arr = np.ascontiguousarray(np.rollaxis(arr, axis, arr.ndim))
nbytes = arr.dtype.itemsize * shape[axis]
voidtype = np.dtype((np.void, nbytes))
return arr.view(voidtype).reshape(np.delete(shape, axis)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:rank; 3, parameters; 3, 4; 3, 5; 4, identifier:keys; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, attribute; 7, 8; 7, 9; 8, identifier:semantics; 9, identifier:axis_default; 10, block; 10, 11; 10, 19; 11, expression_statement; 11, ... | def rank(keys, axis=semantics.axis_default):
index = as_index(keys, axis)
return index.rank |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_by; 3, parameters; 3, 4; 4, identifier:function; 5, block; 5, 6; 5, 16; 5, 28; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:f; 9, call; 9, 10; 9, 11; 10, identifier:partial; 11, argument_list; 11, 12; 11, 13; 12,... | def sort_by(function):
f = partial(sorted, key=function)
f.attrs = {'descending': _descending_sort_by(function)}
return f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:in_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:values; 5, identifier:value; 6, block; 6, 7; 6, 17; 6, 27; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:index; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, ... | def in_sorted(values, value):
index = bisect.bisect_left(values, value)
if index >= len(values):
return False
return values[index] == value |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:handle_keypress; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:k; 6, block; 6, 7; 7, if_statement; 7, 8; 7, 11; 7, 24; 7, 37; 7, 50; 8, comparison_operator:==; 8, 9; 8, 10; 9, identifier:k; 10, string:"esc"; 11, block; 11, 12; 11... | def handle_keypress(self, k):
if k == "esc":
self.save_file()
raise urwid.ExitMainLoop()
elif k == "delete":
self.walker.combine_focus_with_next()
elif k == "backspace":
self.walker.combine_focus_with_prev()
elif k == "enter":
s... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:fsort; 6, block; 6, 7; 6, 9; 6, 23; 6, 31; 7, expression_statement; 7, 8; 8, string:'''
Allows to add one or more sort on specific fields. Each sort can be reversed as... | def sorted(self, fsort):
'''
Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per field level, with special field name for _score to sort by score.
'''
if not self.params:
self.params = dict()
self.params['... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_filter_sources; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:sources; 6, block; 6, 7; 6, 15; 6, 41; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:filtered; 11, identifi... | def _filter_sources(self, sources):
filtered, hosts = [], []
for source in sources:
if 'error' in source:
continue
filtered.append(source)
hosts.append(source['host_name'])
return sorted(filtered, key=lambda s:
self._hosts... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_cantons; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13; 13, c... | def get_cantons(self):
return sorted(list(set([
location.canton for location in self.get_locations().values()
]))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_municipalities; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 6, return_statement; 6, 7; 7, call; 7, 8; 7, 9; 8, identifier:sorted; 9, argument_list; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:list; 12, argument_list; 12, 13... | def get_municipalities(self):
return sorted(list(set([
location.municipality for location in self.get_locations().values()
]))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:execute; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 8; 4, identifier:self; 5, identifier:sql; 6, list_splat_pattern; 6, 7; 7, identifier:args; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 10, 13; 10, 48; 10, 58; 10, 65;... | def execute(self, sql, *args, **kwargs):
'''
Run raw SQL on the database, and receive relaxing output.
This is sort of the foundational method that most of the
others build on.
'''
try:
self.cursor.execute(sql, *args)
except self.sqlite3.InterfaceError, msg:
raise self.sqlite3.In... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:check_message; 3, parameters; 3, 4; 3, 5; 4, identifier:message; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 29; 7, 39; 7, 50; 7, 61; 7, 65; 7, 74; 7, 98; 8, if_statement; 8, 9; 8, 16; 9, call; 9, 10; 9, 13; 10, ... | def check_message(message, **kwargs):
if kwargs.pop("allow_empty", False):
if not message or message.isspace():
return []
lines = re.split(r"\r\n|\r|\n", message)
errors = _check_1st_line(lines[0], **kwargs)
err, signature_lines = _check_bullets(lines, **kwargs)
errors += err
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_getArrays; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:items; 5, identifier:attr; 6, identifier:defaultValue; 7, block; 7, 8; 7, 21; 7, 43; 7, 67; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:arrays; 11, call; ... | def _getArrays(items, attr, defaultValue):
arrays = dict([(key, []) for key in attr])
for item in items:
for key in attr:
arrays[key].append(getattr(item, key, defaultValue))
for key in [_ for _ in viewkeys(arrays)]:
arrays[key] = numpy.array(arrays[key])
return arrays |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_log_board_ports; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:ports; 6, block; 6, 7; 6, 26; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:ports; 10, call; 10, 11; 10, 12; 11, identifier:sorted; 12, ar... | def _log_board_ports(self, ports):
ports = sorted(ports, key=lambda port: (port.tile_id, port.direction))
self._logln('ports: {0}'.format(' '.join('{}({} {})'.format(p.type.value, p.tile_id, p.direction)
for p in ports))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:attr; 6, block; 6, 7; 6, 26; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:entries; 12, call; 12, 13... | def sort(self, attr):
self.entries = Sorter(self.entries, self.category, attr).sort_entries()
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_visit; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:L; 6, identifier:marked; 7, identifier:tempmarked; 8, block; 8, 9; 8, 14; 8, 24; 9, assert_statement; 9, 10; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 1... | def _visit(self, L, marked, tempmarked):
assert not self.is_pseudo
if self in tempmarked:
raise Exception('feature graph is cyclic')
if self not in marked:
tempmarked[self] = True
features = list()
if self.siblings is not None and self.is_toplevel:... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:pseudoify; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 14; 5, 25; 5, 31; 5, 49; 5, 67; 5, 74; 5, 80; 5, 88; 5, 96; 5, 104; 5, 123; 5, 134; 5, 145; 6, assert_statement; 6, 7; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9... | def pseudoify(self):
assert self.is_toplevel
assert self.is_multi
assert len(self.multi_rep.siblings) > 0
rep = self.multi_rep
start = min([s.start for s in rep.siblings + [rep]])
end = max([s.end for s in rep.siblings + [rep]])
parent = Feature(None)
pare... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:attribute_crawl; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:key; 6, block; 6, 7; 6, 13; 6, 44; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:union; 10, call; 10, 11; 10, 12; 11, identifier:set; 12, a... | def attribute_crawl(self, key):
union = set()
for feature in self:
values = feature.get_attribute(key, as_list=True)
if values is not None:
union.update(set(values))
return union |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_findSamesetProteins; 3, parameters; 3, 4; 3, 5; 4, identifier:protToPeps; 5, default_parameter; 5, 6; 5, 7; 6, identifier:proteins; 7, None; 8, block; 8, 9; 8, 21; 8, 28; 8, 53; 8, 59; 8, 87; 9, expression_statement; 9, 10; 10, assignment; 10,... | def _findSamesetProteins(protToPeps, proteins=None):
proteins = viewkeys(protToPeps) if proteins is None else proteins
equalEvidence = ddict(set)
for protein in proteins:
peptides = protToPeps[protein]
equalEvidence[tuple(sorted(peptides))].add(protein)
equalProteins = list()
for pro... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.