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
pyblish/pyblish-qml
pyblish_qml/control.py
https://github.com/pyblish/pyblish-qml/blob/6095d18b2ec0afd0409a9b1a17e53b0658887283/pyblish_qml/control.py#L657-L660
def comment_sync(self, comment): """Update comments to host and notify subscribers""" self.host.update(key="comment", value=comment) self.host.emit("commented", comment=comment)
[ "def", "comment_sync", "(", "self", ",", "comment", ")", ":", "self", ".", "host", ".", "update", "(", "key", "=", "\"comment\"", ",", "value", "=", "comment", ")", "self", ".", "host", ".", "emit", "(", "\"commented\"", ",", "comment", "=", "comment",...
Update comments to host and notify subscribers
[ "Update", "comments", "to", "host", "and", "notify", "subscribers" ]
python
train
49.5
libnano/primer3-py
primer3/bindings.py
https://github.com/libnano/primer3-py/blob/0901c0ef3ac17afd69329d23db71136c00bcb635/primer3/bindings.py#L204-L234
def calcTm(seq, mv_conc=50, dv_conc=0, dntp_conc=0.8, dna_conc=50, max_nn_length=60, tm_method='santalucia', salt_corrections_method='santalucia'): ''' Calculate the melting temperature (Tm) of a DNA sequence. Note that NN thermodynamics will be used to calculate the Tm of sequences up to 60 bp in length, after which point the following formula will be used:: Tm = 81.5 + 16.6(log10([mv_conc])) + 0.41(%GC) - 600/length Args: seq (str) : DNA sequence mv_conc (float/int, optional) : Monovalent cation conc. (mM) dv_conc (float/int, optional) : Divalent cation conc. (mM) dntp_conc (float/int, optional) : dNTP conc. (mM) dna_conc (float/int, optional) : DNA conc. (nM) max_nn_length (int, optional) : Maximum length for nearest-neighbor calcs tm_method (str, optional) : Tm calculation method (breslauer or santalucia) salt_corrections_method (str, optional) : Salt correction method (schildkraut, owczarzy, santalucia) Returns: The melting temperature in degrees Celsius (float). ''' _setThermoArgs(**locals()) return _THERMO_ANALYSIS.calcTm(seq)
[ "def", "calcTm", "(", "seq", ",", "mv_conc", "=", "50", ",", "dv_conc", "=", "0", ",", "dntp_conc", "=", "0.8", ",", "dna_conc", "=", "50", ",", "max_nn_length", "=", "60", ",", "tm_method", "=", "'santalucia'", ",", "salt_corrections_method", "=", "'san...
Calculate the melting temperature (Tm) of a DNA sequence. Note that NN thermodynamics will be used to calculate the Tm of sequences up to 60 bp in length, after which point the following formula will be used:: Tm = 81.5 + 16.6(log10([mv_conc])) + 0.41(%GC) - 600/length Args: seq (str) : DNA sequence mv_conc (float/int, optional) : Monovalent cation conc. (mM) dv_conc (float/int, optional) : Divalent cation conc. (mM) dntp_conc (float/int, optional) : dNTP conc. (mM) dna_conc (float/int, optional) : DNA conc. (nM) max_nn_length (int, optional) : Maximum length for nearest-neighbor calcs tm_method (str, optional) : Tm calculation method (breslauer or santalucia) salt_corrections_method (str, optional) : Salt correction method (schildkraut, owczarzy, santalucia) Returns: The melting temperature in degrees Celsius (float).
[ "Calculate", "the", "melting", "temperature", "(", "Tm", ")", "of", "a", "DNA", "sequence", "." ]
python
train
46.870968
openai/universe
universe/remotes/compose/container.py
https://github.com/openai/universe/blob/cc9ce6ec241821bfb0f3b85dd455bd36e4ee7a8c/universe/remotes/compose/container.py#L170-L175
def attach_log_stream(self): """A log stream can only be attached if the container uses a json-file log driver. """ if self.has_api_logs: self.log_stream = self.attach(stdout=True, stderr=True, stream=True)
[ "def", "attach_log_stream", "(", "self", ")", ":", "if", "self", ".", "has_api_logs", ":", "self", ".", "log_stream", "=", "self", ".", "attach", "(", "stdout", "=", "True", ",", "stderr", "=", "True", ",", "stream", "=", "True", ")" ]
A log stream can only be attached if the container uses a json-file log driver.
[ "A", "log", "stream", "can", "only", "be", "attached", "if", "the", "container", "uses", "a", "json", "-", "file", "log", "driver", "." ]
python
train
40.833333
tonioo/sievelib
sievelib/managesieve.py
https://github.com/tonioo/sievelib/blob/88822d1f1daf30ef3dd9ac74911301b0773ef3c8/sievelib/managesieve.py#L535-L548
def havespace(self, scriptname, scriptsize): """Ask for available space. See MANAGESIEVE specifications, section 2.5 :param scriptname: script's name :param scriptsize: script's size :rtype: boolean """ code, data = self.__send_command( "HAVESPACE", [scriptname.encode("utf-8"), scriptsize]) if code == "OK": return True return False
[ "def", "havespace", "(", "self", ",", "scriptname", ",", "scriptsize", ")", ":", "code", ",", "data", "=", "self", ".", "__send_command", "(", "\"HAVESPACE\"", ",", "[", "scriptname", ".", "encode", "(", "\"utf-8\"", ")", ",", "scriptsize", "]", ")", "if...
Ask for available space. See MANAGESIEVE specifications, section 2.5 :param scriptname: script's name :param scriptsize: script's size :rtype: boolean
[ "Ask", "for", "available", "space", "." ]
python
train
29.857143
zooniverse/panoptes-python-client
panoptes_client/exportable.py
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/exportable.py#L30-L92
def get_export( self, export_type, generate=False, wait=False, wait_timeout=None, ): """ Downloads a data export over HTTP. Returns a `Requests Response <http://docs.python-requests.org/en/master/api/#requests.Response>`_ object containing the content of the export. - **export_type** is a string specifying which type of export should be downloaded. - **generate** is a boolean specifying whether to generate a new export and wait for it to be ready, or to just download the latest export. - **wait** is a boolean specifying whether to wait for an in-progress export to finish, if there is one. Has no effect if ``generate`` is ``True``. - **wait_timeout** is the number of seconds to wait if ``wait`` is ``True``. Has no effect if ``wait`` is ``False`` or if ``generate`` is ``True``. The returned :py:class:`.Response` object has two additional attributes as a convenience for working with the CSV content; **csv_reader** and **csv_dictreader**, which are wrappers for :py:meth:`.csv.reader` and :py:class:`csv.DictReader` respectively. These wrappers take care of correctly decoding the export content for the CSV parser. Example:: classification_export = Project(1234).get_export('classifications') for row in classification_export.csv_reader(): print(row) classification_export = Project(1234).get_export('classifications') for row in classification_export.csv_dictreader(): print(row) """ if generate: self.generate_export(export_type) if generate or wait: export = self.wait_export(export_type, wait_timeout) else: export = self.describe_export(export_type) if export_type in TALK_EXPORT_TYPES: media_url = export['data_requests'][0]['url'] else: media_url = export['media'][0]['src'] response = requests.get(media_url, stream=True) response.csv_reader = functools.partial( csv.reader, response.iter_lines(decode_unicode=True), ) response.csv_dictreader = functools.partial( csv.DictReader, response.iter_lines(decode_unicode=True), ) return response
[ "def", "get_export", "(", "self", ",", "export_type", ",", "generate", "=", "False", ",", "wait", "=", "False", ",", "wait_timeout", "=", "None", ",", ")", ":", "if", "generate", ":", "self", ".", "generate_export", "(", "export_type", ")", "if", "genera...
Downloads a data export over HTTP. Returns a `Requests Response <http://docs.python-requests.org/en/master/api/#requests.Response>`_ object containing the content of the export. - **export_type** is a string specifying which type of export should be downloaded. - **generate** is a boolean specifying whether to generate a new export and wait for it to be ready, or to just download the latest export. - **wait** is a boolean specifying whether to wait for an in-progress export to finish, if there is one. Has no effect if ``generate`` is ``True``. - **wait_timeout** is the number of seconds to wait if ``wait`` is ``True``. Has no effect if ``wait`` is ``False`` or if ``generate`` is ``True``. The returned :py:class:`.Response` object has two additional attributes as a convenience for working with the CSV content; **csv_reader** and **csv_dictreader**, which are wrappers for :py:meth:`.csv.reader` and :py:class:`csv.DictReader` respectively. These wrappers take care of correctly decoding the export content for the CSV parser. Example:: classification_export = Project(1234).get_export('classifications') for row in classification_export.csv_reader(): print(row) classification_export = Project(1234).get_export('classifications') for row in classification_export.csv_dictreader(): print(row)
[ "Downloads", "a", "data", "export", "over", "HTTP", ".", "Returns", "a", "Requests", "Response", "<http", ":", "//", "docs", ".", "python", "-", "requests", ".", "org", "/", "en", "/", "master", "/", "api", "/", "#requests", ".", "Response", ">", "_", ...
python
train
38.174603
senaite/senaite.core
bika/lims/content/samplinground.py
https://github.com/senaite/senaite.core/blob/7602ce2ea2f9e81eb34e20ce17b98a3e70713f85/bika/lims/content/samplinground.py#L417-L439
def hasUserAddEditPermission(self): """ Checks if the current user has privileges to access to the editing view. From Jira LIMS-1549: - Creation/Edit: Lab manager, Client Contact, Lab Clerk, Client Contact (for Client-specific SRTs) :returns: True/False """ mtool = getToolByName(self, 'portal_membership') checkPermission = mtool.checkPermission # In bika_samplinground_workflow.csv there are defined the ModifyPortalContent statements. There is said that # client has ModifyPortalContent permission enabled, so here we have to check if the client satisfy the # condition wrote in the function's description if (checkPermission(ModifyPortalContent, self) or checkPermission(AddPortalContent, self)) \ and 'Client' in api.user.get_current().getRoles(): # Checking if the current user is a current client's contact userID = api.user.get_current().id contact_objs = self.getContacts() contact_ids = [obj.getUsername() for obj in contact_objs] if userID in contact_ids: return True else: return False return checkPermission(ModifyPortalContent, self) or checkPermission(AddPortalContent, self)
[ "def", "hasUserAddEditPermission", "(", "self", ")", ":", "mtool", "=", "getToolByName", "(", "self", ",", "'portal_membership'", ")", "checkPermission", "=", "mtool", ".", "checkPermission", "# In bika_samplinground_workflow.csv there are defined the ModifyPortalContent statem...
Checks if the current user has privileges to access to the editing view. From Jira LIMS-1549: - Creation/Edit: Lab manager, Client Contact, Lab Clerk, Client Contact (for Client-specific SRTs) :returns: True/False
[ "Checks", "if", "the", "current", "user", "has", "privileges", "to", "access", "to", "the", "editing", "view", ".", "From", "Jira", "LIMS", "-", "1549", ":", "-", "Creation", "/", "Edit", ":", "Lab", "manager", "Client", "Contact", "Lab", "Clerk", "Clien...
python
train
56.304348
stevearc/dql
dql/expressions/constraint.py
https://github.com/stevearc/dql/blob/e9d3aa22873076dae5ebd02e35318aa996b1e56a/dql/expressions/constraint.py#L269-L282
def from_clause(cls, clause): """ Factory method """ fn_name = clause[0] if fn_name == "size": return SizeConstraint.from_clause(clause) elif fn_name == "attribute_type": return TypeConstraint.from_clause(clause) else: fn_name = clause[0] field = clause[1] if len(clause) > 2: return cls(fn_name, field, resolve(clause[2])) else: return cls(fn_name, field)
[ "def", "from_clause", "(", "cls", ",", "clause", ")", ":", "fn_name", "=", "clause", "[", "0", "]", "if", "fn_name", "==", "\"size\"", ":", "return", "SizeConstraint", ".", "from_clause", "(", "clause", ")", "elif", "fn_name", "==", "\"attribute_type\"", "...
Factory method
[ "Factory", "method" ]
python
train
34.785714
Microsoft/ApplicationInsights-Python
applicationinsights/TelemetryClient.py
https://github.com/Microsoft/ApplicationInsights-Python/blob/8452ab7126f9bb6964637d4aa1258c2af17563d6/applicationinsights/TelemetryClient.py#L193-L222
def track_request(self, name, url, success, start_time=None, duration=None, response_code=None, http_method=None, properties=None, measurements=None, request_id=None): """Sends a single request that was captured for the application. Args: name (str). the name for this request. All requests with the same name will be grouped together.\n url (str). the actual URL for this request (to show in individual request instances).\n success (bool). true if the request ended in success, false otherwise.\n start_time (str). the start time of the request. The value should look the same as the one returned by :func:`datetime.isoformat()` (defaults to: None)\n duration (int). the number of milliseconds that this request lasted. (defaults to: None)\n response_code (str). the response code that this request returned. (defaults to: None)\n http_method (str). the HTTP method that triggered this request. (defaults to: None)\n properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)\n measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)\n request_id (str). the id for this request. If None, a new uuid will be generated. (defaults to: None) """ data = channel.contracts.RequestData() data.id = request_id or str(uuid.uuid4()) data.name = name data.url = url data.success = success data.start_time = start_time or datetime.datetime.utcnow().isoformat() + 'Z' data.duration = self.__ms_to_duration(duration) data.response_code = str(response_code) or '200' data.http_method = http_method or 'GET' if properties: data.properties = properties if measurements: data.measurements = measurements self.track(data, self._context)
[ "def", "track_request", "(", "self", ",", "name", ",", "url", ",", "success", ",", "start_time", "=", "None", ",", "duration", "=", "None", ",", "response_code", "=", "None", ",", "http_method", "=", "None", ",", "properties", "=", "None", ",", "measurem...
Sends a single request that was captured for the application. Args: name (str). the name for this request. All requests with the same name will be grouped together.\n url (str). the actual URL for this request (to show in individual request instances).\n success (bool). true if the request ended in success, false otherwise.\n start_time (str). the start time of the request. The value should look the same as the one returned by :func:`datetime.isoformat()` (defaults to: None)\n duration (int). the number of milliseconds that this request lasted. (defaults to: None)\n response_code (str). the response code that this request returned. (defaults to: None)\n http_method (str). the HTTP method that triggered this request. (defaults to: None)\n properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)\n measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)\n request_id (str). the id for this request. If None, a new uuid will be generated. (defaults to: None)
[ "Sends", "a", "single", "request", "that", "was", "captured", "for", "the", "application", "." ]
python
train
65.733333
SmokinCaterpillar/pypet
pypet/storageservice.py
https://github.com/SmokinCaterpillar/pypet/blob/97ad3e80d46dbdea02deeb98ea41f05a19565826/pypet/storageservice.py#L2867-L2895
def _srn_store_single_run(self, traj, recursive=True, store_data=pypetconstants.STORE_DATA, max_depth=None): """ Stores a single run instance to disk (only meta data)""" if store_data != pypetconstants.STORE_NOTHING: self._logger.debug('Storing Data of single run `%s`.' % traj.v_crun) if max_depth is None: max_depth = float('inf') for name_pair in traj._new_nodes: _, name = name_pair parent_group, child_node = traj._new_nodes[name_pair] if not child_node._stored: self._tree_store_sub_branch(parent_group, name, store_data=store_data, with_links=True, recursive=recursive, max_depth=max_depth - child_node.v_depth, hdf5_group=None) for name_pair in traj._new_links: _, link = name_pair parent_group, _ = traj._new_links[name_pair] self._tree_store_sub_branch(parent_group, link, store_data=store_data, with_links=True, recursive=recursive, max_depth=max_depth - parent_group.v_depth - 1, hdf5_group=None)
[ "def", "_srn_store_single_run", "(", "self", ",", "traj", ",", "recursive", "=", "True", ",", "store_data", "=", "pypetconstants", ".", "STORE_DATA", ",", "max_depth", "=", "None", ")", ":", "if", "store_data", "!=", "pypetconstants", ".", "STORE_NOTHING", ":"...
Stores a single run instance to disk (only meta data)
[ "Stores", "a", "single", "run", "instance", "to", "disk", "(", "only", "meta", "data", ")" ]
python
test
55.068966
unt-libraries/pyuntl
pyuntl/etd_ms_structure.py
https://github.com/unt-libraries/pyuntl/blob/f92413302897dab948aac18ee9e482ace0187bd4/pyuntl/etd_ms_structure.py#L234-L245
def date_director(**kwargs): """Direct which class should be used based on the date qualifier or if the date should be converted at all. """ # If the date is a creation date, return the element object. if kwargs.get('qualifier') == 'creation': return ETD_MSDate(content=kwargs.get('content').strip()) elif kwargs.get('qualifier') != 'digitized': # Return the element object. return ETD_MSDate(content=kwargs.get('content').strip()) else: return None
[ "def", "date_director", "(", "*", "*", "kwargs", ")", ":", "# If the date is a creation date, return the element object.", "if", "kwargs", ".", "get", "(", "'qualifier'", ")", "==", "'creation'", ":", "return", "ETD_MSDate", "(", "content", "=", "kwargs", ".", "ge...
Direct which class should be used based on the date qualifier or if the date should be converted at all.
[ "Direct", "which", "class", "should", "be", "used", "based", "on", "the", "date", "qualifier", "or", "if", "the", "date", "should", "be", "converted", "at", "all", "." ]
python
train
41.5
luiscberrocal/pyjavaprops
pyjavaprops/javaproperties.py
https://github.com/luiscberrocal/pyjavaprops/blob/7d0327b1758b3d907af657e0df3b0618776ac46d/pyjavaprops/javaproperties.py#L250-L264
def load(self, stream): """ Load properties from an open file stream """ # For the time being only accept file input streams if not _is_file(stream): raise TypeError('Argument should be a file object!') # Check for the opened mode if stream.mode != 'r': raise ValueError('Stream should be opened in read-only mode!') try: lines = stream.readlines() self.__parse(lines) except IOError: raise
[ "def", "load", "(", "self", ",", "stream", ")", ":", "# For the time being only accept file input streams", "if", "not", "_is_file", "(", "stream", ")", ":", "raise", "TypeError", "(", "'Argument should be a file object!'", ")", "# Check for the opened mode", "if", "str...
Load properties from an open file stream
[ "Load", "properties", "from", "an", "open", "file", "stream" ]
python
train
32.933333
FujiMakoto/AgentML
agentml/parser/trigger/response/__init__.py
https://github.com/FujiMakoto/AgentML/blob/c8cb64b460d876666bf29ea2c682189874c7c403/agentml/parser/trigger/response/__init__.py#L59-L85
def get(self): """ Parse a response into string format and clear out its temporary containers :return: The parsed response message :rtype : str """ self._log.debug('Converting Response object to string format') response = ''.join(map(str, self._response)).strip() self._log.debug('Resetting parent Trigger temporary containers') self.stars = { 'normalized': (), 'case_preserved': (), 'raw': () } user = self.trigger.user self.trigger.user = None if self.redirect: self._log.info('Redirecting response to: {msg}'.format(msg=response)) groups = self.agentml.request_log.most_recent().groups response = self.agentml.get_reply(user.id, response, groups) if not response: self._log.info('Failed to retrieve a valid response when redirecting') return '' return response
[ "def", "get", "(", "self", ")", ":", "self", ".", "_log", ".", "debug", "(", "'Converting Response object to string format'", ")", "response", "=", "''", ".", "join", "(", "map", "(", "str", ",", "self", ".", "_response", ")", ")", ".", "strip", "(", "...
Parse a response into string format and clear out its temporary containers :return: The parsed response message :rtype : str
[ "Parse", "a", "response", "into", "string", "format", "and", "clear", "out", "its", "temporary", "containers", ":", "return", ":", "The", "parsed", "response", "message", ":", "rtype", ":", "str" ]
python
train
35.851852
tanghaibao/goatools
goatools/go_enrichment.py
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L136-L143
def set_goterm(self, go2obj): """Set goterm and copy GOTerm's name and namespace.""" if self.GO in go2obj: goterm = go2obj[self.GO] self.goterm = goterm self.name = goterm.name self.depth = goterm.depth self.NS = self.namespace2NS[self.goterm.namespace]
[ "def", "set_goterm", "(", "self", ",", "go2obj", ")", ":", "if", "self", ".", "GO", "in", "go2obj", ":", "goterm", "=", "go2obj", "[", "self", ".", "GO", "]", "self", ".", "goterm", "=", "goterm", "self", ".", "name", "=", "goterm", ".", "name", ...
Set goterm and copy GOTerm's name and namespace.
[ "Set", "goterm", "and", "copy", "GOTerm", "s", "name", "and", "namespace", "." ]
python
train
40.25
spyder-ide/conda-manager
conda_manager/api/conda_api.py
https://github.com/spyder-ide/conda-manager/blob/89a2126cbecefc92185cf979347ccac1c5ee5d9d/conda_manager/api/conda_api.py#L832-L861
def dependencies(self, name=None, prefix=None, pkgs=None, channels=None, dep=True): """Get dependenciy list for packages to be installed in an env.""" if not pkgs or not isinstance(pkgs, (list, tuple)): raise TypeError('must specify a list of one or more packages to ' 'install into existing environment') cmd_list = ['install', '--dry-run', '--json', '--force-pscheck'] if not dep: cmd_list.extend(['--no-deps']) if name: cmd_list.extend(['--name', name]) elif prefix: cmd_list.extend(['--prefix', prefix]) else: pass cmd_list.extend(pkgs) # TODO: Check if correct if channels: cmd_list.extend(['--override-channels']) for channel in channels: cmd_list.extend(['--channel']) cmd_list.extend([channel]) return self._call_and_parse(cmd_list)
[ "def", "dependencies", "(", "self", ",", "name", "=", "None", ",", "prefix", "=", "None", ",", "pkgs", "=", "None", ",", "channels", "=", "None", ",", "dep", "=", "True", ")", ":", "if", "not", "pkgs", "or", "not", "isinstance", "(", "pkgs", ",", ...
Get dependenciy list for packages to be installed in an env.
[ "Get", "dependenciy", "list", "for", "packages", "to", "be", "installed", "in", "an", "env", "." ]
python
train
32.366667
limodou/uliweb
uliweb/orm/__init__.py
https://github.com/limodou/uliweb/blob/34472f25e4bc0b954a35346672f94e84ef18b076/uliweb/orm/__init__.py#L1479-L1488
def migrate_tables(tables, engine_name=None): """ Used to migrate dynamic table to database :param tables: tables name list, such as ['user'] """ from alembic.migration import MigrationContext engine = engine_manager[engine_name] mc = MigrationContext.configure(engine.session().connection) script = get_migrate_script(mc, tables, engine.metadata) run_migrate_script(mc, script)
[ "def", "migrate_tables", "(", "tables", ",", "engine_name", "=", "None", ")", ":", "from", "alembic", ".", "migration", "import", "MigrationContext", "engine", "=", "engine_manager", "[", "engine_name", "]", "mc", "=", "MigrationContext", ".", "configure", "(", ...
Used to migrate dynamic table to database :param tables: tables name list, such as ['user']
[ "Used", "to", "migrate", "dynamic", "table", "to", "database", ":", "param", "tables", ":", "tables", "name", "list", "such", "as", "[", "user", "]" ]
python
train
40.6
redcap-tools/PyCap
redcap/request.py
https://github.com/redcap-tools/PyCap/blob/f44c9b62a4f62675aa609c06608663f37e12097e/redcap/request.py#L129-L150
def get_content(self, r): """Abstraction for grabbing content from a returned response""" if self.type == 'exp_file': # don't use the decoded r.text return r.content elif self.type == 'version': return r.content else: if self.fmt == 'json': content = {} # Decode try: # Watch out for bad/empty json content = json.loads(r.text, strict=False) except ValueError as e: if not self.expect_empty_json(): # reraise for requests that shouldn't send empty json raise ValueError(e) finally: return content else: return r.text
[ "def", "get_content", "(", "self", ",", "r", ")", ":", "if", "self", ".", "type", "==", "'exp_file'", ":", "# don't use the decoded r.text", "return", "r", ".", "content", "elif", "self", ".", "type", "==", "'version'", ":", "return", "r", ".", "content", ...
Abstraction for grabbing content from a returned response
[ "Abstraction", "for", "grabbing", "content", "from", "a", "returned", "response" ]
python
train
36.863636
ethereum/py-trie
trie/utils/nibbles.py
https://github.com/ethereum/py-trie/blob/d33108d21b54d59ee311f61d978496c84a6f1f8b/trie/utils/nibbles.py#L78-L104
def encode_nibbles(nibbles): """ The Hex Prefix function """ if is_nibbles_terminated(nibbles): flag = HP_FLAG_2 else: flag = HP_FLAG_0 raw_nibbles = remove_nibbles_terminator(nibbles) is_odd = len(raw_nibbles) % 2 if is_odd: flagged_nibbles = tuple(itertools.chain( (flag + 1,), raw_nibbles, )) else: flagged_nibbles = tuple(itertools.chain( (flag, 0), raw_nibbles, )) prefixed_value = nibbles_to_bytes(flagged_nibbles) return prefixed_value
[ "def", "encode_nibbles", "(", "nibbles", ")", ":", "if", "is_nibbles_terminated", "(", "nibbles", ")", ":", "flag", "=", "HP_FLAG_2", "else", ":", "flag", "=", "HP_FLAG_0", "raw_nibbles", "=", "remove_nibbles_terminator", "(", "nibbles", ")", "is_odd", "=", "l...
The Hex Prefix function
[ "The", "Hex", "Prefix", "function" ]
python
train
20.777778
CamDavidsonPilon/lifetimes
lifetimes/fitters/beta_geo_fitter.py
https://github.com/CamDavidsonPilon/lifetimes/blob/f926308bc03c17c1d12fead729de43885cf13321/lifetimes/fitters/beta_geo_fitter.py#L209-L238
def conditional_probability_alive(self, frequency, recency, T): """ Compute conditional probability alive. Compute the probability that a customer with history (frequency, recency, T) is currently alive. From http://www.brucehardie.com/notes/021/palive_for_BGNBD.pdf Parameters ---------- frequency: array or scalar historical frequency of customer. recency: array or scalar historical recency of customer. T: array or scalar age of the customer. Returns ------- array value representing a probability """ r, alpha, a, b = self._unload_params("r", "alpha", "a", "b") log_div = (r + frequency) * np.log((alpha + T) / (alpha + recency)) + np.log( a / (b + np.maximum(frequency, 1) - 1) ) return np.atleast_1d(np.where(frequency == 0, 1.0, expit(-log_div)))
[ "def", "conditional_probability_alive", "(", "self", ",", "frequency", ",", "recency", ",", "T", ")", ":", "r", ",", "alpha", ",", "a", ",", "b", "=", "self", ".", "_unload_params", "(", "\"r\"", ",", "\"alpha\"", ",", "\"a\"", ",", "\"b\"", ")", "log_...
Compute conditional probability alive. Compute the probability that a customer with history (frequency, recency, T) is currently alive. From http://www.brucehardie.com/notes/021/palive_for_BGNBD.pdf Parameters ---------- frequency: array or scalar historical frequency of customer. recency: array or scalar historical recency of customer. T: array or scalar age of the customer. Returns ------- array value representing a probability
[ "Compute", "conditional", "probability", "alive", "." ]
python
train
31.166667
streeter/pelican-gist
pelican_gist/plugin.py
https://github.com/streeter/pelican-gist/blob/395e619534b404fb2b94456dc400dc2a8a2f934a/pelican_gist/plugin.py#L103-L153
def replace_gist_tags(generator): """Replace gist tags in the article content.""" from jinja2 import Template template = Template(gist_template) should_cache = generator.context.get('GIST_CACHE_ENABLED') cache_location = generator.context.get('GIST_CACHE_LOCATION') pygments_style = generator.context.get('GIST_PYGMENTS_STYLE') body = None for article in generator.articles: for match in gist_regex.findall(article._content): gist_id = match[1] filename = None filetype = None if match[3]: filename = match[3] if match[5]: filetype = match[5] logger.info('[gist]: Found gist id {} with filename {} and filetype {}'.format( gist_id, filename, filetype, )) if should_cache: body = get_cache(cache_location, gist_id, filename) # Fetch the gist if not body: logger.info('[gist]: Gist did not exist in cache, fetching...') body = fetch_gist(gist_id, filename) if should_cache: logger.info('[gist]: Saving gist to cache...') set_cache(cache_location, gist_id, body, filename) else: logger.info('[gist]: Found gist in cache.') # Create a context to render with context = generator.context.copy() context.update({ 'script_url': script_url(gist_id, filename), 'code': render_code(body, filetype, pygments_style) }) # Render the template replacement = template.render(context) article._content = article._content.replace(match[0], replacement)
[ "def", "replace_gist_tags", "(", "generator", ")", ":", "from", "jinja2", "import", "Template", "template", "=", "Template", "(", "gist_template", ")", "should_cache", "=", "generator", ".", "context", ".", "get", "(", "'GIST_CACHE_ENABLED'", ")", "cache_location"...
Replace gist tags in the article content.
[ "Replace", "gist", "tags", "in", "the", "article", "content", "." ]
python
train
34.980392
ngmarchant/oasis
oasis/sawade.py
https://github.com/ngmarchant/oasis/blob/28a037a8924b85ae97db8a93960a910a219d6a4a/oasis/sawade.py#L145-L151
def _sample_item(self, **kwargs): """Sample an item from the pool according to the instrumental distribution """ loc = np.random.choice(self._n_items, p = self._inst_pmf) weight = (1/self._n_items)/self._inst_pmf[loc] return loc, weight, {}
[ "def", "_sample_item", "(", "self", ",", "*", "*", "kwargs", ")", ":", "loc", "=", "np", ".", "random", ".", "choice", "(", "self", ".", "_n_items", ",", "p", "=", "self", ".", "_inst_pmf", ")", "weight", "=", "(", "1", "/", "self", ".", "_n_item...
Sample an item from the pool according to the instrumental distribution
[ "Sample", "an", "item", "from", "the", "pool", "according", "to", "the", "instrumental", "distribution" ]
python
train
40.285714
gem/oq-engine
openquake/hazardlib/gsim/lin_2009.py
https://github.com/gem/oq-engine/blob/8294553a0b8aba33fd96437a35065d03547d0040/openquake/hazardlib/gsim/lin_2009.py#L128-L137
def _get_stddevs(self, C, stddev_types, nsites): """ Compute total standard deviation, see table 4.2, page 50. """ stddevs = [] for stddev_type in stddev_types: assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES if stddev_type == const.StdDev.TOTAL: stddevs.append(C['sigma'] + np.zeros(nsites, dtype=float)) return stddevs
[ "def", "_get_stddevs", "(", "self", ",", "C", ",", "stddev_types", ",", "nsites", ")", ":", "stddevs", "=", "[", "]", "for", "stddev_type", "in", "stddev_types", ":", "assert", "stddev_type", "in", "self", ".", "DEFINED_FOR_STANDARD_DEVIATION_TYPES", "if", "st...
Compute total standard deviation, see table 4.2, page 50.
[ "Compute", "total", "standard", "deviation", "see", "table", "4", ".", "2", "page", "50", "." ]
python
train
41.5
tensorpack/tensorpack
tensorpack/models/tflayer.py
https://github.com/tensorpack/tensorpack/blob/d7a13cb74c9066bc791d7aafc3b744b60ee79a9f/tensorpack/models/tflayer.py#L73-L89
def rename_get_variable(mapping): """ Args: mapping(dict): an old -> new mapping for variable basename. e.g. {'kernel': 'W'} Returns: A context where the variables are renamed. """ def custom_getter(getter, name, *args, **kwargs): splits = name.split('/') basename = splits[-1] if basename in mapping: basename = mapping[basename] splits[-1] = basename name = '/'.join(splits) return getter(name, *args, **kwargs) return custom_getter_scope(custom_getter)
[ "def", "rename_get_variable", "(", "mapping", ")", ":", "def", "custom_getter", "(", "getter", ",", "name", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "splits", "=", "name", ".", "split", "(", "'/'", ")", "basename", "=", "splits", "[", "-"...
Args: mapping(dict): an old -> new mapping for variable basename. e.g. {'kernel': 'W'} Returns: A context where the variables are renamed.
[ "Args", ":", "mapping", "(", "dict", ")", ":", "an", "old", "-", ">", "new", "mapping", "for", "variable", "basename", ".", "e", ".", "g", ".", "{", "kernel", ":", "W", "}" ]
python
train
32.235294
SchroterQuentin/django-search-listview
fabfile.py
https://github.com/SchroterQuentin/django-search-listview/blob/8b027a6908dc30c6ebc613bb4fde6b1ba40124a3/fabfile.py#L68-L85
def dev(): """Define dev stage""" env.roledefs = { 'web': ['192.168.1.2'], 'lb': ['192.168.1.2'], } env.user = 'vagrant' env.backends = env.roledefs['web'] env.server_name = 'django_search_model-dev.net' env.short_server_name = 'django_search_model-dev' env.static_folder = '/site_media/' env.server_ip = '192.168.1.2' env.no_shared_sessions = False env.server_ssl_on = False env.goal = 'dev' env.socket_port = '8001' env.map_settings = {} execute(build_env)
[ "def", "dev", "(", ")", ":", "env", ".", "roledefs", "=", "{", "'web'", ":", "[", "'192.168.1.2'", "]", ",", "'lb'", ":", "[", "'192.168.1.2'", "]", ",", "}", "env", ".", "user", "=", "'vagrant'", "env", ".", "backends", "=", "env", ".", "roledefs"...
Define dev stage
[ "Define", "dev", "stage" ]
python
train
29.666667
JNRowe/upoints
upoints/point.py
https://github.com/JNRowe/upoints/blob/1e4b7a53ed2a06cd854523d54c36aabdccea3830/upoints/point.py#L41-L68
def _dms_formatter(latitude, longitude, mode, unistr=False): """Generate a human readable DM/DMS location string. Args: latitude (float): Location's latitude longitude (float): Location's longitude mode (str): Coordinate formatting system to use unistr (bool): Whether to use extended character set """ if unistr: chars = ('°', '′', '″') else: chars = ('°', "'", '"') latitude_dms = tuple(map(abs, utils.to_dms(latitude, mode))) longitude_dms = tuple(map(abs, utils.to_dms(longitude, mode))) text = [] if mode == 'dms': text.append('%%02i%s%%02i%s%%02i%s' % chars % latitude_dms) else: text.append('%%02i%s%%05.2f%s' % chars[:2] % latitude_dms) text.append('S' if latitude < 0 else 'N') if mode == 'dms': text.append(', %%03i%s%%02i%s%%02i%s' % chars % longitude_dms) else: text.append(', %%03i%s%%05.2f%s' % chars[:2] % longitude_dms) text.append('W' if longitude < 0 else 'E') return text
[ "def", "_dms_formatter", "(", "latitude", ",", "longitude", ",", "mode", ",", "unistr", "=", "False", ")", ":", "if", "unistr", ":", "chars", "=", "(", "'°',", " ", "′', '", "″", ")", "", "else", ":", "chars", "=", "(", "'°',", " ", "'\",", " ", ...
Generate a human readable DM/DMS location string. Args: latitude (float): Location's latitude longitude (float): Location's longitude mode (str): Coordinate formatting system to use unistr (bool): Whether to use extended character set
[ "Generate", "a", "human", "readable", "DM", "/", "DMS", "location", "string", "." ]
python
train
35.892857
fcvarela/pyremotezip
pyremotezip/remotezip.py
https://github.com/fcvarela/pyremotezip/blob/52cc885b2ed1e690d92d3b41fef7a1a3fcc2b509/pyremotezip/remotezip.py#L138-L192
def extractFile(self, filename): """ This function will extract a single file from the remote zip without downloading the entire zip file. The filename argument should match whatever is in the 'filename' key of the tableOfContents. """ files = [x for x in self.tableOfContents if x['filename'] == filename] if len(files) == 0: raise FileNotFoundException() fileRecord = files[0] # got here? need to fetch the file size metaheadroom = 1024 # should be enough request = urllib2.Request(self.zipURI) start = fileRecord['filestart'] end = fileRecord['filestart'] + fileRecord['compressedsize'] + metaheadroom request.headers['Range'] = "bytes=%s-%s" % (start, end) handle = urllib2.urlopen(request) # make sure the response is ranged return_range = handle.headers.get('Content-Range') if return_range != "bytes %d-%d/%s" % (start, end, self.filesize): raise Exception("Ranged requests are not supported for this URI") filedata = handle.read() # find start of raw file data zip_n = unpack("H", filedata[26:28])[0] zip_m = unpack("H", filedata[28:30])[0] # check compressed size has_data_descriptor = bool(unpack("H", filedata[6:8])[0] & 8) comp_size = unpack("I", filedata[18:22])[0] if comp_size == 0 and has_data_descriptor: # assume compressed size in the Central Directory is correct comp_size = fileRecord['compressedsize'] elif comp_size != fileRecord['compressedsize']: raise Exception("Something went wrong. Directory and file header disagree of compressed file size") raw_zip_data = filedata[30 + zip_n + zip_m: 30 + zip_n + zip_m + comp_size] uncompressed_data = "" # can't decompress if stored without compression compression_method = unpack("H", filedata[8:10])[0] if compression_method == 0: return raw_zip_data dec = zlib.decompressobj(-zlib.MAX_WBITS) for chunk in raw_zip_data: rv = dec.decompress(chunk) if rv: uncompressed_data = uncompressed_data + rv return uncompressed_data
[ "def", "extractFile", "(", "self", ",", "filename", ")", ":", "files", "=", "[", "x", "for", "x", "in", "self", ".", "tableOfContents", "if", "x", "[", "'filename'", "]", "==", "filename", "]", "if", "len", "(", "files", ")", "==", "0", ":", "raise...
This function will extract a single file from the remote zip without downloading the entire zip file. The filename argument should match whatever is in the 'filename' key of the tableOfContents.
[ "This", "function", "will", "extract", "a", "single", "file", "from", "the", "remote", "zip", "without", "downloading", "the", "entire", "zip", "file", ".", "The", "filename", "argument", "should", "match", "whatever", "is", "in", "the", "filename", "key", "...
python
valid
40.818182
openstack/proliantutils
proliantutils/redfish/resources/system/storage/logical_drive.py
https://github.com/openstack/proliantutils/blob/86ef3b47b4eca97c221577e3570b0240d6a25f22/proliantutils/redfish/resources/system/storage/logical_drive.py#L56-L64
def logical_raid_levels(self): """Gets the raid level for each logical volume :returns the set of list of raid levels configured. """ lg_raid_lvls = set() for member in self.get_members(): lg_raid_lvls.add(mappings.RAID_LEVEL_MAP_REV.get(member.raid)) return lg_raid_lvls
[ "def", "logical_raid_levels", "(", "self", ")", ":", "lg_raid_lvls", "=", "set", "(", ")", "for", "member", "in", "self", ".", "get_members", "(", ")", ":", "lg_raid_lvls", ".", "add", "(", "mappings", ".", "RAID_LEVEL_MAP_REV", ".", "get", "(", "member", ...
Gets the raid level for each logical volume :returns the set of list of raid levels configured.
[ "Gets", "the", "raid", "level", "for", "each", "logical", "volume" ]
python
train
36
Microsoft/azure-devops-python-api
azure-devops/azure/devops/v5_0/work_item_tracking_process/work_item_tracking_process_client.py
https://github.com/Microsoft/azure-devops-python-api/blob/4777ffda2f5052fabbaddb2abe9cb434e0cf1aa8/azure-devops/azure/devops/v5_0/work_item_tracking_process/work_item_tracking_process_client.py#L650-L661
def delete_process_by_id(self, process_type_id): """DeleteProcessById. [Preview API] Removes a process of a specific ID. :param str process_type_id: """ route_values = {} if process_type_id is not None: route_values['processTypeId'] = self._serialize.url('process_type_id', process_type_id, 'str') self._send(http_method='DELETE', location_id='02cc6a73-5cfb-427d-8c8e-b49fb086e8af', version='5.0-preview.2', route_values=route_values)
[ "def", "delete_process_by_id", "(", "self", ",", "process_type_id", ")", ":", "route_values", "=", "{", "}", "if", "process_type_id", "is", "not", "None", ":", "route_values", "[", "'processTypeId'", "]", "=", "self", ".", "_serialize", ".", "url", "(", "'pr...
DeleteProcessById. [Preview API] Removes a process of a specific ID. :param str process_type_id:
[ "DeleteProcessById", ".", "[", "Preview", "API", "]", "Removes", "a", "process", "of", "a", "specific", "ID", ".", ":", "param", "str", "process_type_id", ":" ]
python
train
45.666667
hendrix/hendrix
hendrix/contrib/cache/resource.py
https://github.com/hendrix/hendrix/blob/175af011a7e5822b772bfec0e11a46466bb8688d/hendrix/contrib/cache/resource.py#L148-L156
def getChild(self, path, request): """ This is necessary because the parent class would call proxy.ReverseProxyResource instead of CacheProxyResource """ return CacheProxyResource( self.host, self.port, self.path + '/' + urlquote(path, safe=""), self.reactor )
[ "def", "getChild", "(", "self", ",", "path", ",", "request", ")", ":", "return", "CacheProxyResource", "(", "self", ".", "host", ",", "self", ".", "port", ",", "self", ".", "path", "+", "'/'", "+", "urlquote", "(", "path", ",", "safe", "=", "\"\"", ...
This is necessary because the parent class would call proxy.ReverseProxyResource instead of CacheProxyResource
[ "This", "is", "necessary", "because", "the", "parent", "class", "would", "call", "proxy", ".", "ReverseProxyResource", "instead", "of", "CacheProxyResource" ]
python
train
36
wilson-eft/wilson
wilson/util/wetutil.py
https://github.com/wilson-eft/wilson/blob/4164f55ff663d4f668c6e2b4575fd41562662cc9/wilson/util/wetutil.py#L108-L146
def symmetrize_JMS_dict(C): """For a dictionary with JMS Wilson coefficients but keys that might not be in the non-redundant basis, return a dictionary with keys from the basis and values conjugated if necessary.""" wc_keys = set(wcxf.Basis['WET', 'JMS'].all_wcs) Cs = {} for op, v in C.items(): if '_' not in op or op in wc_keys: Cs[op] = v continue name, ind = op.split('_') if name in C_symm_keys[5]: i, j, k, l = ind indnew = ''.join([j, i, l, k]) Cs['_'.join([name, indnew])] = v.conjugate() elif name in C_symm_keys[41]: i, j, k, l = ind indnew = ''.join([k, l, i, j]) Cs['_'.join([name, indnew])] = v elif name in C_symm_keys[4]: i, j, k, l = ind indnew = ''.join([l, k, j, i]) newname = '_'.join([name, indnew]) if newname in wc_keys: Cs[newname] = v.conjugate() else: indnew = ''.join([j, i, l, k]) newname = '_'.join([name, indnew]) if newname in wc_keys: Cs[newname] = v.conjugate() else: indnew = ''.join([k, l, i, j]) newname = '_'.join([name, indnew]) Cs[newname] = v elif name in C_symm_keys[9]: i, j, k, l = ind indnew = ''.join([j, i, k, l]) Cs['_'.join([name, indnew])] = -v return Cs
[ "def", "symmetrize_JMS_dict", "(", "C", ")", ":", "wc_keys", "=", "set", "(", "wcxf", ".", "Basis", "[", "'WET'", ",", "'JMS'", "]", ".", "all_wcs", ")", "Cs", "=", "{", "}", "for", "op", ",", "v", "in", "C", ".", "items", "(", ")", ":", "if", ...
For a dictionary with JMS Wilson coefficients but keys that might not be in the non-redundant basis, return a dictionary with keys from the basis and values conjugated if necessary.
[ "For", "a", "dictionary", "with", "JMS", "Wilson", "coefficients", "but", "keys", "that", "might", "not", "be", "in", "the", "non", "-", "redundant", "basis", "return", "a", "dictionary", "with", "keys", "from", "the", "basis", "and", "values", "conjugated",...
python
train
38.25641
KnowledgeLinks/rdfframework
rdfframework/connections/fedoracommons.py
https://github.com/KnowledgeLinks/rdfframework/blob/9ec32dcc4bed51650a4b392cc5c15100fef7923a/rdfframework/connections/fedoracommons.py#L70-L100
def check_status(self): """ tests both the ext_url and local_url to see if the database is running returns: True if a connection can be made False if the connection cannot me made """ log = logging.getLogger("%s.%s" % (self.log_name, inspect.stack()[0][3])) log.setLevel(self.log_level) if self.url: return True try: result = requests.get(self.ext_url) self.url = self.ext_url return True except requests.exceptions.ConnectionError: pass try: result = requests.get(self.local_url) log.warning("Url '%s' not connecting. Using local_url '%s'" % \ (self.ext_url, self.local_url)) self.url = self.local_url return True except requests.exceptions.ConnectionError: self.url = None log.warning("Unable to connect using urls: %s" % set([self.ext_url, self.local_url])) return False
[ "def", "check_status", "(", "self", ")", ":", "log", "=", "logging", ".", "getLogger", "(", "\"%s.%s\"", "%", "(", "self", ".", "log_name", ",", "inspect", ".", "stack", "(", ")", "[", "0", "]", "[", "3", "]", ")", ")", "log", ".", "setLevel", "(...
tests both the ext_url and local_url to see if the database is running returns: True if a connection can be made False if the connection cannot me made
[ "tests", "both", "the", "ext_url", "and", "local_url", "to", "see", "if", "the", "database", "is", "running" ]
python
train
36.903226
leonidessaguisagjr/unicodeutil
unicodeutil/unicodeutil.py
https://github.com/leonidessaguisagjr/unicodeutil/blob/c25c882cf9cb38c123df49fad365be67e5818928/unicodeutil/unicodeutil.py#L49-L62
def _unichr(i): """ Helper function for taking a Unicode scalar value and returning a Unicode character. :param s: Unicode scalar value to convert. :return: Unicode character """ if not isinstance(i, int): raise TypeError try: return six.unichr(i) except ValueError: # Workaround the error "ValueError: unichr() arg not in range(0x10000) (narrow Python build)" return struct.pack("i", i).decode("utf-32")
[ "def", "_unichr", "(", "i", ")", ":", "if", "not", "isinstance", "(", "i", ",", "int", ")", ":", "raise", "TypeError", "try", ":", "return", "six", ".", "unichr", "(", "i", ")", "except", "ValueError", ":", "# Workaround the error \"ValueError: unichr() arg ...
Helper function for taking a Unicode scalar value and returning a Unicode character. :param s: Unicode scalar value to convert. :return: Unicode character
[ "Helper", "function", "for", "taking", "a", "Unicode", "scalar", "value", "and", "returning", "a", "Unicode", "character", "." ]
python
train
32.571429
bcbio/bcbio-nextgen
bcbio/variation/mutect.py
https://github.com/bcbio/bcbio-nextgen/blob/6a9348c0054ccd5baffd22f1bb7d0422f6978b20/bcbio/variation/mutect.py#L191-L217
def _SID_call_prep(align_bams, items, ref_file, assoc_files, region=None, out_file=None): """Preparation work for SomaticIndelDetector. """ base_config = items[0]["config"] for x in align_bams: bam.index(x, base_config) params = ["-R", ref_file, "-T", "SomaticIndelDetector", "-U", "ALLOW_N_CIGAR_READS"] # Limit per base read start count to between 200-10000, i.e. from any base # can no more 10000 new reads begin. # Further, limit maxNumberOfReads accordingly, otherwise SID discards # windows for high coverage panels. paired = vcfutils.get_paired_bams(align_bams, items) params += ["--read_filter", "NotPrimaryAlignment"] params += ["-I:tumor", paired.tumor_bam] min_af = float(get_in(paired.tumor_config, ("algorithm", "min_allele_fraction"), 10)) / 100.0 if paired.normal_bam is not None: params += ["-I:normal", paired.normal_bam] # notice there must be at least 4 reads of coverage in normal params += ["--filter_expressions", "T_COV<6||N_COV<4||T_INDEL_F<%s||T_INDEL_CF<0.7" % min_af] else: params += ["--unpaired"] params += ["--filter_expressions", "COV<6||INDEL_F<%s||INDEL_CF<0.7" % min_af] if region: params += ["-L", bamprep.region_to_gatk(region), "--interval_set_rule", "INTERSECTION"] return params
[ "def", "_SID_call_prep", "(", "align_bams", ",", "items", ",", "ref_file", ",", "assoc_files", ",", "region", "=", "None", ",", "out_file", "=", "None", ")", ":", "base_config", "=", "items", "[", "0", "]", "[", "\"config\"", "]", "for", "x", "in", "al...
Preparation work for SomaticIndelDetector.
[ "Preparation", "work", "for", "SomaticIndelDetector", "." ]
python
train
49.444444
elifesciences/elife-tools
elifetools/parseJATS.py
https://github.com/elifesciences/elife-tools/blob/4b9e38cbe485c61a4ed7cbd8970c6b318334fd86/elifetools/parseJATS.py#L2108-L2126
def body_json(soup, base_url=None): """ Get body json and then alter it with section wrapping and removing boxed-text """ body_content = body(soup, remove_key_info_box=True, base_url=base_url) # Wrap in a section if the first block is not a section if (body_content and len(body_content) > 0 and "type" in body_content[0] and body_content[0]["type"] != "section"): # Wrap this one new_body_section = OrderedDict() new_body_section["type"] = "section" new_body_section["id"] = "s0" new_body_section["title"] = "Main text" new_body_section["content"] = [] for body_block in body_content: new_body_section["content"].append(body_block) new_body = [] new_body.append(new_body_section) body_content = new_body body_content_rewritten = elifetools.json_rewrite.rewrite_json("body_json", soup, body_content) return body_content_rewritten
[ "def", "body_json", "(", "soup", ",", "base_url", "=", "None", ")", ":", "body_content", "=", "body", "(", "soup", ",", "remove_key_info_box", "=", "True", ",", "base_url", "=", "base_url", ")", "# Wrap in a section if the first block is not a section", "if", "(",...
Get body json and then alter it with section wrapping and removing boxed-text
[ "Get", "body", "json", "and", "then", "alter", "it", "with", "section", "wrapping", "and", "removing", "boxed", "-", "text" ]
python
train
49.210526
alorence/django-modern-rpc
modernrpc/handlers/base.py
https://github.com/alorence/django-modern-rpc/blob/6dc42857d35764b24e2c09334f4b578629a75f9e/modernrpc/handlers/base.py#L63-L110
def execute_procedure(self, name, args=None, kwargs=None): """ Call the concrete python function corresponding to given RPC Method `name` and return the result. Raise RPCUnknownMethod, AuthenticationFailed, RPCInvalidParams or any Exception sub-class. """ _method = registry.get_method(name, self.entry_point, self.protocol) if not _method: raise RPCUnknownMethod(name) logger.debug('Check authentication / permissions for method {} and user {}' .format(name, self.request.user)) if not _method.check_permissions(self.request): raise AuthenticationFailed(name) logger.debug('RPC method {} will be executed'.format(name)) # Replace default None value with empty instance of corresponding type args = args or [] kwargs = kwargs or {} # If the RPC method needs to access some internals, update kwargs dict if _method.accept_kwargs: kwargs.update({ REQUEST_KEY: self.request, ENTRY_POINT_KEY: self.entry_point, PROTOCOL_KEY: self.protocol, HANDLER_KEY: self, }) if six.PY2: method_std, encoding = _method.str_standardization, _method.str_std_encoding args = modernrpc.compat.standardize_strings(args, strtype=method_std, encoding=encoding) kwargs = modernrpc.compat.standardize_strings(kwargs, strtype=method_std, encoding=encoding) logger.debug('Params: args = {} - kwargs = {}'.format(args, kwargs)) try: # Call the rpc method, as standard python function return _method.function(*args, **kwargs) except TypeError as e: # If given arguments cannot be transmitted properly to python function, # raise an Invalid Params exceptions raise RPCInvalidParams(str(e))
[ "def", "execute_procedure", "(", "self", ",", "name", ",", "args", "=", "None", ",", "kwargs", "=", "None", ")", ":", "_method", "=", "registry", ".", "get_method", "(", "name", ",", "self", ".", "entry_point", ",", "self", ".", "protocol", ")", "if", ...
Call the concrete python function corresponding to given RPC Method `name` and return the result. Raise RPCUnknownMethod, AuthenticationFailed, RPCInvalidParams or any Exception sub-class.
[ "Call", "the", "concrete", "python", "function", "corresponding", "to", "given", "RPC", "Method", "name", "and", "return", "the", "result", "." ]
python
train
39.479167
binux/pyspider
pyspider/scheduler/scheduler.py
https://github.com/binux/pyspider/blob/3fccfabe2b057b7a56d4a4c79dc0dd6cd2239fe9/pyspider/scheduler/scheduler.py#L263-L280
def _load_tasks(self, project): '''load tasks from database''' task_queue = project.task_queue for task in self.taskdb.load_tasks( self.taskdb.ACTIVE, project.name, self.scheduler_task_fields ): taskid = task['taskid'] _schedule = task.get('schedule', self.default_schedule) priority = _schedule.get('priority', self.default_schedule['priority']) exetime = _schedule.get('exetime', self.default_schedule['exetime']) task_queue.put(taskid, priority, exetime) project.task_loaded = True logger.debug('project: %s loaded %d tasks.', project.name, len(task_queue)) if project not in self._cnt['all']: self._update_project_cnt(project.name) self._cnt['all'].value((project.name, 'pending'), len(project.task_queue))
[ "def", "_load_tasks", "(", "self", ",", "project", ")", ":", "task_queue", "=", "project", ".", "task_queue", "for", "task", "in", "self", ".", "taskdb", ".", "load_tasks", "(", "self", ".", "taskdb", ".", "ACTIVE", ",", "project", ".", "name", ",", "s...
load tasks from database
[ "load", "tasks", "from", "database" ]
python
train
47.055556
cknoll/ipydex
ipydex/core.py
https://github.com/cknoll/ipydex/blob/ca528ce4c97ee934e48efbd5983c1b7cd88bec9d/ipydex/core.py#L701-L719
def publish_attrs(self, upcount=1): """ Magic function which inject all attrs into the callers namespace :param upcount int, how many stack levels we go up :return: """ frame = inspect.currentframe() i = upcount while True: if frame.f_back is None: break frame = frame.f_back i -= 1 if i == 0: break for k, v in self.__dict__.items(): frame.f_globals[k] = v
[ "def", "publish_attrs", "(", "self", ",", "upcount", "=", "1", ")", ":", "frame", "=", "inspect", ".", "currentframe", "(", ")", "i", "=", "upcount", "while", "True", ":", "if", "frame", ".", "f_back", "is", "None", ":", "break", "frame", "=", "frame...
Magic function which inject all attrs into the callers namespace :param upcount int, how many stack levels we go up :return:
[ "Magic", "function", "which", "inject", "all", "attrs", "into", "the", "callers", "namespace", ":", "param", "upcount", "int", "how", "many", "stack", "levels", "we", "go", "up", ":", "return", ":" ]
python
train
26.789474
eandersson/amqpstorm
amqpstorm/channel.py
https://github.com/eandersson/amqpstorm/blob/38330906c0af19eea482f43c5ce79bab98a1e064/amqpstorm/channel.py#L197-L209
def confirm_deliveries(self): """Set the channel to confirm that each message has been successfully delivered. :raises AMQPChannelError: Raises if the channel encountered an error. :raises AMQPConnectionError: Raises if the connection encountered an error. :return: """ self._confirming_deliveries = True confirm_frame = specification.Confirm.Select() return self.rpc_request(confirm_frame)
[ "def", "confirm_deliveries", "(", "self", ")", ":", "self", ".", "_confirming_deliveries", "=", "True", "confirm_frame", "=", "specification", ".", "Confirm", ".", "Select", "(", ")", "return", "self", ".", "rpc_request", "(", "confirm_frame", ")" ]
Set the channel to confirm that each message has been successfully delivered. :raises AMQPChannelError: Raises if the channel encountered an error. :raises AMQPConnectionError: Raises if the connection encountered an error. :return:
[ "Set", "the", "channel", "to", "confirm", "that", "each", "message", "has", "been", "successfully", "delivered", "." ]
python
train
37.615385
SeleniumHQ/selenium
py/selenium/webdriver/common/alert.py
https://github.com/SeleniumHQ/selenium/blob/df40c28b41d4b3953f90eaff84838a9ac052b84a/py/selenium/webdriver/common/alert.py#L92-L105
def send_keys(self, keysToSend): """ Send Keys to the Alert. :Args: - keysToSend: The text to be sent to Alert. """ if self.driver.w3c: self.driver.execute(Command.W3C_SET_ALERT_VALUE, {'value': keys_to_typing(keysToSend), 'text': keysToSend}) else: self.driver.execute(Command.SET_ALERT_VALUE, {'text': keysToSend})
[ "def", "send_keys", "(", "self", ",", "keysToSend", ")", ":", "if", "self", ".", "driver", ".", "w3c", ":", "self", ".", "driver", ".", "execute", "(", "Command", ".", "W3C_SET_ALERT_VALUE", ",", "{", "'value'", ":", "keys_to_typing", "(", "keysToSend", ...
Send Keys to the Alert. :Args: - keysToSend: The text to be sent to Alert.
[ "Send", "Keys", "to", "the", "Alert", "." ]
python
train
32.071429
alberanid/python-iplib
iplib.py
https://github.com/alberanid/python-iplib/blob/488b56fe57ad836b27feec9e76f51883db28faa6/iplib.py#L125-L136
def is_bin(ip): """Return true if the IP address is in binary notation.""" try: ip = str(ip) if len(ip) != 32: return False dec = int(ip, 2) except (TypeError, ValueError): return False if dec > 4294967295 or dec < 0: return False return True
[ "def", "is_bin", "(", "ip", ")", ":", "try", ":", "ip", "=", "str", "(", "ip", ")", "if", "len", "(", "ip", ")", "!=", "32", ":", "return", "False", "dec", "=", "int", "(", "ip", ",", "2", ")", "except", "(", "TypeError", ",", "ValueError", "...
Return true if the IP address is in binary notation.
[ "Return", "true", "if", "the", "IP", "address", "is", "in", "binary", "notation", "." ]
python
valid
25.25
adrn/gala
gala/dynamics/orbit.py
https://github.com/adrn/gala/blob/ea95575a0df1581bb4b0986aebd6eea8438ab7eb/gala/dynamics/orbit.py#L885-L916
def to_frame(self, frame, current_frame=None, **kwargs): """ TODO: Parameters ---------- frame : `gala.potential.CFrameBase` The frame to transform to. current_frame : `gala.potential.CFrameBase` (optional) If the Orbit has no associated Hamiltonian, this specifies the current frame of the orbit. Returns ------- orbit : `gala.dynamics.Orbit` The orbit in the new reference frame. """ kw = kwargs.copy() # TODO: need a better way to do this! from ..potential.frame.builtin import ConstantRotatingFrame for fr in [frame, current_frame, self.frame]: if isinstance(fr, ConstantRotatingFrame): if 't' not in kw: kw['t'] = self.t psp = super(Orbit, self).to_frame(frame, current_frame, **kw) return Orbit(pos=psp.pos, vel=psp.vel, t=self.t, frame=frame, potential=self.potential)
[ "def", "to_frame", "(", "self", ",", "frame", ",", "current_frame", "=", "None", ",", "*", "*", "kwargs", ")", ":", "kw", "=", "kwargs", ".", "copy", "(", ")", "# TODO: need a better way to do this!", "from", ".", ".", "potential", ".", "frame", ".", "bu...
TODO: Parameters ---------- frame : `gala.potential.CFrameBase` The frame to transform to. current_frame : `gala.potential.CFrameBase` (optional) If the Orbit has no associated Hamiltonian, this specifies the current frame of the orbit. Returns ------- orbit : `gala.dynamics.Orbit` The orbit in the new reference frame.
[ "TODO", ":" ]
python
train
31.125
bitesofcode/projexui
projexui/widgets/xchart/xchart.py
https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xchart/xchart.py#L154-L168
def _addDatasetAction(self, dataset): """ Adds an action for the inputed dataset to the toolbar :param dataset | <XChartDataset> """ # create the toolbar action action = QAction(dataset.name(), self) action.setIcon(XColorIcon(dataset.color())) action.setCheckable(True) action.setChecked(True) action.setData(wrapVariant(dataset)) action.toggled.connect(self.toggleDataset) self.uiDatasetTBAR.addAction(action)
[ "def", "_addDatasetAction", "(", "self", ",", "dataset", ")", ":", "# create the toolbar action\r", "action", "=", "QAction", "(", "dataset", ".", "name", "(", ")", ",", "self", ")", "action", ".", "setIcon", "(", "XColorIcon", "(", "dataset", ".", "color", ...
Adds an action for the inputed dataset to the toolbar :param dataset | <XChartDataset>
[ "Adds", "an", "action", "for", "the", "inputed", "dataset", "to", "the", "toolbar", ":", "param", "dataset", "|", "<XChartDataset", ">" ]
python
train
35.266667
gitpython-developers/GitPython
git/refs/log.py
https://github.com/gitpython-developers/GitPython/blob/1f66e25c25cde2423917ee18c4704fff83b837d1/git/refs/log.py#L180-L186
def path(cls, ref): """ :return: string to absolute path at which the reflog of the given ref instance would be found. The path is not guaranteed to point to a valid file though. :param ref: SymbolicReference instance""" return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path))
[ "def", "path", "(", "cls", ",", "ref", ")", ":", "return", "osp", ".", "join", "(", "ref", ".", "repo", ".", "git_dir", ",", "\"logs\"", ",", "to_native_path", "(", "ref", ".", "path", ")", ")" ]
:return: string to absolute path at which the reflog of the given ref instance would be found. The path is not guaranteed to point to a valid file though. :param ref: SymbolicReference instance
[ ":", "return", ":", "string", "to", "absolute", "path", "at", "which", "the", "reflog", "of", "the", "given", "ref", "instance", "would", "be", "found", ".", "The", "path", "is", "not", "guaranteed", "to", "point", "to", "a", "valid", "file", "though", ...
python
train
48.285714
devassistant/devassistant
devassistant/dapi/dapicli.py
https://github.com/devassistant/devassistant/blob/2dbfeaa666a64127263664d18969c55d19ecc83e/devassistant/dapi/dapicli.py#L610-L628
def _get_dependencies_of(name, location=None): ''' Returns list of first level dependencies of the given installed dap or dap from Dapi if not installed If a location is specified, this only checks for dap installed in that path and return [] if the dap is not located there ''' if not location: detailed_dap_list = get_installed_daps_detailed() if name not in detailed_dap_list: return _get_api_dependencies_of(name) location = detailed_dap_list[name][0]['location'] meta = '{d}/meta/{dap}.yaml'.format(d=location, dap=name) try: data = yaml.load(open(meta), Loader=Loader) except IOError: return [] return data.get('dependencies', [])
[ "def", "_get_dependencies_of", "(", "name", ",", "location", "=", "None", ")", ":", "if", "not", "location", ":", "detailed_dap_list", "=", "get_installed_daps_detailed", "(", ")", "if", "name", "not", "in", "detailed_dap_list", ":", "return", "_get_api_dependenci...
Returns list of first level dependencies of the given installed dap or dap from Dapi if not installed If a location is specified, this only checks for dap installed in that path and return [] if the dap is not located there
[ "Returns", "list", "of", "first", "level", "dependencies", "of", "the", "given", "installed", "dap", "or", "dap", "from", "Dapi", "if", "not", "installed", "If", "a", "location", "is", "specified", "this", "only", "checks", "for", "dap", "installed", "in", ...
python
train
37.684211
GuiltyTargets/ppi-network-annotation
src/ppi_network_annotation/parsers.py
https://github.com/GuiltyTargets/ppi-network-annotation/blob/4d7b6713485f2d0a0957e6457edc1b1b5a237460/src/ppi_network_annotation/parsers.py#L132-L155
def parse_gene_list(path: str, graph: Graph, anno_type: str = "name") -> list: """Parse a list of genes and return them if they are in the network. :param str path: The path of input file. :param Graph graph: The graph with genes as nodes. :param str anno_type: The type of annotation with two options:name-Entrez ID, symbol-HGNC symbol. :return list: A list of genes, all of which are in the network. """ # read the file genes = pd.read_csv(path, header=None)[0].tolist() genes = [str(int(gene)) for gene in genes] # get those genes which are in the network ind = [] if anno_type == "name": ind = graph.vs.select(name_in=genes).indices elif anno_type == "symbol": ind = graph.vs.select(symbol_in=genes).indices else: raise Exception("The type can either be name or symbol, {} is not " "supported".format(anno_type)) genes = graph.vs[ind][anno_type] return genes
[ "def", "parse_gene_list", "(", "path", ":", "str", ",", "graph", ":", "Graph", ",", "anno_type", ":", "str", "=", "\"name\"", ")", "->", "list", ":", "# read the file", "genes", "=", "pd", ".", "read_csv", "(", "path", ",", "header", "=", "None", ")", ...
Parse a list of genes and return them if they are in the network. :param str path: The path of input file. :param Graph graph: The graph with genes as nodes. :param str anno_type: The type of annotation with two options:name-Entrez ID, symbol-HGNC symbol. :return list: A list of genes, all of which are in the network.
[ "Parse", "a", "list", "of", "genes", "and", "return", "them", "if", "they", "are", "in", "the", "network", "." ]
python
train
39.75
olt/scriptine
scriptine/_path.py
https://github.com/olt/scriptine/blob/f4cfea939f2f3ad352b24c5f6410f79e78723d0e/scriptine/_path.py#L561-L596
def text(self, encoding=None, errors='strict'): r""" Open this file, read it in, return the content as a string. This uses 'U' mode in Python 2.3 and later, so '\r\n' and '\r' are automatically translated to '\n'. Optional arguments: encoding - The Unicode encoding (or character set) of the file. If present, the content of the file is decoded and returned as a unicode object; otherwise it is returned as an 8-bit str. errors - How to handle Unicode errors; see help(str.decode) for the options. Default is 'strict'. """ if encoding is None: # 8-bit f = self.open(_textmode) try: return f.read() finally: f.close() else: # Unicode f = codecs.open(self, 'r', encoding, errors) # (Note - Can't use 'U' mode here, since codecs.open # doesn't support 'U' mode, even in Python 2.3.) try: t = f.read() finally: f.close() return (t.replace(u'\r\n', u'\n') .replace(u'\r\x85', u'\n') .replace(u'\r', u'\n') .replace(u'\x85', u'\n') .replace(u'\u2028', u'\n'))
[ "def", "text", "(", "self", ",", "encoding", "=", "None", ",", "errors", "=", "'strict'", ")", ":", "if", "encoding", "is", "None", ":", "# 8-bit", "f", "=", "self", ".", "open", "(", "_textmode", ")", "try", ":", "return", "f", ".", "read", "(", ...
r""" Open this file, read it in, return the content as a string. This uses 'U' mode in Python 2.3 and later, so '\r\n' and '\r' are automatically translated to '\n'. Optional arguments: encoding - The Unicode encoding (or character set) of the file. If present, the content of the file is decoded and returned as a unicode object; otherwise it is returned as an 8-bit str. errors - How to handle Unicode errors; see help(str.decode) for the options. Default is 'strict'.
[ "r", "Open", "this", "file", "read", "it", "in", "return", "the", "content", "as", "a", "string", "." ]
python
train
36.75
GoogleCloudPlatform/python-repo-tools
gcp_devrel/tools/pylint.py
https://github.com/GoogleCloudPlatform/python-repo-tools/blob/87422ba91814529848a2b8bf8be4294283a3e041/gcp_devrel/tools/pylint.py#L148-L167
def determine_final_config(config_module): """Determines the final additions and replacements. Combines the config module with the defaults. Args: config_module: The loaded local configuration module. Returns: Config: the final configuration. """ config = Config( DEFAULT_LIBRARY_RC_ADDITIONS, DEFAULT_LIBRARY_RC_REPLACEMENTS, DEFAULT_TEST_RC_ADDITIONS, DEFAULT_TEST_RC_REPLACEMENTS) for field in config._fields: if hasattr(config_module, field): config = config._replace(**{field: getattr(config_module, field)}) return config
[ "def", "determine_final_config", "(", "config_module", ")", ":", "config", "=", "Config", "(", "DEFAULT_LIBRARY_RC_ADDITIONS", ",", "DEFAULT_LIBRARY_RC_REPLACEMENTS", ",", "DEFAULT_TEST_RC_ADDITIONS", ",", "DEFAULT_TEST_RC_REPLACEMENTS", ")", "for", "field", "in", "config",...
Determines the final additions and replacements. Combines the config module with the defaults. Args: config_module: The loaded local configuration module. Returns: Config: the final configuration.
[ "Determines", "the", "final", "additions", "and", "replacements", "." ]
python
train
29.85
PythonicNinja/pydrill
pydrill/connection/base.py
https://github.com/PythonicNinja/pydrill/blob/0713e78c84d44cd438018e4ba1588a8e242f78c4/pydrill/connection/base.py#L62-L83
def log_request_success(self, method, full_url, path, body, status_code, response, duration): """ Log a successful API call. """ if body and not isinstance(body, dict): body = body.decode('utf-8') logger.info( '%s %s [status:%s request:%.3fs]', method, full_url, status_code, duration ) logger.debug('> %s', body) logger.debug('< %s', response) if tracer.isEnabledFor(logging.INFO): if self.url_prefix: path = path.replace(self.url_prefix, '', 1) tracer.info("curl -X%s 'http://localhost:8047%s' -d '%s'", method, path, self._pretty_json(body) if body else '') if tracer.isEnabledFor(logging.DEBUG): tracer.debug('#[%s] (%.3fs)\n#%s', status_code, duration, self._pretty_json(response).replace('\n', '\n#') if response else '')
[ "def", "log_request_success", "(", "self", ",", "method", ",", "full_url", ",", "path", ",", "body", ",", "status_code", ",", "response", ",", "duration", ")", ":", "if", "body", "and", "not", "isinstance", "(", "body", ",", "dict", ")", ":", "body", "...
Log a successful API call.
[ "Log", "a", "successful", "API", "call", "." ]
python
train
41.454545
ARMmbed/mbed-cloud-sdk-python
src/mbed_cloud/device_directory/device_directory.py
https://github.com/ARMmbed/mbed-cloud-sdk-python/blob/c0af86fb2cdd4dc7ed26f236139241067d293509/src/mbed_cloud/device_directory/device_directory.py#L268-L276
def delete_query(self, query_id): """Delete query in device query service. :param int query_id: ID of the query to delete (Required) :return: void """ api = self._get_api(device_directory.DefaultApi) api.device_query_destroy(query_id) return
[ "def", "delete_query", "(", "self", ",", "query_id", ")", ":", "api", "=", "self", ".", "_get_api", "(", "device_directory", ".", "DefaultApi", ")", "api", ".", "device_query_destroy", "(", "query_id", ")", "return" ]
Delete query in device query service. :param int query_id: ID of the query to delete (Required) :return: void
[ "Delete", "query", "in", "device", "query", "service", "." ]
python
train
32.222222
secdev/scapy
scapy/layers/can.py
https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/can.py#L87-L147
def rdcandump(filename, count=None, is_not_log_file_format=False, interface=None): """Read a candump log file and return a packet list count: read only <count> packets is_not_log_file_format: read input with candumps stdout format interfaces: return only packets from a specified interface """ try: if isinstance(filename, six.string_types): file = open(filename, "rb") else: file = filename pkts = list() ifilter = None if interface is not None: if isinstance(interface, six.string_types): ifilter = [interface] else: ifilter = interface for l in file.readlines(): if is_not_log_file_format: h, data = l.split(b']') intf, idn, le = h.split() t = None else: t, intf, f = l.split() idn, data = f.split(b'#') le = None t = float(t[1:-1]) if ifilter is not None and intf.decode('ASCII') not in ifilter: continue data = data.replace(b' ', b'') data = data.strip() pkt = CAN(identifier=int(idn, 16), data=binascii.unhexlify(data)) if le is not None: pkt.length = int(le[1:]) else: pkt.length = len(pkt.data) if len(idn) > 3: pkt.flags = 0b100 if t is not None: pkt.time = t pkts.append(pkt) if count is not None and len(pkts) >= count: break finally: file.close() return pkts
[ "def", "rdcandump", "(", "filename", ",", "count", "=", "None", ",", "is_not_log_file_format", "=", "False", ",", "interface", "=", "None", ")", ":", "try", ":", "if", "isinstance", "(", "filename", ",", "six", ".", "string_types", ")", ":", "file", "=",...
Read a candump log file and return a packet list count: read only <count> packets is_not_log_file_format: read input with candumps stdout format interfaces: return only packets from a specified interface
[ "Read", "a", "candump", "log", "file", "and", "return", "a", "packet", "list" ]
python
train
27.180328
treycucco/pyebnf
pyebnf/_hand_written_parser.py
https://github.com/treycucco/pyebnf/blob/3634ddabbe5d73508bcc20f4a591f86a46634e1d/pyebnf/_hand_written_parser.py#L93-L140
def expression(self, text): """expression = number , op_mult , expression | expression_terminal , op_mult , number , [operator , expression] | expression_terminal , op_add , [operator , expression] | expression_terminal , [operator , expression] ; """ self._attempting(text) return alternation([ # number , op_mult , expression concatenation([ self.number, self.op_mult, self.expression ], ignore_whitespace=True), # expression_terminal , op_mult , number , [operator , expression] concatenation([ self.expression_terminal, self.op_mult, self.number, option( concatenation([ self.operator, self.expression ], ignore_whitespace=True) ) ], ignore_whitespace=True), # expression_terminal , op_add , [operator , expression] concatenation([ self.expression_terminal, self.op_add, option( concatenation([ self.operator, self.expression ], ignore_whitespace=True) ) ], ignore_whitespace=True), # expression_terminal , [operator , expression] concatenation([ self.expression_terminal, option( concatenation([ self.operator, self.expression ], ignore_whitespace=True) ) ], ignore_whitespace=True) ])(text).retyped(TokenType.expression)
[ "def", "expression", "(", "self", ",", "text", ")", ":", "self", ".", "_attempting", "(", "text", ")", "return", "alternation", "(", "[", "# number , op_mult , expression", "concatenation", "(", "[", "self", ".", "number", ",", "self", ".", "op_mult", ",", ...
expression = number , op_mult , expression | expression_terminal , op_mult , number , [operator , expression] | expression_terminal , op_add , [operator , expression] | expression_terminal , [operator , expression] ;
[ "expression", "=", "number", "op_mult", "expression", "|", "expression_terminal", "op_mult", "number", "[", "operator", "expression", "]", "|", "expression_terminal", "op_add", "[", "operator", "expression", "]", "|", "expression_terminal", "[", "operator", "expressio...
python
test
30.770833
Crunch-io/crunch-cube
src/cr/cube/crunch_cube.py
https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/crunch_cube.py#L1490-L1500
def _flat_values(self): """Return tuple of mean values as found in cube response. Mean data may include missing items represented by a dict like {'?': -1} in the cube response. These are replaced by np.nan in the returned value. """ return tuple( np.nan if type(x) is dict else x for x in self._cube_dict["result"]["measures"]["mean"]["data"] )
[ "def", "_flat_values", "(", "self", ")", ":", "return", "tuple", "(", "np", ".", "nan", "if", "type", "(", "x", ")", "is", "dict", "else", "x", "for", "x", "in", "self", ".", "_cube_dict", "[", "\"result\"", "]", "[", "\"measures\"", "]", "[", "\"m...
Return tuple of mean values as found in cube response. Mean data may include missing items represented by a dict like {'?': -1} in the cube response. These are replaced by np.nan in the returned value.
[ "Return", "tuple", "of", "mean", "values", "as", "found", "in", "cube", "response", "." ]
python
train
37.727273
Gandi/gandi.cli
gandi/cli/core/conf.py
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/conf.py#L75-L89
def load(cls, filename, name=None): """ Load yaml configuration from filename. """ if not os.path.exists(filename): return {} name = name or filename if name not in cls._conffiles: with open(filename) as fdesc: content = yaml.load(fdesc, YAMLLoader) # in case the file is empty if content is None: content = {} cls._conffiles[name] = content return cls._conffiles[name]
[ "def", "load", "(", "cls", ",", "filename", ",", "name", "=", "None", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "filename", ")", ":", "return", "{", "}", "name", "=", "name", "or", "filename", "if", "name", "not", "in", "cls",...
Load yaml configuration from filename.
[ "Load", "yaml", "configuration", "from", "filename", "." ]
python
train
33.666667
google/grr
grr/core/grr_response_core/lib/rdfvalues/paths.py
https://github.com/google/grr/blob/5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74/grr/core/grr_response_core/lib/rdfvalues/paths.py#L335-L346
def AsRegEx(self): """Return the current glob as a simple regex. Note: No interpolation is performed. Returns: A RegularExpression() object. """ parts = self.__class__.REGEX_SPLIT_PATTERN.split(self._value) result = u"".join(self._ReplaceRegExPart(p) for p in parts) return rdf_standard.RegularExpression(u"(?i)\\A%s\\Z" % result)
[ "def", "AsRegEx", "(", "self", ")", ":", "parts", "=", "self", ".", "__class__", ".", "REGEX_SPLIT_PATTERN", ".", "split", "(", "self", ".", "_value", ")", "result", "=", "u\"\"", ".", "join", "(", "self", ".", "_ReplaceRegExPart", "(", "p", ")", "for"...
Return the current glob as a simple regex. Note: No interpolation is performed. Returns: A RegularExpression() object.
[ "Return", "the", "current", "glob", "as", "a", "simple", "regex", "." ]
python
train
29.666667
agile-geoscience/welly
welly/project.py
https://github.com/agile-geoscience/welly/blob/ed4c991011d6290938fef365553041026ba29f42/welly/project.py#L145-L172
def add_canstrat_striplogs(self, path, uwi_transform=None, name='canstrat'): """ This may be too specific a method... just move it to the workflow. Requires striplog. """ from striplog import Striplog uwi_transform = uwi_transform or utils.null for w in self.__list: try: dat_file = utils.find_file(str(uwi_transform(w.uwi)), path) except: print("- Skipping {}: something went wrong".format(w.uwi)) continue if dat_file is None: print("- Omitting {}: no data".format(w.uwi)) continue # If we got here, we're using it. print("+ Adding {} from {}".format(w.uwi, dat_file)) w.data[name] = Striplog.from_canstrat(dat_file) return
[ "def", "add_canstrat_striplogs", "(", "self", ",", "path", ",", "uwi_transform", "=", "None", ",", "name", "=", "'canstrat'", ")", ":", "from", "striplog", "import", "Striplog", "uwi_transform", "=", "uwi_transform", "or", "utils", ".", "null", "for", "w", "...
This may be too specific a method... just move it to the workflow. Requires striplog.
[ "This", "may", "be", "too", "specific", "a", "method", "...", "just", "move", "it", "to", "the", "workflow", "." ]
python
train
30.428571
Alignak-monitoring/alignak
alignak/objects/item.py
https://github.com/Alignak-monitoring/alignak/blob/f3c145207e83159b799d3714e4241399c7740a64/alignak/objects/item.py#L1092-L1101
def old_properties_names_to_new(self): # pragma: no cover, never called """Convert old Nagios2 names to Nagios3 new names TODO: still useful? :return: None """ for i in itertools.chain(iter(list(self.items.values())), iter(list(self.templates.values()))): i.old_properties_names_to_new()
[ "def", "old_properties_names_to_new", "(", "self", ")", ":", "# pragma: no cover, never called", "for", "i", "in", "itertools", ".", "chain", "(", "iter", "(", "list", "(", "self", ".", "items", ".", "values", "(", ")", ")", ")", ",", "iter", "(", "list", ...
Convert old Nagios2 names to Nagios3 new names TODO: still useful? :return: None
[ "Convert", "old", "Nagios2", "names", "to", "Nagios3", "new", "names" ]
python
train
36.6
apache/incubator-mxnet
tools/caffe_converter/convert_symbol.py
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/convert_symbol.py#L127-L295
def _parse_proto(prototxt_fname): """Parse Caffe prototxt into symbol string """ proto = caffe_parser.read_prototxt(prototxt_fname) # process data layer input_name, input_dim, layers = _get_input(proto) # only support single input, so always use `data` as the input data mapping = {input_name: 'data'} need_flatten = {input_name: False} symbol_string = "import mxnet as mx\ndata = mx.symbol.Variable(name='data')\n" flatten_count = 0 output_name = "" prev_name = None _output_name = {} # convert reset layers one by one for i, layer in enumerate(layers): type_string = '' param_string = '' skip_layer = False name = re.sub('[-/]', '_', layer.name) for k in range(len(layer.bottom)): if layer.bottom[k] in _output_name: _output_name[layer.bottom[k]]['count'] = _output_name[layer.bottom[k]]['count']+1 else: _output_name[layer.bottom[k]] = {'count':0} for k in range(len(layer.top)): if layer.top[k] in _output_name: _output_name[layer.top[k]]['count'] = _output_name[layer.top[k]]['count']+1 else: _output_name[layer.top[k]] = {'count':0, 'name':name} if layer.type == 'Convolution' or layer.type == 4: type_string = 'mx.symbol.Convolution' param_string = _convert_conv_param(layer.convolution_param) need_flatten[name] = True if layer.type == 'Deconvolution' or layer.type == 39: type_string = 'mx.symbol.Deconvolution' param_string = _convert_conv_param(layer.convolution_param) need_flatten[name] = True if layer.type == 'Pooling' or layer.type == 17: type_string = 'mx.symbol.Pooling' param_string = _convert_pooling_param(layer.pooling_param) need_flatten[name] = True if layer.type == 'ReLU' or layer.type == 18: type_string = 'mx.symbol.Activation' param_string = "act_type='relu'" param = layer.relu_param if hasattr(param, 'negative_slope'): if param.negative_slope > 0: type_string = 'mx.symbol.LeakyReLU' param_string = "act_type='leaky', slope=%f" % param.negative_slope need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if layer.type == 'TanH' or layer.type == 23: type_string = 'mx.symbol.Activation' param_string = "act_type='tanh'" need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if layer.type == 'Sigmoid' or layer.type == 19: type_string = 'mx.symbol.Activation' param_string = "act_type='sigmoid'" need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if layer.type == 'LRN' or layer.type == 15: type_string = 'mx.symbol.LRN' param = layer.lrn_param param_string = "alpha=%f, beta=%f, knorm=%f, nsize=%d" % ( param.alpha, param.beta, param.k, param.local_size) need_flatten[name] = True if layer.type == 'InnerProduct' or layer.type == 14: type_string = 'mx.symbol.FullyConnected' param = layer.inner_product_param param_string = "num_hidden=%d, no_bias=%s" % ( param.num_output, not param.bias_term) need_flatten[name] = False if layer.type == 'Dropout' or layer.type == 6: type_string = 'mx.symbol.Dropout' param = layer.dropout_param param_string = "p=%f" % param.dropout_ratio need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if layer.type == 'Softmax' or layer.type == 20: type_string = 'mx.symbol.SoftmaxOutput' if layer.type == 'Flatten' or layer.type == 8: type_string = 'mx.symbol.Flatten' need_flatten[name] = False if layer.type == 'Split' or layer.type == 22: type_string = 'split' # will process later if layer.type == 'Concat' or layer.type == 3: type_string = 'mx.symbol.Concat' need_flatten[name] = True if layer.type == 'Crop': type_string = 'mx.symbol.Crop' need_flatten[name] = True param_string = 'center_crop=True' if layer.type == 'BatchNorm': type_string = 'mx.symbol.BatchNorm' param = layer.batch_norm_param # CuDNN requires eps to be greater than 1e-05 # We compensate for this change in convert_model epsilon = param.eps if (epsilon <= 1e-05): epsilon = 1e-04 # if next layer is scale, don't fix gamma fix_gamma = layers[i+1].type != 'Scale' param_string = 'use_global_stats=%s, fix_gamma=%s, eps=%f' % ( param.use_global_stats, fix_gamma, epsilon) need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if layer.type == 'Scale': assert layers[i-1].type == 'BatchNorm' need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] skip_layer = True prev_name = re.sub('[-/]', '_', layers[i-1].name) if layer.type == 'PReLU': type_string = 'mx.symbol.LeakyReLU' param = layer.prelu_param param_string = "act_type='prelu', slope=%f" % param.filler.value need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if layer.type == 'Eltwise': type_string = 'mx.symbol.broadcast_add' param = layer.eltwise_param param_string = "" need_flatten[name] = False if layer.type == 'Reshape': type_string = 'mx.symbol.Reshape' need_flatten[name] = False param = layer.reshape_param param_string = "shape=(%s)" % (','.join(param.shape.dim),) if layer.type == 'AbsVal': type_string = 'mx.symbol.abs' need_flatten[name] = need_flatten[mapping[layer.bottom[0]]] if skip_layer: assert len(layer.bottom) == 1 symbol_string += "%s = %s\n" % (name, prev_name) elif type_string == '': raise ValueError('Unknown layer %s!' % layer.type) elif type_string != 'split': bottom = layer.bottom if param_string != "": param_string = ", " + param_string if len(bottom) == 1: if need_flatten[mapping[bottom[0]]] and type_string == 'mx.symbol.FullyConnected': flatten_name = "flatten_%d" % flatten_count symbol_string += "%s=mx.symbol.Flatten(name='%s', data=%s)\n" % ( flatten_name, flatten_name, mapping[bottom[0]]) flatten_count += 1 need_flatten[flatten_name] = False bottom[0] = flatten_name mapping[bottom[0]] = bottom[0] symbol_string += "%s = %s(name='%s', data=%s %s)\n" % ( name, type_string, name, mapping[bottom[0]], param_string) else: if layer.type == 'Eltwise' and param.operation == 1 and len(param.coeff) > 0: symbol_string += "%s = " % name symbol_string += " + ".join(["%s * %s" % ( mapping[bottom[i]], param.coeff[i]) for i in range(len(param.coeff))]) symbol_string += "\n" else: symbol_string += "%s = %s(name='%s', *[%s] %s)\n" % ( name, type_string, name, ','.join( [mapping[x] for x in bottom]), param_string) for j in range(len(layer.top)): mapping[layer.top[j]] = name output_name = name output_name = [] for i in _output_name: if 'name' in _output_name[i] and _output_name[i]['count'] == 0: output_name.append(_output_name[i]['name']) return symbol_string, output_name, input_dim
[ "def", "_parse_proto", "(", "prototxt_fname", ")", ":", "proto", "=", "caffe_parser", ".", "read_prototxt", "(", "prototxt_fname", ")", "# process data layer", "input_name", ",", "input_dim", ",", "layers", "=", "_get_input", "(", "proto", ")", "# only support singl...
Parse Caffe prototxt into symbol string
[ "Parse", "Caffe", "prototxt", "into", "symbol", "string" ]
python
train
47.319527
undertheseanlp/languageflow
languageflow/flow.py
https://github.com/undertheseanlp/languageflow/blob/1436e0bf72803e02ccf727f41e8fc85ba167d9fe/languageflow/flow.py#L86-L98
def train(self): """ Train model with transformed data """ for i, model in enumerate(self.models): N = [int(i * len(self.y)) for i in self.lc_range] for n in N: X = self.X[:n] y = self.y[:n] e = Experiment(X, y, model.estimator, self.scores, self.validation_method) e.log_folder = self.log_folder e.train()
[ "def", "train", "(", "self", ")", ":", "for", "i", ",", "model", "in", "enumerate", "(", "self", ".", "models", ")", ":", "N", "=", "[", "int", "(", "i", "*", "len", "(", "self", ".", "y", ")", ")", "for", "i", "in", "self", ".", "lc_range", ...
Train model with transformed data
[ "Train", "model", "with", "transformed", "data" ]
python
valid
35.461538
camsci/meteor-pi
src/pythonModules/meteorpi_db/meteorpi_db/generators.py
https://github.com/camsci/meteor-pi/blob/7b01527650bd1b2b76d6f364e8122e25b8812c8d/src/pythonModules/meteorpi_db/meteorpi_db/generators.py#L28-L43
def first_from_generator(generator): """Pull the first value from a generator and return it, closing the generator :param generator: A generator, this will be mapped onto a list and the first item extracted. :return: None if there are no items, or the first item otherwise. :internal: """ try: result = next(generator) except StopIteration: result = None finally: generator.close() return result
[ "def", "first_from_generator", "(", "generator", ")", ":", "try", ":", "result", "=", "next", "(", "generator", ")", "except", "StopIteration", ":", "result", "=", "None", "finally", ":", "generator", ".", "close", "(", ")", "return", "result" ]
Pull the first value from a generator and return it, closing the generator :param generator: A generator, this will be mapped onto a list and the first item extracted. :return: None if there are no items, or the first item otherwise. :internal:
[ "Pull", "the", "first", "value", "from", "a", "generator", "and", "return", "it", "closing", "the", "generator" ]
python
train
28.5625
rochacbruno/dynaconf
dynaconf/utils/__init__.py
https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/__init__.py#L148-L154
def deduplicate(list_object): """Rebuild `list_object` removing duplicated and keeping order""" new = [] for item in list_object: if item not in new: new.append(item) return new
[ "def", "deduplicate", "(", "list_object", ")", ":", "new", "=", "[", "]", "for", "item", "in", "list_object", ":", "if", "item", "not", "in", "new", ":", "new", ".", "append", "(", "item", ")", "return", "new" ]
Rebuild `list_object` removing duplicated and keeping order
[ "Rebuild", "list_object", "removing", "duplicated", "and", "keeping", "order" ]
python
train
29.571429
secdev/scapy
scapy/contrib/mac_control.py
https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/mac_control.py#L152-L169
def get_pause_time(self, speed=ETHER_SPEED_MBIT_1000): """ get pause time for given link speed in seconds :param speed: select link speed to get the pause time for, must be ETHER_SPEED_MBIT_[10,100,1000] # noqa: E501 :return: pause time in seconds :raises MACControlInvalidSpeedException: on invalid speed selector """ try: return self.pause_time * { ETHER_SPEED_MBIT_10: (0.0000001 * 512), ETHER_SPEED_MBIT_100: (0.00000001 * 512), ETHER_SPEED_MBIT_1000: (0.000000001 * 512 * 2) }[speed] except KeyError: raise MACControlInvalidSpeedException('Invalid speed selector given. ' # noqa: E501 'Must be one of ETHER_SPEED_MBIT_[10,100,1000]')
[ "def", "get_pause_time", "(", "self", ",", "speed", "=", "ETHER_SPEED_MBIT_1000", ")", ":", "try", ":", "return", "self", ".", "pause_time", "*", "{", "ETHER_SPEED_MBIT_10", ":", "(", "0.0000001", "*", "512", ")", ",", "ETHER_SPEED_MBIT_100", ":", "(", "0.00...
get pause time for given link speed in seconds :param speed: select link speed to get the pause time for, must be ETHER_SPEED_MBIT_[10,100,1000] # noqa: E501 :return: pause time in seconds :raises MACControlInvalidSpeedException: on invalid speed selector
[ "get", "pause", "time", "for", "given", "link", "speed", "in", "seconds" ]
python
train
45.722222
rigetti/pyquil
pyquil/reference_simulator.py
https://github.com/rigetti/pyquil/blob/ec98e453084b0037d69d8c3245f6822a5422593d/pyquil/reference_simulator.py#L51-L68
def sample_bitstrings(self, n_samples): """ Sample bitstrings from the distribution defined by the wavefunction. Qubit 0 is at ``out[:, 0]``. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits) """ if self.rs is None: raise ValueError("You have tried to perform a stochastic operation without setting the " "random state of the simulator. Might I suggest using a PyQVM object?") probabilities = np.abs(self.wf) ** 2 possible_bitstrings = all_bitstrings(self.n_qubits) inds = self.rs.choice(2 ** self.n_qubits, n_samples, p=probabilities) bitstrings = possible_bitstrings[inds, :] bitstrings = np.flip(bitstrings, axis=1) # qubit ordering: 0 on the left. return bitstrings
[ "def", "sample_bitstrings", "(", "self", ",", "n_samples", ")", ":", "if", "self", ".", "rs", "is", "None", ":", "raise", "ValueError", "(", "\"You have tried to perform a stochastic operation without setting the \"", "\"random state of the simulator. Might I suggest using a Py...
Sample bitstrings from the distribution defined by the wavefunction. Qubit 0 is at ``out[:, 0]``. :param n_samples: The number of bitstrings to sample :return: An array of shape (n_samples, n_qubits)
[ "Sample", "bitstrings", "from", "the", "distribution", "defined", "by", "the", "wavefunction", "." ]
python
train
47.333333
aio-libs/aioredis
aioredis/commands/generic.py
https://github.com/aio-libs/aioredis/blob/e8c33e39558d4cc91cf70dde490d8b330c97dc2e/aioredis/commands/generic.py#L10-L13
def delete(self, key, *keys): """Delete a key.""" fut = self.execute(b'DEL', key, *keys) return wait_convert(fut, int)
[ "def", "delete", "(", "self", ",", "key", ",", "*", "keys", ")", ":", "fut", "=", "self", ".", "execute", "(", "b'DEL'", ",", "key", ",", "*", "keys", ")", "return", "wait_convert", "(", "fut", ",", "int", ")" ]
Delete a key.
[ "Delete", "a", "key", "." ]
python
train
34.75
LonamiWebs/Telethon
telethon/extensions/binaryreader.py
https://github.com/LonamiWebs/Telethon/blob/1ead9757d366b58c1e0567cddb0196e20f1a445f/telethon/extensions/binaryreader.py#L108-L116
def tgread_bool(self): """Reads a Telegram boolean value.""" value = self.read_int(signed=False) if value == 0x997275b5: # boolTrue return True elif value == 0xbc799737: # boolFalse return False else: raise RuntimeError('Invalid boolean code {}'.format(hex(value)))
[ "def", "tgread_bool", "(", "self", ")", ":", "value", "=", "self", ".", "read_int", "(", "signed", "=", "False", ")", "if", "value", "==", "0x997275b5", ":", "# boolTrue", "return", "True", "elif", "value", "==", "0xbc799737", ":", "# boolFalse", "return",...
Reads a Telegram boolean value.
[ "Reads", "a", "Telegram", "boolean", "value", "." ]
python
train
37.222222
thespacedoctor/sloancone
build/lib/sloancone/cl_utils.py
https://github.com/thespacedoctor/sloancone/blob/106ea6533ad57f5f0ca82bf6db3053132bdb42e1/build/lib/sloancone/cl_utils.py#L178-L258
def main(arguments=None): """ *The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command* """ # setup the command-line util settings su = tools( arguments=arguments, docString=__doc__, logLevel="DEBUG", options_first=False, projectName="sloancone", tunnel=False ) arguments, settings, log, dbConn = su.setup() # tab completion for raw_input readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(tab_complete) # unpack remaining cl arguments using `exec` to setup the variable names # automatically for arg, val in arguments.iteritems(): if arg[0] == "-": varname = arg.replace("-", "") + "Flag" else: varname = arg.replace("<", "").replace(">", "") if isinstance(val, str) or isinstance(val, unicode): exec(varname + " = '%s'" % (val,)) else: exec(varname + " = %s" % (val,)) if arg == "--dbConn": dbConn = val log.debug('%s = %s' % (varname, val,)) ## START LOGGING ## startTime = times.get_now_sql_datetime() log.info( '--- STARTING TO RUN THE cl_utils.py AT %s' % (startTime,)) # set options interactively if user requests if "interactiveFlag" in locals() and interactiveFlag: # load previous settings moduleDirectory = os.path.dirname(__file__) + "/resources" pathToPickleFile = "%(moduleDirectory)s/previousSettings.p" % locals() try: with open(pathToPickleFile): pass previousSettingsExist = True except: previousSettingsExist = False previousSettings = {} if previousSettingsExist: previousSettings = pickle.load(open(pathToPickleFile, "rb")) # x-raw-input # x-boolean-raw-input # x-raw-input-with-default-value-from-previous-settings # save the most recently used requests pickleMeObjects = [] pickleMe = {} theseLocals = locals() for k in pickleMeObjects: pickleMe[k] = theseLocals[k] pickle.dump(pickleMe, open(pathToPickleFile, "wb")) # CALL FUNCTIONS/OBJECTS if "dbConn" in locals() and dbConn: dbConn.commit() dbConn.close() ## FINISH LOGGING ## endTime = times.get_now_sql_datetime() runningTime = times.calculate_time_difference(startTime, endTime) log.info('-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --' % (endTime, runningTime, )) return
[ "def", "main", "(", "arguments", "=", "None", ")", ":", "# setup the command-line util settings", "su", "=", "tools", "(", "arguments", "=", "arguments", ",", "docString", "=", "__doc__", ",", "logLevel", "=", "\"DEBUG\"", ",", "options_first", "=", "False", "...
*The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command*
[ "*", "The", "main", "function", "used", "when", "cl_utils", ".", "py", "is", "run", "as", "a", "single", "script", "from", "the", "cl", "or", "when", "installed", "as", "a", "cl", "command", "*" ]
python
train
32.382716
kodexlab/reliure
reliure/engine.py
https://github.com/kodexlab/reliure/blob/0450c7a9254c5c003162738458bbe0c49e777ba5/reliure/engine.py#L362-L373
def selected(self): """ returns the list of selected component names. if no component selected return the one marked as default. If the block is required and no component where indicated as default, then the first component is selected. """ selected = self._selected if len(self._selected) == 0 and self.required: # nothing has been selected yet BUT the component is required selected = self.defaults return selected
[ "def", "selected", "(", "self", ")", ":", "selected", "=", "self", ".", "_selected", "if", "len", "(", "self", ".", "_selected", ")", "==", "0", "and", "self", ".", "required", ":", "# nothing has been selected yet BUT the component is required", "selected", "="...
returns the list of selected component names. if no component selected return the one marked as default. If the block is required and no component where indicated as default, then the first component is selected.
[ "returns", "the", "list", "of", "selected", "component", "names", "." ]
python
train
41.166667
materialsproject/pymatgen
pymatgen/io/qchem/outputs.py
https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/io/qchem/outputs.py#L651-L696
def _check_completion_errors(self): """ Parses four potential errors that can cause jobs to crash: inability to transform coordinates due to a bad symmetric specification, an input file that fails to pass inspection, and errors reading and writing files. """ if read_pattern( self.text, { "key": r"Coordinates do not transform within specified threshold" }, terminate_on_match=True).get('key') == [[]]: self.data["errors"] += ["failed_to_transform_coords"] elif read_pattern( self.text, { "key": r"The Q\-Chem input file has failed to pass inspection" }, terminate_on_match=True).get('key') == [[]]: self.data["errors"] += ["input_file_error"] elif read_pattern( self.text, { "key": r"Error opening input stream" }, terminate_on_match=True).get('key') == [[]]: self.data["errors"] += ["failed_to_read_input"] elif read_pattern( self.text, { "key": r"FileMan error: End of file reached prematurely" }, terminate_on_match=True).get('key') == [[]]: self.data["errors"] += ["IO_error"] elif read_pattern( self.text, { "key": r"Could not find \$molecule section in ParseQInput" }, terminate_on_match=True).get('key') == [[]]: self.data["errors"] += ["read_molecule_error"] elif read_pattern( self.text, { "key": r"Welcome to Q-Chem" }, terminate_on_match=True).get('key') != [[]]: self.data["errors"] += ["never_called_qchem"] else: self.data["errors"] += ["unknown_error"]
[ "def", "_check_completion_errors", "(", "self", ")", ":", "if", "read_pattern", "(", "self", ".", "text", ",", "{", "\"key\"", ":", "r\"Coordinates do not transform within specified threshold\"", "}", ",", "terminate_on_match", "=", "True", ")", ".", "get", "(", "...
Parses four potential errors that can cause jobs to crash: inability to transform coordinates due to a bad symmetric specification, an input file that fails to pass inspection, and errors reading and writing files.
[ "Parses", "four", "potential", "errors", "that", "can", "cause", "jobs", "to", "crash", ":", "inability", "to", "transform", "coordinates", "due", "to", "a", "bad", "symmetric", "specification", "an", "input", "file", "that", "fails", "to", "pass", "inspection...
python
train
42.065217
OCHA-DAP/hdx-python-utilities
src/hdx/utilities/downloader.py
https://github.com/OCHA-DAP/hdx-python-utilities/blob/9c89e0aa5afac2c002b02a2d8f0e5b91eeb3d2a3/src/hdx/utilities/downloader.py#L135-L152
def get_url_for_get(url, parameters=None): # type: (str, Optional[Dict]) -> str """Get full url for GET request including parameters Args: url (str): URL to download parameters (Optional[Dict]): Parameters to pass. Defaults to None. Returns: str: Full url """ spliturl = urlsplit(url) getparams = OrderedDict(parse_qsl(spliturl.query)) if parameters is not None: getparams.update(parameters) spliturl = spliturl._replace(query=urlencode(getparams)) return urlunsplit(spliturl)
[ "def", "get_url_for_get", "(", "url", ",", "parameters", "=", "None", ")", ":", "# type: (str, Optional[Dict]) -> str", "spliturl", "=", "urlsplit", "(", "url", ")", "getparams", "=", "OrderedDict", "(", "parse_qsl", "(", "spliturl", ".", "query", ")", ")", "i...
Get full url for GET request including parameters Args: url (str): URL to download parameters (Optional[Dict]): Parameters to pass. Defaults to None. Returns: str: Full url
[ "Get", "full", "url", "for", "GET", "request", "including", "parameters" ]
python
train
32.777778
Robin8Put/pmes
storage/rpc_methods.py
https://github.com/Robin8Put/pmes/blob/338bec94162098f05b75bad035417317e1252fd2/storage/rpc_methods.py#L685-L718
async def set_access_string(self, **params): """Writes content access string to database """ if params.get("message"): params = json.loads(params.get("message", "{}")) cid = int(params.get("cid", "0")) seller_access_string = params.get("seller_access_string") seller_pubkey = params.get("seller_pubkey") coinid = params.get("coinid") try: coinid = coinid.replace("TEST", "") except: pass database = client[coinid] collection = database[settings.CONTENT] content = await collection.find_one({"cid":cid}) if not content: return {"error":404, "reason":"Content not found"} if not all([cid, seller_access_string, seller_pubkey]): return {"error":400, "reason":"Missed required fields"} await collection.find_one_and_update({"cid":cid}, {"$set":{"seller_access_string":seller_access_string}}) await collection.find_one_and_update({"cid":cid}, {"$set":{"seller_pubkey":seller_pubkey}}) content = await collection.find_one({"cid":cid}) return {i:content[i] for i in content if i != "_id"}
[ "async", "def", "set_access_string", "(", "self", ",", "*", "*", "params", ")", ":", "if", "params", ".", "get", "(", "\"message\"", ")", ":", "params", "=", "json", ".", "loads", "(", "params", ".", "get", "(", "\"message\"", ",", "\"{}\"", ")", ")"...
Writes content access string to database
[ "Writes", "content", "access", "string", "to", "database" ]
python
train
30
tensorflow/mesh
mesh_tensorflow/auto_mtf/graph_interface.py
https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/graph_interface.py#L292-L299
def set_tensor_final(self, tensor_name): """Denotes a tensor as a final output of the computation. Args: tensor_name: a string, name of a tensor in the graph. """ tensor = self._name_to_tensor(tensor_name) self._final_tensors.add(tensor)
[ "def", "set_tensor_final", "(", "self", ",", "tensor_name", ")", ":", "tensor", "=", "self", ".", "_name_to_tensor", "(", "tensor_name", ")", "self", ".", "_final_tensors", ".", "add", "(", "tensor", ")" ]
Denotes a tensor as a final output of the computation. Args: tensor_name: a string, name of a tensor in the graph.
[ "Denotes", "a", "tensor", "as", "a", "final", "output", "of", "the", "computation", "." ]
python
train
32.125
isislovecruft/python-gnupg
pretty_bad_protocol/_util.py
https://github.com/isislovecruft/python-gnupg/blob/784571449032e811587249743e183fc5e908a673/pretty_bad_protocol/_util.py#L596-L602
def _make_random_string(length): """Returns a random lowercase, uppercase, alphanumerical string. :param int length: The length in bytes of the string to generate. """ chars = string.ascii_lowercase + string.ascii_uppercase + string.digits return ''.join(random.choice(chars) for x in range(length))
[ "def", "_make_random_string", "(", "length", ")", ":", "chars", "=", "string", ".", "ascii_lowercase", "+", "string", ".", "ascii_uppercase", "+", "string", ".", "digits", "return", "''", ".", "join", "(", "random", ".", "choice", "(", "chars", ")", "for",...
Returns a random lowercase, uppercase, alphanumerical string. :param int length: The length in bytes of the string to generate.
[ "Returns", "a", "random", "lowercase", "uppercase", "alphanumerical", "string", "." ]
python
train
44.857143
cloud9ers/gurumate
environment/lib/python2.7/site-packages/IPython/parallel/client/client.py
https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1204-L1246
def send_apply_request(self, socket, f, args=None, kwargs=None, subheader=None, track=False, ident=None): """construct and send an apply message via a socket. This is the principal method with which all engine execution is performed by views. """ if self._closed: raise RuntimeError("Client cannot be used after its sockets have been closed") # defaults: args = args if args is not None else [] kwargs = kwargs if kwargs is not None else {} subheader = subheader if subheader is not None else {} # validate arguments if not callable(f) and not isinstance(f, Reference): raise TypeError("f must be callable, not %s"%type(f)) if not isinstance(args, (tuple, list)): raise TypeError("args must be tuple or list, not %s"%type(args)) if not isinstance(kwargs, dict): raise TypeError("kwargs must be dict, not %s"%type(kwargs)) if not isinstance(subheader, dict): raise TypeError("subheader must be dict, not %s"%type(subheader)) bufs = util.pack_apply_message(f,args,kwargs) msg = self.session.send(socket, "apply_request", buffers=bufs, ident=ident, subheader=subheader, track=track) msg_id = msg['header']['msg_id'] self.outstanding.add(msg_id) if ident: # possibly routed to a specific engine if isinstance(ident, list): ident = ident[-1] if ident in self._engines.values(): # save for later, in case of engine death self._outstanding_dict[ident].add(msg_id) self.history.append(msg_id) self.metadata[msg_id]['submitted'] = datetime.now() return msg
[ "def", "send_apply_request", "(", "self", ",", "socket", ",", "f", ",", "args", "=", "None", ",", "kwargs", "=", "None", ",", "subheader", "=", "None", ",", "track", "=", "False", ",", "ident", "=", "None", ")", ":", "if", "self", ".", "_closed", "...
construct and send an apply message via a socket. This is the principal method with which all engine execution is performed by views.
[ "construct", "and", "send", "an", "apply", "message", "via", "a", "socket", "." ]
python
test
41.604651
treyhunner/django-simple-history
simple_history/models.py
https://github.com/treyhunner/django-simple-history/blob/85758ecfe608279508a3fb5b71654d3e202eb63d/simple_history/models.py#L193-L228
def create_history_model(self, model, inherited): """ Creates a historical model to associate with the model provided. """ attrs = { "__module__": self.module, "_history_excluded_fields": self.excluded_fields, } app_module = "%s.models" % model._meta.app_label if inherited: # inherited use models module attrs["__module__"] = model.__module__ elif model.__module__ != self.module: # registered under different app attrs["__module__"] = self.module elif app_module != self.module: # Abuse an internal API because the app registry is loading. app = apps.app_configs[model._meta.app_label] models_module = app.name attrs["__module__"] = models_module fields = self.copy_fields(model) attrs.update(fields) attrs.update(self.get_extra_fields(model, fields)) # type in python2 wants str as a first argument attrs.update(Meta=type(str("Meta"), (), self.get_meta_options(model))) if self.table_name is not None: attrs["Meta"].db_table = self.table_name # Set as the default then check for overrides name = self.get_history_model_name(model) registered_models[model._meta.db_table] = model return python_2_unicode_compatible(type(str(name), self.bases, attrs))
[ "def", "create_history_model", "(", "self", ",", "model", ",", "inherited", ")", ":", "attrs", "=", "{", "\"__module__\"", ":", "self", ".", "module", ",", "\"_history_excluded_fields\"", ":", "self", ".", "excluded_fields", ",", "}", "app_module", "=", "\"%s....
Creates a historical model to associate with the model provided.
[ "Creates", "a", "historical", "model", "to", "associate", "with", "the", "model", "provided", "." ]
python
train
39.055556
aalireza/SimpleAudioIndexer
SimpleAudioIndexer/__init__.py
https://github.com/aalireza/SimpleAudioIndexer/blob/73f9d75897d785bdaea9d28dde5fa48104428164/SimpleAudioIndexer/__init__.py#L1112-L1170
def _timestamp_regulator(self): """ Makes a dictionary whose keys are audio file basenames and whose values are a list of word blocks from unregulated timestamps and updates the main timestamp attribute. After all done, purges unregulated ones. In case the audio file was large enough to be splitted, it adds seconds to correct timing and in case the timestamp was manually loaded, it leaves it alone. Note that the difference between self.__timestamps and self.__timestamps_unregulated is that in the regulated version, right after the word, a list of word blocks must appear. However in the unregulated version, after a word, a list of individual splits containing word blocks would appear! """ unified_timestamps = _PrettyDefaultDict(list) staged_files = self._list_audio_files(sub_dir="staging") for timestamp_basename in self.__timestamps_unregulated: if len(self.__timestamps_unregulated[timestamp_basename]) > 1: # File has been splitted timestamp_name = ''.join(timestamp_basename.split('.')[:-1]) staged_splitted_files_of_timestamp = list( filter(lambda staged_file: ( timestamp_name == staged_file[:-3] and all([(x in set(map(str, range(10)))) for x in staged_file[-3:]])), staged_files)) if len(staged_splitted_files_of_timestamp) == 0: self.__errors[(time(), timestamp_basename)] = { "reason": "Missing staged file", "current_staged_files": staged_files} continue staged_splitted_files_of_timestamp.sort() unified_timestamp = list() for staging_digits, splitted_file in enumerate( self.__timestamps_unregulated[timestamp_basename]): prev_splits_sec = 0 if int(staging_digits) != 0: prev_splits_sec = self._get_audio_duration_seconds( "{}/staging/{}{:03d}".format( self.src_dir, timestamp_name, staging_digits - 1)) for word_block in splitted_file: unified_timestamp.append( _WordBlock( word=word_block.word, start=round(word_block.start + prev_splits_sec, 2), end=round(word_block.end + prev_splits_sec, 2))) unified_timestamps[ str(timestamp_basename)] += unified_timestamp else: unified_timestamps[ timestamp_basename] += self.__timestamps_unregulated[ timestamp_basename][0] self.__timestamps.update(unified_timestamps) self.__timestamps_unregulated = _PrettyDefaultDict(list)
[ "def", "_timestamp_regulator", "(", "self", ")", ":", "unified_timestamps", "=", "_PrettyDefaultDict", "(", "list", ")", "staged_files", "=", "self", ".", "_list_audio_files", "(", "sub_dir", "=", "\"staging\"", ")", "for", "timestamp_basename", "in", "self", ".",...
Makes a dictionary whose keys are audio file basenames and whose values are a list of word blocks from unregulated timestamps and updates the main timestamp attribute. After all done, purges unregulated ones. In case the audio file was large enough to be splitted, it adds seconds to correct timing and in case the timestamp was manually loaded, it leaves it alone. Note that the difference between self.__timestamps and self.__timestamps_unregulated is that in the regulated version, right after the word, a list of word blocks must appear. However in the unregulated version, after a word, a list of individual splits containing word blocks would appear!
[ "Makes", "a", "dictionary", "whose", "keys", "are", "audio", "file", "basenames", "and", "whose", "values", "are", "a", "list", "of", "word", "blocks", "from", "unregulated", "timestamps", "and", "updates", "the", "main", "timestamp", "attribute", ".", "After"...
python
train
53.186441
WhyNotHugo/django-afip
django_afip/admin.py
https://github.com/WhyNotHugo/django-afip/blob/5fb73213f1fe86ca52b501ffd0737911ef26ddb3/django_afip/admin.py#L24-L59
def catch_errors(f): """ Catches specific errors in admin actions and shows a friendly error. """ @functools.wraps(f) def wrapper(self, request, *args, **kwargs): try: return f(self, request, *args, **kwargs) except exceptions.CertificateExpired: self.message_user( request, _('The AFIP Taxpayer certificate has expired.'), messages.ERROR, ) except exceptions.UntrustedCertificate: self.message_user( request, _('The AFIP Taxpayer certificate is untrusted.'), messages.ERROR, ) except exceptions.CorruptCertificate: self.message_user( request, _('The AFIP Taxpayer certificate is corrupt.'), messages.ERROR, ) except exceptions.AuthenticationError as e: logger.exception('AFIP auth failed') self.message_user( request, _('An unknown authentication error has ocurred: %s') % e, messages.ERROR, ) return wrapper
[ "def", "catch_errors", "(", "f", ")", ":", "@", "functools", ".", "wraps", "(", "f", ")", "def", "wrapper", "(", "self", ",", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "return", "f", "(", "self", ",", "request", ...
Catches specific errors in admin actions and shows a friendly error.
[ "Catches", "specific", "errors", "in", "admin", "actions", "and", "shows", "a", "friendly", "error", "." ]
python
train
32
log2timeline/plaso
plaso/parsers/sqlite_plugins/mackeeper_cache.py
https://github.com/log2timeline/plaso/blob/9c564698d2da3ffbe23607a3c54c0582ea18a6cc/plaso/parsers/sqlite_plugins/mackeeper_cache.py#L100-L131
def _ExtractJQuery(self, jquery_raw): """Extracts values from a JQuery string. Args: jquery_raw (str): JQuery string. Returns: dict[str, str]: extracted values. """ data_part = '' if not jquery_raw: return {} if '[' in jquery_raw: _, _, first_part = jquery_raw.partition('[') data_part, _, _ = first_part.partition(']') elif jquery_raw.startswith('//'): _, _, first_part = jquery_raw.partition('{') data_part = '{{{0:s}'.format(first_part) elif '({' in jquery_raw: _, _, first_part = jquery_raw.partition('(') data_part, _, _ = first_part.rpartition(')') if not data_part: return {} try: data_dict = json.loads(data_part) except ValueError: return {} return data_dict
[ "def", "_ExtractJQuery", "(", "self", ",", "jquery_raw", ")", ":", "data_part", "=", "''", "if", "not", "jquery_raw", ":", "return", "{", "}", "if", "'['", "in", "jquery_raw", ":", "_", ",", "_", ",", "first_part", "=", "jquery_raw", ".", "partition", ...
Extracts values from a JQuery string. Args: jquery_raw (str): JQuery string. Returns: dict[str, str]: extracted values.
[ "Extracts", "values", "from", "a", "JQuery", "string", "." ]
python
train
23.9375
bapakode/OmMongo
ommongo/fields/fields.py
https://github.com/bapakode/OmMongo/blob/52b5a5420516dc709f2d2eb065818c7973991ce3/ommongo/fields/fields.py#L444-L450
def wrap(self, value, session=None): ''' Validates that ``value`` is an ObjectId (or hex representation of one), then returns it ''' self.validate_wrap(value) if isinstance(value, bytes) or isinstance(value, basestring): return ObjectId(value) return value
[ "def", "wrap", "(", "self", ",", "value", ",", "session", "=", "None", ")", ":", "self", ".", "validate_wrap", "(", "value", ")", "if", "isinstance", "(", "value", ",", "bytes", ")", "or", "isinstance", "(", "value", ",", "basestring", ")", ":", "ret...
Validates that ``value`` is an ObjectId (or hex representation of one), then returns it
[ "Validates", "that", "value", "is", "an", "ObjectId", "(", "or", "hex", "representation", "of", "one", ")", "then", "returns", "it" ]
python
train
43.714286
project-rig/rig
rig/machine_control/machine_controller.py
https://github.com/project-rig/rig/blob/3a3e053d3214899b6d68758685835de0afd5542b/rig/machine_control/machine_controller.py#L1252-L1262
def _send_ffe(self, pid, app_id, app_flags, fr): """Send a flood-fill end packet. The cores and regions that the application should be loaded to will have been specified by a stream of flood-fill core select packets (FFCS). """ arg1 = (NNCommands.flood_fill_end << 24) | pid arg2 = (app_id << 24) | (app_flags << 18) self._send_scp(255, 255, 0, SCPCommands.nearest_neighbour_packet, arg1, arg2, fr)
[ "def", "_send_ffe", "(", "self", ",", "pid", ",", "app_id", ",", "app_flags", ",", "fr", ")", ":", "arg1", "=", "(", "NNCommands", ".", "flood_fill_end", "<<", "24", ")", "|", "pid", "arg2", "=", "(", "app_id", "<<", "24", ")", "|", "(", "app_flags...
Send a flood-fill end packet. The cores and regions that the application should be loaded to will have been specified by a stream of flood-fill core select packets (FFCS).
[ "Send", "a", "flood", "-", "fill", "end", "packet", "." ]
python
train
43.272727
PyCQA/prospector
prospector/run.py
https://github.com/PyCQA/prospector/blob/7cfc6d587049a786f935a722d6851cd3b72d7972/prospector/run.py#L150-L157
def get_parser(): """ This is a helper method to return an argparse parser, to be used with the Sphinx argparse plugin for documentation. """ manager = cfg.build_manager() source = cfg.build_command_line_source(prog='prospector', description=None) return source.build_parser(manager.settings, None)
[ "def", "get_parser", "(", ")", ":", "manager", "=", "cfg", ".", "build_manager", "(", ")", "source", "=", "cfg", ".", "build_command_line_source", "(", "prog", "=", "'prospector'", ",", "description", "=", "None", ")", "return", "source", ".", "build_parser"...
This is a helper method to return an argparse parser, to be used with the Sphinx argparse plugin for documentation.
[ "This", "is", "a", "helper", "method", "to", "return", "an", "argparse", "parser", "to", "be", "used", "with", "the", "Sphinx", "argparse", "plugin", "for", "documentation", "." ]
python
train
39.875
unt-libraries/pyuntl
pyuntl/dc_structure.py
https://github.com/unt-libraries/pyuntl/blob/f92413302897dab948aac18ee9e482ace0187bd4/pyuntl/dc_structure.py#L104-L114
def resolver(self, vocab_data, attribute): """Pull the requested attribute based on the given vocabulary and content. """ term_list = vocab_data.get(self.content_vocab, []) # Loop through the terms from the vocabulary. for term_dict in term_list: # Match the name to the current content. if term_dict['name'] == self.content: return term_dict[attribute] return self.content
[ "def", "resolver", "(", "self", ",", "vocab_data", ",", "attribute", ")", ":", "term_list", "=", "vocab_data", ".", "get", "(", "self", ".", "content_vocab", ",", "[", "]", ")", "# Loop through the terms from the vocabulary.", "for", "term_dict", "in", "term_lis...
Pull the requested attribute based on the given vocabulary and content.
[ "Pull", "the", "requested", "attribute", "based", "on", "the", "given", "vocabulary", "and", "content", "." ]
python
train
41.727273
deepmipt/DeepPavlov
deeppavlov/core/layers/tf_attention_mechanisms.py
https://github.com/deepmipt/DeepPavlov/blob/f3e4a69a3764d25d2f5bad4f1f1aebc872b00f9c/deeppavlov/core/layers/tf_attention_mechanisms.py#L278-L337
def cs_bahdanau_attention(key, context, hidden_size, depth, projected_align=False): """ It is a implementation of the Bahdanau et al. attention mechanism. Based on the papers: https://arxiv.org/abs/1409.0473 "Neural Machine Translation by Jointly Learning to Align and Translate" https://andre-martins.github.io/docs/emnlp2017_final.pdf "Learning What's Easy: Fully Differentiable Neural Easy-First Taggers" Args: key: A tensorflow tensor with dimensionality [None, None, key_size] context: A tensorflow tensor with dimensionality [None, None, max_num_tokens, token_size] hidden_size: Number of units in hidden representation depth: Number of csoftmax usages projected_align: Using bidirectional lstm for hidden representation of context. If true, beetween input and attention mechanism insert layer of bidirectional lstm with dimensionality [hidden_size]. If false, bidirectional lstm is not used. Returns: output: Tensor at the output with dimensionality [None, None, depth * hidden_size] """ if hidden_size % 2 != 0: raise ValueError("hidden size must be dividable by two") batch_size = tf.shape(context)[0] max_num_tokens, token_size = context.get_shape().as_list()[-2:] r_context = tf.reshape(context, shape=[-1, max_num_tokens, token_size]) # projected context: [None, max_num_tokens, token_size] projected_context = tf.layers.dense(r_context, token_size, kernel_initializer=xav(), name='projected_context') # projected_key: [None, None, hidden_size] projected_key = tf.layers.dense(key, hidden_size, kernel_initializer=xav(), name='projected_key') r_projected_key = \ tf.tile(tf.reshape(projected_key, shape=[-1, 1, hidden_size]), [1, max_num_tokens, 1]) lstm_fw_cell = tf.nn.rnn_cell.LSTMCell(hidden_size//2) lstm_bw_cell = tf.nn.rnn_cell.LSTMCell(hidden_size//2) (output_fw, output_bw), states = \ tf.nn.bidirectional_dynamic_rnn(cell_fw=lstm_fw_cell, cell_bw=lstm_bw_cell, inputs=projected_context, dtype=tf.float32) # bilstm_output: [-1, max_num_tokens, hidden_size] bilstm_output = tf.concat([output_fw, output_bw], -1) concat_h_state = tf.concat([r_projected_key, output_fw, output_bw], -1) if projected_align: log.info("Using projected attention alignment") h_state_for_attn_alignment = bilstm_output aligned_h_state = csoftmax_attention.attention_bah_block( concat_h_state, h_state_for_attn_alignment, depth) output = \ tf.reshape(aligned_h_state, shape=[batch_size, -1, depth * hidden_size]) else: log.info("Using without projected attention alignment") h_state_for_attn_alignment = projected_context aligned_h_state = csoftmax_attention.attention_bah_block( concat_h_state, h_state_for_attn_alignment, depth) output = \ tf.reshape(aligned_h_state, shape=[batch_size, -1, depth * token_size]) return output
[ "def", "cs_bahdanau_attention", "(", "key", ",", "context", ",", "hidden_size", ",", "depth", ",", "projected_align", "=", "False", ")", ":", "if", "hidden_size", "%", "2", "!=", "0", ":", "raise", "ValueError", "(", "\"hidden size must be dividable by two\"", "...
It is a implementation of the Bahdanau et al. attention mechanism. Based on the papers: https://arxiv.org/abs/1409.0473 "Neural Machine Translation by Jointly Learning to Align and Translate" https://andre-martins.github.io/docs/emnlp2017_final.pdf "Learning What's Easy: Fully Differentiable Neural Easy-First Taggers" Args: key: A tensorflow tensor with dimensionality [None, None, key_size] context: A tensorflow tensor with dimensionality [None, None, max_num_tokens, token_size] hidden_size: Number of units in hidden representation depth: Number of csoftmax usages projected_align: Using bidirectional lstm for hidden representation of context. If true, beetween input and attention mechanism insert layer of bidirectional lstm with dimensionality [hidden_size]. If false, bidirectional lstm is not used. Returns: output: Tensor at the output with dimensionality [None, None, depth * hidden_size]
[ "It", "is", "a", "implementation", "of", "the", "Bahdanau", "et", "al", ".", "attention", "mechanism", ".", "Based", "on", "the", "papers", ":", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1409", ".", "0473", "Neural", "Machine", "Transl...
python
test
53.733333
iotile/coretools
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/intelc.py
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/intelc.py#L120-L135
def get_version_from_list(v, vlist): """See if we can match v (string) in vlist (list of strings) Linux has to match in a fuzzy way.""" if is_windows: # Simple case, just find it in the list if v in vlist: return v else: return None else: # Fuzzy match: normalize version number first, but still return # original non-normalized form. fuzz = 0.001 for vi in vlist: if math.fabs(linux_ver_normalize(vi) - linux_ver_normalize(v)) < fuzz: return vi # Not found return None
[ "def", "get_version_from_list", "(", "v", ",", "vlist", ")", ":", "if", "is_windows", ":", "# Simple case, just find it in the list", "if", "v", "in", "vlist", ":", "return", "v", "else", ":", "return", "None", "else", ":", "# Fuzzy match: normalize version number f...
See if we can match v (string) in vlist (list of strings) Linux has to match in a fuzzy way.
[ "See", "if", "we", "can", "match", "v", "(", "string", ")", "in", "vlist", "(", "list", "of", "strings", ")", "Linux", "has", "to", "match", "in", "a", "fuzzy", "way", "." ]
python
train
35.625
Scoppio/RagnarokEngine3
RagnarokEngine3/RE3.py
https://github.com/Scoppio/RagnarokEngine3/blob/4395d419ccd64fe9327c41f200b72ee0176ad896/RagnarokEngine3/RE3.py#L665-L675
def to_vec3(self): """Convert this vector4 instance into a vector3 instance.""" vec3 = Vector3() vec3.x = self.x vec3.y = self.y vec3.z = self.z if self.w != 0: vec3 /= self.w return vec3
[ "def", "to_vec3", "(", "self", ")", ":", "vec3", "=", "Vector3", "(", ")", "vec3", ".", "x", "=", "self", ".", "x", "vec3", ".", "y", "=", "self", ".", "y", "vec3", ".", "z", "=", "self", ".", "z", "if", "self", ".", "w", "!=", "0", ":", ...
Convert this vector4 instance into a vector3 instance.
[ "Convert", "this", "vector4", "instance", "into", "a", "vector3", "instance", "." ]
python
train
22.454545
ibm-watson-iot/iot-python
tmp/src/things/things.py
https://github.com/ibm-watson-iot/iot-python/blob/195f05adce3fba4ec997017e41e02ebd85c0c4cc/tmp/src/things/things.py#L1617-L1649
def updateMappingsOnDeviceType(self, thingTypeId, logicalInterfaceId, mappingsObject, notificationStrategy = "never"): """ Add mappings for a thing type. Parameters: - thingTypeId (string) - the thing type - logicalInterfaceId (string) - the id of the application interface these mappings are for - notificationStrategy (string) - the notification strategy to use for these mappings - mappingsObject (Python dictionary corresponding to JSON object) example: { # eventid -> { property -> eventid property expression } "status" : { "eventCount" : "($state.eventCount == -1) ? $event.d.count : ($state.eventCount+1)", } } Throws APIException on failure. """ req = ApiClient.oneThingTypeMappingUrl % (self.host, "/draft", thingTypeId, logicalInterfaceId) try: mappings = json.dumps({ "logicalInterfaceId" : logicalInterfaceId, "notificationStrategy" : notificationStrategy, "propertyMappings" : mappingsObject }) except Exception as exc: raise ibmiotf.APIException(-1, "Exception formatting mappings object to JSON", exc) resp = requests.put(req, auth=self.credentials, headers={"Content-Type":"application/json"}, data=mappings, verify=self.verify) if resp.status_code == 200: self.logger.debug("Thing type mappings updated for logical interface") else: raise ibmiotf.APIException(resp.status_code, "HTTP error updating thing type mappings for logical interface", resp) return resp.json()
[ "def", "updateMappingsOnDeviceType", "(", "self", ",", "thingTypeId", ",", "logicalInterfaceId", ",", "mappingsObject", ",", "notificationStrategy", "=", "\"never\"", ")", ":", "req", "=", "ApiClient", ".", "oneThingTypeMappingUrl", "%", "(", "self", ".", "host", ...
Add mappings for a thing type. Parameters: - thingTypeId (string) - the thing type - logicalInterfaceId (string) - the id of the application interface these mappings are for - notificationStrategy (string) - the notification strategy to use for these mappings - mappingsObject (Python dictionary corresponding to JSON object) example: { # eventid -> { property -> eventid property expression } "status" : { "eventCount" : "($state.eventCount == -1) ? $event.d.count : ($state.eventCount+1)", } } Throws APIException on failure.
[ "Add", "mappings", "for", "a", "thing", "type", ".", "Parameters", ":", "-", "thingTypeId", "(", "string", ")", "-", "the", "thing", "type", "-", "logicalInterfaceId", "(", "string", ")", "-", "the", "id", "of", "the", "application", "interface", "these", ...
python
test
50.818182
agoragames/haigha
haigha/connection.py
https://github.com/agoragames/haigha/blob/7b004e1c0316ec14b94fec1c54554654c38b1a25/haigha/connection.py#L393-L458
def read_frames(self): ''' Read frames from the transport and process them. Some transports may choose to do this in the background, in several threads, and so on. ''' # It's possible in a concurrent environment that our transport handle # has gone away, so handle that cleanly. # TODO: Consider moving this block into Translator base class. In many # ways it belongs there. One of the problems though is that this is # essentially the read loop. Each Transport has different rules for # how to kick this off, and in the case of gevent, this is how a # blocking call to read from the socket is kicked off. if self._transport is None: return # Send a heartbeat (if needed) self._channels[0].send_heartbeat() data = self._transport.read(self._heartbeat) current_time = time.time() if data is None: # Wait for 2 heartbeat intervals before giving up. See AMQP 4.2.7: # "If a peer detects no incoming traffic (i.e. received octets) for two heartbeat intervals or longer, # it should close the connection" if self._heartbeat and (current_time-self._last_octet_time > 2*self._heartbeat): msg = 'Heartbeats not received from %s for %d seconds' % (self._host, 2*self._heartbeat) self.transport_closed(msg=msg) raise ConnectionClosed('Connection is closed: ' + msg) return self._last_octet_time = current_time reader = Reader(data) p_channels = set() try: for frame in Frame.read_frames(reader): if self._debug > 1: self.logger.debug("READ: %s", frame) self._frames_read += 1 ch = self.channel(frame.channel_id) ch.buffer_frame(frame) p_channels.add(ch) except Frame.FrameError as e: # Frame error in the peer, disconnect self.close(reply_code=501, reply_text='frame error from %s : %s' % ( self._host, str(e)), class_id=0, method_id=0, disconnect=True) raise ConnectionClosed("connection is closed: %s : %s" % (self._close_info['reply_code'], self._close_info['reply_text'])) # NOTE: we process channels after buffering unused data in order to # preserve the integrity of the input stream in case a channel needs to # read input, such as when a channel framing error necessitates the use # of the synchronous channel.close method. See `Channel.process_frames`. # # HACK: read the buffer contents and re-buffer. Would prefer to pass # buffer back, but there's no good way of asking the total size of the # buffer, comparing to tell(), and then re-buffering. There's also no # ability to clear the buffer up to the current position. It would be # awesome if we could free that memory without a new allocation. if reader.tell() < len(data): self._transport.buffer(data[reader.tell():]) self._transport.process_channels(p_channels)
[ "def", "read_frames", "(", "self", ")", ":", "# It's possible in a concurrent environment that our transport handle", "# has gone away, so handle that cleanly.", "# TODO: Consider moving this block into Translator base class. In many", "# ways it belongs there. One of the problems though is that t...
Read frames from the transport and process them. Some transports may choose to do this in the background, in several threads, and so on.
[ "Read", "frames", "from", "the", "transport", "and", "process", "them", ".", "Some", "transports", "may", "choose", "to", "do", "this", "in", "the", "background", "in", "several", "threads", "and", "so", "on", "." ]
python
train
49.348485
ergoithz/unicategories
unicategories/tools.py
https://github.com/ergoithz/unicategories/blob/70ade9fa3662ac3fc62fb2648a29a360a4d82025/unicategories/tools.py#L133-L161
def generate(categorize=unicodedata.category, group_class=RangeGroup): ''' Generate a dict of RangeGroups for each unicode character category, including general ones. :param categorize: category function, defaults to unicodedata.category. :type categorize: callable :param group_class: class for range groups, defaults to RangeGroup :type group_class: type :returns: dictionary of categories and range groups :rtype: dict of RangeGroup ''' categories = collections.defaultdict(list) last_category = None last_range = None for c in range(sys.maxunicode + 1): category = categorize(chr(c)) if category != last_category: last_category = category last_range = [c, c + 1] categories[last_category].append(last_range) else: last_range[1] += 1 categories = {k: group_class(v) for k, v in categories.items()} categories.update({ k: merge(*map(categories.__getitem__, g)) for k, g in itertools.groupby(sorted(categories), key=lambda k: k[0]) }) return categories
[ "def", "generate", "(", "categorize", "=", "unicodedata", ".", "category", ",", "group_class", "=", "RangeGroup", ")", ":", "categories", "=", "collections", ".", "defaultdict", "(", "list", ")", "last_category", "=", "None", "last_range", "=", "None", "for", ...
Generate a dict of RangeGroups for each unicode character category, including general ones. :param categorize: category function, defaults to unicodedata.category. :type categorize: callable :param group_class: class for range groups, defaults to RangeGroup :type group_class: type :returns: dictionary of categories and range groups :rtype: dict of RangeGroup
[ "Generate", "a", "dict", "of", "RangeGroups", "for", "each", "unicode", "character", "category", "including", "general", "ones", "." ]
python
train
37.586207
mikedh/trimesh
trimesh/ray/ray_triangle.py
https://github.com/mikedh/trimesh/blob/25e059bf6d4caa74f62ffd58ce4f61a90ee4e518/trimesh/ray/ray_triangle.py#L28-L64
def intersects_id(self, ray_origins, ray_directions, return_locations=False, multiple_hits=True, **kwargs): """ Find the intersections between the current mesh and a list of rays. Parameters ------------ ray_origins: (m,3) float, ray origin points ray_directions: (m,3) float, ray direction vectors multiple_hits: bool, consider multiple hits of each ray or not return_locations: bool, return hit locations or not Returns ----------- index_triangle: (h,) int, index of triangles hit index_ray: (h,) int, index of ray that hit triangle locations: (h,3) float, (optional) position of intersection in space """ (index_tri, index_ray, locations) = ray_triangle_id(triangles=self.mesh.triangles, ray_origins=ray_origins, ray_directions=ray_directions, tree=self.mesh.triangles_tree, multiple_hits=multiple_hits, triangles_normal=self.mesh.face_normals) if return_locations: if len(index_tri) == 0: return index_tri, index_ray, locations unique = grouping.unique_rows(np.column_stack((locations, index_ray)))[0] return index_tri[unique], index_ray[unique], locations[unique] return index_tri, index_ray
[ "def", "intersects_id", "(", "self", ",", "ray_origins", ",", "ray_directions", ",", "return_locations", "=", "False", ",", "multiple_hits", "=", "True", ",", "*", "*", "kwargs", ")", ":", "(", "index_tri", ",", "index_ray", ",", "locations", ")", "=", "ra...
Find the intersections between the current mesh and a list of rays. Parameters ------------ ray_origins: (m,3) float, ray origin points ray_directions: (m,3) float, ray direction vectors multiple_hits: bool, consider multiple hits of each ray or not return_locations: bool, return hit locations or not Returns ----------- index_triangle: (h,) int, index of triangles hit index_ray: (h,) int, index of ray that hit triangle locations: (h,3) float, (optional) position of intersection in space
[ "Find", "the", "intersections", "between", "the", "current", "mesh", "and", "a", "list", "of", "rays", "." ]
python
train
44.675676
yyuu/botornado
boto/rds/__init__.py
https://github.com/yyuu/botornado/blob/fffb056f5ff2324d1d5c1304014cfb1d899f602e/boto/rds/__init__.py#L815-L831
def create_dbsnapshot(self, snapshot_id, dbinstance_id): """ Create a new DB snapshot. :type snapshot_id: string :param snapshot_id: The identifier for the DBSnapshot :type dbinstance_id: string :param dbinstance_id: The source identifier for the RDS instance from which the snapshot is created. :rtype: :class:`boto.rds.dbsnapshot.DBSnapshot` :return: The newly created DBSnapshot """ params = {'DBSnapshotIdentifier' : snapshot_id, 'DBInstanceIdentifier' : dbinstance_id} return self.get_object('CreateDBSnapshot', params, DBSnapshot)
[ "def", "create_dbsnapshot", "(", "self", ",", "snapshot_id", ",", "dbinstance_id", ")", ":", "params", "=", "{", "'DBSnapshotIdentifier'", ":", "snapshot_id", ",", "'DBInstanceIdentifier'", ":", "dbinstance_id", "}", "return", "self", ".", "get_object", "(", "'Cre...
Create a new DB snapshot. :type snapshot_id: string :param snapshot_id: The identifier for the DBSnapshot :type dbinstance_id: string :param dbinstance_id: The source identifier for the RDS instance from which the snapshot is created. :rtype: :class:`boto.rds.dbsnapshot.DBSnapshot` :return: The newly created DBSnapshot
[ "Create", "a", "new", "DB", "snapshot", "." ]
python
train
38.764706
Unidata/siphon
siphon/catalog.py
https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/catalog.py#L622-L650
def subset(self, service=None): """Subset the dataset. Open the remote dataset and get a client for talking to ``service``. Parameters ---------- service : str, optional The name of the service for subsetting the dataset. Defaults to 'NetcdfSubset' or 'NetcdfServer', in that order, depending on the services listed in the catalog. Returns ------- a client for communicating using ``service`` """ if service is None: for serviceName in self.ncssServiceNames: if serviceName in self.access_urls: service = serviceName break else: raise RuntimeError('Subset access is not available for this dataset.') elif service not in self.ncssServiceNames: raise ValueError(service + ' is not a valid service for subset. Options are: ' + ', '.join(self.ncssServiceNames)) return self.access_with_service(service)
[ "def", "subset", "(", "self", ",", "service", "=", "None", ")", ":", "if", "service", "is", "None", ":", "for", "serviceName", "in", "self", ".", "ncssServiceNames", ":", "if", "serviceName", "in", "self", ".", "access_urls", ":", "service", "=", "servic...
Subset the dataset. Open the remote dataset and get a client for talking to ``service``. Parameters ---------- service : str, optional The name of the service for subsetting the dataset. Defaults to 'NetcdfSubset' or 'NetcdfServer', in that order, depending on the services listed in the catalog. Returns ------- a client for communicating using ``service``
[ "Subset", "the", "dataset", "." ]
python
train
36
alvations/pywsd
pywsd/semeval.py
https://github.com/alvations/pywsd/blob/4c12394c8adbcfed71dd912bdbef2e36370821bf/pywsd/semeval.py#L112-L147
def sentences(self): """ Returns the instances by sentences, and yields a list of tokens, similar to the pywsd.semcor.sentences. >>> coarse_wsd = SemEval2007_Coarse_WSD() >>> for sent in coarse_wsd.sentences(): >>> for token in sent: >>> print token >>> break >>> break word(id=None, text=u'Your', offset=None, sentid=0, paraid=u'd001', term=None) """ for sentid, ys in enumerate(self.yield_sentences()): sent, context_sent, context_doc, inst2ans, textid = ys instances = {} for instance in sent.findAll('instance'): instid = instance['id'] lemma = instance['lemma'] word = instance.text instances[instid] = Instance(instid, lemma, word) tokens = [] for i in sent: # Iterates through BeautifulSoup object. if str(i).startswith('<instance'): # BeautifulSoup.Tag instid = sent.find('instance')['id'] inst = instances[instid] answer = inst2ans[instid] term = Term(instid, answer.pos, inst.lemma, answer.sensekey, type='open') tokens.append(Word(instid, inst.word, sentid, textid, term)) else: # if BeautifulSoup.NavigableString tokens+=[Word(None, w, sentid, textid, None) for w in i.split()] yield tokens
[ "def", "sentences", "(", "self", ")", ":", "for", "sentid", ",", "ys", "in", "enumerate", "(", "self", ".", "yield_sentences", "(", ")", ")", ":", "sent", ",", "context_sent", ",", "context_doc", ",", "inst2ans", ",", "textid", "=", "ys", "instances", ...
Returns the instances by sentences, and yields a list of tokens, similar to the pywsd.semcor.sentences. >>> coarse_wsd = SemEval2007_Coarse_WSD() >>> for sent in coarse_wsd.sentences(): >>> for token in sent: >>> print token >>> break >>> break word(id=None, text=u'Your', offset=None, sentid=0, paraid=u'd001', term=None)
[ "Returns", "the", "instances", "by", "sentences", "and", "yields", "a", "list", "of", "tokens", "similar", "to", "the", "pywsd", ".", "semcor", ".", "sentences", "." ]
python
train
43.805556
mdsol/rwslib
rwslib/builders/metadata.py
https://github.com/mdsol/rwslib/blob/1a86bc072d408c009ed1de8bf6e98a1769f54d18/rwslib/builders/metadata.py#L229-L234
def build(self, builder): """Build XML by appending to builder""" builder.start("Symbol", {}) for child in self.translations: child.build(builder) builder.end("Symbol")
[ "def", "build", "(", "self", ",", "builder", ")", ":", "builder", ".", "start", "(", "\"Symbol\"", ",", "{", "}", ")", "for", "child", "in", "self", ".", "translations", ":", "child", ".", "build", "(", "builder", ")", "builder", ".", "end", "(", "...
Build XML by appending to builder
[ "Build", "XML", "by", "appending", "to", "builder" ]
python
train
34.5
aouyar/PyMunin
pymunin/plugins/nginxstats.py
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/nginxstats.py#L188-L197
def autoconf(self): """Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise. """ nginxInfo = NginxInfo(self._host, self._port, self._user, self._password, self._statuspath, self._ssl) return nginxInfo is not None
[ "def", "autoconf", "(", "self", ")", ":", "nginxInfo", "=", "NginxInfo", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_user", ",", "self", ".", "_password", ",", "self", ".", "_statuspath", ",", "self", ".", "_ssl", ")", ...
Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise.
[ "Implements", "Munin", "Plugin", "Auto", "-", "Configuration", "Option", "." ]
python
train
39.8
MattBroach/DjangoRestMultipleModels
drf_multiple_model/pagination.py
https://github.com/MattBroach/DjangoRestMultipleModels/blob/893969ed38d614a5e2f060e560824fa7c5c49cfd/drf_multiple_model/pagination.py#L13-L31
def paginate_queryset(self, queryset, request, view=None): """ adds `max_count` as a running tally of the largest table size. Used for calculating next/previous links later """ result = super(MultipleModelLimitOffsetPagination, self).paginate_queryset(queryset, request, view) try: if self.max_count < self.count: self.max_count = self.count except AttributeError: self.max_count = self.count try: self.total += self.count except AttributeError: self.total = self.count return result
[ "def", "paginate_queryset", "(", "self", ",", "queryset", ",", "request", ",", "view", "=", "None", ")", ":", "result", "=", "super", "(", "MultipleModelLimitOffsetPagination", ",", "self", ")", ".", "paginate_queryset", "(", "queryset", ",", "request", ",", ...
adds `max_count` as a running tally of the largest table size. Used for calculating next/previous links later
[ "adds", "max_count", "as", "a", "running", "tally", "of", "the", "largest", "table", "size", ".", "Used", "for", "calculating", "next", "/", "previous", "links", "later" ]
python
train
32.263158
twilio/twilio-python
twilio/rest/api/v2010/account/message/__init__.py
https://github.com/twilio/twilio-python/blob/c867895f55dcc29f522e6e8b8868d0d18483132f/twilio/rest/api/v2010/account/message/__init__.py#L92-L127
def stream(self, to=values.unset, from_=values.unset, date_sent_before=values.unset, date_sent=values.unset, date_sent_after=values.unset, limit=None, page_size=None): """ Streams MessageInstance records from the API as a generator stream. This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. :param unicode to: Filter by messages sent to this number :param unicode from_: Filter by from number :param datetime date_sent_before: Filter by date sent :param datetime date_sent: Filter by date sent :param datetime date_sent_after: Filter by date sent :param int limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param int page_size: Number of records to fetch per request, when not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000) :returns: Generator that will yield up to limit results :rtype: list[twilio.rest.api.v2010.account.message.MessageInstance] """ limits = self._version.read_limits(limit, page_size) page = self.page( to=to, from_=from_, date_sent_before=date_sent_before, date_sent=date_sent, date_sent_after=date_sent_after, page_size=limits['page_size'], ) return self._version.stream(page, limits['limit'], limits['page_limit'])
[ "def", "stream", "(", "self", ",", "to", "=", "values", ".", "unset", ",", "from_", "=", "values", ".", "unset", ",", "date_sent_before", "=", "values", ".", "unset", ",", "date_sent", "=", "values", ".", "unset", ",", "date_sent_after", "=", "values", ...
Streams MessageInstance records from the API as a generator stream. This operation lazily loads records as efficiently as possible until the limit is reached. The results are returned as a generator, so this operation is memory efficient. :param unicode to: Filter by messages sent to this number :param unicode from_: Filter by from number :param datetime date_sent_before: Filter by date sent :param datetime date_sent: Filter by date sent :param datetime date_sent_after: Filter by date sent :param int limit: Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit :param int page_size: Number of records to fetch per request, when not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000) :returns: Generator that will yield up to limit results :rtype: list[twilio.rest.api.v2010.account.message.MessageInstance]
[ "Streams", "MessageInstance", "records", "from", "the", "API", "as", "a", "generator", "stream", ".", "This", "operation", "lazily", "loads", "records", "as", "efficiently", "as", "possible", "until", "the", "limit", "is", "reached", ".", "The", "results", "ar...
python
train
50.722222
mardix/Juice
juice/plugins/user/__init__.py
https://github.com/mardix/Juice/blob/7afa8d4238868235dfcdae82272bd77958dd416a/juice/plugins/user/__init__.py#L265-L807
def auth(view, **kwargs): """ This plugin allow user to login to application kwargs: - signin_view - signout_view - template_dir - menu: - name - group_name - ... @plugin(user.login, model=model.User) class MyAccount(Juice): pass """ endpoint_namespace = view.__name__ + ":%s" view_name = view.__name__ UserModel = kwargs.pop("model") User = UserModel.User login_view = endpoint_namespace % "login" on_signin_view = kwargs.get("signin_view", "Index:index") on_signout_view = kwargs.get("signout_view", "Index:index") template_dir = kwargs.get("template_dir", "Juice/Plugin/User/Account") template_page = template_dir + "/%s.html" login_manager = LoginManager() login_manager.login_view = login_view login_manager.login_message_category = "error" init_app(login_manager.init_app) menu_context = view _menu = kwargs.get("menu", {}) if _menu: @menu(**_menu) class UserAccountMenu(object): pass menu_context = UserAccountMenu @login_manager.user_loader def load_user(userid): return User.get(userid) View.g(__USER_AUTH_ENABLED__=True) class Auth(object): decorators = view.decorators + [login_required] SESSION_KEY_SET_EMAIL_DATA = "set_email_tmp_data" TEMP_DATA_KEY = "login_tmp_data" @property def tmp_data(self): return session[self.TEMP_DATA_KEY] @tmp_data.setter def tmp_data(self, data): session[self.TEMP_DATA_KEY] = data def _login_enabled(self): if self.get_config("USER_AUTH_ALLOW_LOGIN") is not True: abort("UserLoginDisabledError") def _signup_enabled(self): if self.get_config("USER_AUTH_ALLOW_SIGNUP") is not True: abort("UserSignupDisabledError") def _oauth_enabled(self): if self.get_config("USER_AUTH_ALLOW_OAUTH") is not True: abort("UserOAuthDisabledError") def _send_reset_password(self, user): delivery = self.get_config("USER_AUTH_PASSWORD_RESET_METHOD") token_reset_ttl = self.get_config("USER_AUTH_TOKEN_RESET_TTL", 60) new_password = None if delivery.upper() == "TOKEN": token = user.set_temp_login(token_reset_ttl) url = url_for(endpoint_namespace % "reset_password", token=token, _external=True) else: new_password = user.set_password(password=None, random=True) url = url_for(endpoint_namespace % "login", _external=True) mail.send(template="reset-password.txt", method_=delivery, to=user.email, name=user.email, url=url, new_password=new_password) @classmethod def login_user(cls, user): login_user(user) now = datetime.datetime.now() user.update(last_login=now, last_visited=now) @menu("Login", endpoint=endpoint_namespace % "login", visible_with_auth_user=False, extends=menu_context) @template(template_page % "login", endpoint_namespace=endpoint_namespace) @route("login/", methods=["GET", "POST"], endpoint=endpoint_namespace % "login") @no_login_required def login(self): """ Login page """ self._login_enabled() logout_user() self.tmp_data = None self.meta_tags(title="Login") if request.method == "POST": email = request.form.get("email").strip() password = request.form.get("password").strip() if not email or not password: flash("Email or Password is empty", "error") return redirect(url_for(login_view, next=request.form.get("next"))) user = User.get_by_email(email) if user and user.password_hash and user.password_matched(password): self.login_user(user) return redirect(request.form.get("next") or url_for(on_signin_view)) else: flash("Email or Password is invalid", "error") return redirect(url_for(login_view, next=request.form.get("next"))) return dict(login_url_next=request.args.get("next", ""), login_url_default=url_for(on_signin_view), signup_enabled=self.get_config("USER_AUTH_ALLOW_SIGNUP"), oauth_enabled=self.get_config("USER_AUTH_ALLOW_LOGIN")) @menu("Logout", endpoint=endpoint_namespace % "logout", visible_with_auth_user=True, order=100, extends=menu_context) @route("logout/", endpoint=endpoint_namespace % "logout") @no_login_required def logout(self): logout_user() return redirect(url_for(on_signout_view or login_view)) @menu("Signup", endpoint=endpoint_namespace % "signup", visible_with_auth_user=False, extends=menu_context) @template(template_page % "signup", endpoint_namespace=endpoint_namespace) @route("signup/", methods=["GET", "POST"], endpoint=endpoint_namespace % "signup") @no_login_required def signup(self): """ For Email Signup :return: """ self._login_enabled() self._signup_enabled() self.meta_tags(title="Signup") if request.method == "POST": # reCaptcha if not recaptcha.verify(): flash("Invalid Security code", "error") return redirect(url_for(endpoint_namespace % "signup", next=request.form.get("next"))) try: name = request.form.get("name") email = request.form.get("email") password = request.form.get("password") password2 = request.form.get("password2") profile_image_url = request.form.get("profile_image_url", None) if not name: raise UserError("Name is required") elif not utils.is_valid_email(email): raise UserError("Invalid email address '%s'" % email) elif not password.strip() or password.strip() != password2.strip(): raise UserError("Passwords don't match") elif not utils.is_valid_password(password): raise UserError("Invalid password") else: new_account = User.new(email=email, password=password.strip(), first_name=name, profile_image_url=profile_image_url, signup_method="email") self.login_user(new_account) return redirect(request.form.get("next") or url_for(on_signin_view)) except ApplicationError as ex: flash(ex.message, "error") return redirect(url_for(endpoint_namespace % "signup", next=request.form.get("next"))) logout_user() return dict(login_url_next=request.args.get("next", "")) @route("lost-password/", methods=["GET", "POST"], endpoint=endpoint_namespace % "lost_password") @template(template_page % "lost_password", endpoint_namespace=endpoint_namespace) @no_login_required def lost_password(self): self._login_enabled() logout_user() self.meta_tags(title="Lost Password") if request.method == "POST": email = request.form.get("email") user = User.get_by_email(email) if user: self._send_reset_password(user) flash("A new password has been sent to '%s'" % email, "success") else: flash("Invalid email address", "error") return redirect(url_for(login_view)) else: return {} @menu("Account Settings", endpoint=endpoint_namespace % "account_settings", order=99, visible_with_auth_user=True, extends=menu_context) @template(template_page % "account_settings", endpoint_namespace=endpoint_namespace) @route("account-settings", methods=["GET", "POST"], endpoint=endpoint_namespace % "account_settings") @fresh_login_required def account_settings(self): self.meta_tags(title="Account Settings") if request.method == "POST": action = request.form.get("action") try: action = action.lower() # if action == "info": first_name = request.form.get("first_name").strip() last_name = request.form.get("last_name", "").strip() data = { "first_name": first_name, "last_name": last_name } current_user.update(**data) flash("Account info updated successfully!", "success") # elif action == "login": confirm_password = request.form.get("confirm-password").strip() if current_user.password_matched(confirm_password): self.change_login_handler() flash("Login Info updated successfully!", "success") else: flash("Invalid password", "error") # elif action == "password": confirm_password = request.form.get("confirm-password").strip() if current_user.password_matched(confirm_password): self.change_password_handler() flash("Password updated successfully!", "success") else: flash("Invalid password", "error") elif action == "profile-photo": file = request.files.get("file") if file: prefix = "profile-photos/%s/" % current_user.id extensions = ["jpg", "jpeg", "png", "gif"] my_photo = storage.upload(file, prefix=prefix, allowed_extensions=extensions) if my_photo: url = my_photo.url current_user.update(profile_image_url=url) flash("Profile Image updated successfully!", "success") else: raise UserError("Invalid action") except Exception as e: flash(e.message, "error") return redirect(url_for(endpoint_namespace % "account_settings")) return {} @classmethod def change_login_handler(cls, user_context=None, email=None): if not user_context: user_context = current_user if not email: email = request.form.get("email").strip() if not utils.is_valid_email(email): raise UserWarning("Invalid email address '%s'" % email) else: if email != user_context.email and User.get_by_email(email): raise UserWarning("Email exists already '%s'" % email) elif email != user_context.email: user_context.update(email=email) return True return False @classmethod def change_password_handler(cls, user_context=None, password=None, password2=None): if not user_context: user_context = current_user if not password: password = request.form.get("password").strip() if not password2: password2 = request.form.get("password2").strip() if password: if password != password2: raise UserWarning("Password don't match") elif not utils.is_valid_password(password): raise UserWarning("Invalid password") else: user_context.set_password(password) return True else: raise UserWarning("Password is empty") # OAUTH Login @route("oauth-login/<provider>", methods=["GET", "POST"], endpoint=endpoint_namespace % "oauth_login") @template(template_page % "oauth_login", endpoint_namespace=endpoint_namespace) @no_login_required def oauth_login(self, provider): """ Login via oauth providers """ self._login_enabled() self._oauth_enabled() provider = provider.lower() result = oauth.login(provider) response = oauth.response popup_js_custom = { "action": "", "url": "" } if result: if result.error: pass elif result.user: result.user.update() oauth_user = result.user user = User.get_by_oauth(provider=provider, provider_user_id=oauth_user.id) if not user: if oauth_user.email and User.get_by_email(oauth_user.email): flash("Account already exists with this email '%s'. " "Try to login or retrieve your password " % oauth_user.email, "error") popup_js_custom.update({ "action": "redirect", "url": url_for(login_view, next=request.form.get("next")) }) else: tmp_data = { "is_oauth": True, "provider": provider, "id": oauth_user.id, "name": oauth_user.name, "picture": oauth_user.picture, "first_name": oauth_user.first_name, "last_name": oauth_user.last_name, "email": oauth_user.email, "link": oauth_user.link } if not oauth_user.email: self.tmp_data = tmp_data popup_js_custom.update({ "action": "redirect", "url": url_for(endpoint_namespace % "setup_login") }) else: try: picture = oauth_user.picture user = User.new(email=oauth_user.email, name=oauth_user.name, signup_method=provider, profile_image_url=picture ) user.add_oauth(provider, oauth_user.provider_id, name=oauth_user.name, email=oauth_user.email, profile_image_url=oauth_user.picture, link=oauth_user.link) except ModelError as e: flash(e.message, "error") popup_js_custom.update({ "action": "redirect", "url": url_for(endpoint_namespace % "login") }) if user: self.login_user(user) return dict(popup_js=result.popup_js(custom=popup_js_custom), template_=template_page % "oauth_login") return response @template(template_page % "setup_login", endpoint_namespace=endpoint_namespace) @route("setup-login/", methods=["GET", "POST"], endpoint=endpoint_namespace % "setup_login") def setup_login(self): """ Allows to setup a email password if it's not provided specially coming from oauth-login :return: """ self._login_enabled() self.meta_tags(title="Setup Login") # Only user without email can set email if current_user.is_authenticated() and current_user.email: return redirect(url_for(endpoint_namespace % "account_settings")) if self.tmp_data: if request.method == "POST": if not self.tmp_data["is_oauth"]: return redirect(endpoint_namespace % "login") try: email = request.form.get("email") password = request.form.get("password") password2 = request.form.get("password2") if not utils.is_valid_email(email): raise UserError("Invalid email address '%s'" % email) elif User.get_by_email(email): raise UserError("An account exists already with this email address '%s' " % email) elif not password.strip() or password.strip() != password2.strip(): raise UserError("Passwords don't match") elif not utils.is_valid_password(password): raise UserError("Invalid password") else: user = User.new(email=email, password=password.strip(), name=self.tmp_data["name"], profile_image_url=self.tmp_data["picture"], signup_method=self.tmp_data["provider"]) user.add_oauth(self.tmp_data["provider"], self.tmp_data["id"], name=self.tmp_data["name"], email=email, profile_image_url=self.tmp_data["picture"], link=self.tmp_data["link"]) self.login_user(user) self.tmp_data = None return redirect(request.form.get("next") or url_for(on_signin_view)) except ApplicationError as ex: flash(ex.message, "error") return redirect(url_for(endpoint_namespace % "login")) return dict(provider=self.tmp_data) else: return redirect(url_for(endpoint_namespace % "login")) @route("reset-password/<token>", methods=["GET", "POST"], endpoint=endpoint_namespace % "reset_password") @template(template_page % "reset_password", endpoint_namespace=endpoint_namespace) @no_login_required def reset_password(self, token): self._login_enabled() logout_user() self.meta_tags(title="Reset Password") user = User.get_by_temp_login(token) if user: if not user.has_temp_login: return redirect(url_for(on_signin_view)) if request.method == "POST": try: self.change_password_handler(user_context=user) user.clear_temp_login() flash("Password updated successfully!", "success") return redirect(url_for(on_signin_view)) except Exception as ex: flash("Error: %s" % ex.message, "error") return redirect(url_for(endpoint_namespace % "reset_password", token=token)) else: return dict(token=token) else: abort(404, "Invalid token") @route("oauth-connect", methods=["POST"], endpoint="%s:oauth_connect" % endpoint_namespace) def oauth_connect(self): """ To login via social """ email = request.form.get("email").strip() name = request.form.get("name").strip() provider = request.form.get("provider").strip() provider_user_id = request.form.get("provider_user_id").strip() image_url = request.form.get("image_url").strip() next = request.form.get("next", "") try: current_user.oauth_connect(provider=provider, provider_user_id=provider_user_id, email=email, name=name, image_url=image_url) except Exception as ex: flash("Unable to link your account", "error") return redirect(url_for(endpoint_namespace % "account_settings")) return Auth
[ "def", "auth", "(", "view", ",", "*", "*", "kwargs", ")", ":", "endpoint_namespace", "=", "view", ".", "__name__", "+", "\":%s\"", "view_name", "=", "view", ".", "__name__", "UserModel", "=", "kwargs", ".", "pop", "(", "\"model\"", ")", "User", "=", "U...
This plugin allow user to login to application kwargs: - signin_view - signout_view - template_dir - menu: - name - group_name - ... @plugin(user.login, model=model.User) class MyAccount(Juice): pass
[ "This", "plugin", "allow", "user", "to", "login", "to", "application" ]
python
train
41.650092
rsalmaso/django-fluo
fluo/views/decorators.py
https://github.com/rsalmaso/django-fluo/blob/1321c1e7d6a912108f79be02a9e7f2108c57f89f/fluo/views/decorators.py#L34-L51
def ajax_required(func): # taken from djangosnippets.org """ AJAX request required decorator use it in your views: @ajax_required def my_view(request): .... """ def wrap(request, *args, **kwargs): if not request.is_ajax(): return HttpResponseBadRequest return func(request, *args, **kwargs) wrap.__doc__ = func.__doc__ wrap.__name__ = func.__name__ return wrap
[ "def", "ajax_required", "(", "func", ")", ":", "# taken from djangosnippets.org", "def", "wrap", "(", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "request", ".", "is_ajax", "(", ")", ":", "return", "HttpResponseBadRequest", ...
AJAX request required decorator use it in your views: @ajax_required def my_view(request): ....
[ "AJAX", "request", "required", "decorator", "use", "it", "in", "your", "views", ":" ]
python
train
23.611111
basho/riak-python-client
riak/client/transport.py
https://github.com/basho/riak-python-client/blob/91de13a16607cdf553d1a194e762734e3bec4231/riak/client/transport.py#L190-L210
def _choose_pool(self, protocol=None): """ Selects a connection pool according to the default protocol and the passed one. :param protocol: the protocol to use :type protocol: string :rtype: Pool """ if not protocol: protocol = self.protocol if protocol == 'http': pool = self._http_pool elif protocol == 'tcp' or protocol == 'pbc': pool = self._tcp_pool else: raise ValueError("invalid protocol %s" % protocol) if pool is None or self._closed: # NB: GH-500, this can happen if client is closed raise RuntimeError("Client is closed.") return pool
[ "def", "_choose_pool", "(", "self", ",", "protocol", "=", "None", ")", ":", "if", "not", "protocol", ":", "protocol", "=", "self", ".", "protocol", "if", "protocol", "==", "'http'", ":", "pool", "=", "self", ".", "_http_pool", "elif", "protocol", "==", ...
Selects a connection pool according to the default protocol and the passed one. :param protocol: the protocol to use :type protocol: string :rtype: Pool
[ "Selects", "a", "connection", "pool", "according", "to", "the", "default", "protocol", "and", "the", "passed", "one", "." ]
python
train
33.47619
jackmaney/python-stdlib-list
stdlib_list/base.py
https://github.com/jackmaney/python-stdlib-list/blob/f343504405435fcc4bc49bc064f70006813f6845/stdlib_list/base.py#L25-L47
def stdlib_list(version=None): """ Given a ``version``, return a ``list`` of names of the Python Standard Libraries for that version. These names are obtained from the Sphinx inventory file (used in :py:mod:`sphinx.ext.intersphinx`). :param str|None version: The version (as a string) whose list of libraries you want (one of ``"2.6"``, ``"2.7"``, ``"3.2"``, ``"3.3"``, ``"3.4"``, or ``"3.5"``). If not specified, the current version of Python will be used. :return: A list of standard libraries from the specified version of Python :rtype: list """ version = get_canonical_version(version) if version is not None else '.'.join( str(x) for x in sys.version_info[:2]) module_list_file = os.path.join(list_dir, "{}.txt".format(version)) with open(module_list_file) as f: result = [y for y in [x.strip() for x in f.readlines()] if y] return result
[ "def", "stdlib_list", "(", "version", "=", "None", ")", ":", "version", "=", "get_canonical_version", "(", "version", ")", "if", "version", "is", "not", "None", "else", "'.'", ".", "join", "(", "str", "(", "x", ")", "for", "x", "in", "sys", ".", "ver...
Given a ``version``, return a ``list`` of names of the Python Standard Libraries for that version. These names are obtained from the Sphinx inventory file (used in :py:mod:`sphinx.ext.intersphinx`). :param str|None version: The version (as a string) whose list of libraries you want (one of ``"2.6"``, ``"2.7"``, ``"3.2"``, ``"3.3"``, ``"3.4"``, or ``"3.5"``). If not specified, the current version of Python will be used. :return: A list of standard libraries from the specified version of Python :rtype: list
[ "Given", "a", "version", "return", "a", "list", "of", "names", "of", "the", "Python", "Standard", "Libraries", "for", "that", "version", ".", "These", "names", "are", "obtained", "from", "the", "Sphinx", "inventory", "file", "(", "used", "in", ":", "py", ...
python
train
39.130435
rwl/pylon
pylon/util.py
https://github.com/rwl/pylon/blob/916514255db1ae1661406f0283df756baf960d14/pylon/util.py#L262-L269
def factorial(n): """ Returns the factorial of n. """ f = 1 while (n > 0): f = f * n n = n - 1 return f
[ "def", "factorial", "(", "n", ")", ":", "f", "=", "1", "while", "(", "n", ">", "0", ")", ":", "f", "=", "f", "*", "n", "n", "=", "n", "-", "1", "return", "f" ]
Returns the factorial of n.
[ "Returns", "the", "factorial", "of", "n", "." ]
python
train
16.5
Erotemic/utool
utool/util_decor.py
https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_decor.py#L601-L651
def memoize(func): """ simple memoization decorator References: https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize Args: func (function): live python function Returns: func: CommandLine: python -m utool.util_decor memoize Example: >>> # ENABLE_DOCTEST >>> from utool.util_decor import * # NOQA >>> import utool as ut >>> closure = {'a': 'b', 'c': 'd'} >>> incr = [0] >>> def foo(key): >>> value = closure[key] >>> incr[0] += 1 >>> return value >>> foo_memo = memoize(foo) >>> assert foo('a') == 'b' and foo('c') == 'd' >>> assert incr[0] == 2 >>> print('Call memoized version') >>> assert foo_memo('a') == 'b' and foo_memo('c') == 'd' >>> assert incr[0] == 4 >>> assert foo_memo('a') == 'b' and foo_memo('c') == 'd' >>> print('Counter should no longer increase') >>> assert incr[0] == 4 >>> print('Closure changes result without memoization') >>> closure = {'a': 0, 'c': 1} >>> assert foo('a') == 0 and foo('c') == 1 >>> assert incr[0] == 6 >>> assert foo_memo('a') == 'b' and foo_memo('c') == 'd' """ cache = func._util_decor_memoize_cache = {} # @functools.wraps(func) def memoizer(*args, **kwargs): key = str(args) + str(kwargs) if key not in cache: cache[key] = func(*args, **kwargs) return cache[key] memoizer = preserve_sig(memoizer, func) memoizer.cache = cache return memoizer
[ "def", "memoize", "(", "func", ")", ":", "cache", "=", "func", ".", "_util_decor_memoize_cache", "=", "{", "}", "# @functools.wraps(func)", "def", "memoizer", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "key", "=", "str", "(", "args", ")", "+"...
simple memoization decorator References: https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize Args: func (function): live python function Returns: func: CommandLine: python -m utool.util_decor memoize Example: >>> # ENABLE_DOCTEST >>> from utool.util_decor import * # NOQA >>> import utool as ut >>> closure = {'a': 'b', 'c': 'd'} >>> incr = [0] >>> def foo(key): >>> value = closure[key] >>> incr[0] += 1 >>> return value >>> foo_memo = memoize(foo) >>> assert foo('a') == 'b' and foo('c') == 'd' >>> assert incr[0] == 2 >>> print('Call memoized version') >>> assert foo_memo('a') == 'b' and foo_memo('c') == 'd' >>> assert incr[0] == 4 >>> assert foo_memo('a') == 'b' and foo_memo('c') == 'd' >>> print('Counter should no longer increase') >>> assert incr[0] == 4 >>> print('Closure changes result without memoization') >>> closure = {'a': 0, 'c': 1} >>> assert foo('a') == 0 and foo('c') == 1 >>> assert incr[0] == 6 >>> assert foo_memo('a') == 'b' and foo_memo('c') == 'd'
[ "simple", "memoization", "decorator" ]
python
train
30.784314
pandas-dev/pandas
pandas/core/frame.py
https://github.com/pandas-dev/pandas/blob/9feb3ad92cc0397a04b665803a49299ee7aa1037/pandas/core/frame.py#L725-L778
def iteritems(self): r""" Iterator over (column name, Series) pairs. Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. Yields ------ label : object The column names for the DataFrame being iterated over. content : Series The column entries belonging to each label, as a Series. See Also -------- DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. DataFrame.itertuples : Iterate over DataFrame rows as namedtuples of the values. Examples -------- >>> df = pd.DataFrame({'species': ['bear', 'bear', 'marsupial'], ... 'population': [1864, 22000, 80000]}, ... index=['panda', 'polar', 'koala']) >>> df species population panda bear 1864 polar bear 22000 koala marsupial 80000 >>> for label, content in df.iteritems(): ... print('label:', label) ... print('content:', content, sep='\n') ... label: species content: panda bear polar bear koala marsupial Name: species, dtype: object label: population content: panda 1864 polar 22000 koala 80000 Name: population, dtype: int64 """ if self.columns.is_unique and hasattr(self, '_item_cache'): for k in self.columns: yield k, self._get_item_cache(k) else: for i, k in enumerate(self.columns): yield k, self._ixs(i, axis=1)
[ "def", "iteritems", "(", "self", ")", ":", "if", "self", ".", "columns", ".", "is_unique", "and", "hasattr", "(", "self", ",", "'_item_cache'", ")", ":", "for", "k", "in", "self", ".", "columns", ":", "yield", "k", ",", "self", ".", "_get_item_cache", ...
r""" Iterator over (column name, Series) pairs. Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. Yields ------ label : object The column names for the DataFrame being iterated over. content : Series The column entries belonging to each label, as a Series. See Also -------- DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. DataFrame.itertuples : Iterate over DataFrame rows as namedtuples of the values. Examples -------- >>> df = pd.DataFrame({'species': ['bear', 'bear', 'marsupial'], ... 'population': [1864, 22000, 80000]}, ... index=['panda', 'polar', 'koala']) >>> df species population panda bear 1864 polar bear 22000 koala marsupial 80000 >>> for label, content in df.iteritems(): ... print('label:', label) ... print('content:', content, sep='\n') ... label: species content: panda bear polar bear koala marsupial Name: species, dtype: object label: population content: panda 1864 polar 22000 koala 80000 Name: population, dtype: int64
[ "r", "Iterator", "over", "(", "column", "name", "Series", ")", "pairs", "." ]
python
train
31.777778