repo
stringlengths
7
55
path
stringlengths
4
223
url
stringlengths
87
315
code
stringlengths
75
104k
code_tokens
list
docstring
stringlengths
1
46.9k
docstring_tokens
list
language
stringclasses
1 value
partition
stringclasses
3 values
avg_line_len
float64
7.91
980
log2timeline/plaso
plaso/analysis/manager.py
https://github.com/log2timeline/plaso/blob/9c564698d2da3ffbe23607a3c54c0582ea18a6cc/plaso/analysis/manager.py#L48-L71
def GetAllPluginInformation(cls, show_all=True): """Retrieves a list of the registered analysis plugins. Args: show_all (Optional[bool]): True if all analysis plugin names should be listed. Returns: list[tuple[str, str, str]]: the name, docstring and type string of each analysis plugin in alphabetical order. """ results = [] for plugin_class in iter(cls._plugin_classes.values()): plugin_object = plugin_class() if not show_all and not plugin_class.ENABLE_IN_EXTRACTION: continue # TODO: Use a specific description variable, not the docstring. doc_string, _, _ = plugin_class.__doc__.partition('\n') type_string = cls._PLUGIN_TYPE_STRINGS.get(plugin_object.plugin_type) information_tuple = (plugin_object.plugin_name, doc_string, type_string) results.append(information_tuple) return sorted(results)
[ "def", "GetAllPluginInformation", "(", "cls", ",", "show_all", "=", "True", ")", ":", "results", "=", "[", "]", "for", "plugin_class", "in", "iter", "(", "cls", ".", "_plugin_classes", ".", "values", "(", ")", ")", ":", "plugin_object", "=", "plugin_class"...
Retrieves a list of the registered analysis plugins. Args: show_all (Optional[bool]): True if all analysis plugin names should be listed. Returns: list[tuple[str, str, str]]: the name, docstring and type string of each analysis plugin in alphabetical order.
[ "Retrieves", "a", "list", "of", "the", "registered", "analysis", "plugins", "." ]
python
train
37.166667
AustralianSynchrotron/lightflow
lightflow/models/signal.py
https://github.com/AustralianSynchrotron/lightflow/blob/dc53dbc1d961e20fb144273baca258060705c03e/lightflow/models/signal.py#L131-L138
def send(self, response): """ Send a response back to the client that issued a request. Args: response (Response): Reference to the response object that should be sent. """ self._connection.connection.set('{}:{}'.format(SIGNAL_REDIS_PREFIX, response.uid), pickle.dumps(response))
[ "def", "send", "(", "self", ",", "response", ")", ":", "self", ".", "_connection", ".", "connection", ".", "set", "(", "'{}:{}'", ".", "format", "(", "SIGNAL_REDIS_PREFIX", ",", "response", ".", "uid", ")", ",", "pickle", ".", "dumps", "(", "response", ...
Send a response back to the client that issued a request. Args: response (Response): Reference to the response object that should be sent.
[ "Send", "a", "response", "back", "to", "the", "client", "that", "issued", "a", "request", "." ]
python
train
44.625
Microsoft/nni
src/sdk/pynni/nni/networkmorphism_tuner/networkmorphism_tuner.py
https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/networkmorphism_tuner.py#L194-L211
def generate(self): """Generate the next neural architecture. Returns ------- other_info: any object Anything to be saved in the training queue together with the architecture. generated_graph: Graph An instance of Graph. """ generated_graph, new_father_id = self.bo.generate(self.descriptors) if new_father_id is None: new_father_id = 0 generated_graph = self.generators[0]( self.n_classes, self.input_shape ).generate(self.default_model_len, self.default_model_width) return new_father_id, generated_graph
[ "def", "generate", "(", "self", ")", ":", "generated_graph", ",", "new_father_id", "=", "self", ".", "bo", ".", "generate", "(", "self", ".", "descriptors", ")", "if", "new_father_id", "is", "None", ":", "new_father_id", "=", "0", "generated_graph", "=", "...
Generate the next neural architecture. Returns ------- other_info: any object Anything to be saved in the training queue together with the architecture. generated_graph: Graph An instance of Graph.
[ "Generate", "the", "next", "neural", "architecture", "." ]
python
train
35.5
allenai/allennlp
allennlp/nn/util.py
https://github.com/allenai/allennlp/blob/648a36f77db7e45784c047176074f98534c76636/allennlp/nn/util.py#L792-L829
def combine_tensors_and_multiply(combination: str, tensors: List[torch.Tensor], weights: torch.nn.Parameter) -> torch.Tensor: """ Like :func:`combine_tensors`, but does a weighted (linear) multiplication while combining. This is a separate function from ``combine_tensors`` because we try to avoid instantiating large intermediate tensors during the combination, which is possible because we know that we're going to be multiplying by a weight vector in the end. Parameters ---------- combination : ``str`` Same as in :func:`combine_tensors` tensors : ``List[torch.Tensor]`` A list of tensors to combine, where the integers in the ``combination`` are (1-indexed) positions in this list of tensors. These tensors are all expected to have either three or four dimensions, with the final dimension being an embedding. If there are four dimensions, one of them must have length 1. weights : ``torch.nn.Parameter`` A vector of weights to use for the combinations. This should have shape (combined_dim,), as calculated by :func:`get_combined_dim`. """ if len(tensors) > 9: raise ConfigurationError("Double-digit tensor lists not currently supported") combination = combination.replace('x', '1').replace('y', '2') pieces = combination.split(',') tensor_dims = [tensor.size(-1) for tensor in tensors] combination_dims = [_get_combination_dim(piece, tensor_dims) for piece in pieces] dims_so_far = 0 to_sum = [] for piece, combination_dim in zip(pieces, combination_dims): weight = weights[dims_so_far:(dims_so_far + combination_dim)] dims_so_far += combination_dim to_sum.append(_get_combination_and_multiply(piece, tensors, weight)) result = to_sum[0] for result_piece in to_sum[1:]: result = result + result_piece return result
[ "def", "combine_tensors_and_multiply", "(", "combination", ":", "str", ",", "tensors", ":", "List", "[", "torch", ".", "Tensor", "]", ",", "weights", ":", "torch", ".", "nn", ".", "Parameter", ")", "->", "torch", ".", "Tensor", ":", "if", "len", "(", "...
Like :func:`combine_tensors`, but does a weighted (linear) multiplication while combining. This is a separate function from ``combine_tensors`` because we try to avoid instantiating large intermediate tensors during the combination, which is possible because we know that we're going to be multiplying by a weight vector in the end. Parameters ---------- combination : ``str`` Same as in :func:`combine_tensors` tensors : ``List[torch.Tensor]`` A list of tensors to combine, where the integers in the ``combination`` are (1-indexed) positions in this list of tensors. These tensors are all expected to have either three or four dimensions, with the final dimension being an embedding. If there are four dimensions, one of them must have length 1. weights : ``torch.nn.Parameter`` A vector of weights to use for the combinations. This should have shape (combined_dim,), as calculated by :func:`get_combined_dim`.
[ "Like", ":", "func", ":", "combine_tensors", "but", "does", "a", "weighted", "(", "linear", ")", "multiplication", "while", "combining", ".", "This", "is", "a", "separate", "function", "from", "combine_tensors", "because", "we", "try", "to", "avoid", "instanti...
python
train
51
pybel/pybel-tools
src/pybel_tools/dict_manager.py
https://github.com/pybel/pybel-tools/blob/3491adea0ac4ee60f57275ef72f9b73da6dbfe0c/src/pybel_tools/dict_manager.py#L39-L44
def get_graphs_by_ids(self, network_ids: Iterable[int]) -> List[BELGraph]: """Get several graphs by their identifiers.""" return [ self.networks[network_id] for network_id in network_ids ]
[ "def", "get_graphs_by_ids", "(", "self", ",", "network_ids", ":", "Iterable", "[", "int", "]", ")", "->", "List", "[", "BELGraph", "]", ":", "return", "[", "self", ".", "networks", "[", "network_id", "]", "for", "network_id", "in", "network_ids", "]" ]
Get several graphs by their identifiers.
[ "Get", "several", "graphs", "by", "their", "identifiers", "." ]
python
valid
38.5
edmondburnett/twitter-text-python
ttp/ttp.py
https://github.com/edmondburnett/twitter-text-python/blob/2a23ced35bfd34c4bc4b7148afd85771e9eb8669/ttp/ttp.py#L197-L211
def _parse_users(self, match): '''Parse usernames.''' # Don't parse lists here if match.group(2) is not None: return match.group(0) mat = match.group(0) if self._include_spans: self._users.append((mat[1:], match.span(0))) else: self._users.append(mat[1:]) if self._html: return self.format_username(mat[0:1], mat[1:])
[ "def", "_parse_users", "(", "self", ",", "match", ")", ":", "# Don't parse lists here", "if", "match", ".", "group", "(", "2", ")", "is", "not", "None", ":", "return", "match", ".", "group", "(", "0", ")", "mat", "=", "match", ".", "group", "(", "0",...
Parse usernames.
[ "Parse", "usernames", "." ]
python
train
27.333333
noahbenson/neuropythy
neuropythy/vision/retinotopy.py
https://github.com/noahbenson/neuropythy/blob/b588889f6db36ddb9602ae4a72c1c0d3f41586b2/neuropythy/vision/retinotopy.py#L79-L96
def basic_retinotopy_data(hemi, retino_type): ''' basic_retinotopy_data(hemi, t) yields a numpy array of data for the given cortex object hemi and retinotopy type t; it does this by looking at the properties in hemi and picking out any combination that is commonly used to denote empirical retinotopy data. These common names are stored in _predicted_retintopy_names, in order of preference, which may be modified. The argument t should be one of 'polar_angle', 'eccentricity', 'visual_area', or 'weight'. Unlike the related functions empirical_retinotopy_data and predicted_retinotopy_data, this function calls both of these (predicted first then empirical) in the case that it does not find a valid property. ''' dat = _retinotopy_names[retino_type.lower()] val = next((hemi.prop(s) for s in six.iterkeys(hemi.properties) if s.lower() in dat), None) if val is None and retino_type.lower() != 'weight': val = predicted_retinotopy_data(hemi, retino_type) if val is None and retino_type.lower() != 'visual_area': val = empirical_retinotopy_data(hemi, retino_type) return val
[ "def", "basic_retinotopy_data", "(", "hemi", ",", "retino_type", ")", ":", "dat", "=", "_retinotopy_names", "[", "retino_type", ".", "lower", "(", ")", "]", "val", "=", "next", "(", "(", "hemi", ".", "prop", "(", "s", ")", "for", "s", "in", "six", "....
basic_retinotopy_data(hemi, t) yields a numpy array of data for the given cortex object hemi and retinotopy type t; it does this by looking at the properties in hemi and picking out any combination that is commonly used to denote empirical retinotopy data. These common names are stored in _predicted_retintopy_names, in order of preference, which may be modified. The argument t should be one of 'polar_angle', 'eccentricity', 'visual_area', or 'weight'. Unlike the related functions empirical_retinotopy_data and predicted_retinotopy_data, this function calls both of these (predicted first then empirical) in the case that it does not find a valid property.
[ "basic_retinotopy_data", "(", "hemi", "t", ")", "yields", "a", "numpy", "array", "of", "data", "for", "the", "given", "cortex", "object", "hemi", "and", "retinotopy", "type", "t", ";", "it", "does", "this", "by", "looking", "at", "the", "properties", "in",...
python
train
62.888889
NerdWalletOSS/savage
src/savage/api/data.py
https://github.com/NerdWalletOSS/savage/blob/54f64ac1c912528710365107952967d31d56e60d/src/savage/api/data.py#L147-L163
def _get_conditions(pk_conds, and_conds=None): """If and_conds = [a1, a2, ..., an] and pk_conds = [[b11, b12, ..., b1m], ... [bk1, ..., bkm]], this function will return the mysql condition clause: a1 & a2 & ... an & ((b11 and ... b1m) or ... (b11 and ... b1m)) :param pk_conds: a list of list of primary key constraints returned by _get_conditions_list :param and_conds: additional and conditions to be placed on the query """ if and_conds is None: and_conds = [] if len(and_conds) == 0 and len(pk_conds) == 0: return sa.and_() condition1 = sa.and_(*and_conds) condition2 = sa.or_(*[sa.and_(*cond) for cond in pk_conds]) return sa.and_(condition1, condition2)
[ "def", "_get_conditions", "(", "pk_conds", ",", "and_conds", "=", "None", ")", ":", "if", "and_conds", "is", "None", ":", "and_conds", "=", "[", "]", "if", "len", "(", "and_conds", ")", "==", "0", "and", "len", "(", "pk_conds", ")", "==", "0", ":", ...
If and_conds = [a1, a2, ..., an] and pk_conds = [[b11, b12, ..., b1m], ... [bk1, ..., bkm]], this function will return the mysql condition clause: a1 & a2 & ... an & ((b11 and ... b1m) or ... (b11 and ... b1m)) :param pk_conds: a list of list of primary key constraints returned by _get_conditions_list :param and_conds: additional and conditions to be placed on the query
[ "If", "and_conds", "=", "[", "a1", "a2", "...", "an", "]", "and", "pk_conds", "=", "[[", "b11", "b12", "...", "b1m", "]", "...", "[", "bk1", "...", "bkm", "]]", "this", "function", "will", "return", "the", "mysql", "condition", "clause", ":", "a1", ...
python
train
41.764706
PSPC-SPAC-buyandsell/von_anchor
von_anchor/nodepool/protocol.py
https://github.com/PSPC-SPAC-buyandsell/von_anchor/blob/78ac1de67be42a676274f4bf71fe12f66e72f309/von_anchor/nodepool/protocol.py#L110-L124
def txn2data(self, txn: dict) -> str: """ Given ledger transaction, return its data json. :param txn: transaction as dict :return: transaction data json """ rv_json = json.dumps({}) if self == Protocol.V_13: rv_json = json.dumps(txn['result'].get('data', {})) else: rv_json = json.dumps((txn['result'].get('data', {}) or {}).get('txn', {})) # "data": null for no such txn return rv_json
[ "def", "txn2data", "(", "self", ",", "txn", ":", "dict", ")", "->", "str", ":", "rv_json", "=", "json", ".", "dumps", "(", "{", "}", ")", "if", "self", "==", "Protocol", ".", "V_13", ":", "rv_json", "=", "json", ".", "dumps", "(", "txn", "[", "...
Given ledger transaction, return its data json. :param txn: transaction as dict :return: transaction data json
[ "Given", "ledger", "transaction", "return", "its", "data", "json", "." ]
python
train
31.466667
PBR/MQ2
MQ2/plugins/xls_plugin.py
https://github.com/PBR/MQ2/blob/6d84dea47e6751333004743f588f03158e35c28d/MQ2/plugins/xls_plugin.py#L66-L87
def read_excel_file(inputfile, sheet_name): """ Return a matrix containing all the information present in the excel sheet of the specified excel document. :arg inputfile: excel document to read :arg sheetname: the name of the excel sheet to return """ workbook = xlrd.open_workbook(inputfile) output = [] found = False for sheet in workbook.sheets(): if sheet.name == sheet_name: found = True for row in range(sheet.nrows): values = [] for col in range(sheet.ncols): values.append(sheet.cell(row, col).value) output.append(values) if not found: # pragma: no cover raise MQ2Exception('Invalid session identifier provided') return output
[ "def", "read_excel_file", "(", "inputfile", ",", "sheet_name", ")", ":", "workbook", "=", "xlrd", ".", "open_workbook", "(", "inputfile", ")", "output", "=", "[", "]", "found", "=", "False", "for", "sheet", "in", "workbook", ".", "sheets", "(", ")", ":",...
Return a matrix containing all the information present in the excel sheet of the specified excel document. :arg inputfile: excel document to read :arg sheetname: the name of the excel sheet to return
[ "Return", "a", "matrix", "containing", "all", "the", "information", "present", "in", "the", "excel", "sheet", "of", "the", "specified", "excel", "document", "." ]
python
train
34.954545
Azure/azure-cli-extensions
src/alias/azext_alias/_validators.py
https://github.com/Azure/azure-cli-extensions/blob/3d4854205b0f0d882f688cfa12383d14506c2e35/src/alias/azext_alias/_validators.py#L209-L239
def _validate_positional_arguments(args): """ To validate the positional argument feature - https://github.com/Azure/azure-cli/pull/6055. Assuming that unknown commands are positional arguments immediately led by words that only appear at the end of the commands Slight modification of https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/commands/__init__.py#L356-L373 Args: args: The arguments that the user inputs in the terminal. Returns: Rudimentary parsed arguments. """ nouns = [] for arg in args: if not arg.startswith('-') or not arg.startswith('{{'): nouns.append(arg) else: break while nouns: search = ' '.join(nouns) # Since the command name may be immediately followed by a positional arg, strip those off if not next((x for x in azext_alias.cached_reserved_commands if x.endswith(search)), False): del nouns[-1] else: return raise CLIError(INVALID_ALIAS_COMMAND_ERROR.format(' '.join(args)))
[ "def", "_validate_positional_arguments", "(", "args", ")", ":", "nouns", "=", "[", "]", "for", "arg", "in", "args", ":", "if", "not", "arg", ".", "startswith", "(", "'-'", ")", "or", "not", "arg", ".", "startswith", "(", "'{{'", ")", ":", "nouns", "....
To validate the positional argument feature - https://github.com/Azure/azure-cli/pull/6055. Assuming that unknown commands are positional arguments immediately led by words that only appear at the end of the commands Slight modification of https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/commands/__init__.py#L356-L373 Args: args: The arguments that the user inputs in the terminal. Returns: Rudimentary parsed arguments.
[ "To", "validate", "the", "positional", "argument", "feature", "-", "https", ":", "//", "github", ".", "com", "/", "Azure", "/", "azure", "-", "cli", "/", "pull", "/", "6055", ".", "Assuming", "that", "unknown", "commands", "are", "positional", "arguments",...
python
train
34.483871
rfosterslo/wagtailplus
wagtailplus/wagtailrelations/signals/handlers.py
https://github.com/rfosterslo/wagtailplus/blob/22cac857175d8a6f77e470751831c14a92ccd768/wagtailplus/wagtailrelations/signals/handlers.py#L11-L28
def create_entry_tag(sender, instance, created, **kwargs): """ Creates EntryTag for Entry corresponding to specified ItemBase instance. :param sender: the sending ItemBase class. :param instance: the ItemBase instance. """ from ..models import ( Entry, EntryTag ) entry = Entry.objects.get_for_model(instance.content_object)[0] tag = instance.tag if not EntryTag.objects.filter(tag=tag, entry=entry).exists(): EntryTag.objects.create(tag=tag, entry=entry)
[ "def", "create_entry_tag", "(", "sender", ",", "instance", ",", "created", ",", "*", "*", "kwargs", ")", ":", "from", ".", ".", "models", "import", "(", "Entry", ",", "EntryTag", ")", "entry", "=", "Entry", ".", "objects", ".", "get_for_model", "(", "i...
Creates EntryTag for Entry corresponding to specified ItemBase instance. :param sender: the sending ItemBase class. :param instance: the ItemBase instance.
[ "Creates", "EntryTag", "for", "Entry", "corresponding", "to", "specified", "ItemBase", "instance", "." ]
python
train
28.611111
pyblish/pyblish-qml
pyblish_qml/ipc/formatting.py
https://github.com/pyblish/pyblish-qml/blob/6095d18b2ec0afd0409a9b1a17e53b0658887283/pyblish_qml/ipc/formatting.py#L27-L50
def format_result(result): """Serialise Result""" instance = None error = None if result["instance"] is not None: instance = format_instance(result["instance"]) if result["error"] is not None: error = format_error(result["error"]) result = { "success": result["success"], "plugin": format_plugin(result["plugin"]), "instance": instance, "error": error, "records": format_records(result["records"]), "duration": result["duration"] } if os.getenv("PYBLISH_SAFE"): schema.validate(result, "result") return result
[ "def", "format_result", "(", "result", ")", ":", "instance", "=", "None", "error", "=", "None", "if", "result", "[", "\"instance\"", "]", "is", "not", "None", ":", "instance", "=", "format_instance", "(", "result", "[", "\"instance\"", "]", ")", "if", "r...
Serialise Result
[ "Serialise", "Result" ]
python
train
24.958333
gisgroup/statbank-python
statbank/request.py
https://github.com/gisgroup/statbank-python/blob/3678820d8da35f225d706ea5096c1f08bf0b9c68/statbank/request.py#L50-L59
def csv(self): """Parse raw response as csv and return row object list. """ lines = self._parsecsv(self.raw) # set keys from header line (first line) keys = next(lines) for line in lines: yield dict(zip(keys, line))
[ "def", "csv", "(", "self", ")", ":", "lines", "=", "self", ".", "_parsecsv", "(", "self", ".", "raw", ")", "# set keys from header line (first line)", "keys", "=", "next", "(", "lines", ")", "for", "line", "in", "lines", ":", "yield", "dict", "(", "zip",...
Parse raw response as csv and return row object list.
[ "Parse", "raw", "response", "as", "csv", "and", "return", "row", "object", "list", "." ]
python
train
26.8
HiPERCAM/hcam_widgets
hcam_widgets/misc.py
https://github.com/HiPERCAM/hcam_widgets/blob/7219f0d96dd3a8ebe3139c7f542a72c02d02fce8/hcam_widgets/misc.py#L535-L554
def getFrameNumber(g): """ Polls the data server to find the current frame number. Throws an exceotion if it cannot determine it. """ if not g.cpars['hcam_server_on']: raise DriverError('getRunNumber error: servers are not active') url = g.cpars['hipercam_server'] + 'status/DET.FRAM2.NO' response = urllib.request.urlopen(url, timeout=2) rs = ReadServer(response.read(), status_msg=False) try: msg = rs.msg except: raise DriverError('getFrameNumber error: no message found') try: frame_no = int(msg.split()[1]) except: raise DriverError('getFrameNumber error: invalid msg ' + msg) return frame_no
[ "def", "getFrameNumber", "(", "g", ")", ":", "if", "not", "g", ".", "cpars", "[", "'hcam_server_on'", "]", ":", "raise", "DriverError", "(", "'getRunNumber error: servers are not active'", ")", "url", "=", "g", ".", "cpars", "[", "'hipercam_server'", "]", "+",...
Polls the data server to find the current frame number. Throws an exceotion if it cannot determine it.
[ "Polls", "the", "data", "server", "to", "find", "the", "current", "frame", "number", "." ]
python
train
33.55
awslabs/sockeye
sockeye/utils.py
https://github.com/awslabs/sockeye/blob/5d64a1ee1ef3cbba17c6d1d94bc061020c43f6ab/sockeye/utils.py#L940-L951
def cast_conditionally(data: mx.sym.Symbol, dtype: str) -> mx.sym.Symbol: """ Workaround until no-op cast will be fixed in MXNet codebase. Creates cast symbol only if dtype is different from default one, i.e. float32. :param data: Input symbol. :param dtype: Target dtype. :return: Cast symbol or just data symbol. """ if dtype != C.DTYPE_FP32: return mx.sym.cast(data=data, dtype=dtype) return data
[ "def", "cast_conditionally", "(", "data", ":", "mx", ".", "sym", ".", "Symbol", ",", "dtype", ":", "str", ")", "->", "mx", ".", "sym", ".", "Symbol", ":", "if", "dtype", "!=", "C", ".", "DTYPE_FP32", ":", "return", "mx", ".", "sym", ".", "cast", ...
Workaround until no-op cast will be fixed in MXNet codebase. Creates cast symbol only if dtype is different from default one, i.e. float32. :param data: Input symbol. :param dtype: Target dtype. :return: Cast symbol or just data symbol.
[ "Workaround", "until", "no", "-", "op", "cast", "will", "be", "fixed", "in", "MXNet", "codebase", ".", "Creates", "cast", "symbol", "only", "if", "dtype", "is", "different", "from", "default", "one", "i", ".", "e", ".", "float32", "." ]
python
train
36.083333
apple/turicreate
src/external/coremltools_wrap/coremltools/coremltools/converters/sklearn/_tree_ensemble.py
https://github.com/apple/turicreate/blob/74514c3f99e25b46f22c6e02977fe3da69221c2e/src/external/coremltools_wrap/coremltools/coremltools/converters/sklearn/_tree_ensemble.py#L16-L42
def _get_value(scikit_value, mode = 'regressor', scaling = 1.0, n_classes = 2, tree_index = 0): """ Get the right value from the scikit-tree """ # Regression if mode == 'regressor': return scikit_value[0] * scaling # Binary classification if n_classes == 2: # Decision tree if len(scikit_value[0]) != 1: value = scikit_value[0][1] * scaling / scikit_value[0].sum() # boosted tree else: value = scikit_value[0][0] * scaling if value == 0.5: value = value - 1e-7 # Multiclass classification else: # Decision tree if len(scikit_value[0]) != 1: value = scikit_value[0] / scikit_value[0].sum() # boosted tree else: value = {tree_index: scikit_value[0] * scaling} return value
[ "def", "_get_value", "(", "scikit_value", ",", "mode", "=", "'regressor'", ",", "scaling", "=", "1.0", ",", "n_classes", "=", "2", ",", "tree_index", "=", "0", ")", ":", "# Regression", "if", "mode", "==", "'regressor'", ":", "return", "scikit_value", "[",...
Get the right value from the scikit-tree
[ "Get", "the", "right", "value", "from", "the", "scikit", "-", "tree" ]
python
train
30.444444
ffalcinelli/pydivert
pydivert/packet/__init__.py
https://github.com/ffalcinelli/pydivert/blob/f75eba4126c527b5a43ace0a49369c7479cf5ee8/pydivert/packet/__init__.py#L186-L193
def icmpv6(self): """ - An ICMPv6Header instance, if the packet is valid ICMPv6. - None, otherwise. """ ipproto, proto_start = self.protocol if ipproto == Protocol.ICMPV6: return ICMPv6Header(self, proto_start)
[ "def", "icmpv6", "(", "self", ")", ":", "ipproto", ",", "proto_start", "=", "self", ".", "protocol", "if", "ipproto", "==", "Protocol", ".", "ICMPV6", ":", "return", "ICMPv6Header", "(", "self", ",", "proto_start", ")" ]
- An ICMPv6Header instance, if the packet is valid ICMPv6. - None, otherwise.
[ "-", "An", "ICMPv6Header", "instance", "if", "the", "packet", "is", "valid", "ICMPv6", ".", "-", "None", "otherwise", "." ]
python
train
32.875
aestrivex/bctpy
bct/utils/visualization.py
https://github.com/aestrivex/bctpy/blob/4cb0e759eb4a038750b07e23bd29958c400684b8/bct/utils/visualization.py#L602-L742
def reorder_mod(A, ci): ''' This function reorders the connectivity matrix by modular structure and may hence be useful in visualization of modular structure. Parameters ---------- A : NxN np.ndarray binary/weighted connectivity matrix ci : Nx1 np.ndarray module affiliation vector Returns ------- On : Nx1 np.ndarray new node order Ar : NxN np.ndarray reordered connectivity matrix ''' # TODO update function with 2015 changes from scipy import stats _, max_module_size = stats.mode(ci) u, ci = np.unique(ci, return_inverse=True) # make consecutive n = np.size(ci) # number of nodes m = np.size(u) # number of modules nm = np.zeros((m,)) # number of nodes in modules knm = np.zeros((n, m)) # degree to other modules for i in range(m): nm[i] = np.size(np.where(ci == i)) knm[:, i] = np.sum(A[:, ci == i], axis=1) am = np.zeros((m, m)) # relative intermodular connectivity for i in range(m): am[i, :] = np.sum(knm[ci == i, :], axis=0) am /= np.outer(nm, nm) # 1. Arrange densely connected modules together # symmetrized intermodular connectivity i, j = np.where(np.tril(am, -1) + 1) s = (np.tril(am, -1) + 1)[i, j] ord = np.argsort(s)[::-1] # sort by high relative connectivity i = i[ord] j = j[ord] i += 1 j += 1 # fix off by 1 error so np.where doesnt om = np.array((i[0], j[0])) # catch module 0 i[0] = 0 j[0] = 0 while len(om) < m: # while not all modules ordered ui, = np.where(np.logical_and( i, np.logical_or(j == om[0], j == om[-1]))) uj, = np.where(np.logical_and( j, np.logical_or(i == om[0], i == om[-1]))) if np.size(ui): ui = ui[0] if np.size(uj): uj = uj[0] if ui == uj: i[ui] = 0 j[uj] = 0 continue if not np.size(ui): ui = np.inf if not np.size(uj): uj = np.inf if ui < uj: old = j[ui] new = i[ui] if uj < ui: old = i[uj] new = j[uj] if old == om[0]: om = np.append((new,), om) if old == om[-1]: om = np.append(om, (new,)) i[i == old] = 0 j[j == old] = 0 print(om) # 2. Reorder nodes within modules on = np.zeros((n,), dtype=int) for y, x in enumerate(om): ind, = np.where(ci == x - 1) # indices pos, = np.where(om == x) # position # NOT DONE! OE NOES mod_imp = np.array((om, np.sign(np.arange(m) - pos), np.abs(np.arange(m) - pos), am[x - 1, om - 1])).T print(np.shape((mod_imp[:, 3][::-1], mod_imp[:, 2]))) ix = np.lexsort((mod_imp[:, 3][::-1], mod_imp[:, 2])) mod_imp = mod_imp[ix] # at this point mod_imp agrees with the matlab version signs = mod_imp[:, 1] mod_imp = np.abs(mod_imp[:, 0] * mod_imp[:, 1]) mod_imp = np.append(mod_imp[1:], x) mod_imp = np.array(mod_imp - 1, dtype=int) print(mod_imp, signs) # at this point mod_imp is the absolute value of that in the matlab # version. this limitation comes from sortrows ability to deal with # negative indices, which we would have to do manually. # instead, i punt on its importance; i only bother to order by the # principal dimension. some within-module orderings # may potentially be a little bit out of order. # ksmi=knm[ind,:].T[mod_imp[::-1]] # reverse mod_imp to sort by the first column first and so on # print ksmi # for i,sin in enumerate(signs): # if sin==-1: # ksmi[i,:]=ksmi[i,:][::-1] # print ksmi # print np.shape(ksmi) # ^ this is unworkable and wrong, lexsort alone cannot handle the # negative indices problem of sortrows. you would pretty much need # to rewrite sortrows to do lexsort plus negative indices; the algorithm # cant be further simplified. ord = np.lexsort(knm[np.ix_(ind, mod_imp[::-1])]) # ord=np.lexsort(knm[ind,:].T[mod_imp[::-1]]) if signs[mod_imp[0]] == -1: ord = ord[::-1] # reverse just the principal level and punt on the other levels. # this will basically be fine for most purposes and probably won't # ever show a difference for weighted graphs. on[ind[ord]] = y * int(max_module_size) + \ np.arange(nm[x - 1], dtype=int) on = np.argsort(on) ar = A[np.ix_(on, on)] return on, ar
[ "def", "reorder_mod", "(", "A", ",", "ci", ")", ":", "# TODO update function with 2015 changes", "from", "scipy", "import", "stats", "_", ",", "max_module_size", "=", "stats", ".", "mode", "(", "ci", ")", "u", ",", "ci", "=", "np", ".", "unique", "(", "c...
This function reorders the connectivity matrix by modular structure and may hence be useful in visualization of modular structure. Parameters ---------- A : NxN np.ndarray binary/weighted connectivity matrix ci : Nx1 np.ndarray module affiliation vector Returns ------- On : Nx1 np.ndarray new node order Ar : NxN np.ndarray reordered connectivity matrix
[ "This", "function", "reorders", "the", "connectivity", "matrix", "by", "modular", "structure", "and", "may", "hence", "be", "useful", "in", "visualization", "of", "modular", "structure", "." ]
python
train
32.425532
SoCo/SoCo
soco/groups.py
https://github.com/SoCo/SoCo/blob/671937e07d7973b78c0cbee153d4f3ad68ec48c6/soco/groups.py#L106-L116
def short_label(self): """str: A short description of the group. >>> device.group.short_label 'Kitchen + 1' """ group_names = sorted([m.player_name for m in self.members]) group_label = group_names[0] if len(group_names) > 1: group_label += " + {}".format(len(group_names) - 1) return group_label
[ "def", "short_label", "(", "self", ")", ":", "group_names", "=", "sorted", "(", "[", "m", ".", "player_name", "for", "m", "in", "self", ".", "members", "]", ")", "group_label", "=", "group_names", "[", "0", "]", "if", "len", "(", "group_names", ")", ...
str: A short description of the group. >>> device.group.short_label 'Kitchen + 1'
[ "str", ":", "A", "short", "description", "of", "the", "group", "." ]
python
train
33
peopledoc/workalendar
workalendar/core.py
https://github.com/peopledoc/workalendar/blob/d044d5dfc1709ec388db34dab583dd554cc66c4e/workalendar/core.py#L105-L107
def holidays_set(self, year=None): "Return a quick date index (set)" return set([day for day, label in self.holidays(year)])
[ "def", "holidays_set", "(", "self", ",", "year", "=", "None", ")", ":", "return", "set", "(", "[", "day", "for", "day", ",", "label", "in", "self", ".", "holidays", "(", "year", ")", "]", ")" ]
Return a quick date index (set)
[ "Return", "a", "quick", "date", "index", "(", "set", ")" ]
python
train
46
chop-dbhi/varify-data-warehouse
vdw/samples/migrations/0003_remap_names_and_labels.py
https://github.com/chop-dbhi/varify-data-warehouse/blob/1600ee1bc5fae6c68fd03b23624467298570cca8/vdw/samples/migrations/0003_remap_names_and_labels.py#L10-L14
def forwards(self, orm): "Write your forwards methods here." orm.Project.objects.update(label=F('name')) orm.Cohort.objects.update(label=F('name')) orm.Sample.objects.update(name=F('label'))
[ "def", "forwards", "(", "self", ",", "orm", ")", ":", "orm", ".", "Project", ".", "objects", ".", "update", "(", "label", "=", "F", "(", "'name'", ")", ")", "orm", ".", "Cohort", ".", "objects", ".", "update", "(", "label", "=", "F", "(", "'name'...
Write your forwards methods here.
[ "Write", "your", "forwards", "methods", "here", "." ]
python
train
43.6
gmr/tinman
tinman/serializers.py
https://github.com/gmr/tinman/blob/98f0acd15a228d752caa1864cdf02aaa3d492a9f/tinman/serializers.py#L92-L99
def serialize(self, data): """Return the data as serialized string. :param dict data: The data to serialize :rtype: str """ return json.dumps(self._serialize_datetime(data), ensure_ascii=False)
[ "def", "serialize", "(", "self", ",", "data", ")", ":", "return", "json", ".", "dumps", "(", "self", ".", "_serialize_datetime", "(", "data", ")", ",", "ensure_ascii", "=", "False", ")" ]
Return the data as serialized string. :param dict data: The data to serialize :rtype: str
[ "Return", "the", "data", "as", "serialized", "string", "." ]
python
train
28.5
bitesofcode/projexui
projexui/widgets/xorbrecordbox.py
https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbrecordbox.py#L951-L967
def setVisible(self, state): """ Sets the visibility for this record box. :param state | <bool> """ super(XOrbRecordBox, self).setVisible(state) if state and not self._loaded: if self.autoInitialize(): table = self.tableType() if not table: return self.setRecords(table.select(where=self.query())) else: self.initialized.emit()
[ "def", "setVisible", "(", "self", ",", "state", ")", ":", "super", "(", "XOrbRecordBox", ",", "self", ")", ".", "setVisible", "(", "state", ")", "if", "state", "and", "not", "self", ".", "_loaded", ":", "if", "self", ".", "autoInitialize", "(", ")", ...
Sets the visibility for this record box. :param state | <bool>
[ "Sets", "the", "visibility", "for", "this", "record", "box", ".", ":", "param", "state", "|", "<bool", ">" ]
python
train
30.764706
materialsproject/pymatgen
pymatgen/core/lattice.py
https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/core/lattice.py#L779-L926
def get_niggli_reduced_lattice(self, tol: float = 1e-5) -> "Lattice": """ Get the Niggli reduced lattice using the numerically stable algo proposed by R. W. Grosse-Kunstleve, N. K. Sauter, & P. D. Adams, Acta Crystallographica Section A Foundations of Crystallography, 2003, 60(1), 1-6. doi:10.1107/S010876730302186X Args: tol (float): The numerical tolerance. The default of 1e-5 should result in stable behavior for most cases. Returns: Niggli-reduced lattice. """ # lll reduction is more stable for skewed cells matrix = self.lll_matrix a = matrix[0] b = matrix[1] c = matrix[2] e = tol * self.volume ** (1 / 3) # Define metric tensor G = [ [dot(a, a), dot(a, b), dot(a, c)], [dot(a, b), dot(b, b), dot(b, c)], [dot(a, c), dot(b, c), dot(c, c)], ] G = np.array(G) # This sets an upper limit on the number of iterations. for count in range(100): # The steps are labelled as Ax as per the labelling scheme in the # paper. (A, B, C, E, N, Y) = ( G[0, 0], G[1, 1], G[2, 2], 2 * G[1, 2], 2 * G[0, 2], 2 * G[0, 1], ) if A > B + e or (abs(A - B) < e and abs(E) > abs(N) + e): # A1 M = [[0, -1, 0], [-1, 0, 0], [0, 0, -1]] G = dot(transpose(M), dot(G, M)) if (B > C + e) or (abs(B - C) < e and abs(N) > abs(Y) + e): # A2 M = [[-1, 0, 0], [0, 0, -1], [0, -1, 0]] G = dot(transpose(M), dot(G, M)) continue l = 0 if abs(E) < e else E / abs(E) m = 0 if abs(N) < e else N / abs(N) n = 0 if abs(Y) < e else Y / abs(Y) if l * m * n == 1: # A3 i = -1 if l == -1 else 1 j = -1 if m == -1 else 1 k = -1 if n == -1 else 1 M = [[i, 0, 0], [0, j, 0], [0, 0, k]] G = dot(transpose(M), dot(G, M)) elif l * m * n == 0 or l * m * n == -1: # A4 i = -1 if l == 1 else 1 j = -1 if m == 1 else 1 k = -1 if n == 1 else 1 if i * j * k == -1: if n == 0: k = -1 elif m == 0: j = -1 elif l == 0: i = -1 M = [[i, 0, 0], [0, j, 0], [0, 0, k]] G = dot(transpose(M), dot(G, M)) (A, B, C, E, N, Y) = ( G[0, 0], G[1, 1], G[2, 2], 2 * G[1, 2], 2 * G[0, 2], 2 * G[0, 1], ) # A5 if ( abs(E) > B + e or (abs(E - B) < e and 2 * N < Y - e) or (abs(E + B) < e and Y < -e) ): M = [[1, 0, 0], [0, 1, -E / abs(E)], [0, 0, 1]] G = dot(transpose(M), dot(G, M)) continue # A6 if ( abs(N) > A + e or (abs(A - N) < e and 2 * E < Y - e) or (abs(A + N) < e and Y < -e) ): M = [[1, 0, -N / abs(N)], [0, 1, 0], [0, 0, 1]] G = dot(transpose(M), dot(G, M)) continue # A7 if ( abs(Y) > A + e or (abs(A - Y) < e and 2 * E < N - e) or (abs(A + Y) < e and N < -e) ): M = [[1, -Y / abs(Y), 0], [0, 1, 0], [0, 0, 1]] G = dot(transpose(M), dot(G, M)) continue # A8 if E + N + Y + A + B < -e or (abs(E + N + Y + A + B) < e < Y + (A + N) * 2): M = [[1, 0, 1], [0, 1, 1], [0, 0, 1]] G = dot(transpose(M), dot(G, M)) continue break A = G[0, 0] B = G[1, 1] C = G[2, 2] E = 2 * G[1, 2] N = 2 * G[0, 2] Y = 2 * G[0, 1] a = math.sqrt(A) b = math.sqrt(B) c = math.sqrt(C) alpha = math.acos(E / 2 / b / c) / math.pi * 180 beta = math.acos(N / 2 / a / c) / math.pi * 180 gamma = math.acos(Y / 2 / a / b) / math.pi * 180 latt = Lattice.from_parameters(a, b, c, alpha, beta, gamma) mapped = self.find_mapping(latt, e, skip_rotation_matrix=True) if mapped is not None: if np.linalg.det(mapped[0].matrix) > 0: return mapped[0] else: return Lattice(-mapped[0].matrix) raise ValueError("can't find niggli")
[ "def", "get_niggli_reduced_lattice", "(", "self", ",", "tol", ":", "float", "=", "1e-5", ")", "->", "\"Lattice\"", ":", "# lll reduction is more stable for skewed cells", "matrix", "=", "self", ".", "lll_matrix", "a", "=", "matrix", "[", "0", "]", "b", "=", "m...
Get the Niggli reduced lattice using the numerically stable algo proposed by R. W. Grosse-Kunstleve, N. K. Sauter, & P. D. Adams, Acta Crystallographica Section A Foundations of Crystallography, 2003, 60(1), 1-6. doi:10.1107/S010876730302186X Args: tol (float): The numerical tolerance. The default of 1e-5 should result in stable behavior for most cases. Returns: Niggli-reduced lattice.
[ "Get", "the", "Niggli", "reduced", "lattice", "using", "the", "numerically", "stable", "algo", "proposed", "by", "R", ".", "W", ".", "Grosse", "-", "Kunstleve", "N", ".", "K", ".", "Sauter", "&", "P", ".", "D", ".", "Adams", "Acta", "Crystallographica", ...
python
train
32.391892
venthur/python-debianbts
debianbts/debianbts.py
https://github.com/venthur/python-debianbts/blob/72cf11ae3458a8544142e9f365aaafe25634dd4f/debianbts/debianbts.py#L511-L521
def _soap_client_call(method_name, *args): """Wrapper to call SoapClient method""" # a new client instance is built for threading issues soap_client = _build_soap_client() soap_args = _convert_soap_method_args(*args) # if pysimplesoap version requires it, apply a workaround for # https://github.com/pysimplesoap/pysimplesoap/issues/31 if PYSIMPLESOAP_1_16_2: return getattr(soap_client, method_name)(*soap_args) else: return getattr(soap_client, method_name)(soap_client, *soap_args)
[ "def", "_soap_client_call", "(", "method_name", ",", "*", "args", ")", ":", "# a new client instance is built for threading issues", "soap_client", "=", "_build_soap_client", "(", ")", "soap_args", "=", "_convert_soap_method_args", "(", "*", "args", ")", "# if pysimplesoa...
Wrapper to call SoapClient method
[ "Wrapper", "to", "call", "SoapClient", "method" ]
python
train
47.454545
python-openxml/python-docx
docx/table.py
https://github.com/python-openxml/python-docx/blob/6756f6cd145511d3eb6d1d188beea391b1ddfd53/docx/table.py#L99-L106
def row_cells(self, row_idx): """ Sequence of cells in the row at *row_idx* in this table. """ column_count = self._column_count start = row_idx * column_count end = start + column_count return self._cells[start:end]
[ "def", "row_cells", "(", "self", ",", "row_idx", ")", ":", "column_count", "=", "self", ".", "_column_count", "start", "=", "row_idx", "*", "column_count", "end", "=", "start", "+", "column_count", "return", "self", ".", "_cells", "[", "start", ":", "end",...
Sequence of cells in the row at *row_idx* in this table.
[ "Sequence", "of", "cells", "in", "the", "row", "at", "*", "row_idx", "*", "in", "this", "table", "." ]
python
train
33.125
Jajcus/pyxmpp2
pyxmpp2/iq.py
https://github.com/Jajcus/pyxmpp2/blob/14a40a3950910a9cd008b55f0d8905aa0186ce18/pyxmpp2/iq.py#L131-L143
def make_result_response(self): """Create result response for the a "get" or "set" iq stanza. :return: new `Iq` object with the same "id" as self, "from" and "to" attributes replaced and type="result". :returntype: `Iq`""" if self.stanza_type not in ("set", "get"): raise ValueError("Results may only be generated for" " 'set' or 'get' iq") stanza = Iq(stanza_type = "result", from_jid = self.to_jid, to_jid = self.from_jid, stanza_id = self.stanza_id) return stanza
[ "def", "make_result_response", "(", "self", ")", ":", "if", "self", ".", "stanza_type", "not", "in", "(", "\"set\"", ",", "\"get\"", ")", ":", "raise", "ValueError", "(", "\"Results may only be generated for\"", "\" 'set' or 'get' iq\"", ")", "stanza", "=", "Iq", ...
Create result response for the a "get" or "set" iq stanza. :return: new `Iq` object with the same "id" as self, "from" and "to" attributes replaced and type="result". :returntype: `Iq`
[ "Create", "result", "response", "for", "the", "a", "get", "or", "set", "iq", "stanza", "." ]
python
valid
46.769231
Gandi/gandi.cli
gandi/cli/modules/hostedcert.py
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/hostedcert.py#L44-L59
def infos(cls, fqdn): """ Display information about hosted certificates for a fqdn. """ if isinstance(fqdn, (list, tuple)): ids = [] for fqd_ in fqdn: ids.extend(cls.infos(fqd_)) return ids ids = cls.usable_id(fqdn) if not ids: return [] if not isinstance(ids, (list, tuple)): ids = [ids] return [cls.info(id_) for id_ in ids]
[ "def", "infos", "(", "cls", ",", "fqdn", ")", ":", "if", "isinstance", "(", "fqdn", ",", "(", "list", ",", "tuple", ")", ")", ":", "ids", "=", "[", "]", "for", "fqd_", "in", "fqdn", ":", "ids", ".", "extend", "(", "cls", ".", "infos", "(", "f...
Display information about hosted certificates for a fqdn.
[ "Display", "information", "about", "hosted", "certificates", "for", "a", "fqdn", "." ]
python
train
27.375
wmayner/pyphi
pyphi/memory.py
https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/memory.py#L18-L39
def cache(ignore=None): """Decorator for memoizing a function using either the filesystem or a database. """ def decorator(func): # Initialize both cached versions joblib_cached = constants.joblib_memory.cache(func, ignore=ignore) db_cached = DbMemoizedFunc(func, ignore) @functools.wraps(func) def wrapper(*args, **kwargs): """Dynamically choose the cache at call-time, not at import.""" if func.__name__ == '_sia' and not config.CACHE_SIAS: f = func elif config.CACHING_BACKEND == 'fs': f = joblib_cached elif config.CACHING_BACKEND == 'db': f = db_cached return f(*args, **kwargs) return wrapper return decorator
[ "def", "cache", "(", "ignore", "=", "None", ")", ":", "def", "decorator", "(", "func", ")", ":", "# Initialize both cached versions", "joblib_cached", "=", "constants", ".", "joblib_memory", ".", "cache", "(", "func", ",", "ignore", "=", "ignore", ")", "db_c...
Decorator for memoizing a function using either the filesystem or a database.
[ "Decorator", "for", "memoizing", "a", "function", "using", "either", "the", "filesystem", "or", "a", "database", "." ]
python
train
35.090909
bskinn/opan
opan/utils/symm.py
https://github.com/bskinn/opan/blob/0b1b21662df6abc971407a9386db21a8796fbfe5/opan/utils/symm.py#L42-L68
def point_displ(pt1, pt2): """ Calculate the displacement vector between two n-D points. pt1 - pt2 .. todo:: Complete point_disp docstring """ #Imports import numpy as np # Make iterable if not np.iterable(pt1): pt1 = np.float64(np.array([pt1])) else: pt1 = np.float64(np.array(pt1).squeeze()) ## end if if not np.iterable(pt2): pt2 = np.float64(np.array([pt2])) else: pt2 = np.float64(np.array(pt2).squeeze()) ## end if # Calculate the displacement vector and return displ = np.matrix(np.subtract(pt2, pt1)).reshape(3,1) return displ
[ "def", "point_displ", "(", "pt1", ",", "pt2", ")", ":", "#Imports", "import", "numpy", "as", "np", "# Make iterable", "if", "not", "np", ".", "iterable", "(", "pt1", ")", ":", "pt1", "=", "np", ".", "float64", "(", "np", ".", "array", "(", "[", "pt...
Calculate the displacement vector between two n-D points. pt1 - pt2 .. todo:: Complete point_disp docstring
[ "Calculate", "the", "displacement", "vector", "between", "two", "n", "-", "D", "points", "." ]
python
train
22.592593
pgjones/hypercorn
hypercorn/asgi/h11.py
https://github.com/pgjones/hypercorn/blob/ef93d741fe246846a127f9318b54505ac65f1ae7/hypercorn/asgi/h11.py#L123-L151
async def asgi_send(self, message: dict) -> None: """Called by the ASGI instance to send a message.""" if message["type"] == "http.response.start" and self.state == ASGIHTTPState.REQUEST: self.response = message elif message["type"] == "http.response.body" and self.state in { ASGIHTTPState.REQUEST, ASGIHTTPState.RESPONSE, }: if self.state == ASGIHTTPState.REQUEST: headers = build_and_validate_headers(self.response["headers"]) headers.extend(self.response_headers()) await self.asend( h11.Response(status_code=int(self.response["status"]), headers=headers) ) self.state = ASGIHTTPState.RESPONSE if ( not suppress_body(self.scope["method"], int(self.response["status"])) and message.get("body", b"") != b"" ): await self.asend(h11.Data(data=bytes(message["body"]))) if not message.get("more_body", False): if self.state != ASGIHTTPState.CLOSED: await self.asend(h11.EndOfMessage()) await self.asgi_put({"type": "http.disconnect"}) self.state = ASGIHTTPState.CLOSED else: raise UnexpectedMessage(self.state, message["type"])
[ "async", "def", "asgi_send", "(", "self", ",", "message", ":", "dict", ")", "->", "None", ":", "if", "message", "[", "\"type\"", "]", "==", "\"http.response.start\"", "and", "self", ".", "state", "==", "ASGIHTTPState", ".", "REQUEST", ":", "self", ".", "...
Called by the ASGI instance to send a message.
[ "Called", "by", "the", "ASGI", "instance", "to", "send", "a", "message", "." ]
python
test
46.862069
ihmeuw/vivarium
src/vivarium/framework/randomness.py
https://github.com/ihmeuw/vivarium/blob/c5f5d50f775c8bf337d3aae1ff7c57c025a8e258/src/vivarium/framework/randomness.py#L152-L154
def digit(m: Union[int, pd.Series], n: int) -> Union[int, pd.Series]: """Returns the nth digit of each number in m.""" return (m // (10 ** n)) % 10
[ "def", "digit", "(", "m", ":", "Union", "[", "int", ",", "pd", ".", "Series", "]", ",", "n", ":", "int", ")", "->", "Union", "[", "int", ",", "pd", ".", "Series", "]", ":", "return", "(", "m", "//", "(", "10", "**", "n", ")", ")", "%", "1...
Returns the nth digit of each number in m.
[ "Returns", "the", "nth", "digit", "of", "each", "number", "in", "m", "." ]
python
train
53.666667
orangain/scrapy-s3pipeline
s3pipeline/pipelines.py
https://github.com/orangain/scrapy-s3pipeline/blob/6301a3a057da6407b04a09c717498026f88706a4/s3pipeline/pipelines.py#L45-L54
def process_item(self, item, spider): """ Process single item. Add item to items and then upload to S3 if size of items >= max_chunk_size. """ self.items.append(item) if len(self.items) >= self.max_chunk_size: self._upload_chunk(spider) return item
[ "def", "process_item", "(", "self", ",", "item", ",", "spider", ")", ":", "self", ".", "items", ".", "append", "(", "item", ")", "if", "len", "(", "self", ".", "items", ")", ">=", "self", ".", "max_chunk_size", ":", "self", ".", "_upload_chunk", "(",...
Process single item. Add item to items and then upload to S3 if size of items >= max_chunk_size.
[ "Process", "single", "item", ".", "Add", "item", "to", "items", "and", "then", "upload", "to", "S3", "if", "size", "of", "items", ">", "=", "max_chunk_size", "." ]
python
test
30.8
tmr232/Sark
sark/ui.py
https://github.com/tmr232/Sark/blob/bee62879c2aea553a3924d887e2b30f2a6008581/sark/ui.py#L276-L282
def _get_handling_triplet(self, node_id): """_get_handling_triplet(node_id) -> (handler, value, attrs)""" handler = self._get_handler(node_id) value = self[node_id] attrs = self._get_attrs(node_id) return handler, value, attrs
[ "def", "_get_handling_triplet", "(", "self", ",", "node_id", ")", ":", "handler", "=", "self", ".", "_get_handler", "(", "node_id", ")", "value", "=", "self", "[", "node_id", "]", "attrs", "=", "self", ".", "_get_attrs", "(", "node_id", ")", "return", "h...
_get_handling_triplet(node_id) -> (handler, value, attrs)
[ "_get_handling_triplet", "(", "node_id", ")", "-", ">", "(", "handler", "value", "attrs", ")" ]
python
train
37.285714
IS-ENES-Data/esgf-pid
esgfpid/utils/timeutils.py
https://github.com/IS-ENES-Data/esgf-pid/blob/2f4909bb3ff79c0b6ed2932e0dd8b3bb6aec5e41/esgfpid/utils/timeutils.py#L10-L27
def get_now_utc(): ''' date in UTC, ISO format''' # Helper class for UTC time # Source: http://stackoverflow.com/questions/2331592/datetime-datetime-utcnow-why-no-tzinfo ZERO = datetime.timedelta(0) class UTC(datetime.tzinfo): """UTC""" def utcoffset(self, dt): return ZERO def tzname(self, dt): return "UTC" def dst(self, dt): return ZERO #now = datetime.datetime.now(timezone.utc) # Python 3.2 now = datetime.datetime.now(UTC()) return now
[ "def", "get_now_utc", "(", ")", ":", "# Helper class for UTC time", "# Source: http://stackoverflow.com/questions/2331592/datetime-datetime-utcnow-why-no-tzinfo", "ZERO", "=", "datetime", ".", "timedelta", "(", "0", ")", "class", "UTC", "(", "datetime", ".", "tzinfo", ")", ...
date in UTC, ISO format
[ "date", "in", "UTC", "ISO", "format" ]
python
train
29.222222
limodou/uliweb
uliweb/orm/__init__.py
https://github.com/limodou/uliweb/blob/34472f25e4bc0b954a35346672f94e84ef18b076/uliweb/orm/__init__.py#L2661-L2669
def count(self): """ If result is True, then the count will process result set , if result if False, then only use condition to count """ if self._group_by or self._join or self.distinct_field: return self.do_(self.get_query().limit(None).order_by(None).offset(None).alias().count()).scalar() else: return self.do_(self.get_query().with_only_columns([func.count()]).limit(None).order_by(None).offset(None)).scalar()
[ "def", "count", "(", "self", ")", ":", "if", "self", ".", "_group_by", "or", "self", ".", "_join", "or", "self", ".", "distinct_field", ":", "return", "self", ".", "do_", "(", "self", ".", "get_query", "(", ")", ".", "limit", "(", "None", ")", ".",...
If result is True, then the count will process result set , if result if False, then only use condition to count
[ "If", "result", "is", "True", "then", "the", "count", "will", "process", "result", "set", "if", "result", "if", "False", "then", "only", "use", "condition", "to", "count" ]
python
train
53.222222
samdobson/image_slicer
image_slicer/main.py
https://github.com/samdobson/image_slicer/blob/54ec036f73862085156e0544fe30e61a509c06d2/image_slicer/main.py#L120-L168
def slice(filename, number_tiles=None, col=None, row=None, save=True): """ Split an image into a specified number of tiles. Args: filename (str): The filename of the image to split. number_tiles (int): The number of tiles required. Kwargs: save (bool): Whether or not to save tiles to disk. Returns: Tuple of :class:`Tile` instances. """ im = Image.open(filename) im_w, im_h = im.size columns = 0 rows = 0 if not number_tiles is None: validate_image(im, number_tiles) columns, rows = calc_columns_rows(number_tiles) extras = (columns * rows) - number_tiles else: validate_image_col_row(im, col, row) columns = col rows = row extras = (columns * rows) - number_tiles tile_w, tile_h = int(floor(im_w / columns)), int(floor(im_h / rows)) tiles = [] number = 1 for pos_y in range(0, im_h - rows, tile_h): # -rows for rounding error. for pos_x in range(0, im_w - columns, tile_w): # as above. area = (pos_x, pos_y, pos_x + tile_w, pos_y + tile_h) image = im.crop(area) position = (int(floor(pos_x / tile_w)) + 1, int(floor(pos_y / tile_h)) + 1) coords = (pos_x, pos_y) tile = Tile(image, number, position, coords) tiles.append(tile) number += 1 if save: save_tiles(tiles, prefix=get_basename(filename), directory=os.path.dirname(filename)) return tuple(tiles)
[ "def", "slice", "(", "filename", ",", "number_tiles", "=", "None", ",", "col", "=", "None", ",", "row", "=", "None", ",", "save", "=", "True", ")", ":", "im", "=", "Image", ".", "open", "(", "filename", ")", "im_w", ",", "im_h", "=", "im", ".", ...
Split an image into a specified number of tiles. Args: filename (str): The filename of the image to split. number_tiles (int): The number of tiles required. Kwargs: save (bool): Whether or not to save tiles to disk. Returns: Tuple of :class:`Tile` instances.
[ "Split", "an", "image", "into", "a", "specified", "number", "of", "tiles", "." ]
python
train
31.306122
istresearch/scrapy-cluster
rest/rest_service.py
https://github.com/istresearch/scrapy-cluster/blob/13aaed2349af5d792d6bcbfcadc5563158aeb599/rest/rest_service.py#L540-L565
def _feed_to_kafka(self, json_item): """Sends a request to Kafka :param json_item: The json item to send :returns: A boolean indicating whther the data was sent successfully or not """ @MethodTimer.timeout(self.settings['KAFKA_FEED_TIMEOUT'], False) def _feed(json_item): try: self.logger.debug("Sending json to kafka at " + str(self.settings['KAFKA_PRODUCER_TOPIC'])) future = self.producer.send(self.settings['KAFKA_PRODUCER_TOPIC'], json_item) future.add_callback(self._kafka_success) future.add_errback(self._kafka_failure) self.producer.flush() return True except Exception as e: self.logger.error("Lost connection to Kafka") self._spawn_kafka_connection_thread() return False return _feed(json_item)
[ "def", "_feed_to_kafka", "(", "self", ",", "json_item", ")", ":", "@", "MethodTimer", ".", "timeout", "(", "self", ".", "settings", "[", "'KAFKA_FEED_TIMEOUT'", "]", ",", "False", ")", "def", "_feed", "(", "json_item", ")", ":", "try", ":", "self", ".", ...
Sends a request to Kafka :param json_item: The json item to send :returns: A boolean indicating whther the data was sent successfully or not
[ "Sends", "a", "request", "to", "Kafka" ]
python
train
37.615385
peri-source/peri
peri/opt/optimize.py
https://github.com/peri-source/peri/blob/61beed5deaaf978ab31ed716e8470d86ba639867/peri/opt/optimize.py#L1414-L1418
def update_function(self, param_vals): """Takes an array param_vals, updates function, returns the new error""" self.model = self.func(param_vals, *self.func_args, **self.func_kwargs) d = self.calc_residuals() return np.dot(d.flat, d.flat)
[ "def", "update_function", "(", "self", ",", "param_vals", ")", ":", "self", ".", "model", "=", "self", ".", "func", "(", "param_vals", ",", "*", "self", ".", "func_args", ",", "*", "*", "self", ".", "func_kwargs", ")", "d", "=", "self", ".", "calc_re...
Takes an array param_vals, updates function, returns the new error
[ "Takes", "an", "array", "param_vals", "updates", "function", "returns", "the", "new", "error" ]
python
valid
53.4
pypa/pipenv
pipenv/patched/notpip/_vendor/pkg_resources/__init__.py
https://github.com/pypa/pipenv/blob/cae8d76c210b9777e90aab76e9c4b0e53bb19cde/pipenv/patched/notpip/_vendor/pkg_resources/__init__.py#L644-L656
def iter_entry_points(self, group, name=None): """Yield entry point objects from `group` matching `name` If `name` is None, yields all entry points in `group` from all distributions in the working set, otherwise only ones matching both `group` and `name` are yielded (in distribution order). """ return ( entry for dist in self for entry in dist.get_entry_map(group).values() if name is None or name == entry.name )
[ "def", "iter_entry_points", "(", "self", ",", "group", ",", "name", "=", "None", ")", ":", "return", "(", "entry", "for", "dist", "in", "self", "for", "entry", "in", "dist", ".", "get_entry_map", "(", "group", ")", ".", "values", "(", ")", "if", "nam...
Yield entry point objects from `group` matching `name` If `name` is None, yields all entry points in `group` from all distributions in the working set, otherwise only ones matching both `group` and `name` are yielded (in distribution order).
[ "Yield", "entry", "point", "objects", "from", "group", "matching", "name" ]
python
train
39.076923
waqasbhatti/astrobase
astrobase/periodbase/spdm.py
https://github.com/waqasbhatti/astrobase/blob/2922a14619d183fb28005fa7d02027ac436f2265/astrobase/periodbase/spdm.py#L71-L141
def stellingwerf_pdm_theta(times, mags, errs, frequency, binsize=0.05, minbin=9): ''' This calculates the Stellingwerf PDM theta value at a test frequency. Parameters ---------- times,mags,errs : np.array The input time-series and associated errors. frequency : float The test frequency to calculate the theta statistic at. binsize : float The phase bin size to use. minbin : int The minimum number of items in a phase bin to consider in the calculation of the statistic. Returns ------- theta_pdm : float The value of the theta statistic at the specified `frequency`. ''' period = 1.0/frequency fold_time = times[0] phased = phase_magseries(times, mags, period, fold_time, wrap=False, sort=True) phases = phased['phase'] pmags = phased['mags'] bins = nparange(0.0, 1.0, binsize) binnedphaseinds = npdigitize(phases, bins) binvariances = [] binndets = [] goodbins = 0 for x in npunique(binnedphaseinds): thisbin_inds = binnedphaseinds == x thisbin_mags = pmags[thisbin_inds] if thisbin_mags.size > minbin: thisbin_variance = npvar(thisbin_mags,ddof=1) binvariances.append(thisbin_variance) binndets.append(thisbin_mags.size) goodbins = goodbins + 1 # now calculate theta binvariances = nparray(binvariances) binndets = nparray(binndets) theta_top = npsum(binvariances*(binndets - 1)) / (npsum(binndets) - goodbins) theta_bot = npvar(pmags,ddof=1) theta = theta_top/theta_bot return theta
[ "def", "stellingwerf_pdm_theta", "(", "times", ",", "mags", ",", "errs", ",", "frequency", ",", "binsize", "=", "0.05", ",", "minbin", "=", "9", ")", ":", "period", "=", "1.0", "/", "frequency", "fold_time", "=", "times", "[", "0", "]", "phased", "=", ...
This calculates the Stellingwerf PDM theta value at a test frequency. Parameters ---------- times,mags,errs : np.array The input time-series and associated errors. frequency : float The test frequency to calculate the theta statistic at. binsize : float The phase bin size to use. minbin : int The minimum number of items in a phase bin to consider in the calculation of the statistic. Returns ------- theta_pdm : float The value of the theta statistic at the specified `frequency`.
[ "This", "calculates", "the", "Stellingwerf", "PDM", "theta", "value", "at", "a", "test", "frequency", "." ]
python
valid
25.394366
inasafe/inasafe
safe/impact_function/impact_function.py
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/impact_function/impact_function.py#L1223-L1257
def _compute_output_layer_expected(self): """Compute output layers expected that the IF will produce. Be careful when you call this function. It's a private function, better to use the public function `output_layers_expected()`. :return: List of expected layer keys. :rtype: list """ # Actually, an IF can produce maximum 6 layers, by default. expected = [ layer_purpose_exposure_summary['key'], # 1 layer_purpose_aggregate_hazard_impacted['key'], # 2 layer_purpose_aggregation_summary['key'], # 3 layer_purpose_analysis_impacted['key'], # 4 layer_purpose_exposure_summary_table['key'], # 5 layer_purpose_profiling['key'], # 6 ] if is_raster_layer(self.exposure): if self.exposure.keywords.get('layer_mode') == 'continuous': # If the exposure is a continuous raster, we can't provide the # exposure impacted layer. expected.remove(layer_purpose_exposure_summary['key']) if not self.exposure.keywords.get('classification'): # If the exposure doesn't have a classification, such as population # census layer, we can't provide an exposure breakdown layer. expected.remove(layer_purpose_exposure_summary_table['key']) # We add any layers produced by pre-processors for preprocessor in self._preprocessors: if preprocessor['output'].get('type') == 'layer': expected.append(preprocessor['output'].get('value')['key']) return expected
[ "def", "_compute_output_layer_expected", "(", "self", ")", ":", "# Actually, an IF can produce maximum 6 layers, by default.", "expected", "=", "[", "layer_purpose_exposure_summary", "[", "'key'", "]", ",", "# 1", "layer_purpose_aggregate_hazard_impacted", "[", "'key'", "]", ...
Compute output layers expected that the IF will produce. Be careful when you call this function. It's a private function, better to use the public function `output_layers_expected()`. :return: List of expected layer keys. :rtype: list
[ "Compute", "output", "layers", "expected", "that", "the", "IF", "will", "produce", "." ]
python
train
46.057143
saltstack/salt
salt/modules/pkgin.py
https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/pkgin.py#L320-L341
def list_upgrades(refresh=True, **kwargs): ''' List all available package upgrades. .. versionadded:: 2018.3.0 refresh Whether or not to refresh the package database before installing. CLI Example: .. code-block:: bash salt '*' pkg.list_upgrades ''' pkgs = {} for pkg in sorted(list_pkgs(refresh=refresh).keys()): # NOTE: we already optionally refreshed in de list_pkg call pkg_upgrade = latest_version(pkg, refresh=False) if pkg_upgrade: pkgs[pkg] = pkg_upgrade return pkgs
[ "def", "list_upgrades", "(", "refresh", "=", "True", ",", "*", "*", "kwargs", ")", ":", "pkgs", "=", "{", "}", "for", "pkg", "in", "sorted", "(", "list_pkgs", "(", "refresh", "=", "refresh", ")", ".", "keys", "(", ")", ")", ":", "# NOTE: we already o...
List all available package upgrades. .. versionadded:: 2018.3.0 refresh Whether or not to refresh the package database before installing. CLI Example: .. code-block:: bash salt '*' pkg.list_upgrades
[ "List", "all", "available", "package", "upgrades", "." ]
python
train
25
coded-by-hand/mass
env/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.py
https://github.com/coded-by-hand/mass/blob/59005479efed3cd8598a8f0c66791a4482071899/env/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/util.py#L98-L103
def get_pathext(default_pathext=None): """Returns the path extensions from environment or a default""" if default_pathext is None: default_pathext = os.pathsep.join([ '.COM', '.EXE', '.BAT', '.CMD' ]) pathext = os.environ.get('PATHEXT', default_pathext) return pathext
[ "def", "get_pathext", "(", "default_pathext", "=", "None", ")", ":", "if", "default_pathext", "is", "None", ":", "default_pathext", "=", "os", ".", "pathsep", ".", "join", "(", "[", "'.COM'", ",", "'.EXE'", ",", "'.BAT'", ",", "'.CMD'", "]", ")", "pathex...
Returns the path extensions from environment or a default
[ "Returns", "the", "path", "extensions", "from", "environment", "or", "a", "default" ]
python
train
47.833333
quantumlib/Cirq
cirq/linalg/transformations.py
https://github.com/quantumlib/Cirq/blob/0827da80dd7880e5b923eb69407e980ed9bc0bd2/cirq/linalg/transformations.py#L152-L201
def targeted_conjugate_about(tensor: np.ndarray, target: np.ndarray, indices: Sequence[int], conj_indices: Sequence[int] = None, buffer: Optional[np.ndarray] = None, out: Optional[np.ndarray] = None) -> np.ndarray: r"""Conjugates the given tensor about the target tensor. This method computes a target tensor conjugated by another tensor. Here conjugate is used in the sense of conjugating by a matrix, i.a. A conjugated about B is $A B A^\dagger$ where $\dagger$ represents the conjugate transpose. Abstractly this compute $A \cdot B \cdot A^\dagger$ where A and B are multi-dimensional arrays, and instead of matrix multiplication $\cdot$ is a contraction between the given indices (indices for first $\cdot$, conj_indices for second $\cdot$). More specifically this computes sum tensor_{i_0,...,i_{r-1},j_0,...,j_{r-1}} * target_{k_0,...,k_{r-1},l_0,...,l_{r-1} * tensor_{m_0,...,m_{r-1},n_0,...,n_{r-1}}^* where the sum is over indices where j_s = k_s and s is in `indices` and l_s = m_s and s is in `conj_indices`. Args: tensor: The tensor that will be conjugated about the target tensor. target: The tensor that will receive the conjugation. indices: The indices which will be contracted between the tensor and target. conj_indices; The indices which will be contracted between the complex conjugate of the tensor and the target. If this is None, then these will be the values in indices plus half the number of dimensions of the target (`ndim`). This is the most common case and corresponds to the case where the target is an operator on a n-dimensional tensor product space (here `n` would be `ndim`). buffer: A buffer to store partial results in. If not specified or None, a new buffer is used. out: The buffer to store the results in. If not specified or None, a new buffer is used. Must have the same shape as target. Returns: The result the conjugation. """ conj_indices = conj_indices or [i + target.ndim // 2 for i in indices] first_multiply = targeted_left_multiply(tensor, target, indices, out=buffer) return targeted_left_multiply(np.conjugate(tensor), first_multiply, conj_indices, out=out)
[ "def", "targeted_conjugate_about", "(", "tensor", ":", "np", ".", "ndarray", ",", "target", ":", "np", ".", "ndarray", ",", "indices", ":", "Sequence", "[", "int", "]", ",", "conj_indices", ":", "Sequence", "[", "int", "]", "=", "None", ",", "buffer", ...
r"""Conjugates the given tensor about the target tensor. This method computes a target tensor conjugated by another tensor. Here conjugate is used in the sense of conjugating by a matrix, i.a. A conjugated about B is $A B A^\dagger$ where $\dagger$ represents the conjugate transpose. Abstractly this compute $A \cdot B \cdot A^\dagger$ where A and B are multi-dimensional arrays, and instead of matrix multiplication $\cdot$ is a contraction between the given indices (indices for first $\cdot$, conj_indices for second $\cdot$). More specifically this computes sum tensor_{i_0,...,i_{r-1},j_0,...,j_{r-1}} * target_{k_0,...,k_{r-1},l_0,...,l_{r-1} * tensor_{m_0,...,m_{r-1},n_0,...,n_{r-1}}^* where the sum is over indices where j_s = k_s and s is in `indices` and l_s = m_s and s is in `conj_indices`. Args: tensor: The tensor that will be conjugated about the target tensor. target: The tensor that will receive the conjugation. indices: The indices which will be contracted between the tensor and target. conj_indices; The indices which will be contracted between the complex conjugate of the tensor and the target. If this is None, then these will be the values in indices plus half the number of dimensions of the target (`ndim`). This is the most common case and corresponds to the case where the target is an operator on a n-dimensional tensor product space (here `n` would be `ndim`). buffer: A buffer to store partial results in. If not specified or None, a new buffer is used. out: The buffer to store the results in. If not specified or None, a new buffer is used. Must have the same shape as target. Returns: The result the conjugation.
[ "r", "Conjugates", "the", "given", "tensor", "about", "the", "target", "tensor", "." ]
python
train
51.2
radjkarl/fancyWidgets
fancywidgets/pyQtBased/CodeEditor.py
https://github.com/radjkarl/fancyWidgets/blob/ffe0d5747c5296c78575f0e0909af915a4a5698f/fancywidgets/pyQtBased/CodeEditor.py#L349-L376
def _updateNumbers(self, linenumers): """ add/remove line numbers """ b = self.blockCount() c = b - linenumers if c > 0: # remove lines numbers for _ in range(c): # remove last line: self.setFocus() storeCursorPos = self.textCursor() self.moveCursor( QtGui.QTextCursor.End, QtGui.QTextCursor.MoveAnchor) self.moveCursor( QtGui.QTextCursor.StartOfLine, QtGui.QTextCursor.MoveAnchor) self.moveCursor( QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor) self.textCursor().removeSelectedText() self.textCursor().deletePreviousChar() self.setTextCursor(storeCursorPos) elif c < 0: # add line numbers for i in range(-c): self.appendPlainText(str(b + i + 1))
[ "def", "_updateNumbers", "(", "self", ",", "linenumers", ")", ":", "b", "=", "self", ".", "blockCount", "(", ")", "c", "=", "b", "-", "linenumers", "if", "c", ">", "0", ":", "# remove lines numbers", "for", "_", "in", "range", "(", "c", ")", ":", "...
add/remove line numbers
[ "add", "/", "remove", "line", "numbers" ]
python
train
36.035714
mwgielen/jackal
jackal/core.py
https://github.com/mwgielen/jackal/blob/7fe62732eb5194b7246215d5277fb37c398097bf/jackal/core.py#L495-L519
def find_object(self, username, secret, domain=None, host_ip=None, service_id=None): """ Searches elasticsearch for objects with the same username, password, optional domain, host_ip and service_id. """ # Not sure yet if this is advisable... Older passwords can be overwritten... search = Credential.search() search = search.filter("term", username=username) search = search.filter("term", secret=secret) if domain: search = search.filter("term", domain=domain) else: search = search.exclude("exists", field="domain") if host_ip: search = search.filter("term", host_ip=host_ip) else: search = search.exclude("exists", field="host_ip") if service_id: search = search.filter("term", service_id=service_id) else: search = search.exclude("exists", field="service_id") if search.count(): result = search[0].execute()[0] return result else: return None
[ "def", "find_object", "(", "self", ",", "username", ",", "secret", ",", "domain", "=", "None", ",", "host_ip", "=", "None", ",", "service_id", "=", "None", ")", ":", "# Not sure yet if this is advisable... Older passwords can be overwritten...", "search", "=", "Cred...
Searches elasticsearch for objects with the same username, password, optional domain, host_ip and service_id.
[ "Searches", "elasticsearch", "for", "objects", "with", "the", "same", "username", "password", "optional", "domain", "host_ip", "and", "service_id", "." ]
python
valid
42.16
twilio/twilio-python
twilio/rest/autopilot/v1/assistant/style_sheet.py
https://github.com/twilio/twilio-python/blob/c867895f55dcc29f522e6e8b8868d0d18483132f/twilio/rest/autopilot/v1/assistant/style_sheet.py#L86-L95
def get_instance(self, payload): """ Build an instance of StyleSheetInstance :param dict payload: Payload response from the API :returns: twilio.rest.autopilot.v1.assistant.style_sheet.StyleSheetInstance :rtype: twilio.rest.autopilot.v1.assistant.style_sheet.StyleSheetInstance """ return StyleSheetInstance(self._version, payload, assistant_sid=self._solution['assistant_sid'], )
[ "def", "get_instance", "(", "self", ",", "payload", ")", ":", "return", "StyleSheetInstance", "(", "self", ".", "_version", ",", "payload", ",", "assistant_sid", "=", "self", ".", "_solution", "[", "'assistant_sid'", "]", ",", ")" ]
Build an instance of StyleSheetInstance :param dict payload: Payload response from the API :returns: twilio.rest.autopilot.v1.assistant.style_sheet.StyleSheetInstance :rtype: twilio.rest.autopilot.v1.assistant.style_sheet.StyleSheetInstance
[ "Build", "an", "instance", "of", "StyleSheetInstance" ]
python
train
42.9
JdeRobot/base
src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L389-L396
def mag_discrepancy(RAW_IMU, ATTITUDE, inclination, declination=None): '''give the magnitude of the discrepancy between observed and expected magnetic field''' if declination is None: import mavutil declination = degrees(mavutil.mavfile_global.param('COMPASS_DEC', 0)) expected = expected_mag(RAW_IMU, ATTITUDE, inclination, declination) mag = Vector3(RAW_IMU.xmag, RAW_IMU.ymag, RAW_IMU.zmag) return degrees(expected.angle(mag))
[ "def", "mag_discrepancy", "(", "RAW_IMU", ",", "ATTITUDE", ",", "inclination", ",", "declination", "=", "None", ")", ":", "if", "declination", "is", "None", ":", "import", "mavutil", "declination", "=", "degrees", "(", "mavutil", ".", "mavfile_global", ".", ...
give the magnitude of the discrepancy between observed and expected magnetic field
[ "give", "the", "magnitude", "of", "the", "discrepancy", "between", "observed", "and", "expected", "magnetic", "field" ]
python
train
57.25
nion-software/nionswift-io
nionswift_plugin/TIFF_IO/tifffile.py
https://github.com/nion-software/nionswift-io/blob/e9ae37f01faa9332c48b647f93afd5ef2166b155/nionswift_plugin/TIFF_IO/tifffile.py#L9187-L9217
def metaseries_description_metadata(description): """Return metatata from MetaSeries image description as dict.""" if not description.startswith('<MetaData>'): raise ValueError('invalid MetaSeries image description') from xml.etree import cElementTree as etree # delayed import root = etree.fromstring(description) types = {'float': float, 'int': int, 'bool': lambda x: asbool(x, 'on', 'off')} def parse(root, result): # recursive for child in root: attrib = child.attrib if not attrib: result[child.tag] = parse(child, {}) continue if 'id' in attrib: i = attrib['id'] t = attrib['type'] v = attrib['value'] if t in types: result[i] = types[t](v) else: result[i] = v return result adict = parse(root, {}) if 'Description' in adict: adict['Description'] = adict['Description'].replace('&#13;&#10;', '\n') return adict
[ "def", "metaseries_description_metadata", "(", "description", ")", ":", "if", "not", "description", ".", "startswith", "(", "'<MetaData>'", ")", ":", "raise", "ValueError", "(", "'invalid MetaSeries image description'", ")", "from", "xml", ".", "etree", "import", "c...
Return metatata from MetaSeries image description as dict.
[ "Return", "metatata", "from", "MetaSeries", "image", "description", "as", "dict", "." ]
python
train
34.419355
mitsei/dlkit
dlkit/json_/assessment/sessions.py
https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/assessment/sessions.py#L3973-L3995
def get_assessments(self): """Gets all ``Assessments``. In plenary mode, the returned list contains all known assessments or an error results. Otherwise, the returned list may contain only those assessments that are accessible through this session. return: (osid.assessment.AssessmentList) - a list of ``Assessments`` raise: OperationFailed - unable to complete request raise: PermissionDenied - authorization failure occurred *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for # osid.resource.ResourceLookupSession.get_resources # NOTE: This implementation currently ignores plenary view collection = JSONClientValidated('assessment', collection='Assessment', runtime=self._runtime) result = collection.find(self._view_filter()).sort('_id', DESCENDING) return objects.AssessmentList(result, runtime=self._runtime, proxy=self._proxy)
[ "def", "get_assessments", "(", "self", ")", ":", "# Implemented from template for", "# osid.resource.ResourceLookupSession.get_resources", "# NOTE: This implementation currently ignores plenary view", "collection", "=", "JSONClientValidated", "(", "'assessment'", ",", "collection", "...
Gets all ``Assessments``. In plenary mode, the returned list contains all known assessments or an error results. Otherwise, the returned list may contain only those assessments that are accessible through this session. return: (osid.assessment.AssessmentList) - a list of ``Assessments`` raise: OperationFailed - unable to complete request raise: PermissionDenied - authorization failure occurred *compliance: mandatory -- This method must be implemented.*
[ "Gets", "all", "Assessments", "." ]
python
train
47.26087
theosysbio/means
src/means/simulation/ssa.py
https://github.com/theosysbio/means/blob/fe164916a1d84ab2a4fa039871d38ccdf638b1db/src/means/simulation/ssa.py#L62-L139
def simulate_system(self, parameters, initial_conditions, timepoints, max_moment_order=1, number_of_processes=1): """ Perform Gillespie SSA simulations and returns trajectories for of each species. Each trajectory is interpolated at the given time points. By default, the average amounts of species for all simulations is returned. :param parameters: list of the initial values for the constants in the model. Must be in the same order as in the model :param initial_conditions: List of the initial values for the equations in the problem. Must be in the same order as these equations occur. :param timepoints: A list of time points to simulate the system for :param number_of_processes: the number of parallel process to be run :param max_moment_order: the highest moment order to calculate the trajectories to. if set to zero, the individual trajectories will be returned, instead of the averaged moments. E.g. a value of one will return means, a values of two, means, variances and covariance and so on. :return: a list of :class:`~means.simulation.Trajectory` one per species in the problem, or a list of lists of trajectories (one per simulation) if `return_average == False`. :rtype: list[:class:`~means.simulation.Trajectory`] """ max_moment_order = int(max_moment_order) assert(max_moment_order >= 0) n_simulations = self.__n_simulations self._validate_parameters(parameters, initial_conditions) t_max= max(timepoints) substitution_pairs = dict(zip(self.__problem.parameters, parameters)) propensities = substitute_all(self.__problem.propensities, substitution_pairs) # lambdify the propensities for fast evaluation propensities_as_function = self.__problem.propensities_as_function def f(*species_parameters): return propensities_as_function(*(np.concatenate((species_parameters, parameters)))) population_rates_as_function = f if not self.__random_seed: seed_for_processes = [None] * n_simulations else: seed_for_processes = [i for i in range(self.__random_seed, n_simulations + self.__random_seed)] if number_of_processes ==1: ssa_generator = _SSAGenerator(population_rates_as_function, self.__problem.change, self.__problem.species, initial_conditions, t_max, seed=self.__random_seed) results = map(ssa_generator.generate_single_simulation, seed_for_processes) else: p = multiprocessing.Pool(number_of_processes, initializer=multiprocessing_pool_initialiser, initargs=[population_rates_as_function, self.__problem.change, self.__problem.species, initial_conditions, t_max, self.__random_seed]) results = p.map(multiprocessing_apply_ssa, seed_for_processes) p.close() p.join() resampled_results = [[traj.resample(timepoints, extrapolate=True) for traj in res] for res in results] for i in resampled_results: idx = len(i[0].values) - 1 if max_moment_order == 0: # Return a list of TrajectoryCollection objects return map(TrajectoryCollection, resampled_results) moments = self._compute_moments(resampled_results, max_moment_order) return TrajectoryCollection(moments)
[ "def", "simulate_system", "(", "self", ",", "parameters", ",", "initial_conditions", ",", "timepoints", ",", "max_moment_order", "=", "1", ",", "number_of_processes", "=", "1", ")", ":", "max_moment_order", "=", "int", "(", "max_moment_order", ")", "assert", "("...
Perform Gillespie SSA simulations and returns trajectories for of each species. Each trajectory is interpolated at the given time points. By default, the average amounts of species for all simulations is returned. :param parameters: list of the initial values for the constants in the model. Must be in the same order as in the model :param initial_conditions: List of the initial values for the equations in the problem. Must be in the same order as these equations occur. :param timepoints: A list of time points to simulate the system for :param number_of_processes: the number of parallel process to be run :param max_moment_order: the highest moment order to calculate the trajectories to. if set to zero, the individual trajectories will be returned, instead of the averaged moments. E.g. a value of one will return means, a values of two, means, variances and covariance and so on. :return: a list of :class:`~means.simulation.Trajectory` one per species in the problem, or a list of lists of trajectories (one per simulation) if `return_average == False`. :rtype: list[:class:`~means.simulation.Trajectory`]
[ "Perform", "Gillespie", "SSA", "simulations", "and", "returns", "trajectories", "for", "of", "each", "species", ".", "Each", "trajectory", "is", "interpolated", "at", "the", "given", "time", "points", ".", "By", "default", "the", "average", "amounts", "of", "s...
python
train
47.025641
happyleavesaoc/python-upsmychoice
upsmychoice/__init__.py
https://github.com/happyleavesaoc/python-upsmychoice/blob/df4d7e9d92f95884c8d86f9d38b5a2291cf9edbe/upsmychoice/__init__.py#L64-L82
def _login(session): """Login to UPS.""" resp = session.get(LOGIN_URL, params=_get_params(session.auth.locale)) parsed = BeautifulSoup(resp.text, HTML_PARSER) csrf = parsed.find(CSRF_FIND_TAG, CSRF_FIND_ATTR).get(VALUE_ATTR) resp = session.post(LOGIN_URL, { 'userID': session.auth.username, 'password': session.auth.password, 'loginAction': 'X', 'CSRFToken': csrf, 'loc': session.auth.locale }) if resp.status_code == 403: raise UPSError('login failure') parsed = BeautifulSoup(resp.text, HTML_PARSER) error = parsed.find(ERROR_FIND_TAG, ERROR_FIND_ATTR) if error and error.string: raise UPSError(error.string.strip()) _save_cookies(session.cookies, session.auth.cookie_path)
[ "def", "_login", "(", "session", ")", ":", "resp", "=", "session", ".", "get", "(", "LOGIN_URL", ",", "params", "=", "_get_params", "(", "session", ".", "auth", ".", "locale", ")", ")", "parsed", "=", "BeautifulSoup", "(", "resp", ".", "text", ",", "...
Login to UPS.
[ "Login", "to", "UPS", "." ]
python
train
39.842105
biolink/biolink-model
metamodel/generators/contextgen.py
https://github.com/biolink/biolink-model/blob/f379e28d5d4085e1115798c6cb28e5acc4dba8b4/metamodel/generators/contextgen.py#L92-L103
def add_prefix(self, ncname: str) -> None: """ Look up ncname and add it to the prefix map if necessary @param ncname: name to add """ if ncname not in self.prefixmap: uri = cu.expand_uri(ncname + ':', self.curi_maps) if uri and '://' in uri: self.prefixmap[ncname] = uri else: print(f"Unrecognized prefix: {ncname}", file=sys.stderr) self.prefixmap[ncname] = f"http://example.org/unknown/{ncname}/"
[ "def", "add_prefix", "(", "self", ",", "ncname", ":", "str", ")", "->", "None", ":", "if", "ncname", "not", "in", "self", ".", "prefixmap", ":", "uri", "=", "cu", ".", "expand_uri", "(", "ncname", "+", "':'", ",", "self", ".", "curi_maps", ")", "if...
Look up ncname and add it to the prefix map if necessary @param ncname: name to add
[ "Look", "up", "ncname", "and", "add", "it", "to", "the", "prefix", "map", "if", "necessary" ]
python
train
42.083333
twilio/twilio-python
twilio/rest/api/v2010/account/call/feedback_summary.py
https://github.com/twilio/twilio-python/blob/c867895f55dcc29f522e6e8b8868d0d18483132f/twilio/rest/api/v2010/account/call/feedback_summary.py#L67-L76
def get(self, sid): """ Constructs a FeedbackSummaryContext :param sid: A string that uniquely identifies this feedback summary resource :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext """ return FeedbackSummaryContext(self._version, account_sid=self._solution['account_sid'], sid=sid, )
[ "def", "get", "(", "self", ",", "sid", ")", ":", "return", "FeedbackSummaryContext", "(", "self", ".", "_version", ",", "account_sid", "=", "self", ".", "_solution", "[", "'account_sid'", "]", ",", "sid", "=", "sid", ",", ")" ]
Constructs a FeedbackSummaryContext :param sid: A string that uniquely identifies this feedback summary resource :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryContext
[ "Constructs", "a", "FeedbackSummaryContext" ]
python
train
45.6
pantsbuild/pants
src/python/pants/reporting/html_reporter.py
https://github.com/pantsbuild/pants/blob/b72e650da0df685824ffdcc71988b8c282d0962d/src/python/pants/reporting/html_reporter.py#L224-L308
def end_workunit(self, workunit): """Implementation of Reporter callback.""" duration = workunit.duration() timing = '{:.3f}'.format(duration) unaccounted_time = '' # Background work may be idle a lot, no point in reporting that as unaccounted. if self.is_under_main_root(workunit): unaccounted_time_secs = workunit.unaccounted_time() if unaccounted_time_secs >= 1 and unaccounted_time_secs > 0.05 * duration: unaccounted_time = '{:.3f}'.format(unaccounted_time_secs) status = HtmlReporter._outcome_css_classes[workunit.outcome()] if workunit.has_label(WorkUnitLabel.TOOL): self._emit(self._end_tool_invocation_fmt_string.format( id=workunit.id, status=status )) self._emit(self._end_workunit_fmt_string.format( id=workunit.id, status=status, timing=timing, unaccounted_time=unaccounted_time, aborted='true' if workunit.outcome() == WorkUnit.ABORTED else 'false' )) # If we're a root workunit, force an overwrite, as we may be the last ever write in this run. force_overwrite = workunit.parent is None # Update the timings. def render_timings(timings): timings_dict = timings.get_all() for item in timings_dict: item['timing_string'] = '{:.3f}'.format(item['timing']) res = ['<table>'] for item in timings_dict: res.append("""<tr><td class="timing-string">{timing:.3f}</td> <td class="timing-label">{label}""".format( timing=item['timing'], label=item['label'] )) if item['is_tool']: res.append("""<i class="icon-cog"></i>""") res.append("""</td></tr>""") res.append('<table>') return ''.join(res) self._overwrite('cumulative_timings', lambda: render_timings(self.run_tracker.cumulative_timings), force=force_overwrite) self._overwrite('self_timings', lambda: render_timings(self.run_tracker.self_timings), force=force_overwrite) # Update the artifact cache stats. def render_cache_stats(artifact_cache_stats): def fix_detail_id(e, _id): return e if isinstance(e, string_types) else e + (_id, ) msg_elements = [] for cache_name, stat in artifact_cache_stats.stats_per_cache.items(): # TODO consider display causes for hit/miss targets hit_targets = [tgt for tgt, cause in stat.hit_targets] miss_targets = [tgt for tgt, cause in stat.miss_targets] msg_elements.extend([ cache_name + ' artifact cache: ', # Explicitly set the detail ids, so their displayed/hidden state survives a refresh. fix_detail_id(items_to_report_element(hit_targets, 'hit'), 'cache-hit-details'), ', ', fix_detail_id(items_to_report_element(miss_targets, 'miss'), 'cache-miss-details'), '.' ]) if not msg_elements: msg_elements = ['No artifact cache use.'] return self._render_message(*msg_elements) self._overwrite('artifact_cache_stats', lambda: render_cache_stats(self.run_tracker.artifact_cache_stats), force=force_overwrite) for f in self._output_files[workunit.id].values(): f.close()
[ "def", "end_workunit", "(", "self", ",", "workunit", ")", ":", "duration", "=", "workunit", ".", "duration", "(", ")", "timing", "=", "'{:.3f}'", ".", "format", "(", "duration", ")", "unaccounted_time", "=", "''", "# Background work may be idle a lot, no point in ...
Implementation of Reporter callback.
[ "Implementation", "of", "Reporter", "callback", "." ]
python
train
38.258824
lamoreauxlab/srpenergy-api-client-python
srpenergy/client.py
https://github.com/lamoreauxlab/srpenergy-api-client-python/blob/dc703510672c2a3e7f3e82c879c9474d04874a40/srpenergy/client.py#L17-L24
def get_iso_time(date_part, time_part): r"""Combign date and time into an iso datetime.""" str_date = datetime.datetime.strptime( date_part, '%m/%d/%Y').strftime('%Y-%m-%d') str_time = datetime.datetime.strptime( time_part, '%I:%M %p').strftime('%H:%M:%S') return str_date + "T" + str_time + "-7:00"
[ "def", "get_iso_time", "(", "date_part", ",", "time_part", ")", ":", "str_date", "=", "datetime", ".", "datetime", ".", "strptime", "(", "date_part", ",", "'%m/%d/%Y'", ")", ".", "strftime", "(", "'%Y-%m-%d'", ")", "str_time", "=", "datetime", ".", "datetime...
r"""Combign date and time into an iso datetime.
[ "r", "Combign", "date", "and", "time", "into", "an", "iso", "datetime", "." ]
python
train
41.5
oauthlib/oauthlib
oauthlib/oauth2/rfc6749/clients/base.py
https://github.com/oauthlib/oauthlib/blob/30321dd3c0ca784d3508a1970cf90d9f76835c79/oauthlib/oauth2/rfc6749/clients/base.py#L375-L423
def parse_request_body_response(self, body, scope=None, **kwargs): """Parse the JSON response body. If the access token request is valid and authorized, the authorization server issues an access token as described in `Section 5.1`_. A refresh token SHOULD NOT be included. If the request failed client authentication or is invalid, the authorization server returns an error response as described in `Section 5.2`_. :param body: The response body from the token request. :param scope: Scopes originally requested. :return: Dictionary of token parameters. :raises: Warning if scope has changed. OAuth2Error if response is invalid. These response are json encoded and could easily be parsed without the assistance of OAuthLib. However, there are a few subtle issues to be aware of regarding the response which are helpfully addressed through the raising of various errors. A successful response should always contain **access_token** The access token issued by the authorization server. Often a random string. **token_type** The type of the token issued as described in `Section 7.1`_. Commonly ``Bearer``. While it is not mandated it is recommended that the provider include **expires_in** The lifetime in seconds of the access token. For example, the value "3600" denotes that the access token will expire in one hour from the time the response was generated. If omitted, the authorization server SHOULD provide the expiration time via other means or document the default value. **scope** Providers may supply this in all responses but are required to only if it has changed since the authorization request. .. _`Section 5.1`: https://tools.ietf.org/html/rfc6749#section-5.1 .. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2 .. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1 """ self.token = parse_token_response(body, scope=scope) self.populate_token_attributes(self.token) return self.token
[ "def", "parse_request_body_response", "(", "self", ",", "body", ",", "scope", "=", "None", ",", "*", "*", "kwargs", ")", ":", "self", ".", "token", "=", "parse_token_response", "(", "body", ",", "scope", "=", "scope", ")", "self", ".", "populate_token_attr...
Parse the JSON response body. If the access token request is valid and authorized, the authorization server issues an access token as described in `Section 5.1`_. A refresh token SHOULD NOT be included. If the request failed client authentication or is invalid, the authorization server returns an error response as described in `Section 5.2`_. :param body: The response body from the token request. :param scope: Scopes originally requested. :return: Dictionary of token parameters. :raises: Warning if scope has changed. OAuth2Error if response is invalid. These response are json encoded and could easily be parsed without the assistance of OAuthLib. However, there are a few subtle issues to be aware of regarding the response which are helpfully addressed through the raising of various errors. A successful response should always contain **access_token** The access token issued by the authorization server. Often a random string. **token_type** The type of the token issued as described in `Section 7.1`_. Commonly ``Bearer``. While it is not mandated it is recommended that the provider include **expires_in** The lifetime in seconds of the access token. For example, the value "3600" denotes that the access token will expire in one hour from the time the response was generated. If omitted, the authorization server SHOULD provide the expiration time via other means or document the default value. **scope** Providers may supply this in all responses but are required to only if it has changed since the authorization request. .. _`Section 5.1`: https://tools.ietf.org/html/rfc6749#section-5.1 .. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2 .. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
[ "Parse", "the", "JSON", "response", "body", "." ]
python
train
45.897959
joelfrederico/SciSalt
scisalt/matplotlib/setup_axes.py
https://github.com/joelfrederico/SciSalt/blob/7bf57c49c7dde0a8b0aa337fbd2fbd527ce7a67f/scisalt/matplotlib/setup_axes.py#L8-L57
def setup_axes(rows=1, cols=1, figsize=(8, 6), expand=True, tight_layout=None, **kwargs): """ Sets up a figure of size *figsize* with a number of rows (*rows*) and columns (*cols*). \*\*kwargs passed through to :meth:`matplotlib.figure.Figure.add_subplot`. .. versionadded:: 1.2 Parameters ---------- rows : int Number of rows to create. cols : int Number of columns to create. figsize : tuple Size of figure to create. expand : bool Make the entire figure with size `figsize`. Returns ------- fig : :class:`matplotlib.figure.Figure` The figure. axes : :class:`numpy.ndarray` An array of all of the axes. (Unless there's only one axis, in which case it returns an object instance :class:`matplotlib.axis.Axis`.) """ if expand: figsize = (figsize[0]*cols, figsize[1]*rows) figargs = {} if isinstance(tight_layout, dict): figargs["tight_layout"] = tight_layout elif tight_layout == "pdf": figargs["tight_layout"] = {"rect": (0, 0, 1, 0.95)} dpi = kwargs.pop('dpi', None) fig, gs = _setup_figure(rows=rows, cols=cols, figsize=figsize, dpi=dpi, **figargs) axes = _np.empty(shape=(rows, cols), dtype=object) for i in range(rows): for j in range(cols): axes[i, j] = fig.add_subplot(gs[i, j], **kwargs) if axes.shape == (1, 1): return fig, axes[0, 0] else: return fig, axes
[ "def", "setup_axes", "(", "rows", "=", "1", ",", "cols", "=", "1", ",", "figsize", "=", "(", "8", ",", "6", ")", ",", "expand", "=", "True", ",", "tight_layout", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "expand", ":", "figsize", "=...
Sets up a figure of size *figsize* with a number of rows (*rows*) and columns (*cols*). \*\*kwargs passed through to :meth:`matplotlib.figure.Figure.add_subplot`. .. versionadded:: 1.2 Parameters ---------- rows : int Number of rows to create. cols : int Number of columns to create. figsize : tuple Size of figure to create. expand : bool Make the entire figure with size `figsize`. Returns ------- fig : :class:`matplotlib.figure.Figure` The figure. axes : :class:`numpy.ndarray` An array of all of the axes. (Unless there's only one axis, in which case it returns an object instance :class:`matplotlib.axis.Axis`.)
[ "Sets", "up", "a", "figure", "of", "size", "*", "figsize", "*", "with", "a", "number", "of", "rows", "(", "*", "rows", "*", ")", "and", "columns", "(", "*", "cols", "*", ")", ".", "\\", "*", "\\", "*", "kwargs", "passed", "through", "to", ":", ...
python
valid
28.74
mcocdawc/chemcoord
src/chemcoord/cartesian_coordinates/_cartesian_class_get_zmat.py
https://github.com/mcocdawc/chemcoord/blob/95561ce387c142227c38fb14a1d182179aef8f5f/src/chemcoord/cartesian_coordinates/_cartesian_class_get_zmat.py#L339-L356
def check_dihedral(self, construction_table): """Checks, if the dihedral defining atom is colinear. Checks for each index starting from the third row of the ``construction_table``, if the reference atoms are colinear. Args: construction_table (pd.DataFrame): Returns: list: A list of problematic indices. """ c_table = construction_table angles = self.get_angle_degrees(c_table.iloc[3:, :].values) problem_index = np.nonzero((175 < angles) | (angles < 5))[0] rename = dict(enumerate(c_table.index[3:])) problem_index = [rename[i] for i in problem_index] return problem_index
[ "def", "check_dihedral", "(", "self", ",", "construction_table", ")", ":", "c_table", "=", "construction_table", "angles", "=", "self", ".", "get_angle_degrees", "(", "c_table", ".", "iloc", "[", "3", ":", ",", ":", "]", ".", "values", ")", "problem_index", ...
Checks, if the dihedral defining atom is colinear. Checks for each index starting from the third row of the ``construction_table``, if the reference atoms are colinear. Args: construction_table (pd.DataFrame): Returns: list: A list of problematic indices.
[ "Checks", "if", "the", "dihedral", "defining", "atom", "is", "colinear", "." ]
python
train
37.777778
sendgrid/sendgrid-python
sendgrid/helpers/mail/mail.py
https://github.com/sendgrid/sendgrid-python/blob/266c2abde7a35dfcce263e06bedc6a0bbdebeac9/sendgrid/helpers/mail/mail.py#L195-L204
def add_personalization(self, personalization, index=0): """Add a Personaliztion object :param personalizations: Add a Personalization object :type personalizations: Personalization :param index: The index where to add the Personalization :type index: int """ self._personalizations = self._ensure_append( personalization, self._personalizations, index)
[ "def", "add_personalization", "(", "self", ",", "personalization", ",", "index", "=", "0", ")", ":", "self", ".", "_personalizations", "=", "self", ".", "_ensure_append", "(", "personalization", ",", "self", ".", "_personalizations", ",", "index", ")" ]
Add a Personaliztion object :param personalizations: Add a Personalization object :type personalizations: Personalization :param index: The index where to add the Personalization :type index: int
[ "Add", "a", "Personaliztion", "object" ]
python
train
41.3
necaris/python3-openid
openid/consumer/discover.py
https://github.com/necaris/python3-openid/blob/4911bbc196dfd6f9eda7155df9903d668720ecbf/openid/consumer/discover.py#L290-L298
def normalizeURL(url): """Normalize a URL, converting normalization failures to DiscoveryFailure""" try: normalized = urinorm.urinorm(url) except ValueError as why: raise DiscoveryFailure('Normalizing identifier: %s' % (why, ), None) else: return urllib.parse.urldefrag(normalized)[0]
[ "def", "normalizeURL", "(", "url", ")", ":", "try", ":", "normalized", "=", "urinorm", ".", "urinorm", "(", "url", ")", "except", "ValueError", "as", "why", ":", "raise", "DiscoveryFailure", "(", "'Normalizing identifier: %s'", "%", "(", "why", ",", ")", "...
Normalize a URL, converting normalization failures to DiscoveryFailure
[ "Normalize", "a", "URL", "converting", "normalization", "failures", "to", "DiscoveryFailure" ]
python
train
35.555556
GeorgeArgyros/symautomata
symautomata/pythondfa.py
https://github.com/GeorgeArgyros/symautomata/blob/f5d66533573b27e155bec3f36b8c00b8e3937cb3/symautomata/pythondfa.py#L389-L400
def symmetric_difference(self, other): """Constructs an unminimized DFA recognizing the symmetric difference of the languages of two given DFAs. Args: other (DFA): The other DFA that will be used for the symmetric difference operation Returns: DFA: The resulting DFA """ operation = bool.__xor__ self.cross_product(other, operation) return self
[ "def", "symmetric_difference", "(", "self", ",", "other", ")", ":", "operation", "=", "bool", ".", "__xor__", "self", ".", "cross_product", "(", "other", ",", "operation", ")", "return", "self" ]
Constructs an unminimized DFA recognizing the symmetric difference of the languages of two given DFAs. Args: other (DFA): The other DFA that will be used for the symmetric difference operation Returns: DFA: The resulting DFA
[ "Constructs", "an", "unminimized", "DFA", "recognizing", "the", "symmetric", "difference", "of", "the", "languages", "of", "two", "given", "DFAs", ".", "Args", ":", "other", "(", "DFA", ")", ":", "The", "other", "DFA", "that", "will", "be", "used", "for", ...
python
train
37.25
tensorflow/tensor2tensor
tensor2tensor/rl/dopamine_connector.py
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/rl/dopamine_connector.py#L450-L468
def get_create_batch_env_fun(batch_env_fn, time_limit): """Factory for dopamine environment initialization function. Args: batch_env_fn: function(in_graph: bool) -> batch environment. time_limit: time steps limit for environment. Returns: function (with optional, unused parameters) initializing environment. """ def create_env_fun(game_name=None, sticky_actions=None): del game_name, sticky_actions batch_env = batch_env_fn(in_graph=False) batch_env = ResizeBatchObservation(batch_env) # pylint: disable=redefined-variable-type batch_env = DopamineBatchEnv(batch_env, max_episode_steps=time_limit) return batch_env return create_env_fun
[ "def", "get_create_batch_env_fun", "(", "batch_env_fn", ",", "time_limit", ")", ":", "def", "create_env_fun", "(", "game_name", "=", "None", ",", "sticky_actions", "=", "None", ")", ":", "del", "game_name", ",", "sticky_actions", "batch_env", "=", "batch_env_fn", ...
Factory for dopamine environment initialization function. Args: batch_env_fn: function(in_graph: bool) -> batch environment. time_limit: time steps limit for environment. Returns: function (with optional, unused parameters) initializing environment.
[ "Factory", "for", "dopamine", "environment", "initialization", "function", "." ]
python
train
35.157895
mozilla-iot/webthing-python
webthing/thing.py
https://github.com/mozilla-iot/webthing-python/blob/65d467c89ed79d0bbc42b8b3c8f9e5a320edd237/webthing/thing.py#L412-L421
def remove_event_subscriber(self, name, ws): """ Remove a websocket subscriber from an event. name -- name of the event ws -- the websocket """ if name in self.available_events and \ ws in self.available_events[name]['subscribers']: self.available_events[name]['subscribers'].remove(ws)
[ "def", "remove_event_subscriber", "(", "self", ",", "name", ",", "ws", ")", ":", "if", "name", "in", "self", ".", "available_events", "and", "ws", "in", "self", ".", "available_events", "[", "name", "]", "[", "'subscribers'", "]", ":", "self", ".", "avai...
Remove a websocket subscriber from an event. name -- name of the event ws -- the websocket
[ "Remove", "a", "websocket", "subscriber", "from", "an", "event", "." ]
python
test
35.4
eerimoq/bincopy
bincopy.py
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L504-L520
def chunks(self, size=32, alignment=1): """Iterate over all segments and return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data. """ if (size % alignment) != 0: raise Error( 'size {} is not a multiple of alignment {}'.format( size, alignment)) for segment in self: for chunk in segment.chunks(size, alignment): yield chunk
[ "def", "chunks", "(", "self", ",", "size", "=", "32", ",", "alignment", "=", "1", ")", ":", "if", "(", "size", "%", "alignment", ")", "!=", "0", ":", "raise", "Error", "(", "'size {} is not a multiple of alignment {}'", ".", "format", "(", "size", ",", ...
Iterate over all segments and return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data.
[ "Iterate", "over", "all", "segments", "and", "return", "chunks", "of", "the", "data", "aligned", "as", "given", "by", "alignment", ".", "size", "must", "be", "a", "multiple", "of", "alignment", ".", "Each", "chunk", "is", "returned", "as", "a", "named", ...
python
train
33.823529
bitesofcode/projexui
projexui/widgets/xorbtreewidget/xorbtreewidget.py
https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbtreewidget/xorbtreewidget.py#L2049-L2062
def setRecords(self, records): """ Manually sets the list of records that will be displayed in this tree. This is a shortcut method to creating a RecordSet with a list of records and assigning it to the tree. :param records | [<orb.Table>, ..] """ self._searchTerms = '' if not isinstance(records, RecordSet): records = RecordSet(records) self.setRecordSet(records)
[ "def", "setRecords", "(", "self", ",", "records", ")", ":", "self", ".", "_searchTerms", "=", "''", "if", "not", "isinstance", "(", "records", ",", "RecordSet", ")", ":", "records", "=", "RecordSet", "(", "records", ")", "self", ".", "setRecordSet", "(",...
Manually sets the list of records that will be displayed in this tree. This is a shortcut method to creating a RecordSet with a list of records and assigning it to the tree. :param records | [<orb.Table>, ..]
[ "Manually", "sets", "the", "list", "of", "records", "that", "will", "be", "displayed", "in", "this", "tree", ".", "This", "is", "a", "shortcut", "method", "to", "creating", "a", "RecordSet", "with", "a", "list", "of", "records", "and", "assigning", "it", ...
python
train
34.357143
bitesofcode/projexui
projexui/widgets/xlogrecordwidget/xlogrecordwidget.py
https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xlogrecordwidget/xlogrecordwidget.py#L298-L319
def restoreXml(self, xml): """ Saves the logging settings for this widget to XML format. :param xml | <xml.etree.ElementTree.Element> """ self.uiFilterTXT.setText(xml.get('filter', '')) xlevels = xml.find('levels') xloggerlevels = xml.find('logger_levels') xtree = xml.find('tree') if xlevels is not None and xlevels.text: self.setActiveLevels(map(int, xlevels.text.split(','))) if xloggerlevels is not None and xloggerlevels.text: for key in xloggerlevels.text.split(','): logger, lvl = key.split(':') lvl = int(lvl) self.setLoggerLevel(logger, lvl) if xtree is not None: self.uiRecordTREE.restoreXml(xtree)
[ "def", "restoreXml", "(", "self", ",", "xml", ")", ":", "self", ".", "uiFilterTXT", ".", "setText", "(", "xml", ".", "get", "(", "'filter'", ",", "''", ")", ")", "xlevels", "=", "xml", ".", "find", "(", "'levels'", ")", "xloggerlevels", "=", "xml", ...
Saves the logging settings for this widget to XML format. :param xml | <xml.etree.ElementTree.Element>
[ "Saves", "the", "logging", "settings", "for", "this", "widget", "to", "XML", "format", ".", ":", "param", "xml", "|", "<xml", ".", "etree", ".", "ElementTree", ".", "Element", ">" ]
python
train
37.318182
yahoo/serviceping
serviceping/network.py
https://github.com/yahoo/serviceping/blob/1f9df5ee5b3cba466426b1164262278472ba4977/serviceping/network.py#L25-L124
def scan(host, port=80, url=None, https=False, timeout=1, max_size=65535): """ Scan a network port Parameters ---------- host : str Host or ip address to scan port : int, optional Port to scan, default=80 url : str, optional URL to perform get request to on the host and port specified https : bool, optional Perform ssl connection on the socket, default=False timeout : float Timeout for network operations, default=1 Returns ------- dict Result dictionary that contains the following keys: host - The host or IP address that was scanned port - The port number that was scanned state - The state of the port, will be either "open" or "closed" durations - An ordered dictionary with floating point value of the time elapsed for each connection operation Raises ------ ScanFailed - The scan operation failed """ starts = OrderedDict() ends = OrderedDict() port = int(port) result = dict( host=host, port=port, state='closed', durations=OrderedDict() ) if url: timeout = 1 result['code'] = None starts['all'] = starts['dns'] = datetime.datetime.now() # DNS Lookup try: hostip = socket.gethostbyname(host) result['ip'] = hostip ends['dns'] = datetime.datetime.now() except socket.gaierror: raise ScanFailed('DNS Lookup failed', result=result) # TCP Connect starts['connect'] = datetime.datetime.now() network_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) network_socket.settimeout(timeout) result_connection = network_socket.connect_ex((hostip, port)) ends['connect'] = datetime.datetime.now() # SSL if https: starts['ssl'] = datetime.datetime.now() try: network_socket = ssl.wrap_socket(network_socket) except socket.timeout: raise ScanFailed('SSL socket timeout', result=result) ends['ssl'] = datetime.datetime.now() # Get request if result_connection == 0 and url: starts['request'] = datetime.datetime.now() network_socket.send( "GET {0} HTTP/1.0\r\nHost: {1}\r\n\r\n".format( url, host ).encode('ascii')) if max_size: data = network_socket.recv(max_size) else: data = network_socket.recv() result['length'] = len(data) data = data.decode('ascii', errors='ignore') result['response'] = (data) try: result['code'] = int(data.split('\n')[0].split()[1]) except IndexError: pass ends['request'] = datetime.datetime.now() network_socket.close() # Calculate durations ends['all'] = datetime.datetime.now() for duration in starts.keys(): if duration in ends.keys(): result['durations'][duration] = ends[duration] - starts[duration] if result_connection == 0: result['state'] = 'open' return result
[ "def", "scan", "(", "host", ",", "port", "=", "80", ",", "url", "=", "None", ",", "https", "=", "False", ",", "timeout", "=", "1", ",", "max_size", "=", "65535", ")", ":", "starts", "=", "OrderedDict", "(", ")", "ends", "=", "OrderedDict", "(", "...
Scan a network port Parameters ---------- host : str Host or ip address to scan port : int, optional Port to scan, default=80 url : str, optional URL to perform get request to on the host and port specified https : bool, optional Perform ssl connection on the socket, default=False timeout : float Timeout for network operations, default=1 Returns ------- dict Result dictionary that contains the following keys: host - The host or IP address that was scanned port - The port number that was scanned state - The state of the port, will be either "open" or "closed" durations - An ordered dictionary with floating point value of the time elapsed for each connection operation Raises ------ ScanFailed - The scan operation failed
[ "Scan", "a", "network", "port" ]
python
train
30.02
sibirrer/lenstronomy
lenstronomy/SimulationAPI/data_api.py
https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/SimulationAPI/data_api.py#L41-L60
def psf_class(self): """ creates instance of PSF() class based on knowledge of the observations For the full possibility of how to create such an instance, see the PSF() class documentation :return: instance of PSF() class """ if self._psf_type == 'GAUSSIAN': psf_type = "GAUSSIAN" fwhm = self._seeing kwargs_psf = {'psf_type': psf_type, 'fwhm': fwhm} elif self._psf_type == 'PIXEL': if self._psf_model is not None: kwargs_psf = {'psf_type': "PIXEL", 'kernel_point_source': self._psf_model} else: raise ValueError("You need to create the class instance with a psf_model!") else: raise ValueError("psf_type %s not supported!" % self._psf_type) psf_class = PSF(kwargs_psf) return psf_class
[ "def", "psf_class", "(", "self", ")", ":", "if", "self", ".", "_psf_type", "==", "'GAUSSIAN'", ":", "psf_type", "=", "\"GAUSSIAN\"", "fwhm", "=", "self", ".", "_seeing", "kwargs_psf", "=", "{", "'psf_type'", ":", "psf_type", ",", "'fwhm'", ":", "fwhm", "...
creates instance of PSF() class based on knowledge of the observations For the full possibility of how to create such an instance, see the PSF() class documentation :return: instance of PSF() class
[ "creates", "instance", "of", "PSF", "()", "class", "based", "on", "knowledge", "of", "the", "observations", "For", "the", "full", "possibility", "of", "how", "to", "create", "such", "an", "instance", "see", "the", "PSF", "()", "class", "documentation" ]
python
train
42.65
ianmiell/shutit
shutit_pexpect.py
https://github.com/ianmiell/shutit/blob/19cd64cdfb23515b106b40213dccff4101617076/shutit_pexpect.py#L585-L627
def expect(self, expect, searchwindowsize=None, maxread=None, timeout=None, iteration_n=1): """Handle child expects, with EOF and TIMEOUT handled iteration_n - Number of times this expect has been called for the send. If 1, (the default) then it gets added to the pane of output (if applicable to this run) """ if isinstance(expect, str): expect = [expect] if searchwindowsize != None: old_searchwindowsize = self.pexpect_child.searchwindowsize self.pexpect_child.searchwindowsize = searchwindowsize if maxread != None: old_maxread = self.pexpect_child.maxread self.pexpect_child.maxread = maxread res = self.pexpect_child.expect(expect + [pexpect.TIMEOUT] + [pexpect.EOF], timeout=timeout) if searchwindowsize != None: self.pexpect_child.searchwindowsize = old_searchwindowsize if maxread != None: self.pexpect_child.maxread = old_maxread # Add to session lines only if pane manager exists. if shutit_global.shutit_global_object.pane_manager and iteration_n == 1: time_seen = time.time() lines_to_add = [] if isinstance(self.pexpect_child.before, (str,unicode)): for line_str in self.pexpect_child.before.split('\n'): lines_to_add.append(line_str) if isinstance(self.pexpect_child.after, (str,unicode)): for line_str in self.pexpect_child.after.split('\n'): lines_to_add.append(line_str) # If first or last line is empty, remove it. #if len(lines_to_add) > 0 and lines_to_add[1] == '': # lines_to_add = lines_to_add[1:] #if len(lines_to_add) > 0 and lines_to_add[-1] == '': # lines_to_add = lines_to_add[:-1] for line in lines_to_add: self.session_output_lines.append(SessionPaneLine(line_str=line, time_seen=time_seen, line_type='output')) return res
[ "def", "expect", "(", "self", ",", "expect", ",", "searchwindowsize", "=", "None", ",", "maxread", "=", "None", ",", "timeout", "=", "None", ",", "iteration_n", "=", "1", ")", ":", "if", "isinstance", "(", "expect", ",", "str", ")", ":", "expect", "=...
Handle child expects, with EOF and TIMEOUT handled iteration_n - Number of times this expect has been called for the send. If 1, (the default) then it gets added to the pane of output (if applicable to this run)
[ "Handle", "child", "expects", "with", "EOF", "and", "TIMEOUT", "handled" ]
python
train
41.860465
bspaans/python-mingus
mingus/midi/midi_track.py
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_track.py#L90-L110
def play_Bar(self, bar): """Convert a Bar object to MIDI events and write them to the track_data.""" self.set_deltatime(self.delay) self.delay = 0 self.set_meter(bar.meter) self.set_deltatime(0) self.set_key(bar.key) for x in bar: tick = int(round((1.0 / x[1]) * 288)) if x[2] is None or len(x[2]) == 0: self.delay += tick else: self.set_deltatime(self.delay) self.delay = 0 if hasattr(x[2], 'bpm'): self.set_deltatime(0) self.set_tempo(x[2].bpm) self.play_NoteContainer(x[2]) self.set_deltatime(self.int_to_varbyte(tick)) self.stop_NoteContainer(x[2])
[ "def", "play_Bar", "(", "self", ",", "bar", ")", ":", "self", ".", "set_deltatime", "(", "self", ".", "delay", ")", "self", ".", "delay", "=", "0", "self", ".", "set_meter", "(", "bar", ".", "meter", ")", "self", ".", "set_deltatime", "(", "0", ")"...
Convert a Bar object to MIDI events and write them to the track_data.
[ "Convert", "a", "Bar", "object", "to", "MIDI", "events", "and", "write", "them", "to", "the", "track_data", "." ]
python
train
37.333333
axialmarket/fsq
fsq/done.py
https://github.com/axialmarket/fsq/blob/43b84c292cb8a187599d86753b947cf73248f989/fsq/done.py#L74-L88
def success(item): '''Successful finish''' try: # mv to done trg_queue = item.queue os.rename(fsq_path.item(trg_queue, item.id, host=item.host), os.path.join(fsq_path.done(trg_queue, host=item.host), item.id)) except AttributeError, e: # DuckType TypeError'ing raise TypeError(u'item must be an FSQWorkItem, not:'\ u' {0}'.format(item.__class__.__name__)) except (OSError, IOError, ), e: raise FSQDoneError(e.errno, u'cannot mv item to done: {0}:'\ u' {1}'.format(item.id, wrap_io_os_err(e)))
[ "def", "success", "(", "item", ")", ":", "try", ":", "# mv to done", "trg_queue", "=", "item", ".", "queue", "os", ".", "rename", "(", "fsq_path", ".", "item", "(", "trg_queue", ",", "item", ".", "id", ",", "host", "=", "item", ".", "host", ")", ",...
Successful finish
[ "Successful", "finish" ]
python
train
42.8
camsci/meteor-pi
src/pythonModules/meteorpi_db/meteorpi_db/__init__.py
https://github.com/camsci/meteor-pi/blob/7b01527650bd1b2b76d6f364e8122e25b8812c8d/src/pythonModules/meteorpi_db/meteorpi_db/__init__.py#L1023-L1037
def get_export_configuration(self, config_id): """ Retrieve the ExportConfiguration with the given ID :param string config_id: ID for which to search :return: a :class:`meteorpi_model.ExportConfiguration` or None, or no match was found. """ sql = ( 'SELECT uid, exportConfigId, exportType, searchString, targetURL, ' 'targetUser, targetPassword, exportName, description, active ' 'FROM archive_exportConfig WHERE exportConfigId = %s') return first_from_generator( self.generators.export_configuration_generator(sql=sql, sql_args=(config_id,)))
[ "def", "get_export_configuration", "(", "self", ",", "config_id", ")", ":", "sql", "=", "(", "'SELECT uid, exportConfigId, exportType, searchString, targetURL, '", "'targetUser, targetPassword, exportName, description, active '", "'FROM archive_exportConfig WHERE exportConfigId = %s'", "...
Retrieve the ExportConfiguration with the given ID :param string config_id: ID for which to search :return: a :class:`meteorpi_model.ExportConfiguration` or None, or no match was found.
[ "Retrieve", "the", "ExportConfiguration", "with", "the", "given", "ID" ]
python
train
44.133333
apache/airflow
airflow/jobs.py
https://github.com/apache/airflow/blob/b69c686ad8a0c89b9136bb4b31767257eb7b2597/airflow/jobs.py#L419-L430
def start(self): """ Launch the process and start processing the DAG. """ self._process = DagFileProcessor._launch_process( self._result_queue, self.file_path, self._pickle_dags, self._dag_id_white_list, "DagFileProcessor{}".format(self._instance_id), self._zombies) self._start_time = timezone.utcnow()
[ "def", "start", "(", "self", ")", ":", "self", ".", "_process", "=", "DagFileProcessor", ".", "_launch_process", "(", "self", ".", "_result_queue", ",", "self", ".", "file_path", ",", "self", ".", "_pickle_dags", ",", "self", ".", "_dag_id_white_list", ",", ...
Launch the process and start processing the DAG.
[ "Launch", "the", "process", "and", "start", "processing", "the", "DAG", "." ]
python
test
33.666667
JonathanRaiman/pytreebank
pytreebank/parse.py
https://github.com/JonathanRaiman/pytreebank/blob/7b4c671d3dff661cc3677e54db817e50c5a1c666/pytreebank/parse.py#L163-L187
def load_sst(path=None, url='http://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip'): """ Download and read in the Stanford Sentiment Treebank dataset into a dictionary with a 'train', 'dev', and 'test' keys. The dictionary keys point to lists of LabeledTrees. Arguments: ---------- path : str, (optional defaults to ~/stanford_sentiment_treebank), directory where the corpus should be downloaded (and imported from). url : str, where the corpus should be downloaded from (defaults to nlp.stanford.edu address). Returns: -------- dict : loaded dataset """ if path is None: # find a good temporary path path = os.path.expanduser("~/stanford_sentiment_treebank/") makedirs(path, exist_ok=True) fnames = download_sst(path, url) return {key: import_tree_corpus(value) for key, value in fnames.items()}
[ "def", "load_sst", "(", "path", "=", "None", ",", "url", "=", "'http://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip'", ")", ":", "if", "path", "is", "None", ":", "# find a good temporary path", "path", "=", "os", ".", "path", ".", "expanduser", "(", "\"~/s...
Download and read in the Stanford Sentiment Treebank dataset into a dictionary with a 'train', 'dev', and 'test' keys. The dictionary keys point to lists of LabeledTrees. Arguments: ---------- path : str, (optional defaults to ~/stanford_sentiment_treebank), directory where the corpus should be downloaded (and imported from). url : str, where the corpus should be downloaded from (defaults to nlp.stanford.edu address). Returns: -------- dict : loaded dataset
[ "Download", "and", "read", "in", "the", "Stanford", "Sentiment", "Treebank", "dataset", "into", "a", "dictionary", "with", "a", "train", "dev", "and", "test", "keys", ".", "The", "dictionary", "keys", "point", "to", "lists", "of", "LabeledTrees", "." ]
python
train
37.04
ColtonProvias/sqlalchemy-jsonapi
sqlalchemy_jsonapi/serializer.py
https://github.com/ColtonProvias/sqlalchemy-jsonapi/blob/40f8b5970d44935b27091c2bf3224482d23311bb/sqlalchemy_jsonapi/serializer.py#L349-L356
def _render_short_instance(self, instance): """ For those very short versions of resources, we have this. :param instance: The instance to render """ check_permission(instance, None, Permissions.VIEW) return {'type': instance.__jsonapi_type__, 'id': instance.id}
[ "def", "_render_short_instance", "(", "self", ",", "instance", ")", ":", "check_permission", "(", "instance", ",", "None", ",", "Permissions", ".", "VIEW", ")", "return", "{", "'type'", ":", "instance", ".", "__jsonapi_type__", ",", "'id'", ":", "instance", ...
For those very short versions of resources, we have this. :param instance: The instance to render
[ "For", "those", "very", "short", "versions", "of", "resources", "we", "have", "this", "." ]
python
train
38
Dallinger/Dallinger
dallinger/recruiters.py
https://github.com/Dallinger/Dallinger/blob/76ca8217c709989c116d0ebd8fca37bd22f591af/dallinger/recruiters.py#L936-L972
def from_config(config): """Return a Recruiter instance based on the configuration. Default is HotAirRecruiter in debug mode (unless we're using the bot recruiter, which can be used in debug mode) and the MTurkRecruiter in other modes. """ debug_mode = config.get("mode") == "debug" name = config.get("recruiter", None) recruiter = None # Special case 1: Don't use a configured recruiter in replay mode if config.get("replay"): return HotAirRecruiter() if name is not None: recruiter = by_name(name) # Special case 2: may run BotRecruiter or MultiRecruiter in any mode # (debug or not), so it trumps everything else: if isinstance(recruiter, (BotRecruiter, MultiRecruiter)): return recruiter # Special case 3: if we're not using bots and we're in debug mode, # ignore any configured recruiter: if debug_mode: return HotAirRecruiter() # Configured recruiter: if recruiter is not None: return recruiter if name and recruiter is None: raise NotImplementedError("No such recruiter {}".format(name)) # Default if we're not in debug mode: return MTurkRecruiter()
[ "def", "from_config", "(", "config", ")", ":", "debug_mode", "=", "config", ".", "get", "(", "\"mode\"", ")", "==", "\"debug\"", "name", "=", "config", ".", "get", "(", "\"recruiter\"", ",", "None", ")", "recruiter", "=", "None", "# Special case 1: Don't use...
Return a Recruiter instance based on the configuration. Default is HotAirRecruiter in debug mode (unless we're using the bot recruiter, which can be used in debug mode) and the MTurkRecruiter in other modes.
[ "Return", "a", "Recruiter", "instance", "based", "on", "the", "configuration", "." ]
python
train
31.891892
kwikteam/phy
phy/electrode/mea.py
https://github.com/kwikteam/phy/blob/7e9313dc364304b7d2bd03b92938347343703003/phy/electrode/mea.py#L53-L57
def _probe_positions(probe, group): """Return the positions of a probe channel group.""" positions = probe['channel_groups'][group]['geometry'] channels = _probe_channels(probe, group) return np.array([positions[channel] for channel in channels])
[ "def", "_probe_positions", "(", "probe", ",", "group", ")", ":", "positions", "=", "probe", "[", "'channel_groups'", "]", "[", "group", "]", "[", "'geometry'", "]", "channels", "=", "_probe_channels", "(", "probe", ",", "group", ")", "return", "np", ".", ...
Return the positions of a probe channel group.
[ "Return", "the", "positions", "of", "a", "probe", "channel", "group", "." ]
python
train
51.6
dj-stripe/dj-stripe
djstripe/models/core.py
https://github.com/dj-stripe/dj-stripe/blob/a5308a3808cd6e2baba49482f7a699f3a8992518/djstripe/models/core.py#L597-L673
def charge( self, amount, currency=None, application_fee=None, capture=None, description=None, destination=None, metadata=None, shipping=None, source=None, statement_descriptor=None, idempotency_key=None, ): """ Creates a charge for this customer. Parameters not implemented: * **receipt_email** - Since this is a charge on a customer, the customer's email address is used. :param amount: The amount to charge. :type amount: Decimal. Precision is 2; anything more will be ignored. :param currency: 3-letter ISO code for currency :type currency: string :param application_fee: A fee that will be applied to the charge and transfered to the platform owner's account. :type application_fee: Decimal. Precision is 2; anything more will be ignored. :param capture: Whether or not to immediately capture the charge. When false, the charge issues an authorization (or pre-authorization), and will need to be captured later. Uncaptured charges expire in 7 days. Default is True :type capture: bool :param description: An arbitrary string. :type description: string :param destination: An account to make the charge on behalf of. :type destination: Account :param metadata: A set of key/value pairs useful for storing additional information. :type metadata: dict :param shipping: Shipping information for the charge. :type shipping: dict :param source: The source to use for this charge. Must be a source attributed to this customer. If None, the customer's default source is used. Can be either the id of the source or the source object itself. :type source: string, Source :param statement_descriptor: An arbitrary string to be displayed on the customer's credit card statement. :type statement_descriptor: string """ if not isinstance(amount, decimal.Decimal): raise ValueError("You must supply a decimal value representing dollars.") # TODO: better default detection (should charge in customer default) currency = currency or "usd" # Convert Source to id if source and isinstance(source, StripeModel): source = source.id stripe_charge = Charge._api_create( amount=int(amount * 100), # Convert dollars into cents currency=currency, application_fee=int(application_fee * 100) if application_fee else None, # Convert dollars into cents capture=capture, description=description, destination=destination, metadata=metadata, shipping=shipping, customer=self.id, source=source, statement_descriptor=statement_descriptor, idempotency_key=idempotency_key, ) return Charge.sync_from_stripe_data(stripe_charge)
[ "def", "charge", "(", "self", ",", "amount", ",", "currency", "=", "None", ",", "application_fee", "=", "None", ",", "capture", "=", "None", ",", "description", "=", "None", ",", "destination", "=", "None", ",", "metadata", "=", "None", ",", "shipping", ...
Creates a charge for this customer. Parameters not implemented: * **receipt_email** - Since this is a charge on a customer, the customer's email address is used. :param amount: The amount to charge. :type amount: Decimal. Precision is 2; anything more will be ignored. :param currency: 3-letter ISO code for currency :type currency: string :param application_fee: A fee that will be applied to the charge and transfered to the platform owner's account. :type application_fee: Decimal. Precision is 2; anything more will be ignored. :param capture: Whether or not to immediately capture the charge. When false, the charge issues an authorization (or pre-authorization), and will need to be captured later. Uncaptured charges expire in 7 days. Default is True :type capture: bool :param description: An arbitrary string. :type description: string :param destination: An account to make the charge on behalf of. :type destination: Account :param metadata: A set of key/value pairs useful for storing additional information. :type metadata: dict :param shipping: Shipping information for the charge. :type shipping: dict :param source: The source to use for this charge. Must be a source attributed to this customer. If None, the customer's default source is used. Can be either the id of the source or the source object itself. :type source: string, Source :param statement_descriptor: An arbitrary string to be displayed on the customer's credit card statement. :type statement_descriptor: string
[ "Creates", "a", "charge", "for", "this", "customer", "." ]
python
train
33.545455
quantmind/pulsar
pulsar/apps/wsgi/content.py
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/apps/wsgi/content.py#L330-L346
def attr(self, *args): '''Add the specific attribute to the attribute dictionary with key ``name`` and value ``value`` and return ``self``.''' attr = self._attr if not args: return attr or {} result, adding = self._attrdata('attr', *args) if adding: for key, value in result.items(): if DATARE.match(key): self.data(key[5:], value) else: if attr is None: self._extra['attr'] = attr = {} attr[key] = value result = self return result
[ "def", "attr", "(", "self", ",", "*", "args", ")", ":", "attr", "=", "self", ".", "_attr", "if", "not", "args", ":", "return", "attr", "or", "{", "}", "result", ",", "adding", "=", "self", ".", "_attrdata", "(", "'attr'", ",", "*", "args", ")", ...
Add the specific attribute to the attribute dictionary with key ``name`` and value ``value`` and return ``self``.
[ "Add", "the", "specific", "attribute", "to", "the", "attribute", "dictionary", "with", "key", "name", "and", "value", "value", "and", "return", "self", "." ]
python
train
36.705882
bskinn/opan
opan/vpt2/repo.py
https://github.com/bskinn/opan/blob/0b1b21662df6abc971407a9386db21a8796fbfe5/opan/vpt2/repo.py#L437-L456
def has_param(self, param): """ .. todo:: has_param docstring """ # Imports from ..error import RepoError # Try to get the param; pass along all errors, except 'data' error # from RepoError retval = True try: self.get_param(param) except RepoError as RErr: if RErr.tc == RErr.DATA: retval = False ## end if ## end try # Should be good to return return retval
[ "def", "has_param", "(", "self", ",", "param", ")", ":", "# Imports", "from", ".", ".", "error", "import", "RepoError", "# Try to get the param; pass along all errors, except 'data' error", "# from RepoError", "retval", "=", "True", "try", ":", "self", ".", "get_para...
.. todo:: has_param docstring
[ "..", "todo", "::", "has_param", "docstring" ]
python
train
24.55
jaraco/irc
irc/client_aio.py
https://github.com/jaraco/irc/blob/571c1f448d5d5bb92bbe2605c33148bf6e698413/irc/client_aio.py#L160-L173
def process_data(self, new_data): """ handles incoming data from the `IrcProtocol` connection. Main data processing/routing is handled by the _process_line method, inherited from `ServerConnection` """ self.buffer.feed(new_data) # process each non-empty line after logging all lines for line in self.buffer: log.debug("FROM SERVER: %s", line) if not line: continue self._process_line(line)
[ "def", "process_data", "(", "self", ",", "new_data", ")", ":", "self", ".", "buffer", ".", "feed", "(", "new_data", ")", "# process each non-empty line after logging all lines", "for", "line", "in", "self", ".", "buffer", ":", "log", ".", "debug", "(", "\"FROM...
handles incoming data from the `IrcProtocol` connection. Main data processing/routing is handled by the _process_line method, inherited from `ServerConnection`
[ "handles", "incoming", "data", "from", "the", "IrcProtocol", "connection", ".", "Main", "data", "processing", "/", "routing", "is", "handled", "by", "the", "_process_line", "method", "inherited", "from", "ServerConnection" ]
python
train
35.214286
ihiji/version_utils
version_utils/rpm.py
https://github.com/ihiji/version_utils/blob/7f63d80faca8e76274b6e8dff7637cc7cb8d848c/version_utils/rpm.py#L356-L393
def _compare_blocks(block_a, block_b): """Compare two blocks of characters Compares two blocks of characters of the form returned by either the :any:`_pop_digits` or :any:`_pop_letters` function. Blocks should be character lists containing only digits or only letters. Both blocks should contain the same character type (digits or letters). The method of comparison mirrors the method used by RPM. If the blocks are digit blocks, any leading zeros are trimmed, and whichever block is longer is assumed to be larger. If the resultant blocks are the same length, or if the blocks are non-numeric, they are checked for string equality and considered equal if the string equality comparison returns True. If not, whichever evaluates as greater than the other (again in string comparison) is assumed to be larger. :param list block_a: an all numeric or all alphabetic character list :param list block_b: an all numeric or all alphabetic character list. Alphabetic or numeric character should match ``block_a`` :return: 1 (if ``a`` is newer), 0 (if versions are equal) or -1 (if ``b`` is newer) :rtype: int """ logger.debug('_compare_blocks(%s, %s)', block_a, block_b) if block_a[0].isdigit(): _trim_zeros(block_a, block_b) if len(block_a) != len(block_b): logger.debug('block lengths are not equal') return a_newer if len(block_a) > len(block_b) else b_newer if block_a == block_b: logger.debug('blocks are equal') return a_eq_b else: logger.debug('blocks are not equal') return a_newer if block_a > block_b else b_newer
[ "def", "_compare_blocks", "(", "block_a", ",", "block_b", ")", ":", "logger", ".", "debug", "(", "'_compare_blocks(%s, %s)'", ",", "block_a", ",", "block_b", ")", "if", "block_a", "[", "0", "]", ".", "isdigit", "(", ")", ":", "_trim_zeros", "(", "block_a",...
Compare two blocks of characters Compares two blocks of characters of the form returned by either the :any:`_pop_digits` or :any:`_pop_letters` function. Blocks should be character lists containing only digits or only letters. Both blocks should contain the same character type (digits or letters). The method of comparison mirrors the method used by RPM. If the blocks are digit blocks, any leading zeros are trimmed, and whichever block is longer is assumed to be larger. If the resultant blocks are the same length, or if the blocks are non-numeric, they are checked for string equality and considered equal if the string equality comparison returns True. If not, whichever evaluates as greater than the other (again in string comparison) is assumed to be larger. :param list block_a: an all numeric or all alphabetic character list :param list block_b: an all numeric or all alphabetic character list. Alphabetic or numeric character should match ``block_a`` :return: 1 (if ``a`` is newer), 0 (if versions are equal) or -1 (if ``b`` is newer) :rtype: int
[ "Compare", "two", "blocks", "of", "characters" ]
python
train
43.921053
astropy/regions
regions/io/core.py
https://github.com/astropy/regions/blob/452d962c417e4ff20d1268f99535c6ff89c83437/regions/io/core.py#L527-L547
def convert_coords(self): """ Process list of coordinates This mainly searches for tuple of coordinates in the coordinate list and creates a SkyCoord or PixCoord object from them if appropriate for a given region type. This involves again some coordinate transformation, so this step could be moved to the parsing process """ if self.coordsys in ['image', 'physical']: coords = self._convert_pix_coords() else: coords = self._convert_sky_coords() if self.region_type == 'line': coords = [coords[0][0], coords[0][1]] if self.region_type == 'text': coords.append(self.meta['text']) return coords
[ "def", "convert_coords", "(", "self", ")", ":", "if", "self", ".", "coordsys", "in", "[", "'image'", ",", "'physical'", "]", ":", "coords", "=", "self", ".", "_convert_pix_coords", "(", ")", "else", ":", "coords", "=", "self", ".", "_convert_sky_coords", ...
Process list of coordinates This mainly searches for tuple of coordinates in the coordinate list and creates a SkyCoord or PixCoord object from them if appropriate for a given region type. This involves again some coordinate transformation, so this step could be moved to the parsing process
[ "Process", "list", "of", "coordinates" ]
python
train
34.333333
numenta/nupic
src/nupic/database/connection.py
https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/database/connection.py#L340-L370
def release(self): """ Release the database connection and cursor The receiver of the Connection instance MUST call this method in order to reclaim resources """ self._logger.debug("Releasing: %r", self) # Discard self from set of outstanding instances if self._addedToInstanceSet: try: self._clsOutstandingInstances.remove(self) except: self._logger.exception( "Failed to remove self from _clsOutstandingInstances: %r;", self) raise self._releaser(dbConn=self.dbConn, cursor=self.cursor) self.__class__._clsNumOutstanding -= 1 assert self._clsNumOutstanding >= 0, \ "_clsNumOutstanding=%r" % (self._clsNumOutstanding,) self._releaser = None self.cursor = None self.dbConn = None self._creationTracebackString = None self._addedToInstanceSet = False self._logger = None return
[ "def", "release", "(", "self", ")", ":", "self", ".", "_logger", ".", "debug", "(", "\"Releasing: %r\"", ",", "self", ")", "# Discard self from set of outstanding instances", "if", "self", ".", "_addedToInstanceSet", ":", "try", ":", "self", ".", "_clsOutstandingI...
Release the database connection and cursor The receiver of the Connection instance MUST call this method in order to reclaim resources
[ "Release", "the", "database", "connection", "and", "cursor" ]
python
valid
28.322581
tcalmant/ipopo
pelix/rsa/__init__.py
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L1165-L1181
def get_string_plus_property_value(value): # type: (Any) -> Optional[List[str]] """ Converts a string or list of string into a list of strings :param value: A string or a list of strings :return: A list of strings or None """ if value: if isinstance(value, str): return [value] if isinstance(value, list): return value if isinstance(value, tuple): return list(value) return None
[ "def", "get_string_plus_property_value", "(", "value", ")", ":", "# type: (Any) -> Optional[List[str]]", "if", "value", ":", "if", "isinstance", "(", "value", ",", "str", ")", ":", "return", "[", "value", "]", "if", "isinstance", "(", "value", ",", "list", ")"...
Converts a string or list of string into a list of strings :param value: A string or a list of strings :return: A list of strings or None
[ "Converts", "a", "string", "or", "list", "of", "string", "into", "a", "list", "of", "strings" ]
python
train
26.823529
xoolive/traffic
traffic/data/adsb/opensky.py
https://github.com/xoolive/traffic/blob/d1a8878098f16759f6b6e0e8d8b8f32e34a680a8/traffic/data/adsb/opensky.py#L257-L270
def api_routes(self, callsign: str) -> Tuple[Airport, ...]: """Returns the route associated to a callsign.""" from .. import airports c = requests.get( f"https://opensky-network.org/api/routes?callsign={callsign}" ) if c.status_code == 404: raise ValueError("Unknown callsign") if c.status_code != 200: raise ValueError(c.content.decode()) json = c.json() return tuple(airports[a] for a in json["route"])
[ "def", "api_routes", "(", "self", ",", "callsign", ":", "str", ")", "->", "Tuple", "[", "Airport", ",", "...", "]", ":", "from", ".", ".", "import", "airports", "c", "=", "requests", ".", "get", "(", "f\"https://opensky-network.org/api/routes?callsign={callsig...
Returns the route associated to a callsign.
[ "Returns", "the", "route", "associated", "to", "a", "callsign", "." ]
python
train
35.214286
Shapeways/coyote_framework
coyote_framework/database/coyote_db.py
https://github.com/Shapeways/coyote_framework/blob/cb29899b984a21d56bf65d0b1d907073948fe16c/coyote_framework/database/coyote_db.py#L276-L293
def execute(*args, **kwargs): """Executes the sql statement, but does not commit. Returns the cursor to commit @return: DB and cursor instance following sql execution """ # Inspect the call stack for the originating call args = CoyoteDb.__add_query_comment(args[0]) db = CoyoteDb.__get_db_write_instance(target_database=kwargs.pop('target_database', None)) filtered_kwargs = {k: v for k, v in kwargs.iteritems() if k != 'target_database'} # Execute the query cursor = db.cursor() try: cursor.execute(*args, **filtered_kwargs) except OperationalError, e: raise OperationalError('{} when executing: {}'.format(e.args, args[0])) return db, cursor
[ "def", "execute", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Inspect the call stack for the originating call", "args", "=", "CoyoteDb", ".", "__add_query_comment", "(", "args", "[", "0", "]", ")", "db", "=", "CoyoteDb", ".", "__get_db_write_instance...
Executes the sql statement, but does not commit. Returns the cursor to commit @return: DB and cursor instance following sql execution
[ "Executes", "the", "sql", "statement", "but", "does", "not", "commit", ".", "Returns", "the", "cursor", "to", "commit" ]
python
train
41.611111
numenta/nupic
src/nupic/frameworks/opf/experiment_runner.py
https://github.com/numenta/nupic/blob/5922fafffdccc8812e72b3324965ad2f7d4bbdad/src/nupic/frameworks/opf/experiment_runner.py#L686-L751
def run(self): """Runs a single experiment task""" self.__logger.debug("run(): Starting task <%s>", self.__task['taskLabel']) # Set up the task # Create our main loop-control iterator if self.__cmdOptions.privateOptions['testMode']: numIters = 10 else: numIters = self.__task['iterationCount'] if numIters >= 0: iterTracker = iter(xrange(numIters)) else: iterTracker = iter(itertools.count()) # Initialize periodic activities periodic = PeriodicActivityMgr( requestedActivities=self._createPeriodicActivities()) # Reset sequence states in the model, so it starts looking for a new # sequence # TODO: should this be done in OPFTaskDriver.setup(), instead? Is it always # desired in Nupic? self.__model.resetSequenceStates() # Have Task Driver perform its initial setup activities, including setup # callbacks self.__taskDriver.setup() # Run it! while True: # Check controlling iterator first try: next(iterTracker) except StopIteration: break # Read next input record try: inputRecord = self.__datasetReader.next() except StopIteration: break # Process input record result = self.__taskDriver.handleInputRecord(inputRecord=inputRecord) if InferenceElement.encodings in result.inferences: result.inferences.pop(InferenceElement.encodings) self.__predictionLogger.writeRecord(result) # Run periodic activities periodic.tick() # Dump the experiment metrics at the end of the task self._getAndEmitExperimentMetrics(final=True) # Have Task Driver perform its final activities self.__taskDriver.finalize() # Reset sequence states in the model, so it starts looking for a new # sequence # TODO: should this be done in OPFTaskDriver.setup(), instead? Is it always # desired in Nupic? self.__model.resetSequenceStates()
[ "def", "run", "(", "self", ")", ":", "self", ".", "__logger", ".", "debug", "(", "\"run(): Starting task <%s>\"", ",", "self", ".", "__task", "[", "'taskLabel'", "]", ")", "# Set up the task", "# Create our main loop-control iterator", "if", "self", ".", "__cmdOpt...
Runs a single experiment task
[ "Runs", "a", "single", "experiment", "task" ]
python
valid
29.242424
ibis-project/ibis
ibis/pandas/udf.py
https://github.com/ibis-project/ibis/blob/1e39a5fd9ef088b45c155e8a5f541767ee8ef2e7/ibis/pandas/udf.py#L219-L237
def parameter_count(funcsig): """Get the number of positional-or-keyword or position-only parameters in a function signature. Parameters ---------- funcsig : inspect.Signature A UDF signature Returns ------- int The number of parameters """ return sum( param.kind in {param.POSITIONAL_OR_KEYWORD, param.POSITIONAL_ONLY} for param in funcsig.parameters.values() if param.default is Parameter.empty )
[ "def", "parameter_count", "(", "funcsig", ")", ":", "return", "sum", "(", "param", ".", "kind", "in", "{", "param", ".", "POSITIONAL_OR_KEYWORD", ",", "param", ".", "POSITIONAL_ONLY", "}", "for", "param", "in", "funcsig", ".", "parameters", ".", "values", ...
Get the number of positional-or-keyword or position-only parameters in a function signature. Parameters ---------- funcsig : inspect.Signature A UDF signature Returns ------- int The number of parameters
[ "Get", "the", "number", "of", "positional", "-", "or", "-", "keyword", "or", "position", "-", "only", "parameters", "in", "a", "function", "signature", "." ]
python
train
24.526316
pytroll/satpy
satpy/readers/eps_l1b.py
https://github.com/pytroll/satpy/blob/1f21d20ac686b745fb0da9b4030d139893e066dd/satpy/readers/eps_l1b.py#L209-L220
def get_full_lonlats(self): """Get the interpolated lons/lats. """ if self.lons is not None and self.lats is not None: return self.lons, self.lats self.lons, self.lats = self._get_full_lonlats() self.lons = da.from_delayed(self.lons, dtype=self["EARTH_LOCATIONS"].dtype, shape=(self.scanlines, self.pixels)) self.lats = da.from_delayed(self.lats, dtype=self["EARTH_LOCATIONS"].dtype, shape=(self.scanlines, self.pixels)) return self.lons, self.lats
[ "def", "get_full_lonlats", "(", "self", ")", ":", "if", "self", ".", "lons", "is", "not", "None", "and", "self", ".", "lats", "is", "not", "None", ":", "return", "self", ".", "lons", ",", "self", ".", "lats", "self", ".", "lons", ",", "self", ".", ...
Get the interpolated lons/lats.
[ "Get", "the", "interpolated", "lons", "/", "lats", "." ]
python
train
48.166667
iotile/coretools
iotilesensorgraph/iotile/sg/update/setconfig_record.py
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilesensorgraph/iotile/sg/update/setconfig_record.py#L33-L61
def encode(self): """Encode this record into binary, suitable for embedded into an update script. This function will create multiple records that correspond to the actual underlying rpcs that SetConfigRecord turns into. Returns: bytearary: The binary version of the record that could be parsed via a call to UpdateRecord.FromBinary() """ begin_payload = struct.pack("<H8s", self.config_id, self.target.encode()) start_record = SendErrorCheckingRPCRecord(8, self.BEGIN_CONFIG_RPC, begin_payload, 4) end_record = SendErrorCheckingRPCRecord(8, self.END_CONFIG_RPC, bytearray(), 4) push_records = [] for i in range(0, len(self.data), 20): chunk = self.data[i:i+20] push_record = SendErrorCheckingRPCRecord(8, self.PUSH_CONFIG_RPC, chunk, 4) push_records.append(push_record) out_blob = bytearray() out_blob += start_record.encode() for push_record in push_records: out_blob += push_record.encode() out_blob += end_record.encode() return out_blob
[ "def", "encode", "(", "self", ")", ":", "begin_payload", "=", "struct", ".", "pack", "(", "\"<H8s\"", ",", "self", ".", "config_id", ",", "self", ".", "target", ".", "encode", "(", ")", ")", "start_record", "=", "SendErrorCheckingRPCRecord", "(", "8", ",...
Encode this record into binary, suitable for embedded into an update script. This function will create multiple records that correspond to the actual underlying rpcs that SetConfigRecord turns into. Returns: bytearary: The binary version of the record that could be parsed via a call to UpdateRecord.FromBinary()
[ "Encode", "this", "record", "into", "binary", "suitable", "for", "embedded", "into", "an", "update", "script", "." ]
python
train
38.448276
diefans/docker-events
src/docker_events/__init__.py
https://github.com/diefans/docker-events/blob/cc07591d908fefcc265285ba7fc0047632e06dea/src/docker_events/__init__.py#L40-L47
def matches(self, client, event_data): """True if all filters are matching.""" for f in self.filters: if not f(client, event_data): return False return True
[ "def", "matches", "(", "self", ",", "client", ",", "event_data", ")", ":", "for", "f", "in", "self", ".", "filters", ":", "if", "not", "f", "(", "client", ",", "event_data", ")", ":", "return", "False", "return", "True" ]
True if all filters are matching.
[ "True", "if", "all", "filters", "are", "matching", "." ]
python
train
25.375
edx/XBlock
xblock/core.py
https://github.com/edx/XBlock/blob/368bf46e2c0ee69bbb21817f428c4684936e18ee/xblock/core.py#L239-L257
def aside_for(cls, view_name): """ A decorator to indicate a function is the aside view for the given view_name. Aside views should have a signature like: @XBlockAside.aside_for('student_view') def student_aside(self, block, context=None): ... return Fragment(...) """ # pylint: disable=protected-access def _decorator(func): # pylint: disable=missing-docstring if not hasattr(func, '_aside_for'): func._aside_for = [] func._aside_for.append(view_name) # pylint: disable=protected-access return func return _decorator
[ "def", "aside_for", "(", "cls", ",", "view_name", ")", ":", "# pylint: disable=protected-access", "def", "_decorator", "(", "func", ")", ":", "# pylint: disable=missing-docstring", "if", "not", "hasattr", "(", "func", ",", "'_aside_for'", ")", ":", "func", ".", ...
A decorator to indicate a function is the aside view for the given view_name. Aside views should have a signature like: @XBlockAside.aside_for('student_view') def student_aside(self, block, context=None): ... return Fragment(...)
[ "A", "decorator", "to", "indicate", "a", "function", "is", "the", "aside", "view", "for", "the", "given", "view_name", "." ]
python
train
35.157895
sibirrer/lenstronomy
lenstronomy/ImSim/MultiBand/multi_data_base.py
https://github.com/sibirrer/lenstronomy/blob/4edb100a4f3f4fdc4fac9b0032d2b0283d0aa1d6/lenstronomy/ImSim/MultiBand/multi_data_base.py#L38-L45
def reset_point_source_cache(self, bool=True): """ deletes all the cache in the point source class and saves it from then on :return: """ for imageModel in self._imageModel_list: imageModel.reset_point_source_cache(bool=bool)
[ "def", "reset_point_source_cache", "(", "self", ",", "bool", "=", "True", ")", ":", "for", "imageModel", "in", "self", ".", "_imageModel_list", ":", "imageModel", ".", "reset_point_source_cache", "(", "bool", "=", "bool", ")" ]
deletes all the cache in the point source class and saves it from then on :return:
[ "deletes", "all", "the", "cache", "in", "the", "point", "source", "class", "and", "saves", "it", "from", "then", "on" ]
python
train
33.875
caseyjlaw/activegit
activegit/activegit.py
https://github.com/caseyjlaw/activegit/blob/2b4a0ee0fecf13345b5257130ba98b48f46e1098/activegit/activegit.py#L54-L75
def initializerepo(self): """ Fill empty directory with products and make first commit """ try: os.mkdir(self.repopath) except OSError: pass cmd = self.repo.init(bare=self.bare, shared=self.shared) if not self.bare: self.write_testing_data([], []) self.write_training_data([], []) self.write_classifier(None) cmd = self.repo.add('training.pkl') cmd = self.repo.add('testing.pkl') cmd = self.repo.add('classifier.pkl') cmd = self.repo.commit(m='initial commit') cmd = self.repo.tag('initial') cmd = self.set_version('initial')
[ "def", "initializerepo", "(", "self", ")", ":", "try", ":", "os", ".", "mkdir", "(", "self", ".", "repopath", ")", "except", "OSError", ":", "pass", "cmd", "=", "self", ".", "repo", ".", "init", "(", "bare", "=", "self", ".", "bare", ",", "shared",...
Fill empty directory with products and make first commit
[ "Fill", "empty", "directory", "with", "products", "and", "make", "first", "commit" ]
python
train
30.954545
cloud9ers/gurumate
environment/lib/python2.7/site-packages/IPython/core/oinspect.py
https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/core/oinspect.py#L118-L145
def getsource(obj,is_binary=False): """Wrapper around inspect.getsource. This can be modified by other projects to provide customized source extraction. Inputs: - obj: an object whose source code we will attempt to extract. Optional inputs: - is_binary: whether the object is known to come from a binary source. This implementation will skip returning any output for binary objects, but custom extractors may know how to meaningfully process them.""" if is_binary: return None else: # get source if obj was decorated with @decorator if hasattr(obj,"__wrapped__"): obj = obj.__wrapped__ try: src = inspect.getsource(obj) except TypeError: if hasattr(obj,'__class__'): src = inspect.getsource(obj.__class__) return src
[ "def", "getsource", "(", "obj", ",", "is_binary", "=", "False", ")", ":", "if", "is_binary", ":", "return", "None", "else", ":", "# get source if obj was decorated with @decorator", "if", "hasattr", "(", "obj", ",", "\"__wrapped__\"", ")", ":", "obj", "=", "ob...
Wrapper around inspect.getsource. This can be modified by other projects to provide customized source extraction. Inputs: - obj: an object whose source code we will attempt to extract. Optional inputs: - is_binary: whether the object is known to come from a binary source. This implementation will skip returning any output for binary objects, but custom extractors may know how to meaningfully process them.
[ "Wrapper", "around", "inspect", ".", "getsource", "." ]
python
test
29.964286
gholt/swiftly
swiftly/cli/iomanager.py
https://github.com/gholt/swiftly/blob/5bcc1c65323b1caf1f85adbefd9fc4988c072149/swiftly/cli/iomanager.py#L86-L96
def client_path_to_os_path(self, client_path): """ Converts a client path into the operating system's path by replacing instances of '/' with os.path.sep. Note: If the client path contains any instances of os.path.sep already, they will be replaced with '-'. """ if os.path.sep == '/': return client_path return client_path.replace(os.path.sep, '-').replace('/', os.path.sep)
[ "def", "client_path_to_os_path", "(", "self", ",", "client_path", ")", ":", "if", "os", ".", "path", ".", "sep", "==", "'/'", ":", "return", "client_path", "return", "client_path", ".", "replace", "(", "os", ".", "path", ".", "sep", ",", "'-'", ")", "....
Converts a client path into the operating system's path by replacing instances of '/' with os.path.sep. Note: If the client path contains any instances of os.path.sep already, they will be replaced with '-'.
[ "Converts", "a", "client", "path", "into", "the", "operating", "system", "s", "path", "by", "replacing", "instances", "of", "/", "with", "os", ".", "path", ".", "sep", "." ]
python
test
40.181818