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
mosdef-hub/mbuild
mbuild/coordinate_transform.py
https://github.com/mosdef-hub/mbuild/blob/dcb80a2becd5d0e6a7e3e7bcb1b59793c46a2dd3/mbuild/coordinate_transform.py#L308-L348
def equivalence_transform(compound, from_positions, to_positions, add_bond=True): """Computes an affine transformation that maps the from_positions to the respective to_positions, and applies this transformation to the compound. Parameters ---------- compound : mb.Compound The Compound to be transformed. from_positions : np.ndarray, shape=(n, 3), dtype=float Original positions. to_positions : np.ndarray, shape=(n, 3), dtype=float New positions. """ warn('The `equivalence_transform` function is being phased out in favor of' ' `force_overlap`.', DeprecationWarning) from mbuild.port import Port T = None if isinstance(from_positions, (list, tuple)) and isinstance(to_positions, (list, tuple)): equivalence_pairs = zip(from_positions, to_positions) elif isinstance(from_positions, Port) and isinstance(to_positions, Port): equivalence_pairs, T = _choose_correct_port(from_positions, to_positions) from_positions.used = True to_positions.used = True else: equivalence_pairs = [(from_positions, to_positions)] if not T: T = _create_equivalence_transform(equivalence_pairs) atom_positions = compound.xyz_with_ports atom_positions = T.apply_to(atom_positions) compound.xyz_with_ports = atom_positions if add_bond: if isinstance(from_positions, Port) and isinstance(to_positions, Port): if not from_positions.anchor or not to_positions.anchor: # TODO: I think warnings is undefined here warn("Attempting to form bond from port that has no anchor") else: from_positions.anchor.parent.add_bond((from_positions.anchor, to_positions.anchor)) to_positions.anchor.parent.add_bond((from_positions.anchor, to_positions.anchor))
[ "def", "equivalence_transform", "(", "compound", ",", "from_positions", ",", "to_positions", ",", "add_bond", "=", "True", ")", ":", "warn", "(", "'The `equivalence_transform` function is being phased out in favor of'", "' `force_overlap`.'", ",", "DeprecationWarning", ")", ...
Computes an affine transformation that maps the from_positions to the respective to_positions, and applies this transformation to the compound. Parameters ---------- compound : mb.Compound The Compound to be transformed. from_positions : np.ndarray, shape=(n, 3), dtype=float Original positions. to_positions : np.ndarray, shape=(n, 3), dtype=float New positions.
[ "Computes", "an", "affine", "transformation", "that", "maps", "the", "from_positions", "to", "the", "respective", "to_positions", "and", "applies", "this", "transformation", "to", "the", "compound", "." ]
python
train
44.731707
materialsproject/pymatgen
pymatgen/core/structure.py
https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/core/structure.py#L1228-L1272
def copy(self, site_properties=None, sanitize=False): """ Convenience method to get a copy of the structure, with options to add site properties. Args: site_properties (dict): Properties to add or override. The properties are specified in the same way as the constructor, i.e., as a dict of the form {property: [values]}. The properties should be in the order of the *original* structure if you are performing sanitization. sanitize (bool): If True, this method will return a sanitized structure. Sanitization performs a few things: (i) The sites are sorted by electronegativity, (ii) a LLL lattice reduction is carried out to obtain a relatively orthogonalized cell, (iii) all fractional coords for sites are mapped into the unit cell. Returns: A copy of the Structure, with optionally new site_properties and optionally sanitized. """ props = self.site_properties if site_properties: props.update(site_properties) if not sanitize: return self.__class__(self._lattice, self.species_and_occu, self.frac_coords, charge=self._charge, site_properties=props) else: reduced_latt = self._lattice.get_lll_reduced_lattice() new_sites = [] for i, site in enumerate(self): frac_coords = reduced_latt.get_fractional_coords(site.coords) site_props = {} for p in props: site_props[p] = props[p][i] new_sites.append(PeriodicSite(site.species, frac_coords, reduced_latt, to_unit_cell=True, properties=site_props)) new_sites = sorted(new_sites) return self.__class__.from_sites(new_sites, charge=self._charge)
[ "def", "copy", "(", "self", ",", "site_properties", "=", "None", ",", "sanitize", "=", "False", ")", ":", "props", "=", "self", ".", "site_properties", "if", "site_properties", ":", "props", ".", "update", "(", "site_properties", ")", "if", "not", "sanitiz...
Convenience method to get a copy of the structure, with options to add site properties. Args: site_properties (dict): Properties to add or override. The properties are specified in the same way as the constructor, i.e., as a dict of the form {property: [values]}. The properties should be in the order of the *original* structure if you are performing sanitization. sanitize (bool): If True, this method will return a sanitized structure. Sanitization performs a few things: (i) The sites are sorted by electronegativity, (ii) a LLL lattice reduction is carried out to obtain a relatively orthogonalized cell, (iii) all fractional coords for sites are mapped into the unit cell. Returns: A copy of the Structure, with optionally new site_properties and optionally sanitized.
[ "Convenience", "method", "to", "get", "a", "copy", "of", "the", "structure", "with", "options", "to", "add", "site", "properties", "." ]
python
train
48.111111
edx/completion
completion/utilities.py
https://github.com/edx/completion/blob/5c23806f6db69ce6be3fd068fc5b5fdf4d66bd60/completion/utilities.py#L13-L29
def get_key_to_last_completed_course_block(user, course_key): """ Returns the last block a "user" completed in a course (stated as "course_key"). raises UnavailableCompletionData when the user has not completed blocks in the course. raises UnavailableCompletionData when the visual progress waffle flag is disabled. """ last_completed_block = BlockCompletion.get_latest_block_completed(user, course_key) if last_completed_block is not None: return last_completed_block.block_key raise UnavailableCompletionData(course_key)
[ "def", "get_key_to_last_completed_course_block", "(", "user", ",", "course_key", ")", ":", "last_completed_block", "=", "BlockCompletion", ".", "get_latest_block_completed", "(", "user", ",", "course_key", ")", "if", "last_completed_block", "is", "not", "None", ":", "...
Returns the last block a "user" completed in a course (stated as "course_key"). raises UnavailableCompletionData when the user has not completed blocks in the course. raises UnavailableCompletionData when the visual progress waffle flag is disabled.
[ "Returns", "the", "last", "block", "a", "user", "completed", "in", "a", "course", "(", "stated", "as", "course_key", ")", "." ]
python
train
32.882353
Jajcus/pyxmpp2
pyxmpp2/stanzaprocessor.py
https://github.com/Jajcus/pyxmpp2/blob/14a40a3950910a9cd008b55f0d8905aa0186ce18/pyxmpp2/stanzaprocessor.py#L302-L312
def process_presence(self, stanza): """Process presence stanza. Pass it to a handler of the stanza's type and payload namespace. :Parameters: - `stanza`: presence stanza to be handled """ stanza_type = stanza.stanza_type return self.__try_handlers(self._presence_handlers, stanza, stanza_type)
[ "def", "process_presence", "(", "self", ",", "stanza", ")", ":", "stanza_type", "=", "stanza", ".", "stanza_type", "return", "self", ".", "__try_handlers", "(", "self", ".", "_presence_handlers", ",", "stanza", ",", "stanza_type", ")" ]
Process presence stanza. Pass it to a handler of the stanza's type and payload namespace. :Parameters: - `stanza`: presence stanza to be handled
[ "Process", "presence", "stanza", "." ]
python
valid
31.454545
jasonrollins/shareplum
shareplum/ListDict.py
https://github.com/jasonrollins/shareplum/blob/404f320808912619920e2d787f2c4387225a14e0/shareplum/ListDict.py#L4-L33
def changes(new_cmp_dict, old_cmp_dict, id_column, columns): """Return a list dict of the changes of the rows that exist in both dictionaries User must provide an ID column for old_cmp_dict """ update_ldict = [] same_keys = set(new_cmp_dict).intersection(set(old_cmp_dict)) for same_key in same_keys: # Get the Union of the set of keys # for both dictionaries to account # for missing keys old_dict = old_cmp_dict[same_key] new_dict = new_cmp_dict[same_key] dict_keys = set(old_dict).intersection(set(new_dict)) update_dict = {} for dict_key in columns: old_val = old_dict.get(dict_key, 'NaN') new_val = new_dict.get(dict_key, 'NaN') if old_val != new_val and new_val != 'NaN': if id_column!=None: try: update_dict[id_column] = old_dict[id_column] except KeyError: print("Input Dictionary 'old_cmp_dict' must have ID column") update_dict[dict_key] = new_val if update_dict: update_ldict.append(update_dict) return update_ldict
[ "def", "changes", "(", "new_cmp_dict", ",", "old_cmp_dict", ",", "id_column", ",", "columns", ")", ":", "update_ldict", "=", "[", "]", "same_keys", "=", "set", "(", "new_cmp_dict", ")", ".", "intersection", "(", "set", "(", "old_cmp_dict", ")", ")", "for",...
Return a list dict of the changes of the rows that exist in both dictionaries User must provide an ID column for old_cmp_dict
[ "Return", "a", "list", "dict", "of", "the", "changes", "of", "the", "rows", "that", "exist", "in", "both", "dictionaries", "User", "must", "provide", "an", "ID", "column", "for", "old_cmp_dict" ]
python
train
39.233333
Alveo/pyalveo
pyalveo/objects.py
https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/objects.py#L361-L377
def append(self, items): """ Add some items to this ItemList and save the changes to the server :param items: the items to add, either as a List of Item objects, an ItemList, a List of item URLs as Strings, a single item URL as a String, or a single Item object :rtype: String :returns: the server success message :raises: APIError if the API request is not successful """ resp = self.client.add_to_item_list(items, self.url()) self.refresh() return resp
[ "def", "append", "(", "self", ",", "items", ")", ":", "resp", "=", "self", ".", "client", ".", "add_to_item_list", "(", "items", ",", "self", ".", "url", "(", ")", ")", "self", ".", "refresh", "(", ")", "return", "resp" ]
Add some items to this ItemList and save the changes to the server :param items: the items to add, either as a List of Item objects, an ItemList, a List of item URLs as Strings, a single item URL as a String, or a single Item object :rtype: String :returns: the server success message :raises: APIError if the API request is not successful
[ "Add", "some", "items", "to", "this", "ItemList", "and", "save", "the", "changes", "to", "the", "server" ]
python
train
31.705882
peri-source/peri
peri/comp/exactpsf.py
https://github.com/peri-source/peri/blob/61beed5deaaf978ab31ed716e8470d86ba639867/peri/comp/exactpsf.py#L661-L667
def psffunc(self, *args, **kwargs): """Calculates a linescan psf""" if self.polychromatic: func = psfcalc.calculate_polychrome_linescan_psf else: func = psfcalc.calculate_linescan_psf return func(*args, **kwargs)
[ "def", "psffunc", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "polychromatic", ":", "func", "=", "psfcalc", ".", "calculate_polychrome_linescan_psf", "else", ":", "func", "=", "psfcalc", ".", "calculate_linescan_psf",...
Calculates a linescan psf
[ "Calculates", "a", "linescan", "psf" ]
python
valid
37.428571
brocade/pynos
pynos/versions/ver_6/ver_6_0_1/yang/brocade_interface_ext.py
https://github.com/brocade/pynos/blob/bd8a34e98f322de3fc06750827d8bbc3a0c00380/pynos/versions/ver_6/ver_6_0_1/yang/brocade_interface_ext.py#L326-L342
def get_interface_switchport_output_switchport_fcoe_port_enabled(self, **kwargs): """Auto Generated Code """ config = ET.Element("config") get_interface_switchport = ET.Element("get_interface_switchport") config = get_interface_switchport output = ET.SubElement(get_interface_switchport, "output") switchport = ET.SubElement(output, "switchport") interface_type_key = ET.SubElement(switchport, "interface-type") interface_type_key.text = kwargs.pop('interface_type') interface_name_key = ET.SubElement(switchport, "interface-name") interface_name_key.text = kwargs.pop('interface_name') fcoe_port_enabled = ET.SubElement(switchport, "fcoe-port-enabled") fcoe_port_enabled.text = kwargs.pop('fcoe_port_enabled') callback = kwargs.pop('callback', self._callback) return callback(config)
[ "def", "get_interface_switchport_output_switchport_fcoe_port_enabled", "(", "self", ",", "*", "*", "kwargs", ")", ":", "config", "=", "ET", ".", "Element", "(", "\"config\"", ")", "get_interface_switchport", "=", "ET", ".", "Element", "(", "\"get_interface_switchport\...
Auto Generated Code
[ "Auto", "Generated", "Code" ]
python
train
52.294118
numenta/htmresearch
htmresearch/algorithms/TM.py
https://github.com/numenta/htmresearch/blob/70c096b09a577ea0432c3f3bfff4442d4871b7aa/htmresearch/algorithms/TM.py#L1808-L1844
def getBestMatchingCell(self, c, activeState): """Find weakly activated cell in column. Returns index and segment of most activated segment above minThreshold. """ # Collect all cells in column c that have at least minThreshold in the most # activated segment bestActivityInCol = self.minThreshold bestSegIdxInCol = -1 bestCellInCol = -1 for i in xrange(self.cellsPerColumn): maxSegActivity = 0 maxSegIdx = 0 for j,s in enumerate(self.cells[c][i]): activity = self.getSegmentActivityLevel(s, activeState, connectedSynapsesOnly =False) if self.verbosity >= 6: print " Segment Activity for column ", c, " cell ", i, " segment ", " j is ", activity if activity > maxSegActivity: maxSegActivity = activity maxSegIdx = j if maxSegActivity >= bestActivityInCol: bestActivityInCol = maxSegActivity bestSegIdxInCol = maxSegIdx bestCellInCol = i if self.verbosity >= 6: print "Best Matching Cell In Col: ", bestCellInCol if bestCellInCol == -1: return (None, None) else: return bestCellInCol, self.cells[c][bestCellInCol][bestSegIdxInCol]
[ "def", "getBestMatchingCell", "(", "self", ",", "c", ",", "activeState", ")", ":", "# Collect all cells in column c that have at least minThreshold in the most", "# activated segment", "bestActivityInCol", "=", "self", ".", "minThreshold", "bestSegIdxInCol", "=", "-", "1", ...
Find weakly activated cell in column. Returns index and segment of most activated segment above minThreshold.
[ "Find", "weakly", "activated", "cell", "in", "column", ".", "Returns", "index", "and", "segment", "of", "most", "activated", "segment", "above", "minThreshold", "." ]
python
train
31.594595
radzak/rtv-downloader
rtv/extractors/common.py
https://github.com/radzak/rtv-downloader/blob/b9114b7f4c35fabe6ec9ad1764a65858667a866e/rtv/extractors/common.py#L48-L52
def update_entries(entries: Entries, data: dict) -> None: """Update each entry in the list with some data.""" # TODO: Is mutating the list okay, making copies is such a pain in the ass for entry in entries: entry.update(data)
[ "def", "update_entries", "(", "entries", ":", "Entries", ",", "data", ":", "dict", ")", "->", "None", ":", "# TODO: Is mutating the list okay, making copies is such a pain in the ass", "for", "entry", "in", "entries", ":", "entry", ".", "update", "(", "data", ")" ]
Update each entry in the list with some data.
[ "Update", "each", "entry", "in", "the", "list", "with", "some", "data", "." ]
python
train
51.4
pydata/xarray
xarray/core/ops.py
https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/ops.py#L135-L165
def fillna(data, other, join="left", dataset_join="left"): """Fill missing values in this object with data from the other object. Follows normal broadcasting and alignment rules. Parameters ---------- join : {'outer', 'inner', 'left', 'right'}, optional Method for joining the indexes of the passed objects along each dimension - 'outer': use the union of object indexes - 'inner': use the intersection of object indexes - 'left': use indexes from the first object with each dimension - 'right': use indexes from the last object with each dimension - 'exact': raise `ValueError` instead of aligning when indexes to be aligned are not equal dataset_join : {'outer', 'inner', 'left', 'right'}, optional Method for joining variables of Dataset objects with mismatched data variables. - 'outer': take variables from both Dataset objects - 'inner': take only overlapped variables - 'left': take only variables from the first object - 'right': take only variables from the last object """ from .computation import apply_ufunc return apply_ufunc(duck_array_ops.fillna, data, other, join=join, dask="allowed", dataset_join=dataset_join, dataset_fill_value=np.nan, keep_attrs=True)
[ "def", "fillna", "(", "data", ",", "other", ",", "join", "=", "\"left\"", ",", "dataset_join", "=", "\"left\"", ")", ":", "from", ".", "computation", "import", "apply_ufunc", "return", "apply_ufunc", "(", "duck_array_ops", ".", "fillna", ",", "data", ",", ...
Fill missing values in this object with data from the other object. Follows normal broadcasting and alignment rules. Parameters ---------- join : {'outer', 'inner', 'left', 'right'}, optional Method for joining the indexes of the passed objects along each dimension - 'outer': use the union of object indexes - 'inner': use the intersection of object indexes - 'left': use indexes from the first object with each dimension - 'right': use indexes from the last object with each dimension - 'exact': raise `ValueError` instead of aligning when indexes to be aligned are not equal dataset_join : {'outer', 'inner', 'left', 'right'}, optional Method for joining variables of Dataset objects with mismatched data variables. - 'outer': take variables from both Dataset objects - 'inner': take only overlapped variables - 'left': take only variables from the first object - 'right': take only variables from the last object
[ "Fill", "missing", "values", "in", "this", "object", "with", "data", "from", "the", "other", "object", ".", "Follows", "normal", "broadcasting", "and", "alignment", "rules", "." ]
python
train
45.451613
MagicStack/asyncpg
asyncpg/connection.py
https://github.com/MagicStack/asyncpg/blob/92c2d81256a1efd8cab12c0118d74ccd1c18131b/asyncpg/connection.py#L532-L592
async def copy_from_query(self, query, *args, output, timeout=None, format=None, oids=None, delimiter=None, null=None, header=None, quote=None, escape=None, force_quote=None, encoding=None): """Copy the results of a query to a file or file-like object. :param str query: The query to copy the results of. :param args: Query arguments. :param output: A :term:`path-like object <python:path-like object>`, or a :term:`file-like object <python:file-like object>`, or a :term:`coroutine function <python:coroutine function>` that takes a ``bytes`` instance as a sole argument. :param float timeout: Optional timeout value in seconds. The remaining keyword arguments are ``COPY`` statement options, see `COPY statement documentation`_ for details. :return: The status string of the COPY command. Example: .. code-block:: pycon >>> import asyncpg >>> import asyncio >>> async def run(): ... con = await asyncpg.connect(user='postgres') ... result = await con.copy_from_query( ... 'SELECT foo, bar FROM mytable WHERE foo > $1', 10, ... output='file.csv', format='csv') ... print(result) ... >>> asyncio.get_event_loop().run_until_complete(run()) 'COPY 10' .. _`COPY statement documentation`: https://www.postgresql.org/docs/current/static/sql-copy.html .. versionadded:: 0.11.0 """ opts = self._format_copy_opts( format=format, oids=oids, delimiter=delimiter, null=null, header=header, quote=quote, escape=escape, force_quote=force_quote, encoding=encoding ) if args: query = await utils._mogrify(self, query, args) copy_stmt = 'COPY ({query}) TO STDOUT {opts}'.format( query=query, opts=opts) return await self._copy_out(copy_stmt, output, timeout)
[ "async", "def", "copy_from_query", "(", "self", ",", "query", ",", "*", "args", ",", "output", ",", "timeout", "=", "None", ",", "format", "=", "None", ",", "oids", "=", "None", ",", "delimiter", "=", "None", ",", "null", "=", "None", ",", "header", ...
Copy the results of a query to a file or file-like object. :param str query: The query to copy the results of. :param args: Query arguments. :param output: A :term:`path-like object <python:path-like object>`, or a :term:`file-like object <python:file-like object>`, or a :term:`coroutine function <python:coroutine function>` that takes a ``bytes`` instance as a sole argument. :param float timeout: Optional timeout value in seconds. The remaining keyword arguments are ``COPY`` statement options, see `COPY statement documentation`_ for details. :return: The status string of the COPY command. Example: .. code-block:: pycon >>> import asyncpg >>> import asyncio >>> async def run(): ... con = await asyncpg.connect(user='postgres') ... result = await con.copy_from_query( ... 'SELECT foo, bar FROM mytable WHERE foo > $1', 10, ... output='file.csv', format='csv') ... print(result) ... >>> asyncio.get_event_loop().run_until_complete(run()) 'COPY 10' .. _`COPY statement documentation`: https://www.postgresql.org/docs/current/static/sql-copy.html .. versionadded:: 0.11.0
[ "Copy", "the", "results", "of", "a", "query", "to", "a", "file", "or", "file", "-", "like", "object", "." ]
python
train
35.672131
bhmm/bhmm
bhmm/hidden/api.py
https://github.com/bhmm/bhmm/blob/9804d18c2ddb684fb4d90b544cc209617a89ca9a/bhmm/hidden/api.py#L277-L302
def sample_path(alpha, A, pobs, T=None): """ Sample the hidden pathway S from the conditional distribution P ( S | Parameters, Observations ) Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hidden state i T : int number of time steps Returns ------- S : numpy.array shape (T) maximum likelihood hidden path """ if __impl__ == __IMPL_PYTHON__: return ip.sample_path(alpha, A, pobs, T=T, dtype=config.dtype) elif __impl__ == __IMPL_C__: return ic.sample_path(alpha, A, pobs, T=T, dtype=config.dtype) else: raise RuntimeError('Nonexisting implementation selected: '+str(__impl__))
[ "def", "sample_path", "(", "alpha", ",", "A", ",", "pobs", ",", "T", "=", "None", ")", ":", "if", "__impl__", "==", "__IMPL_PYTHON__", ":", "return", "ip", ".", "sample_path", "(", "alpha", ",", "A", ",", "pobs", ",", "T", "=", "T", ",", "dtype", ...
Sample the hidden pathway S from the conditional distribution P ( S | Parameters, Observations ) Parameters ---------- alpha : ndarray((T,N), dtype = float), optional, default = None alpha[t,i] is the ith forward coefficient of time t. A : ndarray((N,N), dtype = float) transition matrix of the hidden states pobs : ndarray((T,N), dtype = float) pobs[t,i] is the observation probability for observation at time t given hidden state i T : int number of time steps Returns ------- S : numpy.array shape (T) maximum likelihood hidden path
[ "Sample", "the", "hidden", "pathway", "S", "from", "the", "conditional", "distribution", "P", "(", "S", "|", "Parameters", "Observations", ")" ]
python
train
36.5
zalando/patroni
patroni/postgresql.py
https://github.com/zalando/patroni/blob/f6d29081c90af52064b981cdd877a07338d86038/patroni/postgresql.py#L1699-L1712
def clone(self, clone_member): """ - initialize the replica from an existing member (master or replica) - initialize the replica using the replica creation method that works without the replication connection (i.e. restore from on-disk base backup) """ self._rewind_state = REWIND_STATUS.INITIAL ret = self.create_replica(clone_member) == 0 if ret: self._post_restore() self._configure_server_parameters() return ret
[ "def", "clone", "(", "self", ",", "clone_member", ")", ":", "self", ".", "_rewind_state", "=", "REWIND_STATUS", ".", "INITIAL", "ret", "=", "self", ".", "create_replica", "(", "clone_member", ")", "==", "0", "if", "ret", ":", "self", ".", "_post_restore", ...
- initialize the replica from an existing member (master or replica) - initialize the replica using the replica creation method that works without the replication connection (i.e. restore from on-disk base backup)
[ "-", "initialize", "the", "replica", "from", "an", "existing", "member", "(", "master", "or", "replica", ")", "-", "initialize", "the", "replica", "using", "the", "replica", "creation", "method", "that", "works", "without", "the", "replication", "connection", ...
python
train
38
econ-ark/HARK
HARK/ConsumptionSaving/ConsMarkovModel.py
https://github.com/econ-ark/HARK/blob/3d184153a189e618a87c9540df1cd12044039cc5/HARK/ConsumptionSaving/ConsMarkovModel.py#L820-L869
def getShocks(self): ''' Gets new Markov states and permanent and transitory income shocks for this period. Samples from IncomeDstn for each period-state in the cycle. Parameters ---------- None Returns ------- None ''' # Get new Markov states for each agent if self.global_markov: base_draws = np.ones(self.AgentCount)*drawUniform(1,seed=self.RNG.randint(0,2**31-1)) else: base_draws = self.RNG.permutation(np.arange(self.AgentCount,dtype=float)/self.AgentCount + 1.0/(2*self.AgentCount)) newborn = self.t_age == 0 # Don't change Markov state for those who were just born (unless global_markov) MrkvPrev = self.MrkvNow MrkvNow = np.zeros(self.AgentCount,dtype=int) for t in range(self.T_cycle): Cutoffs = np.cumsum(self.MrkvArray[t],axis=1) for j in range(self.MrkvArray[t].shape[0]): these = np.logical_and(self.t_cycle == t,MrkvPrev == j) MrkvNow[these] = np.searchsorted(Cutoffs[j,:],base_draws[these]).astype(int) if not self.global_markov: MrkvNow[newborn] = MrkvPrev[newborn] self.MrkvNow = MrkvNow.astype(int) # Now get income shocks for each consumer, by cycle-time and discrete state PermShkNow = np.zeros(self.AgentCount) # Initialize shock arrays TranShkNow = np.zeros(self.AgentCount) for t in range(self.T_cycle): for j in range(self.MrkvArray[t].shape[0]): these = np.logical_and(t == self.t_cycle, j == MrkvNow) N = np.sum(these) if N > 0: IncomeDstnNow = self.IncomeDstn[t-1][j] # set current income distribution PermGroFacNow = self.PermGroFac[t-1][j] # and permanent growth factor Indices = np.arange(IncomeDstnNow[0].size) # just a list of integers # Get random draws of income shocks from the discrete distribution EventDraws = drawDiscrete(N,X=Indices,P=IncomeDstnNow[0],exact_match=False,seed=self.RNG.randint(0,2**31-1)) PermShkNow[these] = IncomeDstnNow[1][EventDraws]*PermGroFacNow # permanent "shock" includes expected growth TranShkNow[these] = IncomeDstnNow[2][EventDraws] newborn = self.t_age == 0 PermShkNow[newborn] = 1.0 TranShkNow[newborn] = 1.0 self.PermShkNow = PermShkNow self.TranShkNow = TranShkNow
[ "def", "getShocks", "(", "self", ")", ":", "# Get new Markov states for each agent", "if", "self", ".", "global_markov", ":", "base_draws", "=", "np", ".", "ones", "(", "self", ".", "AgentCount", ")", "*", "drawUniform", "(", "1", ",", "seed", "=", "self", ...
Gets new Markov states and permanent and transitory income shocks for this period. Samples from IncomeDstn for each period-state in the cycle. Parameters ---------- None Returns ------- None
[ "Gets", "new", "Markov", "states", "and", "permanent", "and", "transitory", "income", "shocks", "for", "this", "period", ".", "Samples", "from", "IncomeDstn", "for", "each", "period", "-", "state", "in", "the", "cycle", "." ]
python
train
50.66
flyte/xbee-helper
xbee_helper/device.py
https://github.com/flyte/xbee-helper/blob/8b47675ad44d8a57defea459682d129379af348d/xbee_helper/device.py#L73-L82
def convert_adc(value, output_type, max_volts): """ Converts the output from the ADC into the desired type. """ return { const.ADC_RAW: lambda x: x, const.ADC_PERCENTAGE: adc_to_percentage, const.ADC_VOLTS: adc_to_volts, const.ADC_MILLIVOLTS: adc_to_millivolts }[output_type](value, max_volts)
[ "def", "convert_adc", "(", "value", ",", "output_type", ",", "max_volts", ")", ":", "return", "{", "const", ".", "ADC_RAW", ":", "lambda", "x", ":", "x", ",", "const", ".", "ADC_PERCENTAGE", ":", "adc_to_percentage", ",", "const", ".", "ADC_VOLTS", ":", ...
Converts the output from the ADC into the desired type.
[ "Converts", "the", "output", "from", "the", "ADC", "into", "the", "desired", "type", "." ]
python
train
33.6
yahoo/TensorFlowOnSpark
tensorflowonspark/TFNode.py
https://github.com/yahoo/TensorFlowOnSpark/blob/5e4b6c185ab722fd0104ede0377e1149ea8d6f7c/tensorflowonspark/TFNode.py#L271-L284
def batch_results(self, results): """Push a batch of output results to the Spark output RDD of ``TFCluster.inference()``. Note: this currently expects a one-to-one mapping of input to output data, so the length of the ``results`` array should match the length of the previously retrieved batch of input data. Args: :results: array of output data for the equivalent batch of input data. """ logging.debug("batch_results() invoked") queue = self.mgr.get_queue(self.qname_out) for item in results: queue.put(item, block=True) logging.debug("batch_results() returning data")
[ "def", "batch_results", "(", "self", ",", "results", ")", ":", "logging", ".", "debug", "(", "\"batch_results() invoked\"", ")", "queue", "=", "self", ".", "mgr", ".", "get_queue", "(", "self", ".", "qname_out", ")", "for", "item", "in", "results", ":", ...
Push a batch of output results to the Spark output RDD of ``TFCluster.inference()``. Note: this currently expects a one-to-one mapping of input to output data, so the length of the ``results`` array should match the length of the previously retrieved batch of input data. Args: :results: array of output data for the equivalent batch of input data.
[ "Push", "a", "batch", "of", "output", "results", "to", "the", "Spark", "output", "RDD", "of", "TFCluster", ".", "inference", "()", "." ]
python
train
43.357143
DistrictDataLabs/yellowbrick
yellowbrick/features/importances.py
https://github.com/DistrictDataLabs/yellowbrick/blob/59b67236a3862c73363e8edad7cd86da5b69e3b2/yellowbrick/features/importances.py#L239-L256
def finalize(self, **kwargs): """ Finalize the drawing setting labels and title. """ # Set the title self.set_title('Feature Importances of {} Features using {}'.format( len(self.features_), self.name)) # Set the xlabel self.ax.set_xlabel(self._get_xlabel()) # Remove the ygrid self.ax.grid(False, axis='y') if self.stack: plt.legend(bbox_to_anchor=(1.04, 0.5), loc="center left") # Ensure we have a tight fit plt.tight_layout()
[ "def", "finalize", "(", "self", ",", "*", "*", "kwargs", ")", ":", "# Set the title", "self", ".", "set_title", "(", "'Feature Importances of {} Features using {}'", ".", "format", "(", "len", "(", "self", ".", "features_", ")", ",", "self", ".", "name", ")"...
Finalize the drawing setting labels and title.
[ "Finalize", "the", "drawing", "setting", "labels", "and", "title", "." ]
python
train
29.888889
vhf/confusable_homoglyphs
confusable_homoglyphs/confusables.py
https://github.com/vhf/confusable_homoglyphs/blob/14f43ddd74099520ddcda29fac557c27a28190e6/confusable_homoglyphs/confusables.py#L13-L38
def is_mixed_script(string, allowed_aliases=['COMMON']): """Checks if ``string`` contains mixed-scripts content, excluding script blocks aliases in ``allowed_aliases``. E.g. ``B. C`` is not considered mixed-scripts by default: it contains characters from **Latin** and **Common**, but **Common** is excluded by default. >>> confusables.is_mixed_script('Abç') False >>> confusables.is_mixed_script('ρτ.τ') False >>> confusables.is_mixed_script('ρτ.τ', allowed_aliases=[]) True >>> confusables.is_mixed_script('Alloτ') True :param string: A unicode string :type string: str :param allowed_aliases: Script blocks aliases not to consider. :type allowed_aliases: list(str) :return: Whether ``string`` is considered mixed-scripts or not. :rtype: bool """ allowed_aliases = [a.upper() for a in allowed_aliases] cats = unique_aliases(string) - set(allowed_aliases) return len(cats) > 1
[ "def", "is_mixed_script", "(", "string", ",", "allowed_aliases", "=", "[", "'COMMON'", "]", ")", ":", "allowed_aliases", "=", "[", "a", ".", "upper", "(", ")", "for", "a", "in", "allowed_aliases", "]", "cats", "=", "unique_aliases", "(", "string", ")", "...
Checks if ``string`` contains mixed-scripts content, excluding script blocks aliases in ``allowed_aliases``. E.g. ``B. C`` is not considered mixed-scripts by default: it contains characters from **Latin** and **Common**, but **Common** is excluded by default. >>> confusables.is_mixed_script('Abç') False >>> confusables.is_mixed_script('ρτ.τ') False >>> confusables.is_mixed_script('ρτ.τ', allowed_aliases=[]) True >>> confusables.is_mixed_script('Alloτ') True :param string: A unicode string :type string: str :param allowed_aliases: Script blocks aliases not to consider. :type allowed_aliases: list(str) :return: Whether ``string`` is considered mixed-scripts or not. :rtype: bool
[ "Checks", "if", "string", "contains", "mixed", "-", "scripts", "content", "excluding", "script", "blocks", "aliases", "in", "allowed_aliases", "." ]
python
train
36.269231
annoviko/pyclustering
pyclustering/cluster/optics.py
https://github.com/annoviko/pyclustering/blob/98aa0dd89fd36f701668fb1eb29c8fb5662bf7d0/pyclustering/cluster/optics.py#L143-L182
def calculate_connvectivity_radius(self, amount_clusters, maximum_iterations = 100): """! @brief Calculates connectivity radius of allocation specified amount of clusters using ordering diagram and marks borders of clusters using indexes of values of ordering diagram. @details Parameter 'maximum_iterations' is used to protect from hanging when it is impossible to allocate specified number of clusters. @param[in] amount_clusters (uint): amount of clusters that should be allocated by calculated connectivity radius. @param[in] maximum_iterations (uint): maximum number of iteration for searching connectivity radius to allocated specified amount of clusters (by default it is restricted by 100 iterations). @return (double, list) Value of connectivity radius and borders of clusters like (radius, borders), radius may be 'None' as well as borders may be '[]' if connectivity radius hasn't been found for the specified amount of iterations. """ maximum_distance = max(self.__ordering) upper_distance = maximum_distance lower_distance = 0.0 result = None amount, borders = self.extract_cluster_amount(maximum_distance) if amount <= amount_clusters: for _ in range(maximum_iterations): radius = (lower_distance + upper_distance) / 2.0 amount, borders = self.extract_cluster_amount(radius) if amount == amount_clusters: result = radius break elif amount == 0: break elif amount > amount_clusters: lower_distance = radius elif amount < amount_clusters: upper_distance = radius return result, borders
[ "def", "calculate_connvectivity_radius", "(", "self", ",", "amount_clusters", ",", "maximum_iterations", "=", "100", ")", ":", "maximum_distance", "=", "max", "(", "self", ".", "__ordering", ")", "upper_distance", "=", "maximum_distance", "lower_distance", "=", "0.0...
! @brief Calculates connectivity radius of allocation specified amount of clusters using ordering diagram and marks borders of clusters using indexes of values of ordering diagram. @details Parameter 'maximum_iterations' is used to protect from hanging when it is impossible to allocate specified number of clusters. @param[in] amount_clusters (uint): amount of clusters that should be allocated by calculated connectivity radius. @param[in] maximum_iterations (uint): maximum number of iteration for searching connectivity radius to allocated specified amount of clusters (by default it is restricted by 100 iterations). @return (double, list) Value of connectivity radius and borders of clusters like (radius, borders), radius may be 'None' as well as borders may be '[]' if connectivity radius hasn't been found for the specified amount of iterations.
[ "!" ]
python
valid
49.525
marteinn/genres
genres/db.py
https://github.com/marteinn/genres/blob/4bbc90f7c2c527631380c08b4d99a4e40abed955/genres/db.py#L38-L86
def parse(self, data): """ Split and iterate through the datafile to extract genres, tags and points. """ categories = data.split("\n\n") reference = {} reference_points = {} genre_index = [] tag_index = [] for category in categories: entries = category.strip().split("\n") entry_category, entry_points = self._parse_entry(entries[0].lower()) if entry_category.startswith("#"): continue for entry in entries: entry = entry.lower() if not entry: continue # Comment, ignore if entry.startswith("#"): continue # Handle genre if not entry.startswith("-"): genre, points = self._parse_entry(entry) reference[genre] = entry_category reference_points[genre] = points genre_index.append(genre) # Handle tag else: tag = entry[1:] tag, points = self._parse_entry(tag, limit=9.5) reference[tag] = entry_category reference_points[tag] = points tag_index.append(tag) self.reference = reference self.genres = genre_index self.tags = tag_index self.points = reference_points
[ "def", "parse", "(", "self", ",", "data", ")", ":", "categories", "=", "data", ".", "split", "(", "\"\\n\\n\"", ")", "reference", "=", "{", "}", "reference_points", "=", "{", "}", "genre_index", "=", "[", "]", "tag_index", "=", "[", "]", "for", "cate...
Split and iterate through the datafile to extract genres, tags and points.
[ "Split", "and", "iterate", "through", "the", "datafile", "to", "extract", "genres", "tags", "and", "points", "." ]
python
train
29.489796
tensorflow/probability
tensorflow_probability/python/optimizer/nelder_mead.py
https://github.com/tensorflow/probability/blob/e87fe34111d68c35db0f9eeb4935f1ece9e1a8f5/tensorflow_probability/python/optimizer/nelder_mead.py#L765-L789
def _prepare_args_with_initial_simplex(objective_function, initial_simplex, objective_at_initial_simplex, batch_evaluate_objective): """Evaluates the objective function at the specified initial simplex.""" initial_simplex = tf.convert_to_tensor(value=initial_simplex) # If d is the dimension of the problem, the number of vertices in the # simplex should be d+1. From this, we can infer the number of dimensions # as n - 1 where n is the number of vertices specified. num_vertices = tf.shape(input=initial_simplex)[0] dim = num_vertices - 1 num_evaluations = 0 if objective_at_initial_simplex is None: objective_at_initial_simplex, n_evals = _evaluate_objective_multiple( objective_function, initial_simplex, batch_evaluate_objective) num_evaluations += n_evals objective_at_initial_simplex = tf.convert_to_tensor( value=objective_at_initial_simplex) return (dim, num_vertices, initial_simplex, objective_at_initial_simplex, num_evaluations)
[ "def", "_prepare_args_with_initial_simplex", "(", "objective_function", ",", "initial_simplex", ",", "objective_at_initial_simplex", ",", "batch_evaluate_objective", ")", ":", "initial_simplex", "=", "tf", ".", "convert_to_tensor", "(", "value", "=", "initial_simplex", ")",...
Evaluates the objective function at the specified initial simplex.
[ "Evaluates", "the", "objective", "function", "at", "the", "specified", "initial", "simplex", "." ]
python
test
44.8
thebigmunch/gmusicapi-wrapper
gmusicapi_wrapper/decorators.py
https://github.com/thebigmunch/gmusicapi-wrapper/blob/8708683cd33955def1378fc28319ef37805b851d/gmusicapi_wrapper/decorators.py#L12-L24
def cast_to_list(position): """Cast the positional argument at given position into a list if not already a list.""" @wrapt.decorator def wrapper(function, instance, args, kwargs): if not isinstance(args[position], list): args = list(args) args[position] = [args[position]] args = tuple(args) return function(*args, **kwargs) return wrapper
[ "def", "cast_to_list", "(", "position", ")", ":", "@", "wrapt", ".", "decorator", "def", "wrapper", "(", "function", ",", "instance", ",", "args", ",", "kwargs", ")", ":", "if", "not", "isinstance", "(", "args", "[", "position", "]", ",", "list", ")", ...
Cast the positional argument at given position into a list if not already a list.
[ "Cast", "the", "positional", "argument", "at", "given", "position", "into", "a", "list", "if", "not", "already", "a", "list", "." ]
python
valid
26.692308
sqlboy/fileseq
src/fileseq/filesequence.py
https://github.com/sqlboy/fileseq/blob/f26c3c3c383134ce27d5dfe37793e1ebe88e69ad/src/fileseq/filesequence.py#L636-L690
def findSequenceOnDisk(cls, pattern, strictPadding=False): """ Search for a specific sequence on disk. The padding characters used in the `pattern` are used to filter the frame values of the files on disk (if `strictPadding` is True). Examples: Find sequence matching basename and extension, and a wildcard for any frame. returns bar.1.exr bar.10.exr, bar.100.exr, bar.1000.exr, inclusive >>> findSequenceOnDisk("seq/bar@@@@.exr") Find exactly 4-padded sequence, i.e. seq/bar1-100#.exr returns only frames bar1000.exr through bar9999.exr >>> findSequenceOnDisk("seq/bar#.exr", strictPadding=True) Args: pattern (str): the sequence pattern being searched for strictPadding (bool): if True, ignore files with padding length different from `pattern` Returns: str: Raises: :class:`.FileSeqException`: if no sequence is found on disk """ seq = cls(pattern) if seq.frameRange() == '' and seq.padding() == '': if os.path.isfile(pattern): return seq patt = seq.format('{dirname}{basename}*{extension}') ext = seq.extension() basename = seq.basename() pad = seq.padding() globbed = iglob(patt) if pad and strictPadding: globbed = cls._filterByPaddingNum(globbed, seq.zfill()) pad = cls.conformPadding(pad) matches = cls.yield_sequences_in_list(globbed) for match in matches: if match.basename() == basename and match.extension() == ext: if pad and strictPadding: match.setPadding(pad) return match msg = 'no sequence found on disk matching {0}' raise FileSeqException(msg.format(pattern))
[ "def", "findSequenceOnDisk", "(", "cls", ",", "pattern", ",", "strictPadding", "=", "False", ")", ":", "seq", "=", "cls", "(", "pattern", ")", "if", "seq", ".", "frameRange", "(", ")", "==", "''", "and", "seq", ".", "padding", "(", ")", "==", "''", ...
Search for a specific sequence on disk. The padding characters used in the `pattern` are used to filter the frame values of the files on disk (if `strictPadding` is True). Examples: Find sequence matching basename and extension, and a wildcard for any frame. returns bar.1.exr bar.10.exr, bar.100.exr, bar.1000.exr, inclusive >>> findSequenceOnDisk("seq/bar@@@@.exr") Find exactly 4-padded sequence, i.e. seq/bar1-100#.exr returns only frames bar1000.exr through bar9999.exr >>> findSequenceOnDisk("seq/bar#.exr", strictPadding=True) Args: pattern (str): the sequence pattern being searched for strictPadding (bool): if True, ignore files with padding length different from `pattern` Returns: str: Raises: :class:`.FileSeqException`: if no sequence is found on disk
[ "Search", "for", "a", "specific", "sequence", "on", "disk", "." ]
python
train
33.727273
JosuaKrause/quick_server
quick_server/quick_server.py
https://github.com/JosuaKrause/quick_server/blob/55dc7c5fe726a341f8476f749fe0f9da156fc1cb/quick_server/quick_server.py#L1040-L1060
def do_GET(self): """Handles a GET request.""" thread_local.clock_start = get_time() thread_local.status_code = 200 thread_local.message = None thread_local.headers = [] thread_local.end_headers = [] thread_local.size = -1 thread_local.method = 'GET' try: self.cross_origin_headers() if self.handle_special(True, 'GET'): return SimpleHTTPRequestHandler.do_GET(self) except PreventDefaultResponse as pdr: if pdr.code: self.send_error(pdr.code, pdr.msg) except (KeyboardInterrupt, SystemExit): raise except Exception: self.handle_error()
[ "def", "do_GET", "(", "self", ")", ":", "thread_local", ".", "clock_start", "=", "get_time", "(", ")", "thread_local", ".", "status_code", "=", "200", "thread_local", ".", "message", "=", "None", "thread_local", ".", "headers", "=", "[", "]", "thread_local",...
Handles a GET request.
[ "Handles", "a", "GET", "request", "." ]
python
train
34.047619
apache/incubator-mxnet
cpp-package/scripts/lint.py
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/cpp-package/scripts/lint.py#L123-L144
def get_header_guard_dmlc(filename): """Get Header Guard Convention for DMLC Projects. For headers in include, directly use the path For headers in src, use project name plus path Examples: with project-name = dmlc include/dmlc/timer.h -> DMLC_TIMTER_H_ src/io/libsvm_parser.h -> DMLC_IO_LIBSVM_PARSER_H_ """ fileinfo = cpplint.FileInfo(filename) file_path_from_root = fileinfo.RepositoryName() inc_list = ['include', 'api', 'wrapper'] if file_path_from_root.find('src/') != -1 and _HELPER.project_name is not None: idx = file_path_from_root.find('src/') file_path_from_root = _HELPER.project_name + file_path_from_root[idx + 3:] else: for spath in inc_list: prefix = spath + os.sep if file_path_from_root.startswith(prefix): file_path_from_root = re.sub('^' + prefix, '', file_path_from_root) break return re.sub(r'[-./\s]', '_', file_path_from_root).upper() + '_'
[ "def", "get_header_guard_dmlc", "(", "filename", ")", ":", "fileinfo", "=", "cpplint", ".", "FileInfo", "(", "filename", ")", "file_path_from_root", "=", "fileinfo", ".", "RepositoryName", "(", ")", "inc_list", "=", "[", "'include'", ",", "'api'", ",", "'wrapp...
Get Header Guard Convention for DMLC Projects. For headers in include, directly use the path For headers in src, use project name plus path Examples: with project-name = dmlc include/dmlc/timer.h -> DMLC_TIMTER_H_ src/io/libsvm_parser.h -> DMLC_IO_LIBSVM_PARSER_H_
[ "Get", "Header", "Guard", "Convention", "for", "DMLC", "Projects", ".", "For", "headers", "in", "include", "directly", "use", "the", "path", "For", "headers", "in", "src", "use", "project", "name", "plus", "path", "Examples", ":", "with", "project", "-", "...
python
train
44.818182
mattupstate/flask-security
flask_security/views.py
https://github.com/mattupstate/flask-security/blob/a401fb47018fbbbe0b899ea55afadfd0e3cd847a/flask_security/views.py#L67-L89
def login(): """View function for login view""" form_class = _security.login_form if request.is_json: form = form_class(MultiDict(request.get_json())) else: form = form_class(request.form) if form.validate_on_submit(): login_user(form.user, remember=form.remember.data) after_this_request(_commit) if not request.is_json: return redirect(get_post_login_redirect(form.next.data)) if request.is_json: return _render_json(form, include_auth_token=True) return _security.render_template(config_value('LOGIN_USER_TEMPLATE'), login_user_form=form, **_ctx('login'))
[ "def", "login", "(", ")", ":", "form_class", "=", "_security", ".", "login_form", "if", "request", ".", "is_json", ":", "form", "=", "form_class", "(", "MultiDict", "(", "request", ".", "get_json", "(", ")", ")", ")", "else", ":", "form", "=", "form_cl...
View function for login view
[ "View", "function", "for", "login", "view" ]
python
train
30.608696
Bogdanp/dramatiq
dramatiq/brokers/stub.py
https://github.com/Bogdanp/dramatiq/blob/a8cc2728478e794952a5a50c3fb19ec455fe91b6/dramatiq/brokers/stub.py#L66-L81
def declare_queue(self, queue_name): """Declare a queue. Has no effect if a queue with the given name has already been declared. Parameters: queue_name(str): The name of the new queue. """ if queue_name not in self.queues: self.emit_before("declare_queue", queue_name) self.queues[queue_name] = Queue() self.emit_after("declare_queue", queue_name) delayed_name = dq_name(queue_name) self.queues[delayed_name] = Queue() self.delay_queues.add(delayed_name) self.emit_after("declare_delay_queue", delayed_name)
[ "def", "declare_queue", "(", "self", ",", "queue_name", ")", ":", "if", "queue_name", "not", "in", "self", ".", "queues", ":", "self", ".", "emit_before", "(", "\"declare_queue\"", ",", "queue_name", ")", "self", ".", "queues", "[", "queue_name", "]", "=",...
Declare a queue. Has no effect if a queue with the given name has already been declared. Parameters: queue_name(str): The name of the new queue.
[ "Declare", "a", "queue", ".", "Has", "no", "effect", "if", "a", "queue", "with", "the", "given", "name", "has", "already", "been", "declared", "." ]
python
train
39.3125
aarongarrett/inspyred
inspyred/ec/variators/mutators.py
https://github.com/aarongarrett/inspyred/blob/d5976ab503cc9d51c6f586cbb7bb601a38c01128/inspyred/ec/variators/mutators.py#L141-L171
def scramble_mutation(random, candidate, args): """Return the mutants created by scramble mutation on the candidates. This function performs scramble mutation. It randomly chooses two locations along the candidate and scrambles the values within that slice. .. Arguments: random -- the random number generator object candidate -- the candidate solution args -- a dictionary of keyword arguments Optional keyword arguments in args: - *mutation_rate* -- the rate at which mutation is performed (default 0.1) The mutation rate is applied to the candidate as a whole (i.e., it either mutates or it does not, based on the rate). """ rate = args.setdefault('mutation_rate', 0.1) if random.random() < rate: size = len(candidate) p = random.randint(0, size-1) q = random.randint(0, size-1) p, q = min(p, q), max(p, q) s = candidate[p:q+1] random.shuffle(s) return candidate[:p] + s[::-1] + candidate[q+1:] else: return candidate
[ "def", "scramble_mutation", "(", "random", ",", "candidate", ",", "args", ")", ":", "rate", "=", "args", ".", "setdefault", "(", "'mutation_rate'", ",", "0.1", ")", "if", "random", ".", "random", "(", ")", "<", "rate", ":", "size", "=", "len", "(", "...
Return the mutants created by scramble mutation on the candidates. This function performs scramble mutation. It randomly chooses two locations along the candidate and scrambles the values within that slice. .. Arguments: random -- the random number generator object candidate -- the candidate solution args -- a dictionary of keyword arguments Optional keyword arguments in args: - *mutation_rate* -- the rate at which mutation is performed (default 0.1) The mutation rate is applied to the candidate as a whole (i.e., it either mutates or it does not, based on the rate).
[ "Return", "the", "mutants", "created", "by", "scramble", "mutation", "on", "the", "candidates", "." ]
python
train
33.806452
opencobra/memote
memote/support/biomass.py
https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L129-L163
def find_blocked_biomass_precursors(reaction, model): """ Return a list of all biomass precursors that cannot be produced. Parameters ---------- reaction : cobra.core.reaction.Reaction The biomass reaction of the model under investigation. model : cobra.Model The metabolic model under investigation. Returns ------- list Metabolite objects that are reactants of the biomass reaction excluding ATP and H2O that cannot be produced by flux balance analysis. """ LOGGER.debug("Finding blocked biomass precursors") precursors = find_biomass_precursors(model, reaction) blocked_precursors = list() _, ub = helpers.find_bounds(model) for precursor in precursors: with model: dm_rxn = model.add_boundary( precursor, type="safe-demand", reaction_id="safe_demand", lb=0, ub=ub ) flux = helpers.run_fba(model, dm_rxn.id, direction='max') if np.isnan(flux) or abs(flux) < 1E-08: blocked_precursors.append(precursor) return blocked_precursors
[ "def", "find_blocked_biomass_precursors", "(", "reaction", ",", "model", ")", ":", "LOGGER", ".", "debug", "(", "\"Finding blocked biomass precursors\"", ")", "precursors", "=", "find_biomass_precursors", "(", "model", ",", "reaction", ")", "blocked_precursors", "=", ...
Return a list of all biomass precursors that cannot be produced. Parameters ---------- reaction : cobra.core.reaction.Reaction The biomass reaction of the model under investigation. model : cobra.Model The metabolic model under investigation. Returns ------- list Metabolite objects that are reactants of the biomass reaction excluding ATP and H2O that cannot be produced by flux balance analysis.
[ "Return", "a", "list", "of", "all", "biomass", "precursors", "that", "cannot", "be", "produced", "." ]
python
train
32.771429
libtcod/python-tcod
tcod/libtcodpy.py
https://github.com/libtcod/python-tcod/blob/8ba10c5cfb813eaf3e834de971ba2d6acb7838e4/tcod/libtcodpy.py#L1389-L1408
def console_print_rect( con: tcod.console.Console, x: int, y: int, w: int, h: int, fmt: str ) -> int: """Print a string constrained to a rectangle. If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console. Returns: int: The number of lines of text once word-wrapped. .. deprecated:: 8.5 Use :any:`Console.print_rect` instead. """ return int( lib.TCOD_console_printf_rect(_console(con), x, y, w, h, _fmt(fmt)) )
[ "def", "console_print_rect", "(", "con", ":", "tcod", ".", "console", ".", "Console", ",", "x", ":", "int", ",", "y", ":", "int", ",", "w", ":", "int", ",", "h", ":", "int", ",", "fmt", ":", "str", ")", "->", "int", ":", "return", "int", "(", ...
Print a string constrained to a rectangle. If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console. Returns: int: The number of lines of text once word-wrapped. .. deprecated:: 8.5 Use :any:`Console.print_rect` instead.
[ "Print", "a", "string", "constrained", "to", "a", "rectangle", "." ]
python
train
28
aquatix/ns-api
ns_api.py
https://github.com/aquatix/ns-api/blob/9b3379f8df6217132f457c4363457c16321c2448/ns_api.py#L81-L88
def list_to_json(source_list): """ Serialise all the items in source_list to json """ result = [] for item in source_list: result.append(item.to_json()) return result
[ "def", "list_to_json", "(", "source_list", ")", ":", "result", "=", "[", "]", "for", "item", "in", "source_list", ":", "result", ".", "append", "(", "item", ".", "to_json", "(", ")", ")", "return", "result" ]
Serialise all the items in source_list to json
[ "Serialise", "all", "the", "items", "in", "source_list", "to", "json" ]
python
train
23.875
chriso/timeseries
timeseries/data_frame.py
https://github.com/chriso/timeseries/blob/8b81e6cfd955a7cf75a421dfdb71b3f9e53be64d/timeseries/data_frame.py#L32-L52
def plot(self, overlay=True, **labels): # pragma: no cover '''Plot all time series in the group.''' pylab = LazyImport.pylab() colours = list('rgbymc') colours_len = len(colours) colours_pos = 0 plots = len(self.groups) for name, series in self.groups.iteritems(): colour = colours[colours_pos % colours_len] colours_pos += 1 if not overlay: pylab.subplot(plots, 1, colours_pos) kwargs = {} if name in labels: name = labels[name] if name is not None: kwargs['label'] = name pylab.plot(series.dates, series.values, '%s-' % colour, **kwargs) if name is not None: pylab.legend() pylab.show()
[ "def", "plot", "(", "self", ",", "overlay", "=", "True", ",", "*", "*", "labels", ")", ":", "# pragma: no cover", "pylab", "=", "LazyImport", ".", "pylab", "(", ")", "colours", "=", "list", "(", "'rgbymc'", ")", "colours_len", "=", "len", "(", "colours...
Plot all time series in the group.
[ "Plot", "all", "time", "series", "in", "the", "group", "." ]
python
train
37.714286
rainwoodman/kdcount
kdcount/correlate.py
https://github.com/rainwoodman/kdcount/blob/483548f6d27a4f245cd5d98880b5f4edd6cc8dc1/kdcount/correlate.py#L317-L326
def _update_mean_coords(self, dig, N, centers_sum, **paircoords): """ Update the mean coordinate sums """ if N is None or centers_sum is None: return N.flat[:] += utils.bincount(dig, 1., minlength=N.size) for i, dim in enumerate(self.dims): size = centers_sum[i].size centers_sum[i].flat[:] += utils.bincount(dig, paircoords[dim], minlength=size)
[ "def", "_update_mean_coords", "(", "self", ",", "dig", ",", "N", ",", "centers_sum", ",", "*", "*", "paircoords", ")", ":", "if", "N", "is", "None", "or", "centers_sum", "is", "None", ":", "return", "N", ".", "flat", "[", ":", "]", "+=", "utils", "...
Update the mean coordinate sums
[ "Update", "the", "mean", "coordinate", "sums" ]
python
train
41
echinopsii/net.echinopsii.ariane.community.cli.python3
ariane_clip3/natsd/driver.py
https://github.com/echinopsii/net.echinopsii.ariane.community.cli.python3/blob/0a7feddebf66fee4bef38d64f456d93a7e9fcd68/ariane_clip3/natsd/driver.py#L156-L202
def on_stop(self): """ stop requester """ LOGGER.debug("natsd.Requester.on_stop") self.is_started = False try: LOGGER.debug("natsd.Requester.on_stop - unsubscribe from " + str(self.responseQS)) next(self.nc.unsubscribe(self.responseQS)) except StopIteration as e: pass try: LOGGER.debug("natsd.Requester.on_stop - close nats connection") next(self.nc.close()) except StopIteration as e: pass LOGGER.debug("natsd.Requester.on_stop - nc is closed: " + str(self.nc.is_closed)) try: LOGGER.debug("natsd.Requester.on_stop - cancelling aio tasks loop") loop_to_stop = self.loop for task in asyncio.Task.all_tasks(loop_to_stop): LOGGER.debug("natsd.Requester.on_stop - cancelling task " + str(task)) task.cancel() LOGGER.debug("natsd.Requester.on_stop - stopping aio loop stop") loop_to_stop.stop() count = 0 while loop_to_stop.is_running(): count += 1 if count % 10 == 0: LOGGER.debug("natsd.Requester.on_stop - waiting aio loop to be stopped (" + str(asyncio.Task.all_tasks(loop_to_stop).__len__()) + " tasks left; " + "current task: " + str(asyncio.Task.current_task(loop_to_stop)) + ")") for task in asyncio.Task.all_tasks(loop_to_stop): LOGGER.debug("natsd.Requester.on_stop - cancelling task " + str(task)) task.cancel() time.sleep(1) if count == 120: LOGGER.error("natsd.Requester.on_stop - unable to stop aio loop after 120 sec (" + str(asyncio.Task.all_tasks(loop_to_stop).__len__()) + " tasks left; " + "current task: " + str(asyncio.Task.current_task(loop_to_stop)) + ")") break if not loop_to_stop.is_running(): LOGGER.debug("natsd.Requester.on_stop - close aio loop") loop_to_stop.close() except Exception as e: LOGGER.warn("natsd.Requester.on_stop - exception on aio clean : " + traceback.format_exc())
[ "def", "on_stop", "(", "self", ")", ":", "LOGGER", ".", "debug", "(", "\"natsd.Requester.on_stop\"", ")", "self", ".", "is_started", "=", "False", "try", ":", "LOGGER", ".", "debug", "(", "\"natsd.Requester.on_stop - unsubscribe from \"", "+", "str", "(", "self"...
stop requester
[ "stop", "requester" ]
python
train
50.021277
aksas/pypo4sel
core/pypo4sel/core/waiter.py
https://github.com/aksas/pypo4sel/blob/935b5f9bfa6682aefdef8a43ebcbcf274dec752c/core/pypo4sel/core/waiter.py#L73-L83
def wait_displayed(element, timeout=None, fail_on_timeout=None): """ Wait until element becomes visible or time out. Returns true is element became visible, otherwise false. If timeout is not specified or 0, then uses specific element wait timeout. :param element: :param timeout: :param fail_on_timeout: :return: """ return wait(lambda: element.is_displayed(), timeout or element.wait_timeout, fail_on_timeout)
[ "def", "wait_displayed", "(", "element", ",", "timeout", "=", "None", ",", "fail_on_timeout", "=", "None", ")", ":", "return", "wait", "(", "lambda", ":", "element", ".", "is_displayed", "(", ")", ",", "timeout", "or", "element", ".", "wait_timeout", ",", ...
Wait until element becomes visible or time out. Returns true is element became visible, otherwise false. If timeout is not specified or 0, then uses specific element wait timeout. :param element: :param timeout: :param fail_on_timeout: :return:
[ "Wait", "until", "element", "becomes", "visible", "or", "time", "out", ".", "Returns", "true", "is", "element", "became", "visible", "otherwise", "false", ".", "If", "timeout", "is", "not", "specified", "or", "0", "then", "uses", "specific", "element", "wait...
python
train
40.090909
pybluez/pybluez
examples/advanced/write-inquiry-scan.py
https://github.com/pybluez/pybluez/blob/e0dc4093dcbaa3ecb3fa24f8ccf22bbfe6b57fc9/examples/advanced/write-inquiry-scan.py#L6-L36
def read_inquiry_scan_activity(sock): """returns the current inquiry scan interval and window, or -1 on failure""" # save current filter old_filter = sock.getsockopt( bluez.SOL_HCI, bluez.HCI_FILTER, 14) # Setup socket filter to receive only events related to the # read_inquiry_mode command flt = bluez.hci_filter_new() opcode = bluez.cmd_opcode_pack(bluez.OGF_HOST_CTL, bluez.OCF_READ_INQ_ACTIVITY) bluez.hci_filter_set_ptype(flt, bluez.HCI_EVENT_PKT) bluez.hci_filter_set_event(flt, bluez.EVT_CMD_COMPLETE); bluez.hci_filter_set_opcode(flt, opcode) sock.setsockopt( bluez.SOL_HCI, bluez.HCI_FILTER, flt ) # first read the current inquiry mode. bluez.hci_send_cmd(sock, bluez.OGF_HOST_CTL, bluez.OCF_READ_INQ_ACTIVITY ) pkt = sock.recv(255) status,interval,window = struct.unpack("!xxxxxxBHH", pkt) interval = bluez.btohs(interval) interval = (interval >> 8) | ( (interval & 0xFF) << 8 ) window = (window >> 8) | ( (window & 0xFF) << 8 ) if status != 0: mode = -1 # restore old filter sock.setsockopt( bluez.SOL_HCI, bluez.HCI_FILTER, old_filter ) return interval, window
[ "def", "read_inquiry_scan_activity", "(", "sock", ")", ":", "# save current filter", "old_filter", "=", "sock", ".", "getsockopt", "(", "bluez", ".", "SOL_HCI", ",", "bluez", ".", "HCI_FILTER", ",", "14", ")", "# Setup socket filter to receive only events related to the...
returns the current inquiry scan interval and window, or -1 on failure
[ "returns", "the", "current", "inquiry", "scan", "interval", "and", "window", "or", "-", "1", "on", "failure" ]
python
train
37.645161
apriha/lineage
src/lineage/__init__.py
https://github.com/apriha/lineage/blob/13106a62a959a80ac26c68d1566422de08aa877b/src/lineage/__init__.py#L104-L265
def remap_snps(self, individual, target_assembly, complement_bases=True): """ Remap the SNP coordinates of an individual from one assembly to another. This method uses the assembly map endpoint of the Ensembl REST API service (via ``Resources``'s ``EnsemblRestClient``) to convert SNP coordinates / positions from one assembly to another. After remapping, the coordinates / positions for the individual's SNPs will be that of the target assembly. If the SNPs are already mapped relative to the target assembly, remapping will not be performed. Parameters ---------- target_assembly : {'NCBI36', 'GRCh37', 'GRCh38', 36, 37, 38} assembly to remap to complement_bases : bool complement bases when remapping SNPs to the minus strand Returns ------- chromosomes_remapped : list of str chromosomes remapped; empty if None chromosomes_not_remapped : list of str chromosomes not remapped; empty if None Notes ----- An assembly is also know as a "build." For example: Assembly NCBI36 = Build 36 Assembly GRCh37 = Build 37 Assembly GRCh38 = Build 38 See https://www.ncbi.nlm.nih.gov/assembly for more information about assemblies and remapping. References ---------- ..[1] Ensembl, Assembly Map Endpoint, http://rest.ensembl.org/documentation/info/assembly_map """ chromosomes_remapped = [] chromosomes_not_remapped = [] snps = individual.snps if snps is None: print("No SNPs to remap") return chromosomes_remapped, chromosomes_not_remapped else: chromosomes_not_remapped = list(snps["chrom"].unique()) valid_assemblies = ["NCBI36", "GRCh37", "GRCh38", 36, 37, 38] if target_assembly not in valid_assemblies: print("Invalid target assembly") return chromosomes_remapped, chromosomes_not_remapped if isinstance(target_assembly, int): if target_assembly == 36: target_assembly = "NCBI36" else: target_assembly = "GRCh" + str(target_assembly) if individual.build == 36: source_assembly = "NCBI36" else: source_assembly = "GRCh" + str(individual.build) if source_assembly == target_assembly: return chromosomes_remapped, chromosomes_not_remapped assembly_mapping_data = self._resources.get_assembly_mapping_data( source_assembly, target_assembly ) if assembly_mapping_data is None: return chromosomes_remapped, chromosomes_not_remapped for chrom in snps["chrom"].unique(): # extract SNPs for this chrom for faster remapping temp = pd.DataFrame(snps.loc[snps["chrom"] == chrom]) temp["remapped"] = False if chrom in assembly_mapping_data: chromosomes_remapped.append(chrom) chromosomes_not_remapped.remove(chrom) mappings = assembly_mapping_data[chrom] else: print( "Chromosome " + chrom + " not remapped; " "removing chromosome from SNPs for consistency" ) snps = snps.drop(snps.loc[snps["chrom"] == chrom].index) continue pos_start = int(temp["pos"].describe()["min"]) pos_end = int(temp["pos"].describe()["max"]) for mapping in mappings["mappings"]: # skip if mapping is outside of range of SNP positions if ( mapping["original"]["end"] <= pos_start or mapping["original"]["start"] >= pos_end ): continue orig_range_len = ( mapping["original"]["end"] - mapping["original"]["start"] ) mapped_range_len = mapping["mapped"]["end"] - mapping["mapped"]["start"] orig_region = mapping["original"]["seq_region_name"] mapped_region = mapping["mapped"]["seq_region_name"] if orig_region != mapped_region: print("discrepant chroms") continue if orig_range_len != mapped_range_len: print("discrepant coords") # observed when mapping NCBI36 -> GRCh38 continue # find the SNPs that are being remapped for this mapping snp_indices = temp.loc[ ~temp["remapped"] & (temp["pos"] >= mapping["original"]["start"]) & (temp["pos"] <= mapping["original"]["end"]) ].index if len(snp_indices) > 0: # remap the SNPs if mapping["mapped"]["strand"] == -1: # flip and (optionally) complement since we're mapping to minus strand diff_from_start = ( temp.loc[snp_indices, "pos"] - mapping["original"]["start"] ) temp.loc[snp_indices, "pos"] = ( mapping["mapped"]["end"] - diff_from_start ) if complement_bases: snps.loc[snp_indices, "genotype"] = temp.loc[ snp_indices, "genotype" ].apply(self._complement_bases) else: # mapping is on same (plus) strand, so just remap based on offset offset = ( mapping["mapped"]["start"] - mapping["original"]["start"] ) temp.loc[snp_indices, "pos"] = temp["pos"] + offset # mark these SNPs as remapped temp.loc[snp_indices, "remapped"] = True # update SNP positions for this chrom snps.loc[temp.index, "pos"] = temp["pos"] individual._set_snps(sort_snps(snps), int(target_assembly[-2:])) return chromosomes_remapped, chromosomes_not_remapped
[ "def", "remap_snps", "(", "self", ",", "individual", ",", "target_assembly", ",", "complement_bases", "=", "True", ")", ":", "chromosomes_remapped", "=", "[", "]", "chromosomes_not_remapped", "=", "[", "]", "snps", "=", "individual", ".", "snps", "if", "snps",...
Remap the SNP coordinates of an individual from one assembly to another. This method uses the assembly map endpoint of the Ensembl REST API service (via ``Resources``'s ``EnsemblRestClient``) to convert SNP coordinates / positions from one assembly to another. After remapping, the coordinates / positions for the individual's SNPs will be that of the target assembly. If the SNPs are already mapped relative to the target assembly, remapping will not be performed. Parameters ---------- target_assembly : {'NCBI36', 'GRCh37', 'GRCh38', 36, 37, 38} assembly to remap to complement_bases : bool complement bases when remapping SNPs to the minus strand Returns ------- chromosomes_remapped : list of str chromosomes remapped; empty if None chromosomes_not_remapped : list of str chromosomes not remapped; empty if None Notes ----- An assembly is also know as a "build." For example: Assembly NCBI36 = Build 36 Assembly GRCh37 = Build 37 Assembly GRCh38 = Build 38 See https://www.ncbi.nlm.nih.gov/assembly for more information about assemblies and remapping. References ---------- ..[1] Ensembl, Assembly Map Endpoint, http://rest.ensembl.org/documentation/info/assembly_map
[ "Remap", "the", "SNP", "coordinates", "of", "an", "individual", "from", "one", "assembly", "to", "another", "." ]
python
train
38.407407
sfstpala/pcr
pcr/maths.py
https://github.com/sfstpala/pcr/blob/313ec17585565a0b9740f7b3f47d7a93bf37a7fc/pcr/maths.py#L24-L31
def check_candidate(a, d, n, s): """Part of the Miller-Rabin primality test in is_prime().""" if pow(a, d, n) == 1: return False for i in range(s): if pow(a, 2 ** i * d, n) == n - 1: return False return True
[ "def", "check_candidate", "(", "a", ",", "d", ",", "n", ",", "s", ")", ":", "if", "pow", "(", "a", ",", "d", ",", "n", ")", "==", "1", ":", "return", "False", "for", "i", "in", "range", "(", "s", ")", ":", "if", "pow", "(", "a", ",", "2",...
Part of the Miller-Rabin primality test in is_prime().
[ "Part", "of", "the", "Miller", "-", "Rabin", "primality", "test", "in", "is_prime", "()", "." ]
python
train
30.5
nerdvegas/rez
src/rez/vendor/sortedcontainers/sorteddict.py
https://github.com/nerdvegas/rez/blob/1d3b846d53b5b5404edfe8ddb9083f9ceec8c5e7/src/rez/vendor/sortedcontainers/sorteddict.py#L676-L689
def index(self, key, start=None, stop=None): """ Return the smallest *k* such that `itemssview[k] == key` and `start <= k < end`. Raises `KeyError` if *key* is not present. *stop* defaults to the end of the set. *start* defaults to the beginning. Negative indexes are supported, as for slice indices. """ # pylint: disable=arguments-differ temp, value = key pos = self._list.index(temp, start, stop) if value == self._dict[temp]: return pos else: raise ValueError('{0!r} is not in dict'.format(key))
[ "def", "index", "(", "self", ",", "key", ",", "start", "=", "None", ",", "stop", "=", "None", ")", ":", "# pylint: disable=arguments-differ", "temp", ",", "value", "=", "key", "pos", "=", "self", ".", "_list", ".", "index", "(", "temp", ",", "start", ...
Return the smallest *k* such that `itemssview[k] == key` and `start <= k < end`. Raises `KeyError` if *key* is not present. *stop* defaults to the end of the set. *start* defaults to the beginning. Negative indexes are supported, as for slice indices.
[ "Return", "the", "smallest", "*", "k", "*", "such", "that", "itemssview", "[", "k", "]", "==", "key", "and", "start", "<", "=", "k", "<", "end", ".", "Raises", "KeyError", "if", "*", "key", "*", "is", "not", "present", ".", "*", "stop", "*", "def...
python
train
43
ghukill/pyfc4
pyfc4/models.py
https://github.com/ghukill/pyfc4/blob/59011df592f08978c4a901a908862d112a5dcf02/pyfc4/models.py#L357-L387
def keep_alive(self): ''' Keep current transaction alive, updates self.expires Args: None Return: None: sets new self.expires ''' # keep transaction alive txn_response = self.api.http_request('POST','%sfcr:tx' % self.root, data=None, headers=None) # if 204, transaction kept alive if txn_response.status_code == 204: logger.debug("continuing transaction: %s" % self.root) # update status and timer self.active = True self.expires = txn_response.headers['Expires'] return True # if 410, transaction does not exist elif txn_response.status_code == 410: logger.debug("transaction does not exist: %s" % self.root) self.active = False return False else: raise Exception('HTTP %s, could not continue transaction' % txn_response.status_code)
[ "def", "keep_alive", "(", "self", ")", ":", "# keep transaction alive", "txn_response", "=", "self", ".", "api", ".", "http_request", "(", "'POST'", ",", "'%sfcr:tx'", "%", "self", ".", "root", ",", "data", "=", "None", ",", "headers", "=", "None", ")", ...
Keep current transaction alive, updates self.expires Args: None Return: None: sets new self.expires
[ "Keep", "current", "transaction", "alive", "updates", "self", ".", "expires" ]
python
train
24.806452
StackStorm/pybind
pybind/nos/v6_0_2f/__init__.py
https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/nos/v6_0_2f/__init__.py#L7434-L7457
def _set_openflow_controller(self, v, load=False): """ Setter method for openflow_controller, mapped from YANG variable /openflow_controller (list) If this variable is read-only (config: false) in the source YANG file, then _set_openflow_controller is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_openflow_controller() directly. YANG Description: OpenFlow controller configuration """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGListType("controller_name",openflow_controller.openflow_controller, yang_name="openflow-controller", rest_name="openflow-controller", parent=self, is_container='list', user_ordered=False, path_helper=self._path_helper, yang_keys='controller-name', extensions={u'tailf-common': {u'info': u'OpenFlow controller configuration', u'cli-no-key-completion': None, u'sort-priority': u'66', u'cli-suppress-list-no': None, u'cli-suppress-key-abbreviation': None, u'cli-no-match-completion': None, u'callpoint': u'OpenFlowGlobalController'}}), is_container='list', yang_name="openflow-controller", rest_name="openflow-controller", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'info': u'OpenFlow controller configuration', u'cli-no-key-completion': None, u'sort-priority': u'66', u'cli-suppress-list-no': None, u'cli-suppress-key-abbreviation': None, u'cli-no-match-completion': None, u'callpoint': u'OpenFlowGlobalController'}}, namespace='urn:brocade.com:mgmt:brocade-openflow', defining_module='brocade-openflow', yang_type='list', is_config=True) except (TypeError, ValueError): raise ValueError({ 'error-string': """openflow_controller must be of a type compatible with list""", 'defined-type': "list", 'generated-type': """YANGDynClass(base=YANGListType("controller_name",openflow_controller.openflow_controller, yang_name="openflow-controller", rest_name="openflow-controller", parent=self, is_container='list', user_ordered=False, path_helper=self._path_helper, yang_keys='controller-name', extensions={u'tailf-common': {u'info': u'OpenFlow controller configuration', u'cli-no-key-completion': None, u'sort-priority': u'66', u'cli-suppress-list-no': None, u'cli-suppress-key-abbreviation': None, u'cli-no-match-completion': None, u'callpoint': u'OpenFlowGlobalController'}}), is_container='list', yang_name="openflow-controller", rest_name="openflow-controller", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'info': u'OpenFlow controller configuration', u'cli-no-key-completion': None, u'sort-priority': u'66', u'cli-suppress-list-no': None, u'cli-suppress-key-abbreviation': None, u'cli-no-match-completion': None, u'callpoint': u'OpenFlowGlobalController'}}, namespace='urn:brocade.com:mgmt:brocade-openflow', defining_module='brocade-openflow', yang_type='list', is_config=True)""", }) self.__openflow_controller = t if hasattr(self, '_set'): self._set()
[ "def", "_set_openflow_controller", "(", "self", ",", "v", ",", "load", "=", "False", ")", ":", "if", "hasattr", "(", "v", ",", "\"_utype\"", ")", ":", "v", "=", "v", ".", "_utype", "(", "v", ")", "try", ":", "t", "=", "YANGDynClass", "(", "v", ",...
Setter method for openflow_controller, mapped from YANG variable /openflow_controller (list) If this variable is read-only (config: false) in the source YANG file, then _set_openflow_controller is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_openflow_controller() directly. YANG Description: OpenFlow controller configuration
[ "Setter", "method", "for", "openflow_controller", "mapped", "from", "YANG", "variable", "/", "openflow_controller", "(", "list", ")", "If", "this", "variable", "is", "read", "-", "only", "(", "config", ":", "false", ")", "in", "the", "source", "YANG", "file"...
python
train
130.541667
avalente/appmetrics
appmetrics/meter.py
https://github.com/avalente/appmetrics/blob/366fc7e1ca897e49a2227cbfa43bfa02a47f1acc/appmetrics/meter.py#L112-L125
def notify(self, value): """Add a new observation to the metric""" with self.lock: #TODO: this could slow down slow-rate incoming updates # since the number of ticks depends on the actual time # passed since the latest notification. Consider using # a real timer to tick the EWMA. self.tick() for avg in (self.m1, self.m5, self.m15, self.day): avg.update(value) self.count += value
[ "def", "notify", "(", "self", ",", "value", ")", ":", "with", "self", ".", "lock", ":", "#TODO: this could slow down slow-rate incoming updates", "# since the number of ticks depends on the actual time", "# passed since the latest notification. Consider using", "# a real timer to tic...
Add a new observation to the metric
[ "Add", "a", "new", "observation", "to", "the", "metric" ]
python
train
34.785714
ajyoon/blur
examples/waves/amplitude.py
https://github.com/ajyoon/blur/blob/25fcf083af112bb003956a7a7e1c6ff7d8fef279/examples/waves/amplitude.py#L90-L101
def step_amp(self): """ Change the amplitude according to the change rate and drift target. Returns: None """ difference = self.drift_target - self._raw_value if abs(difference) < self.change_rate: self.value = self.drift_target else: delta = self.change_rate * numpy.sign(difference) self.value = self._raw_value + delta
[ "def", "step_amp", "(", "self", ")", ":", "difference", "=", "self", ".", "drift_target", "-", "self", ".", "_raw_value", "if", "abs", "(", "difference", ")", "<", "self", ".", "change_rate", ":", "self", ".", "value", "=", "self", ".", "drift_target", ...
Change the amplitude according to the change rate and drift target. Returns: None
[ "Change", "the", "amplitude", "according", "to", "the", "change", "rate", "and", "drift", "target", "." ]
python
train
33.583333
hmartiniano/faz
faz/task.py
https://github.com/hmartiniano/faz/blob/36a58c45e8c0718d38cb3c533542c8743e7e7a65/faz/task.py#L82-L101
def expand_variables(self): """ Expand variables in the task code. Only variables who use the $[<variable name>] format are expanded. Variables using the $<variable name> and ${<variable name>} formats are expanded by the shell (in the cases where bash is the interpreter. """ self.environment["INPUTS"] = " ".join(self.inputs) self.environment["OUTPUTS"] = " ".join(self.outputs) for n, input_file in enumerate(self.inputs): self.environment["INPUT{}".format(n +1)] = input_file for n, output_file in enumerate(self.outputs): self.environment["OUTPUT{}".format(n +1)] = output_file for n, line in enumerate(self.code): match = self.__variable_pattern.findall(line) if len(match) > 0: for item in match: value = self.environment.get(item) if value is not None: self.code[n] = self.code[n].replace("$[" + item + "]", value)
[ "def", "expand_variables", "(", "self", ")", ":", "self", ".", "environment", "[", "\"INPUTS\"", "]", "=", "\" \"", ".", "join", "(", "self", ".", "inputs", ")", "self", ".", "environment", "[", "\"OUTPUTS\"", "]", "=", "\" \"", ".", "join", "(", "self...
Expand variables in the task code. Only variables who use the $[<variable name>] format are expanded. Variables using the $<variable name> and ${<variable name>} formats are expanded by the shell (in the cases where bash is the interpreter.
[ "Expand", "variables", "in", "the", "task", "code", ".", "Only", "variables", "who", "use", "the", "$", "[", "<variable", "name", ">", "]", "format", "are", "expanded", ".", "Variables", "using", "the", "$<variable", "name", ">", "and", "$", "{", "<varia...
python
train
50.95
clalancette/pycdlib
pycdlib/pycdlib.py
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4065-L4119
def get_file_from_iso(self, local_path, **kwargs): # type: (str, Any) -> None ''' A method to fetch a single file from the ISO and write it out to a local file. Parameters: local_path - The local file to write to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInvalidInput('This object is not yet initialized; call either open() or new() to create an ISO') blocksize = 8192 joliet_path = None iso_path = None rr_path = None udf_path = None num_paths = 0 for key in kwargs: if key == 'blocksize': blocksize = kwargs[key] elif key == 'iso_path' and kwargs[key] is not None: iso_path = utils.normpath(kwargs[key]) num_paths += 1 elif key == 'rr_path' and kwargs[key] is not None: rr_path = utils.normpath(kwargs[key]) num_paths += 1 elif key == 'joliet_path' and kwargs[key] is not None: joliet_path = utils.normpath(kwargs[key]) num_paths += 1 elif key == 'udf_path' and kwargs[key] is not None: udf_path = utils.normpath(kwargs[key]) num_paths += 1 else: raise pycdlibexception.PyCdlibInvalidInput('Unknown keyword %s' % (key)) if num_paths != 1: raise pycdlibexception.PyCdlibInvalidInput("Exactly one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path' must be passed") with open(local_path, 'wb') as fp: if udf_path is not None: self._udf_get_file_from_iso_fp(fp, blocksize, udf_path) else: self._get_file_from_iso_fp(fp, blocksize, iso_path, rr_path, joliet_path)
[ "def", "get_file_from_iso", "(", "self", ",", "local_path", ",", "*", "*", "kwargs", ")", ":", "# type: (str, Any) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'This object is not yet initializ...
A method to fetch a single file from the ISO and write it out to a local file. Parameters: local_path - The local file to write to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing.
[ "A", "method", "to", "fetch", "a", "single", "file", "from", "the", "ISO", "and", "write", "it", "out", "to", "a", "local", "file", "." ]
python
train
44.290909
ioos/compliance-checker
compliance_checker/util.py
https://github.com/ioos/compliance-checker/blob/ee89c27b0daade58812489a2da3aa3b6859eafd9/compliance_checker/util.py#L16-L25
def datetime_is_iso(date_str): """Attempts to parse a date formatted in ISO 8601 format""" try: if len(date_str) > 10: dt = isodate.parse_datetime(date_str) else: dt = isodate.parse_date(date_str) return True, [] except: # Any error qualifies as not ISO format return False, ['Datetime provided is not in a valid ISO 8601 format']
[ "def", "datetime_is_iso", "(", "date_str", ")", ":", "try", ":", "if", "len", "(", "date_str", ")", ">", "10", ":", "dt", "=", "isodate", ".", "parse_datetime", "(", "date_str", ")", "else", ":", "dt", "=", "isodate", ".", "parse_date", "(", "date_str"...
Attempts to parse a date formatted in ISO 8601 format
[ "Attempts", "to", "parse", "a", "date", "formatted", "in", "ISO", "8601", "format" ]
python
train
39
caseyjlaw/rtpipe
rtpipe/interactive.py
https://github.com/caseyjlaw/rtpipe/blob/ac33e4332cf215091a63afbb3137850876d73ec0/rtpipe/interactive.py#L575-L588
def calcontime(data, inds=None): """ Given indices of good times, calculate total time per scan with indices. """ if not inds: inds = range(len(data['time'])) logger.info('No indices provided. Assuming all are valid.') scans = set([data['scan'][i] for i in inds]) total = 0. for scan in scans: time = [data['time'][i] for i in inds if data['scan'][i] == scan] total += max(time) - min(time) return total
[ "def", "calcontime", "(", "data", ",", "inds", "=", "None", ")", ":", "if", "not", "inds", ":", "inds", "=", "range", "(", "len", "(", "data", "[", "'time'", "]", ")", ")", "logger", ".", "info", "(", "'No indices provided. Assuming all are valid.'", ")"...
Given indices of good times, calculate total time per scan with indices.
[ "Given", "indices", "of", "good", "times", "calculate", "total", "time", "per", "scan", "with", "indices", "." ]
python
train
32.071429
StackStorm/pybind
pybind/slxos/v17s_1_02/mpls_config/router/mpls/mpls_cmds_holder/mpls_interface/rsvp/interface_refresh_reduction/__init__.py
https://github.com/StackStorm/pybind/blob/44c467e71b2b425be63867aba6e6fa28b2cfe7fb/pybind/slxos/v17s_1_02/mpls_config/router/mpls/mpls_cmds_holder/mpls_interface/rsvp/interface_refresh_reduction/__init__.py#L161-L182
def _set_bundle_message(self, v, load=False): """ Setter method for bundle_message, mapped from YANG variable /mpls_config/router/mpls/mpls_cmds_holder/mpls_interface/rsvp/interface_refresh_reduction/bundle_message (container) If this variable is read-only (config: false) in the source YANG file, then _set_bundle_message is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_bundle_message() directly. """ if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=bundle_message.bundle_message, is_container='container', presence=True, yang_name="bundle-message", rest_name="bundle-message", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'info': u'Refresh Reduction bundle messaging feature', u'alt-name': u'bundle-message'}}, namespace='urn:brocade.com:mgmt:brocade-mpls', defining_module='brocade-mpls', yang_type='container', is_config=True) except (TypeError, ValueError): raise ValueError({ 'error-string': """bundle_message must be of a type compatible with container""", 'defined-type': "container", 'generated-type': """YANGDynClass(base=bundle_message.bundle_message, is_container='container', presence=True, yang_name="bundle-message", rest_name="bundle-message", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u'tailf-common': {u'info': u'Refresh Reduction bundle messaging feature', u'alt-name': u'bundle-message'}}, namespace='urn:brocade.com:mgmt:brocade-mpls', defining_module='brocade-mpls', yang_type='container', is_config=True)""", }) self.__bundle_message = t if hasattr(self, '_set'): self._set()
[ "def", "_set_bundle_message", "(", "self", ",", "v", ",", "load", "=", "False", ")", ":", "if", "hasattr", "(", "v", ",", "\"_utype\"", ")", ":", "v", "=", "v", ".", "_utype", "(", "v", ")", "try", ":", "t", "=", "YANGDynClass", "(", "v", ",", ...
Setter method for bundle_message, mapped from YANG variable /mpls_config/router/mpls/mpls_cmds_holder/mpls_interface/rsvp/interface_refresh_reduction/bundle_message (container) If this variable is read-only (config: false) in the source YANG file, then _set_bundle_message is considered as a private method. Backends looking to populate this variable should do so via calling thisObj._set_bundle_message() directly.
[ "Setter", "method", "for", "bundle_message", "mapped", "from", "YANG", "variable", "/", "mpls_config", "/", "router", "/", "mpls", "/", "mpls_cmds_holder", "/", "mpls_interface", "/", "rsvp", "/", "interface_refresh_reduction", "/", "bundle_message", "(", "container...
python
train
82.772727
Ouranosinc/xclim
xclim/indices.py
https://github.com/Ouranosinc/xclim/blob/2080d139188bd8de2aeca097a025c2d89d6e0e09/xclim/indices.py#L2088-L2109
def warm_night_frequency(tasmin, thresh='22 degC', freq='YS'): r"""Frequency of extreme warm nights Return the number of days with tasmin > thresh per period Parameters ---------- tasmin : xarray.DataArray Minimum daily temperature [℃] or [K] thresh : str Threshold temperature on which to base evaluation [℃] or [K]. Default : '22 degC' freq : str, optional Resampling frequency Returns ------- xarray.DataArray The number of days with tasmin > thresh per period """ thresh = utils.convert_units_to(thresh, tasmin, ) events = (tasmin > thresh) * 1 return events.resample(time=freq).sum(dim='time')
[ "def", "warm_night_frequency", "(", "tasmin", ",", "thresh", "=", "'22 degC'", ",", "freq", "=", "'YS'", ")", ":", "thresh", "=", "utils", ".", "convert_units_to", "(", "thresh", ",", "tasmin", ",", ")", "events", "=", "(", "tasmin", ">", "thresh", ")", ...
r"""Frequency of extreme warm nights Return the number of days with tasmin > thresh per period Parameters ---------- tasmin : xarray.DataArray Minimum daily temperature [℃] or [K] thresh : str Threshold temperature on which to base evaluation [℃] or [K]. Default : '22 degC' freq : str, optional Resampling frequency Returns ------- xarray.DataArray The number of days with tasmin > thresh per period
[ "r", "Frequency", "of", "extreme", "warm", "nights" ]
python
train
30
pixelogik/NearPy
nearpy/storage/storage_mongo.py
https://github.com/pixelogik/NearPy/blob/1b534b864d320d875508e95cd2b76b6d8c07a90b/nearpy/storage/storage_mongo.py#L172-L180
def store_hash_configuration(self, lshash): """ Stores hash configuration """ self.mongo_object.insert_one( {'hash_conf_name': lshash.hash_name+'_conf', 'hash_configuration': pickle.dumps(lshash.get_config()) } )
[ "def", "store_hash_configuration", "(", "self", ",", "lshash", ")", ":", "self", ".", "mongo_object", ".", "insert_one", "(", "{", "'hash_conf_name'", ":", "lshash", ".", "hash_name", "+", "'_conf'", ",", "'hash_configuration'", ":", "pickle", ".", "dumps", "(...
Stores hash configuration
[ "Stores", "hash", "configuration" ]
python
train
31.333333
CloverHealth/temple
temple/cli.py
https://github.com/CloverHealth/temple/blob/d7b75da2459f72ba74d6f3b6e1ab95c3d1b92ccd/temple/cli.py#L114-L118
def switch(template, version): """ Switch a project's template to a different template. """ temple.update.update(new_template=template, new_version=version)
[ "def", "switch", "(", "template", ",", "version", ")", ":", "temple", ".", "update", ".", "update", "(", "new_template", "=", "template", ",", "new_version", "=", "version", ")" ]
Switch a project's template to a different template.
[ "Switch", "a", "project", "s", "template", "to", "a", "different", "template", "." ]
python
valid
33.6
chaoss/grimoirelab-sirmordred
sirmordred/eclipse_projects_lib.py
https://github.com/chaoss/grimoirelab-sirmordred/blob/d6ac94d28d707fae23170064d078f1edf937d13e/sirmordred/eclipse_projects_lib.py#L186-L200
def compose_projects_json(projects, data): """ Compose projects.json with all data sources :param projects: projects.json :param data: eclipse JSON :return: projects.json with all data sources """ projects = compose_git(projects, data) projects = compose_mailing_lists(projects, data) projects = compose_bugzilla(projects, data) projects = compose_github(projects, data) projects = compose_gerrit(projects) projects = compose_mbox(projects) return projects
[ "def", "compose_projects_json", "(", "projects", ",", "data", ")", ":", "projects", "=", "compose_git", "(", "projects", ",", "data", ")", "projects", "=", "compose_mailing_lists", "(", "projects", ",", "data", ")", "projects", "=", "compose_bugzilla", "(", "p...
Compose projects.json with all data sources :param projects: projects.json :param data: eclipse JSON :return: projects.json with all data sources
[ "Compose", "projects", ".", "json", "with", "all", "data", "sources" ]
python
valid
32.8
googleapis/google-cloud-python
logging/google/cloud/logging/client.py
https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/logging/google/cloud/logging/client.py#L222-L243
def sink(self, name, filter_=None, destination=None): """Creates a sink bound to the current client. :type name: str :param name: the name of the sink to be constructed. :type filter_: str :param filter_: (optional) the advanced logs filter expression defining the entries exported by the sink. If not passed, the instance should already exist, to be refreshed via :meth:`Sink.reload`. :type destination: str :param destination: destination URI for the entries exported by the sink. If not passed, the instance should already exist, to be refreshed via :meth:`Sink.reload`. :rtype: :class:`google.cloud.logging.sink.Sink` :returns: Sink created with the current client. """ return Sink(name, filter_, destination, client=self)
[ "def", "sink", "(", "self", ",", "name", ",", "filter_", "=", "None", ",", "destination", "=", "None", ")", ":", "return", "Sink", "(", "name", ",", "filter_", ",", "destination", ",", "client", "=", "self", ")" ]
Creates a sink bound to the current client. :type name: str :param name: the name of the sink to be constructed. :type filter_: str :param filter_: (optional) the advanced logs filter expression defining the entries exported by the sink. If not passed, the instance should already exist, to be refreshed via :meth:`Sink.reload`. :type destination: str :param destination: destination URI for the entries exported by the sink. If not passed, the instance should already exist, to be refreshed via :meth:`Sink.reload`. :rtype: :class:`google.cloud.logging.sink.Sink` :returns: Sink created with the current client.
[ "Creates", "a", "sink", "bound", "to", "the", "current", "client", "." ]
python
train
43.409091
googleapis/google-cloud-python
spanner/google/cloud/spanner_v1/pool.py
https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/spanner/google/cloud/spanner_v1/pool.py#L162-L174
def bind(self, database): """Associate the pool with a database. :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed. """ self._database = database while not self._sessions.full(): session = self._new_session() session.create() self._sessions.put(session)
[ "def", "bind", "(", "self", ",", "database", ")", ":", "self", ".", "_database", "=", "database", "while", "not", "self", ".", "_sessions", ".", "full", "(", ")", ":", "session", "=", "self", ".", "_new_session", "(", ")", "session", ".", "create", "...
Associate the pool with a database. :type database: :class:`~google.cloud.spanner_v1.database.Database` :param database: database used by the pool: used to create sessions when needed.
[ "Associate", "the", "pool", "with", "a", "database", "." ]
python
train
34.692308
alexhayes/django-toolkit
django_toolkit/db/models.py
https://github.com/alexhayes/django-toolkit/blob/b64106392fad596defc915b8235fe6e1d0013b5b/django_toolkit/db/models.py#L77-L85
def unlock(self): """ Unlock the table(s) """ cursor = connection.cursor() cursor.execute("UNLOCK TABLES") logger.debug('Unlocked tables') row = cursor.fetchone() return row
[ "def", "unlock", "(", "self", ")", ":", "cursor", "=", "connection", ".", "cursor", "(", ")", "cursor", ".", "execute", "(", "\"UNLOCK TABLES\"", ")", "logger", ".", "debug", "(", "'Unlocked tables'", ")", "row", "=", "cursor", ".", "fetchone", "(", ")",...
Unlock the table(s)
[ "Unlock", "the", "table", "(", "s", ")" ]
python
train
25.444444
bachiraoun/pyrep
Repository.py
https://github.com/bachiraoun/pyrep/blob/0449bf2fad3e3e8dda855d4686a8869efeefd433/Repository.py#L2124-L2297
def dump_file(self, value, relativePath, description=None, dump=None, pull=None, replace=False, raiseError=True, ntrials=3): """ Dump a file using its value to the system and creates its attribute in the Repository with utc timestamp. :Parameters: #. value (object): The value of a file to dump and add to the repository. It is any python object or file. #. relativePath (str): The relative to the repository path to where to dump the file. #. description (None, string): Any description about the file. #. dump (None, string): The dumping method. If None it will be set automatically to pickle and therefore the object must be pickleable. If a string is given, it can be a keyword ('json','pickle','dill') or a string compileable code to dump the data. The string code must include all the necessary imports and a '$FILE_PATH' that replaces the absolute file path when the dumping will be performed.\n e.g. "import numpy as np; np.savetxt(fname='$FILE_PATH', X=value, fmt='%.6e')" #. pull (None, string): The pulling method. If None it will be set automatically to pickle and therefore the object must be pickleable. If a string is given, it can be a keyword ('json','pickle','dill') or a string compileable code to pull the data. The string code must include all the necessary imports, a '$FILE_PATH' that replaces the absolute file path when the dumping will be performed and finally a PULLED_DATA variable.\n e.g "import numpy as np; PULLED_DATA=np.loadtxt(fname='$FILE_PATH')" #. replace (boolean): Whether to replace any existing file. #. raiseError (boolean): Whether to raise encountered error instead of returning failure. #. ntrials (int): After aquiring all locks, ntrials is the maximum number of trials allowed before failing. In rare cases, when multiple processes are accessing the same repository components, different processes can alter repository components between successive lock releases of some other process. Bigger number of trials lowers the likelyhood of failure due to multiple processes same time alteration. :Returns: #. success (boolean): Whether renaming the directory was successful. #. message (None, string): Some explanatory message or error reason why directory was not dumped. """ # check arguments assert isinstance(raiseError, bool), "raiseError must be boolean" assert isinstance(replace, bool), "replace must be boolean" assert isinstance(ntrials, int), "ntrials must be integer" assert ntrials>0, "ntrials must be >0" if description is None: description = '' assert isinstance(description, basestring), "description must be None or a string" # convert dump and pull methods to strings if pull is None and dump is not None: if dump.startswith('pickle') or dump.startswith('dill') or dump.startswith('numpy') or dump =='json': pull = dump dump = get_dump_method(dump, protocol=self._DEFAULT_PICKLE_PROTOCOL) pull = get_pull_method(pull) # check name and path relativePath = self.to_repo_relative_path(path=relativePath, split=False) savePath = os.path.join(self.__path,relativePath) fPath, fName = os.path.split(savePath) # check if name is allowed success, reason = self.is_name_allowed(savePath) if not success: assert not raiseError, reason return False, reason # ensure directory added try: success, reason = self.add_directory(fPath, raiseError=False, ntrials=ntrials) except Exception as err: reason = "Unable to add directory (%s)"%(str(err)) success = False if not success: assert not raiseError, reason return False, reason # lock repository LR = Locker(filePath=None, lockPass=str(uuid.uuid1()), lockPath=os.path.join(self.__path, self.__repoLock)) acquired, code = LR.acquire_lock() if not acquired: m = "code %s. Unable to aquire the repository lock. You may try again!"%(code,) assert raiseError, Exception(m) return False,m # lock file LF = Locker(filePath=None, lockPass=str(uuid.uuid1()), lockPath=os.path.join(fPath,self.__fileLock%fName)) acquired, code = LF.acquire_lock() if not acquired: LR.release_lock() error = "Code %s. Unable to aquire the lock when adding '%s'"%(code,relativePath) assert not raiseError, error return False, error # load repository info for _trial in range(ntrials): try: repo = self.__load_repository_pickle_file(os.path.join(self.__path, self.__repoFile)) self.__repo['walk_repo'] = repo['walk_repo'] except Exception as err: error = str(err) if self.DEBUG_PRINT_FAILED_TRIALS: print("Trial %i failed in Repository.%s (%s). Set Repository.DEBUG_PRINT_FAILED_TRIALS to False to mute"%(_trial, inspect.stack()[1][3], str(error))) else: error = None break if error is not None: LR.release_lock() LF.release_lock() assert not raiseError, Exception(error) return False, error # dump file for _trial in range(ntrials): error = None try: isRepoFile, fileOnDisk, infoOnDisk, classOnDisk = self.is_repository_file(relativePath) if isRepoFile: assert replace, "file is a registered repository file. set replace to True to replace" fileInfoPath = os.path.join(self.__path,os.path.dirname(relativePath),self.__fileInfo%fName) if isRepoFile and fileOnDisk: with open(fileInfoPath, 'rb') as fd: info = pickle.load(fd) assert info['repository_unique_name'] == self.__repo['repository_unique_name'], "it seems that file was created by another repository" info['last_update_utctime'] = time.time() else: info = {'repository_unique_name':self.__repo['repository_unique_name']} info['create_utctime'] = info['last_update_utctime'] = time.time() info['dump'] = dump info['pull'] = pull info['description'] = description # get parent directory list if file is new and not being replaced if not isRepoFile: dirList = self.__get_repository_directory(fPath) # dump file #exec( dump.replace("$FILE_PATH", str(savePath)) ) my_exec( dump.replace("$FILE_PATH", str(savePath)), locals=locals(), globals=globals(), description='dump' ) # update info with open(fileInfoPath, 'wb') as fd: pickle.dump( info,fd, protocol=self._DEFAULT_PICKLE_PROTOCOL) fd.flush() os.fsync(fd.fileno()) # update class file fileClassPath = os.path.join(self.__path,os.path.dirname(relativePath),self.__fileClass%fName) with open(fileClassPath, 'wb') as fd: if value is None: klass = None else: klass = value.__class__ pickle.dump(klass , fd, protocol=self._DEFAULT_PICKLE_PROTOCOL ) fd.flush() os.fsync(fd.fileno()) # add to repo if file is new and not being replaced if not isRepoFile: dirList.append(fName) except Exception as err: error = "unable to dump the file (%s)"%(str(err),) try: if 'pickle.dump(' in dump: mi = get_pickling_errors(value) if mi is not None: error += '\nmore info: %s'%str(mi) except: pass if self.DEBUG_PRINT_FAILED_TRIALS: print("Trial %i failed in Repository.%s (%s). Set Repository.DEBUG_PRINT_FAILED_TRIALS to False to mute"%(_trial, inspect.stack()[1][3], str(error))) else: error = None break # save repository if error is None: _, error = self.__save_repository_pickle_file(lockFirst=False, raiseError=False) # release locks LR.release_lock() LF.release_lock() assert not raiseError or error is None, "unable to dump file '%s' after %i trials (%s)"%(relativePath, ntrials, error,) return success, error
[ "def", "dump_file", "(", "self", ",", "value", ",", "relativePath", ",", "description", "=", "None", ",", "dump", "=", "None", ",", "pull", "=", "None", ",", "replace", "=", "False", ",", "raiseError", "=", "True", ",", "ntrials", "=", "3", ")", ":",...
Dump a file using its value to the system and creates its attribute in the Repository with utc timestamp. :Parameters: #. value (object): The value of a file to dump and add to the repository. It is any python object or file. #. relativePath (str): The relative to the repository path to where to dump the file. #. description (None, string): Any description about the file. #. dump (None, string): The dumping method. If None it will be set automatically to pickle and therefore the object must be pickleable. If a string is given, it can be a keyword ('json','pickle','dill') or a string compileable code to dump the data. The string code must include all the necessary imports and a '$FILE_PATH' that replaces the absolute file path when the dumping will be performed.\n e.g. "import numpy as np; np.savetxt(fname='$FILE_PATH', X=value, fmt='%.6e')" #. pull (None, string): The pulling method. If None it will be set automatically to pickle and therefore the object must be pickleable. If a string is given, it can be a keyword ('json','pickle','dill') or a string compileable code to pull the data. The string code must include all the necessary imports, a '$FILE_PATH' that replaces the absolute file path when the dumping will be performed and finally a PULLED_DATA variable.\n e.g "import numpy as np; PULLED_DATA=np.loadtxt(fname='$FILE_PATH')" #. replace (boolean): Whether to replace any existing file. #. raiseError (boolean): Whether to raise encountered error instead of returning failure. #. ntrials (int): After aquiring all locks, ntrials is the maximum number of trials allowed before failing. In rare cases, when multiple processes are accessing the same repository components, different processes can alter repository components between successive lock releases of some other process. Bigger number of trials lowers the likelyhood of failure due to multiple processes same time alteration. :Returns: #. success (boolean): Whether renaming the directory was successful. #. message (None, string): Some explanatory message or error reason why directory was not dumped.
[ "Dump", "a", "file", "using", "its", "value", "to", "the", "system", "and", "creates", "its", "attribute", "in", "the", "Repository", "with", "utc", "timestamp", "." ]
python
valid
53.051724
ryukinix/decorating
decorating/animation.py
https://github.com/ryukinix/decorating/blob/df78c3f87800205701704c0bc0fb9b6bb908ba7e/decorating/animation.py#L359-L364
def stop(cls): """Change back the normal stdout after the end""" if any(cls.streams): sys.stdout = cls.streams.pop(-1) else: sys.stdout = sys.__stdout__
[ "def", "stop", "(", "cls", ")", ":", "if", "any", "(", "cls", ".", "streams", ")", ":", "sys", ".", "stdout", "=", "cls", ".", "streams", ".", "pop", "(", "-", "1", ")", "else", ":", "sys", ".", "stdout", "=", "sys", ".", "__stdout__" ]
Change back the normal stdout after the end
[ "Change", "back", "the", "normal", "stdout", "after", "the", "end" ]
python
train
32.5
lreis2415/PyGeoC
pygeoc/TauDEM.py
https://github.com/lreis2415/PyGeoC/blob/9a92d1a229bb74298e3c57f27c97079980b5f729/pygeoc/TauDEM.py#L449-L465
def connectdown(np, p, acc, outlet, wtsd=None, workingdir=None, mpiexedir=None, exedir=None, log_file=None, runtime_file=None, hostfile=None): """Reads an ad8 contributing area file, identifies the location of the largest ad8 value as the outlet of the largest watershed""" # If watershed is not specified, use acc to generate a mask layer. if wtsd is None or not os.path.isfile(wtsd): p, workingdir = TauDEM.check_infile_and_wp(p, workingdir) wtsd = workingdir + os.sep + 'wtsd_default.tif' RasterUtilClass.get_mask_from_raster(p, wtsd, True) fname = TauDEM.func_name('connectdown') return TauDEM.run(FileClass.get_executable_fullpath(fname, exedir), {'-p': p, '-ad8': acc, '-w': wtsd}, workingdir, None, {'-o': outlet}, {'mpipath': mpiexedir, 'hostfile': hostfile, 'n': np}, {'logfile': log_file, 'runtimefile': runtime_file})
[ "def", "connectdown", "(", "np", ",", "p", ",", "acc", ",", "outlet", ",", "wtsd", "=", "None", ",", "workingdir", "=", "None", ",", "mpiexedir", "=", "None", ",", "exedir", "=", "None", ",", "log_file", "=", "None", ",", "runtime_file", "=", "None",...
Reads an ad8 contributing area file, identifies the location of the largest ad8 value as the outlet of the largest watershed
[ "Reads", "an", "ad8", "contributing", "area", "file", "identifies", "the", "location", "of", "the", "largest", "ad8", "value", "as", "the", "outlet", "of", "the", "largest", "watershed" ]
python
train
63.058824
gwpy/gwpy
gwpy/detector/channel.py
https://github.com/gwpy/gwpy/blob/7a92b917e7dd2d99b15895293a1fa1d66cdb210a/gwpy/detector/channel.py#L444-L479
def query_nds2(cls, name, host=None, port=None, connection=None, type=None): """Query an NDS server for channel information Parameters ---------- name : `str` name of requested channel host : `str`, optional name of NDS2 server. port : `int`, optional port number for NDS2 connection connection : `nds2.connection` open connection to use for query type : `str`, `int` NDS2 channel type with which to restrict query Returns ------- channel : `Channel` channel with metadata retrieved from NDS2 server Raises ------ ValueError if multiple channels are found for a given name Notes ----- .. warning:: A `host` is required if an open `connection` is not given """ return ChannelList.query_nds2([name], host=host, port=port, connection=connection, type=type, unique=True)[0]
[ "def", "query_nds2", "(", "cls", ",", "name", ",", "host", "=", "None", ",", "port", "=", "None", ",", "connection", "=", "None", ",", "type", "=", "None", ")", ":", "return", "ChannelList", ".", "query_nds2", "(", "[", "name", "]", ",", "host", "=...
Query an NDS server for channel information Parameters ---------- name : `str` name of requested channel host : `str`, optional name of NDS2 server. port : `int`, optional port number for NDS2 connection connection : `nds2.connection` open connection to use for query type : `str`, `int` NDS2 channel type with which to restrict query Returns ------- channel : `Channel` channel with metadata retrieved from NDS2 server Raises ------ ValueError if multiple channels are found for a given name Notes ----- .. warning:: A `host` is required if an open `connection` is not given
[ "Query", "an", "NDS", "server", "for", "channel", "information" ]
python
train
30.027778
tkarabela/pysubs2
pysubs2/ssaevent.py
https://github.com/tkarabela/pysubs2/blob/6439eb5159e6aa6b47e0f8e1d950e8bdd7c5341f/pysubs2/ssaevent.py#L105-L114
def shift(self, h=0, m=0, s=0, ms=0, frames=None, fps=None): """ Shift start and end times. See :meth:`SSAFile.shift()` for full description. """ delta = make_time(h=h, m=m, s=s, ms=ms, frames=frames, fps=fps) self.start += delta self.end += delta
[ "def", "shift", "(", "self", ",", "h", "=", "0", ",", "m", "=", "0", ",", "s", "=", "0", ",", "ms", "=", "0", ",", "frames", "=", "None", ",", "fps", "=", "None", ")", ":", "delta", "=", "make_time", "(", "h", "=", "h", ",", "m", "=", "...
Shift start and end times. See :meth:`SSAFile.shift()` for full description.
[ "Shift", "start", "and", "end", "times", "." ]
python
train
29.6
fastai/fastai
fastai/callbacks/tensorboard.py
https://github.com/fastai/fastai/blob/9fb84a5cdefe5a766cdb792b8f5d8971737b7e67/fastai/callbacks/tensorboard.py#L63-L65
def _write_weight_histograms(self, iteration:int)->None: "Writes model weight histograms to Tensorboard." self.hist_writer.write(model=self.learn.model, iteration=iteration, tbwriter=self.tbwriter)
[ "def", "_write_weight_histograms", "(", "self", ",", "iteration", ":", "int", ")", "->", "None", ":", "self", ".", "hist_writer", ".", "write", "(", "model", "=", "self", ".", "learn", ".", "model", ",", "iteration", "=", "iteration", ",", "tbwriter", "=...
Writes model weight histograms to Tensorboard.
[ "Writes", "model", "weight", "histograms", "to", "Tensorboard", "." ]
python
train
70.333333
PolyJIT/benchbuild
benchbuild/utils/run.py
https://github.com/PolyJIT/benchbuild/blob/9ad2ec54d96e97b642b1f06eddcbad9ba7aeaf58/benchbuild/utils/run.py#L260-L282
def exit_code_from_run_infos(run_infos: t.List[RunInfo]) -> int: """Generate a single exit code from a list of RunInfo objects. Takes a list of RunInfos and returns the exit code that is furthest away from 0. Args: run_infos (t.List[RunInfo]): [description] Returns: int: [description] """ assert run_infos is not None if not hasattr(run_infos, "__iter__"): return run_infos.retcode rcs = [ri.retcode for ri in run_infos] max_rc = max(rcs) min_rc = min(rcs) if max_rc == 0: return min_rc return max_rc
[ "def", "exit_code_from_run_infos", "(", "run_infos", ":", "t", ".", "List", "[", "RunInfo", "]", ")", "->", "int", ":", "assert", "run_infos", "is", "not", "None", "if", "not", "hasattr", "(", "run_infos", ",", "\"__iter__\"", ")", ":", "return", "run_info...
Generate a single exit code from a list of RunInfo objects. Takes a list of RunInfos and returns the exit code that is furthest away from 0. Args: run_infos (t.List[RunInfo]): [description] Returns: int: [description]
[ "Generate", "a", "single", "exit", "code", "from", "a", "list", "of", "RunInfo", "objects", "." ]
python
train
24.695652
capitalone/giraffez
giraffez/cmd.py
https://github.com/capitalone/giraffez/blob/6b4d27eb1a1eaf188c6885c7364ef27e92b1b957/giraffez/cmd.py#L343-L385
def insert(self, table_name, rows, fields=None, delimiter=None, null='NULL', parse_dates=False, quotechar='"'): """ Load a text file into the specified :code:`table_name` or Insert Python :code:`list` rows into the specified :code:`table_name` :param str table_name: The name of the destination table :param list/str rows: A list of rows **or** the name of an input file. Each row must be a :code:`list` of field values. :param list fields: The names of the target fields, in the order that the data will be presented (defaults to :code:`None` for all columns in the table). :param str delimiter: The delimiter used by the input file (or :code:`None` to infer it from the header). :param str null: The string used to indicated nulled values in the file (defaults to :code:`'NULL'`). :param str quotechar: The character used to quote fields containing special characters, like the delimiter. :param bool parse_dates: If :code:`True`, attempts to coerce date fields into a standard format (defaults to :code:`False`). :raises `giraffez.errors.GiraffeEncodeError`: if the number of values in a row does not match the length of :code:`fields` :raises `giraffez.errors.GiraffeError`: if :code:`panic` is set and the insert statement caused an error. :return: A dictionary containing counts of applied rows and errors :rtype: :class:`dict` For most insertions, this will be faster and produce less strain on Teradata than using :class:`~giraffez.load.TeradataBulkLoad` (:class:`giraffez.BulkLoad <giraffez.load.TeradataBulkLoad>`). Requires that any input file be a properly delimited text file, with a header that corresponds to the target fields for insertion. Valid delimiters include '|', ',', and <tab> or a properly encoded JSON stream. """ if not isfile(rows): return self._insert(table_name, rows, fields, parse_dates) with Reader(rows, delimiter=delimiter, quotechar=quotechar) as f: preprocessor = null_handler(null) rows = (preprocessor(l) for l in f) if isinstance(f, CSVReader): self.options("delimiter", unescape_string(f.reader.dialect.delimiter), 1) self.options("quote char", f.reader.dialect.quotechar, 2) elif isinstance(f, JSONReader): self.options("encoding", "json", 1) return self._insert(table_name, rows, f.header, parse_dates)
[ "def", "insert", "(", "self", ",", "table_name", ",", "rows", ",", "fields", "=", "None", ",", "delimiter", "=", "None", ",", "null", "=", "'NULL'", ",", "parse_dates", "=", "False", ",", "quotechar", "=", "'\"'", ")", ":", "if", "not", "isfile", "("...
Load a text file into the specified :code:`table_name` or Insert Python :code:`list` rows into the specified :code:`table_name` :param str table_name: The name of the destination table :param list/str rows: A list of rows **or** the name of an input file. Each row must be a :code:`list` of field values. :param list fields: The names of the target fields, in the order that the data will be presented (defaults to :code:`None` for all columns in the table). :param str delimiter: The delimiter used by the input file (or :code:`None` to infer it from the header). :param str null: The string used to indicated nulled values in the file (defaults to :code:`'NULL'`). :param str quotechar: The character used to quote fields containing special characters, like the delimiter. :param bool parse_dates: If :code:`True`, attempts to coerce date fields into a standard format (defaults to :code:`False`). :raises `giraffez.errors.GiraffeEncodeError`: if the number of values in a row does not match the length of :code:`fields` :raises `giraffez.errors.GiraffeError`: if :code:`panic` is set and the insert statement caused an error. :return: A dictionary containing counts of applied rows and errors :rtype: :class:`dict` For most insertions, this will be faster and produce less strain on Teradata than using :class:`~giraffez.load.TeradataBulkLoad` (:class:`giraffez.BulkLoad <giraffez.load.TeradataBulkLoad>`). Requires that any input file be a properly delimited text file, with a header that corresponds to the target fields for insertion. Valid delimiters include '|', ',', and <tab> or a properly encoded JSON stream.
[ "Load", "a", "text", "file", "into", "the", "specified", ":", "code", ":", "table_name", "or", "Insert", "Python", ":", "code", ":", "list", "rows", "into", "the", "specified", ":", "code", ":", "table_name" ]
python
test
60.534884
pantsbuild/pants
src/python/pants/pantsd/process_manager.py
https://github.com/pantsbuild/pants/blob/b72e650da0df685824ffdcc71988b8c282d0962d/src/python/pants/pantsd/process_manager.py#L397-L407
def purge_metadata(self, force=False): """Instance-based version of ProcessMetadataManager.purge_metadata_by_name() that checks for process liveness before purging metadata. :param bool force: If True, skip process liveness check before purging metadata. :raises: `ProcessManager.MetadataError` when OSError is encountered on metadata dir removal. """ if not force and self.is_alive(): raise ProcessMetadataManager.MetadataError('cannot purge metadata for a running process!') super(ProcessManager, self).purge_metadata_by_name(self._name)
[ "def", "purge_metadata", "(", "self", ",", "force", "=", "False", ")", ":", "if", "not", "force", "and", "self", ".", "is_alive", "(", ")", ":", "raise", "ProcessMetadataManager", ".", "MetadataError", "(", "'cannot purge metadata for a running process!'", ")", ...
Instance-based version of ProcessMetadataManager.purge_metadata_by_name() that checks for process liveness before purging metadata. :param bool force: If True, skip process liveness check before purging metadata. :raises: `ProcessManager.MetadataError` when OSError is encountered on metadata dir removal.
[ "Instance", "-", "based", "version", "of", "ProcessMetadataManager", ".", "purge_metadata_by_name", "()", "that", "checks", "for", "process", "liveness", "before", "purging", "metadata", "." ]
python
train
51.363636
bwohlberg/sporco
sporco/admm/tvl2.py
https://github.com/bwohlberg/sporco/blob/8946a04331106f4e39904fbdf2dc7351900baa04/sporco/admm/tvl2.py#L219-L236
def xstep(self): r"""Minimise Augmented Lagrangian with respect to :math:`\mathbf{x}`. """ ngsit = 0 gsrrs = np.inf while gsrrs > self.opt['GSTol'] and ngsit < self.opt['MaxGSIter']: self.X = self.GaussSeidelStep(self.S, self.X, self.cnst_AT(self.Y-self.U), self.rho, self.lcw, self.Wdf2) gsrrs = sl.rrs( self.rho*self.cnst_AT(self.cnst_A(self.X)) + self.Wdf2*self.X, self.Wdf2*self.S + self.rho*self.cnst_AT(self.Y - self.U)) ngsit += 1 self.xs = (ngsit, gsrrs)
[ "def", "xstep", "(", "self", ")", ":", "ngsit", "=", "0", "gsrrs", "=", "np", ".", "inf", "while", "gsrrs", ">", "self", ".", "opt", "[", "'GSTol'", "]", "and", "ngsit", "<", "self", ".", "opt", "[", "'MaxGSIter'", "]", ":", "self", ".", "X", "...
r"""Minimise Augmented Lagrangian with respect to :math:`\mathbf{x}`.
[ "r", "Minimise", "Augmented", "Lagrangian", "with", "respect", "to", ":", "math", ":", "\\", "mathbf", "{", "x", "}", "." ]
python
train
37.277778
kenjoe41/ghostpaste
ghostpaste/ghostpaste.py
https://github.com/kenjoe41/ghostpaste/blob/7811878fb06c661eb0e7fe2cf5601a87aa858d30/ghostpaste/ghostpaste.py#L84-L92
def detect_lang(path): """Detect the language used in the given file.""" blob = FileBlob(path, os.getcwd()) if blob.is_text: print('Programming language of the file detected: {0}'.format(blob.language.name)) return blob.language.name else:#images, binary and what-have-you won't be pasted print('File not a text file. Exiting...') sys.exit()
[ "def", "detect_lang", "(", "path", ")", ":", "blob", "=", "FileBlob", "(", "path", ",", "os", ".", "getcwd", "(", ")", ")", "if", "blob", ".", "is_text", ":", "print", "(", "'Programming language of the file detected: {0}'", ".", "format", "(", "blob", "."...
Detect the language used in the given file.
[ "Detect", "the", "language", "used", "in", "the", "given", "file", "." ]
python
train
38.333333
rstoneback/pysatMagVect
pysatMagVect/_core.py
https://github.com/rstoneback/pysatMagVect/blob/3fdc87ffbe05be58123f80f880d1237c2f34c7be/pysatMagVect/_core.py#L82-L110
def geodetic_to_ecef(latitude, longitude, altitude): """Convert WGS84 geodetic coordinates into ECEF Parameters ---------- latitude : float or array_like Geodetic latitude (degrees) longitude : float or array_like Geodetic longitude (degrees) altitude : float or array_like Geodetic Height (km) above WGS84 reference ellipsoid. Returns ------- x, y, z numpy arrays of x, y, z locations in km """ ellip = np.sqrt(1. - earth_b ** 2 / earth_a ** 2) r_n = earth_a / np.sqrt(1. - ellip ** 2 * np.sin(np.deg2rad(latitude)) ** 2) # colatitude = 90. - latitude x = (r_n + altitude) * np.cos(np.deg2rad(latitude)) * np.cos(np.deg2rad(longitude)) y = (r_n + altitude) * np.cos(np.deg2rad(latitude)) * np.sin(np.deg2rad(longitude)) z = (r_n * (1. - ellip ** 2) + altitude) * np.sin(np.deg2rad(latitude)) return x, y, z
[ "def", "geodetic_to_ecef", "(", "latitude", ",", "longitude", ",", "altitude", ")", ":", "ellip", "=", "np", ".", "sqrt", "(", "1.", "-", "earth_b", "**", "2", "/", "earth_a", "**", "2", ")", "r_n", "=", "earth_a", "/", "np", ".", "sqrt", "(", "1."...
Convert WGS84 geodetic coordinates into ECEF Parameters ---------- latitude : float or array_like Geodetic latitude (degrees) longitude : float or array_like Geodetic longitude (degrees) altitude : float or array_like Geodetic Height (km) above WGS84 reference ellipsoid. Returns ------- x, y, z numpy arrays of x, y, z locations in km
[ "Convert", "WGS84", "geodetic", "coordinates", "into", "ECEF", "Parameters", "----------", "latitude", ":", "float", "or", "array_like", "Geodetic", "latitude", "(", "degrees", ")", "longitude", ":", "float", "or", "array_like", "Geodetic", "longitude", "(", "degr...
python
train
31.241379
bibanon/BASC-py4chan
basc_py4chan/util.py
https://github.com/bibanon/BASC-py4chan/blob/88e4866d73853e1025e549fbbe9744e750522359/basc_py4chan/util.py#L16-L26
def clean_comment_body(body): """Returns given comment HTML as plaintext. Converts all HTML tags and entities within 4chan comments into human-readable text equivalents. """ body = _parser.unescape(body) body = re.sub(r'<a [^>]+>(.+?)</a>', r'\1', body) body = body.replace('<br>', '\n') body = re.sub(r'<.+?>', '', body) return body
[ "def", "clean_comment_body", "(", "body", ")", ":", "body", "=", "_parser", ".", "unescape", "(", "body", ")", "body", "=", "re", ".", "sub", "(", "r'<a [^>]+>(.+?)</a>'", ",", "r'\\1'", ",", "body", ")", "body", "=", "body", ".", "replace", "(", "'<br...
Returns given comment HTML as plaintext. Converts all HTML tags and entities within 4chan comments into human-readable text equivalents.
[ "Returns", "given", "comment", "HTML", "as", "plaintext", "." ]
python
train
32.727273
sander76/aio-powerview-api
aiopvapi/helpers/powerview_util.py
https://github.com/sander76/aio-powerview-api/blob/08b6ac747aba9de19842359a981a7ff1292f5a6c/aiopvapi/helpers/powerview_util.py#L95-L103
async def activate_scene(self, scene_id: int): """Activate a scene :param scene_id: Scene id. :return: """ _scene = await self.get_scene(scene_id) await _scene.activate()
[ "async", "def", "activate_scene", "(", "self", ",", "scene_id", ":", "int", ")", ":", "_scene", "=", "await", "self", ".", "get_scene", "(", "scene_id", ")", "await", "_scene", ".", "activate", "(", ")" ]
Activate a scene :param scene_id: Scene id. :return:
[ "Activate", "a", "scene" ]
python
train
23.555556
ManiacalLabs/PixelWeb
pixelweb/bottle.py
https://github.com/ManiacalLabs/PixelWeb/blob/9eacbfd40a1d35011c2dcea15c303da9636c6b9e/pixelweb/bottle.py#L769-L774
def add_route(self, route): ''' Add a route object, but do not change the :data:`Route.app` attribute.''' self.routes.append(route) self.router.add(route.rule, route.method, route, name=route.name) if DEBUG: route.prepare()
[ "def", "add_route", "(", "self", ",", "route", ")", ":", "self", ".", "routes", ".", "append", "(", "route", ")", "self", ".", "router", ".", "add", "(", "route", ".", "rule", ",", "route", ".", "method", ",", "route", ",", "name", "=", "route", ...
Add a route object, but do not change the :data:`Route.app` attribute.
[ "Add", "a", "route", "object", "but", "do", "not", "change", "the", ":", "data", ":", "Route", ".", "app", "attribute", "." ]
python
train
43.666667
intel-analytics/BigDL
pyspark/bigdl/optim/optimizer.py
https://github.com/intel-analytics/BigDL/blob/e9c19788285986ab789a2e2998f9a85d7524779f/pyspark/bigdl/optim/optimizer.py#L914-L923
def set_traindata(self, training_rdd, batch_size): """ Set new training dataset, for optimizer reuse :param training_rdd: the training dataset :param batch_size: training batch size :return: """ callBigDlFunc(self.bigdl_type, "setTrainData", self.value, training_rdd, batch_size)
[ "def", "set_traindata", "(", "self", ",", "training_rdd", ",", "batch_size", ")", ":", "callBigDlFunc", "(", "self", ".", "bigdl_type", ",", "\"setTrainData\"", ",", "self", ".", "value", ",", "training_rdd", ",", "batch_size", ")" ]
Set new training dataset, for optimizer reuse :param training_rdd: the training dataset :param batch_size: training batch size :return:
[ "Set", "new", "training", "dataset", "for", "optimizer", "reuse" ]
python
test
34.8
aws/aws-encryption-sdk-python
src/aws_encryption_sdk/internal/formatting/deserialize.py
https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L127-L152
def _deserialize_encrypted_data_keys(stream): # type: (IO) -> Set[EncryptedDataKey] """Deserialize some encrypted data keys from a stream. :param stream: Stream from which to read encrypted data keys :return: Loaded encrypted data keys :rtype: set of :class:`EncryptedDataKey` """ (encrypted_data_key_count,) = unpack_values(">H", stream) encrypted_data_keys = set([]) for _ in range(encrypted_data_key_count): (key_provider_length,) = unpack_values(">H", stream) (key_provider_identifier,) = unpack_values(">{}s".format(key_provider_length), stream) (key_provider_information_length,) = unpack_values(">H", stream) (key_provider_information,) = unpack_values(">{}s".format(key_provider_information_length), stream) (encrypted_data_key_length,) = unpack_values(">H", stream) encrypted_data_key = stream.read(encrypted_data_key_length) encrypted_data_keys.add( EncryptedDataKey( key_provider=MasterKeyInfo( provider_id=to_str(key_provider_identifier), key_info=key_provider_information ), encrypted_data_key=encrypted_data_key, ) ) return encrypted_data_keys
[ "def", "_deserialize_encrypted_data_keys", "(", "stream", ")", ":", "# type: (IO) -> Set[EncryptedDataKey]", "(", "encrypted_data_key_count", ",", ")", "=", "unpack_values", "(", "\">H\"", ",", "stream", ")", "encrypted_data_keys", "=", "set", "(", "[", "]", ")", "f...
Deserialize some encrypted data keys from a stream. :param stream: Stream from which to read encrypted data keys :return: Loaded encrypted data keys :rtype: set of :class:`EncryptedDataKey`
[ "Deserialize", "some", "encrypted", "data", "keys", "from", "a", "stream", "." ]
python
train
47.269231
serge-sans-paille/pythran
pythran/analyses/aliases.py
https://github.com/serge-sans-paille/pythran/blob/7e1b5af2dddfabc50bd2a977f0178be269b349b5/pythran/analyses/aliases.py#L127-L145
def visit_BoolOp(self, node): ''' Resulting node may alias to either operands: >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return a or b') >>> result = pm.gather(Aliases, module) >>> Aliases.dump(result, filter=ast.BoolOp) (a or b) => ['a', 'b'] Note that a literal does not create any alias >>> module = ast.parse('def foo(a, b): return a or 0') >>> result = pm.gather(Aliases, module) >>> Aliases.dump(result, filter=ast.BoolOp) (a or 0) => ['<unbound-value>', 'a'] ''' return self.add(node, set.union(*[self.visit(n) for n in node.values]))
[ "def", "visit_BoolOp", "(", "self", ",", "node", ")", ":", "return", "self", ".", "add", "(", "node", ",", "set", ".", "union", "(", "*", "[", "self", ".", "visit", "(", "n", ")", "for", "n", "in", "node", ".", "values", "]", ")", ")" ]
Resulting node may alias to either operands: >>> from pythran import passmanager >>> pm = passmanager.PassManager('demo') >>> module = ast.parse('def foo(a, b): return a or b') >>> result = pm.gather(Aliases, module) >>> Aliases.dump(result, filter=ast.BoolOp) (a or b) => ['a', 'b'] Note that a literal does not create any alias >>> module = ast.parse('def foo(a, b): return a or 0') >>> result = pm.gather(Aliases, module) >>> Aliases.dump(result, filter=ast.BoolOp) (a or 0) => ['<unbound-value>', 'a']
[ "Resulting", "node", "may", "alias", "to", "either", "operands", ":" ]
python
train
37.894737
raamana/mrivis
mrivis/workflow.py
https://github.com/raamana/mrivis/blob/199ad096b8a1d825f69109e7218a81b2f1cec756/mrivis/workflow.py#L22-L107
def checkerboard(img_spec1=None, img_spec2=None, patch_size=10, view_set=(0, 1, 2), num_slices=(10,), num_rows=2, rescale_method='global', background_threshold=0.05, annot=None, padding=5, output_path=None, figsize=None, ): """ Checkerboard mixer. Parameters ---------- img_spec1 : str or nibabel image-like object MR image (or path to one) to be visualized img_spec2 : str or nibabel image-like object MR image (or path to one) to be visualized patch_size : int or list or (int, int) or None size of checker patch (either square or rectangular) If None, number of voxels/patch are chosen such that, there will be 7 patches through the width/height. view_set : iterable Integers specifying the dimensions to be visualized. Choices: one or more of (0, 1, 2) for a 3D image num_slices : int or iterable of size as view_set number of slices to be selected for each view Must be of the same length as view_set, each element specifying the number of slices for each dimension. If only one number is given, same number will be chosen for all dimensions. num_rows : int number of rows (top to bottom) per each of 3 dimensions rescale_method : bool or str or list or None Range to rescale the intensity values to Default: 'global', min and max values computed based on ranges from both images. If false or None, no rescaling is done (does not work yet). background_threshold : float or str A threshold value below which all the background voxels will be set to zero. Default : 0.05. Other option is a string specifying a percentile: '5%', '10%'. Specify None if you don't want any thresholding. annot : str Text to display to annotate the visualization padding : int number of voxels to pad around each panel. output_path : str path to save the generate collage to. figsize : list Size of figure in inches to be passed on to plt.figure() e.g. [12, 12] or [20, 20] Returns ------- fig : figure handle handle to the collage figure generated. """ img_one, img_two = _preprocess_images(img_spec1, img_spec2, rescale_method=rescale_method, bkground_thresh=background_threshold, padding=padding) display_params = dict(interpolation='none', aspect='auto', origin='lower', cmap='gray', vmin=0.0, vmax=1.0) mixer = partial(_checker_mixer, checker_size=patch_size) collage = Collage(view_set=view_set, num_slices=num_slices, num_rows=num_rows, figsize=figsize, display_params=display_params) collage.transform_and_attach((img_one, img_two), func=mixer) collage.save(output_path=output_path, annot=annot) return collage
[ "def", "checkerboard", "(", "img_spec1", "=", "None", ",", "img_spec2", "=", "None", ",", "patch_size", "=", "10", ",", "view_set", "=", "(", "0", ",", "1", ",", "2", ")", ",", "num_slices", "=", "(", "10", ",", ")", ",", "num_rows", "=", "2", ",...
Checkerboard mixer. Parameters ---------- img_spec1 : str or nibabel image-like object MR image (or path to one) to be visualized img_spec2 : str or nibabel image-like object MR image (or path to one) to be visualized patch_size : int or list or (int, int) or None size of checker patch (either square or rectangular) If None, number of voxels/patch are chosen such that, there will be 7 patches through the width/height. view_set : iterable Integers specifying the dimensions to be visualized. Choices: one or more of (0, 1, 2) for a 3D image num_slices : int or iterable of size as view_set number of slices to be selected for each view Must be of the same length as view_set, each element specifying the number of slices for each dimension. If only one number is given, same number will be chosen for all dimensions. num_rows : int number of rows (top to bottom) per each of 3 dimensions rescale_method : bool or str or list or None Range to rescale the intensity values to Default: 'global', min and max values computed based on ranges from both images. If false or None, no rescaling is done (does not work yet). background_threshold : float or str A threshold value below which all the background voxels will be set to zero. Default : 0.05. Other option is a string specifying a percentile: '5%', '10%'. Specify None if you don't want any thresholding. annot : str Text to display to annotate the visualization padding : int number of voxels to pad around each panel. output_path : str path to save the generate collage to. figsize : list Size of figure in inches to be passed on to plt.figure() e.g. [12, 12] or [20, 20] Returns ------- fig : figure handle handle to the collage figure generated.
[ "Checkerboard", "mixer", "." ]
python
train
36.511628
pydanny/django-tagging-ext
tagging_ext/views.py
https://github.com/pydanny/django-tagging-ext/blob/a25a79ddcd760c5ab272713178f40fedd9146b41/tagging_ext/views.py#L37-L82
def index(request, template_name="tagging_ext/index.html", min_size=0,limit=10): """ min_size: Smallest size count accepted for a tag order_by: asc or desc by count limit: maximum number of tags to display TODO: convert the hand-written query to an ORM call. Right now I know this works with Sqlite3 and PostGreSQL. """ query = """ SELECT tag_item.tag_id as tag_id, COUNT(tag_item.tag_id) as counter FROM tagging_taggeditem as tag_item GROUP BY tag_id HAVING COUNT(tag_item.tag_id) > %s ORDER BY counter desc LIMIT %s """ cursor = connection.cursor() cursor.execute(query, [min_size, limit]) results = [] for row in cursor.fetchall(): try: tag=Tag.objects.get(id=row[0]) except ObjectDoesNotExist: continue if ' ' in tag.name: continue record = dict( tag=tag, count=row[1] ) results.append(record) dictionary = { 'tags':results } return render_to_response(template_name, dictionary, context_instance=RequestContext(request))
[ "def", "index", "(", "request", ",", "template_name", "=", "\"tagging_ext/index.html\"", ",", "min_size", "=", "0", ",", "limit", "=", "10", ")", ":", "query", "=", "\"\"\"\n SELECT tag_item.tag_id as tag_id, COUNT(tag_item.tag_id) as counter \n FROM tagging_tag...
min_size: Smallest size count accepted for a tag order_by: asc or desc by count limit: maximum number of tags to display TODO: convert the hand-written query to an ORM call. Right now I know this works with Sqlite3 and PostGreSQL.
[ "min_size", ":", "Smallest", "size", "count", "accepted", "for", "a", "tag", "order_by", ":", "asc", "or", "desc", "by", "count", "limit", ":", "maximum", "number", "of", "tags", "to", "display", "TODO", ":", "convert", "the", "hand", "-", "written", "qu...
python
train
26.347826
fuzeman/trakt.py
trakt/objects/show.py
https://github.com/fuzeman/trakt.py/blob/14c6b72e3c13ea2975007aeac0c01ad2222b67f3/trakt/objects/show.py#L138-L148
def episodes(self): """Return a flat episode iterator. :returns: Iterator :code:`((season_num, episode_num), Episode)` :rtype: iterator """ for sk, season in iteritems(self.seasons): # Yield each episode in season for ek, episode in iteritems(season.episodes): yield (sk, ek), episode
[ "def", "episodes", "(", "self", ")", ":", "for", "sk", ",", "season", "in", "iteritems", "(", "self", ".", "seasons", ")", ":", "# Yield each episode in season", "for", "ek", ",", "episode", "in", "iteritems", "(", "season", ".", "episodes", ")", ":", "y...
Return a flat episode iterator. :returns: Iterator :code:`((season_num, episode_num), Episode)` :rtype: iterator
[ "Return", "a", "flat", "episode", "iterator", "." ]
python
train
32.363636
bunq/sdk_python
bunq/sdk/model/generated/endpoint.py
https://github.com/bunq/sdk_python/blob/da6c9b83e6d83ee8062617f53c6eb7293c0d863d/bunq/sdk/model/generated/endpoint.py#L1494-L1516
def get(cls, attachment_public_uuid, custom_headers=None): """ Get a specific attachment's metadata through its UUID. The Content-Type header of the response will describe the MIME type of the attachment file. :type api_context: context.ApiContext :type attachment_public_uuid: str :type custom_headers: dict[str, str]|None :rtype: BunqResponseAttachmentPublic """ if custom_headers is None: custom_headers = {} api_client = client.ApiClient(cls._get_api_context()) endpoint_url = cls._ENDPOINT_URL_READ.format(attachment_public_uuid) response_raw = api_client.get(endpoint_url, {}, custom_headers) return BunqResponseAttachmentPublic.cast_from_bunq_response( cls._from_json(response_raw, cls._OBJECT_TYPE_GET) )
[ "def", "get", "(", "cls", ",", "attachment_public_uuid", ",", "custom_headers", "=", "None", ")", ":", "if", "custom_headers", "is", "None", ":", "custom_headers", "=", "{", "}", "api_client", "=", "client", ".", "ApiClient", "(", "cls", ".", "_get_api_conte...
Get a specific attachment's metadata through its UUID. The Content-Type header of the response will describe the MIME type of the attachment file. :type api_context: context.ApiContext :type attachment_public_uuid: str :type custom_headers: dict[str, str]|None :rtype: BunqResponseAttachmentPublic
[ "Get", "a", "specific", "attachment", "s", "metadata", "through", "its", "UUID", ".", "The", "Content", "-", "Type", "header", "of", "the", "response", "will", "describe", "the", "MIME", "type", "of", "the", "attachment", "file", "." ]
python
train
36.478261
OCHA-DAP/hdx-python-api
src/hdx/data/hdxobject.py
https://github.com/OCHA-DAP/hdx-python-api/blob/212440f54f73805826a16db77dbcb6033b18a313/src/hdx/data/hdxobject.py#L365-L383
def _addupdate_hdxobject(self, hdxobjects, id_field, new_hdxobject): # type: (List[HDXObjectUpperBound], str, HDXObjectUpperBound) -> HDXObjectUpperBound """Helper function to add a new HDX object to a supplied list of HDX objects or update existing metadata if the object already exists in the list Args: hdxobjects (List[T <= HDXObject]): list of HDX objects to which to add new objects or update existing ones id_field (str): Field on which to match to determine if object already exists in list new_hdxobject (T <= HDXObject): The HDX object to be added/updated Returns: T <= HDXObject: The HDX object which was added or updated """ for hdxobject in hdxobjects: if hdxobject[id_field] == new_hdxobject[id_field]: merge_two_dictionaries(hdxobject, new_hdxobject) return hdxobject hdxobjects.append(new_hdxobject) return new_hdxobject
[ "def", "_addupdate_hdxobject", "(", "self", ",", "hdxobjects", ",", "id_field", ",", "new_hdxobject", ")", ":", "# type: (List[HDXObjectUpperBound], str, HDXObjectUpperBound) -> HDXObjectUpperBound", "for", "hdxobject", "in", "hdxobjects", ":", "if", "hdxobject", "[", "id_f...
Helper function to add a new HDX object to a supplied list of HDX objects or update existing metadata if the object already exists in the list Args: hdxobjects (List[T <= HDXObject]): list of HDX objects to which to add new objects or update existing ones id_field (str): Field on which to match to determine if object already exists in list new_hdxobject (T <= HDXObject): The HDX object to be added/updated Returns: T <= HDXObject: The HDX object which was added or updated
[ "Helper", "function", "to", "add", "a", "new", "HDX", "object", "to", "a", "supplied", "list", "of", "HDX", "objects", "or", "update", "existing", "metadata", "if", "the", "object", "already", "exists", "in", "the", "list" ]
python
train
51.789474
sublee/zeronimo
zeronimo/helpers.py
https://github.com/sublee/zeronimo/blob/b216638232932718d2cbc5eabd870c8f5b5e83fb/zeronimo/helpers.py#L42-L71
def make_repr(obj, params=None, keywords=None, data=None, name=None, reprs=None): """Generates a string of object initialization code style. It is useful for custom __repr__ methods:: class Example(object): def __init__(self, param, keyword=None): self.param = param self.keyword = keyword def __repr__(self): return make_repr(self, ['param'], ['keyword']) See the representation of example object:: >>> Example('hello', keyword='world') Example('hello', keyword='world') """ opts = [] if params is not None: opts.append(', '.join( _repr_attr(obj, attr, data, reprs) for attr in params)) if keywords is not None: opts.append(', '.join( '%s=%s' % (attr, _repr_attr(obj, attr, data, reprs)) for attr in keywords)) if name is None: name = class_name(obj) return '%s(%s)' % (name, ', '.join(opts))
[ "def", "make_repr", "(", "obj", ",", "params", "=", "None", ",", "keywords", "=", "None", ",", "data", "=", "None", ",", "name", "=", "None", ",", "reprs", "=", "None", ")", ":", "opts", "=", "[", "]", "if", "params", "is", "not", "None", ":", ...
Generates a string of object initialization code style. It is useful for custom __repr__ methods:: class Example(object): def __init__(self, param, keyword=None): self.param = param self.keyword = keyword def __repr__(self): return make_repr(self, ['param'], ['keyword']) See the representation of example object:: >>> Example('hello', keyword='world') Example('hello', keyword='world')
[ "Generates", "a", "string", "of", "object", "initialization", "code", "style", ".", "It", "is", "useful", "for", "custom", "__repr__", "methods", "::" ]
python
test
32.266667
aiven/pghoard
pghoard/transfer.py
https://github.com/aiven/pghoard/blob/2994165d4ef3ff7a5669a2527346bcbfb5b3bd8a/pghoard/transfer.py#L80-L101
def transmit_metrics(self): """ Keep metrics updated about how long time ago each filetype was successfully uploaded. Transmits max once per ten seconds, regardless of how many threads are running. """ global _last_stats_transmit_time # pylint: disable=global-statement with _STATS_LOCK: # pylint: disable=not-context-manager if time.monotonic() - _last_stats_transmit_time < 10.0: return for site in self.state: for filetype, prop in self.state[site]["upload"].items(): if prop["last_success"]: self.metrics.gauge( "pghoard.last_upload_age", time.monotonic() - prop["last_success"], tags={ "site": site, "type": filetype, } ) _last_stats_transmit_time = time.monotonic()
[ "def", "transmit_metrics", "(", "self", ")", ":", "global", "_last_stats_transmit_time", "# pylint: disable=global-statement", "with", "_STATS_LOCK", ":", "# pylint: disable=not-context-manager", "if", "time", ".", "monotonic", "(", ")", "-", "_last_stats_transmit_time", "<...
Keep metrics updated about how long time ago each filetype was successfully uploaded. Transmits max once per ten seconds, regardless of how many threads are running.
[ "Keep", "metrics", "updated", "about", "how", "long", "time", "ago", "each", "filetype", "was", "successfully", "uploaded", ".", "Transmits", "max", "once", "per", "ten", "seconds", "regardless", "of", "how", "many", "threads", "are", "running", "." ]
python
train
46.045455
AguaClara/aguaclara
aguaclara/research/floc_model.py
https://github.com/AguaClara/aguaclara/blob/8dd4e734768b166a7fc2b60388a24df2f93783fc/aguaclara/research/floc_model.py#L505-L513
def dens_floc(ConcAl, ConcClay, DIM_FRACTAL, DiamTarget, coag, material, Temp): """Calculate floc density as a function of size.""" WaterDensity = pc.density_water(Temp).magnitude return ((dens_floc_init(ConcAl, ConcClay, coag, material).magnitude - WaterDensity ) * (material.Diameter / DiamTarget)**(3 - DIM_FRACTAL) + WaterDensity )
[ "def", "dens_floc", "(", "ConcAl", ",", "ConcClay", ",", "DIM_FRACTAL", ",", "DiamTarget", ",", "coag", ",", "material", ",", "Temp", ")", ":", "WaterDensity", "=", "pc", ".", "density_water", "(", "Temp", ")", ".", "magnitude", "return", "(", "(", "dens...
Calculate floc density as a function of size.
[ "Calculate", "floc", "density", "as", "a", "function", "of", "size", "." ]
python
train
44.555556
clalancette/pycdlib
pycdlib/eltorito.py
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L218-L235
def new(self, platform_id): # type: (int) -> None ''' A method to create a new El Torito Validation Entry. Parameters: platform_id - The platform ID to set for this validation entry. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Validation Entry already initialized') self.platform_id = platform_id self.id_string = b'\x00' * 24 # FIXME: let the user set this self.checksum = 0 self.checksum = utils.swab_16bit(self._checksum(self._record()) - 1) self._initialized = True
[ "def", "new", "(", "self", ",", "platform_id", ")", ":", "# type: (int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'El Torito Validation Entry already initialized'", ")", "self", ".", "platform_id", ...
A method to create a new El Torito Validation Entry. Parameters: platform_id - The platform ID to set for this validation entry. Returns: Nothing.
[ "A", "method", "to", "create", "a", "new", "El", "Torito", "Validation", "Entry", "." ]
python
train
35.333333
OpenGov/python_data_wrap
datawrap/listwrap.py
https://github.com/OpenGov/python_data_wrap/blob/7de38bb30d7a500adc336a4a7999528d753e5600/datawrap/listwrap.py#L463-L476
def compress_ranges_to_lists(self): ''' Converts the internal dimension ranges on lists into list of the restricted size. Thus all dimension rules are applied to all dimensions of the list wrapper and returned as a list (of lists). ''' clist = [] for elem in self: if isinstance(elem, FixedListSubset): clist.append(elem.compress_ranges_to_lists()) else: clist.append(elem) return clist
[ "def", "compress_ranges_to_lists", "(", "self", ")", ":", "clist", "=", "[", "]", "for", "elem", "in", "self", ":", "if", "isinstance", "(", "elem", ",", "FixedListSubset", ")", ":", "clist", ".", "append", "(", "elem", ".", "compress_ranges_to_lists", "("...
Converts the internal dimension ranges on lists into list of the restricted size. Thus all dimension rules are applied to all dimensions of the list wrapper and returned as a list (of lists).
[ "Converts", "the", "internal", "dimension", "ranges", "on", "lists", "into", "list", "of", "the", "restricted", "size", ".", "Thus", "all", "dimension", "rules", "are", "applied", "to", "all", "dimensions", "of", "the", "list", "wrapper", "and", "returned", ...
python
train
35.785714
cocaine/cocaine-tools
cocaine/tools/dispatch.py
https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L425-L451
def info(name, m, p, b, w, **kwargs): """ Show information about cocaine runtime. Return json-like string with information about cocaine-runtime. If the name option is not specified, shows information about all applications. Flags can be specified for fine-grained control of the output verbosity. """ m = (m << 1) & 0b010 p = (p << 2) & 0b100 # Brief disables all further flags. if b: flags = 0b000 else: flags = m | p | 0b001 ctx = Context(**kwargs) ctx.execute_action('info', **{ 'node': ctx.repo.create_secure_service('node'), 'locator': ctx.locator, 'name': name, 'flags': flags, 'use_wildcard': w, 'timeout': ctx.timeout, })
[ "def", "info", "(", "name", ",", "m", ",", "p", ",", "b", ",", "w", ",", "*", "*", "kwargs", ")", ":", "m", "=", "(", "m", "<<", "1", ")", "&", "0b010", "p", "=", "(", "p", "<<", "2", ")", "&", "0b100", "# Brief disables all further flags.", ...
Show information about cocaine runtime. Return json-like string with information about cocaine-runtime. If the name option is not specified, shows information about all applications. Flags can be specified for fine-grained control of the output verbosity.
[ "Show", "information", "about", "cocaine", "runtime", "." ]
python
train
26.962963
wbond/asn1crypto
asn1crypto/util.py
https://github.com/wbond/asn1crypto/blob/ecda20176f55d37021cbca1f6da9083a8e491197/asn1crypto/util.py#L295-L320
def replace(self, year=None, month=None, day=None): """ Returns a new datetime.date or asn1crypto.util.extended_date object with the specified components replaced :return: A datetime.date or asn1crypto.util.extended_date object """ if year is None: year = self.year if month is None: month = self.month if day is None: day = self.day if year > 0: cls = date else: cls = extended_date return cls( year, month, day )
[ "def", "replace", "(", "self", ",", "year", "=", "None", ",", "month", "=", "None", ",", "day", "=", "None", ")", ":", "if", "year", "is", "None", ":", "year", "=", "self", ".", "year", "if", "month", "is", "None", ":", "month", "=", "self", "....
Returns a new datetime.date or asn1crypto.util.extended_date object with the specified components replaced :return: A datetime.date or asn1crypto.util.extended_date object
[ "Returns", "a", "new", "datetime", ".", "date", "or", "asn1crypto", ".", "util", ".", "extended_date", "object", "with", "the", "specified", "components", "replaced" ]
python
train
22.961538
elyase/masstable
masstable/masstable.py
https://github.com/elyase/masstable/blob/3eb72b22cd3337bc5c6bb95bb7bb73fdbe6ae9e2/masstable/masstable.py#L500-L507
def ds2p(self): """Calculates the derivative of the neutron separation energies: ds2n(Z,A) = s2n(Z,A) - s2n(Z,A+2) """ idx = [(x[0] + 2, x[1]) for x in self.df.index] values = self.s2p.values - self.s2p.loc[idx].values return Table(df=pd.Series(values, index=self.df.index, name='ds2p' + '(' + self.name + ')'))
[ "def", "ds2p", "(", "self", ")", ":", "idx", "=", "[", "(", "x", "[", "0", "]", "+", "2", ",", "x", "[", "1", "]", ")", "for", "x", "in", "self", ".", "df", ".", "index", "]", "values", "=", "self", ".", "s2p", ".", "values", "-", "self",...
Calculates the derivative of the neutron separation energies: ds2n(Z,A) = s2n(Z,A) - s2n(Z,A+2)
[ "Calculates", "the", "derivative", "of", "the", "neutron", "separation", "energies", ":" ]
python
test
44.125
googleapis/google-cloud-python
core/google/cloud/_http.py
https://github.com/googleapis/google-cloud-python/blob/85e80125a59cb10f8cb105f25ecc099e4b940b50/core/google/cloud/_http.py#L194-L221
def _do_request( self, method, url, headers, data, target_object ): # pylint: disable=unused-argument """Low-level helper: perform the actual API request over HTTP. Allows batch context managers to override and defer a request. :type method: str :param method: The HTTP method to use in the request. :type url: str :param url: The URL to send the request to. :type headers: dict :param headers: A dictionary of HTTP headers to send with the request. :type data: str :param data: The data to send as the body of the request. :type target_object: object :param target_object: (Optional) Unused ``target_object`` here but may be used by a superclass. :rtype: :class:`requests.Response` :returns: The HTTP response. """ return self.http.request(url=url, method=method, headers=headers, data=data)
[ "def", "_do_request", "(", "self", ",", "method", ",", "url", ",", "headers", ",", "data", ",", "target_object", ")", ":", "# pylint: disable=unused-argument", "return", "self", ".", "http", ".", "request", "(", "url", "=", "url", ",", "method", "=", "meth...
Low-level helper: perform the actual API request over HTTP. Allows batch context managers to override and defer a request. :type method: str :param method: The HTTP method to use in the request. :type url: str :param url: The URL to send the request to. :type headers: dict :param headers: A dictionary of HTTP headers to send with the request. :type data: str :param data: The data to send as the body of the request. :type target_object: object :param target_object: (Optional) Unused ``target_object`` here but may be used by a superclass. :rtype: :class:`requests.Response` :returns: The HTTP response.
[ "Low", "-", "level", "helper", ":", "perform", "the", "actual", "API", "request", "over", "HTTP", "." ]
python
train
33.5
alvinwan/TexSoup
TexSoup/data.py
https://github.com/alvinwan/TexSoup/blob/63323ed71510fd2351102b8c36660a3b7703cead/TexSoup/data.py#L366-L384
def count(self, name=None, **attrs): r"""Number of descendants matching criteria. :param Union[None,str] name: name of LaTeX expression :param attrs: LaTeX expression attributes, such as item text. :return: number of matching expressions :rtype: int >>> from TexSoup import TexSoup >>> soup = TexSoup(r''' ... \section{Hey} ... \textit{Silly} ... \textit{Willy}''') >>> soup.count('section') 1 >>> soup.count('textit') 2 """ return len(list(self.find_all(name, **attrs)))
[ "def", "count", "(", "self", ",", "name", "=", "None", ",", "*", "*", "attrs", ")", ":", "return", "len", "(", "list", "(", "self", ".", "find_all", "(", "name", ",", "*", "*", "attrs", ")", ")", ")" ]
r"""Number of descendants matching criteria. :param Union[None,str] name: name of LaTeX expression :param attrs: LaTeX expression attributes, such as item text. :return: number of matching expressions :rtype: int >>> from TexSoup import TexSoup >>> soup = TexSoup(r''' ... \section{Hey} ... \textit{Silly} ... \textit{Willy}''') >>> soup.count('section') 1 >>> soup.count('textit') 2
[ "r", "Number", "of", "descendants", "matching", "criteria", "." ]
python
train
30.684211
joealcorn/laboratory
laboratory/experiment.py
https://github.com/joealcorn/laboratory/blob/e7af560c69d9dbb8f8cf4ca93c3c03523f8fb83d/laboratory/experiment.py#L40-L65
def decorator(cls, candidate, *exp_args, **exp_kwargs): ''' Decorate a control function in order to conduct an experiment when called. :param callable candidate: your candidate function :param iterable exp_args: positional arguments passed to :class:`Experiment` :param dict exp_kwargs: keyword arguments passed to :class:`Experiment` Usage:: candidate_func = lambda: True @Experiment.decorator(candidate_func) def control_func(): return True ''' def wrapper(control): @wraps(control) def inner(*args, **kwargs): experiment = cls(*exp_args, **exp_kwargs) experiment.control(control, args=args, kwargs=kwargs) experiment.candidate(candidate, args=args, kwargs=kwargs) return experiment.conduct() return inner return wrapper
[ "def", "decorator", "(", "cls", ",", "candidate", ",", "*", "exp_args", ",", "*", "*", "exp_kwargs", ")", ":", "def", "wrapper", "(", "control", ")", ":", "@", "wraps", "(", "control", ")", "def", "inner", "(", "*", "args", ",", "*", "*", "kwargs",...
Decorate a control function in order to conduct an experiment when called. :param callable candidate: your candidate function :param iterable exp_args: positional arguments passed to :class:`Experiment` :param dict exp_kwargs: keyword arguments passed to :class:`Experiment` Usage:: candidate_func = lambda: True @Experiment.decorator(candidate_func) def control_func(): return True
[ "Decorate", "a", "control", "function", "in", "order", "to", "conduct", "an", "experiment", "when", "called", "." ]
python
train
35.615385
ktbyers/netmiko
netmiko/paloalto/paloalto_panos.py
https://github.com/ktbyers/netmiko/blob/54e6116c0b4664de2123081937e0a9a27bdfdfea/netmiko/paloalto/paloalto_panos.py#L164-L167
def send_command(self, *args, **kwargs): """Palo Alto requires an extra delay""" kwargs["delay_factor"] = kwargs.get("delay_factor", 2.5) return super(PaloAltoPanosBase, self).send_command(*args, **kwargs)
[ "def", "send_command", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kwargs", "[", "\"delay_factor\"", "]", "=", "kwargs", ".", "get", "(", "\"delay_factor\"", ",", "2.5", ")", "return", "super", "(", "PaloAltoPanosBase", ",", "self"...
Palo Alto requires an extra delay
[ "Palo", "Alto", "requires", "an", "extra", "delay" ]
python
train
56.5
SpriteLink/NIPAP
nipap-www/nipapwww/controllers/pool.py
https://github.com/SpriteLink/NIPAP/blob/f96069f11ab952d80b13cab06e0528f2d24b3de9/nipap-www/nipapwww/controllers/pool.py#L52-L79
def edit(self, id): """ Edit a pool. """ c.pool = Pool.get(int(id)) c.prefix_list = Prefix.list({ 'pool_id': c.pool.id }) c.prefix = '' # save changes to NIPAP if request.method == 'POST': c.pool.name = request.params['name'] c.pool.description = request.params['description'] c.pool.default_type = request.params['default_type'] if request.params['ipv4_default_prefix_length'].strip() == '': c.pool.ipv4_default_prefix_length = None else: c.pool.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length'] if request.params['ipv6_default_prefix_length'].strip() == '': c.pool.ipv6_default_prefix_length = None else: c.pool.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length'] c.pool.save() redirect(url(controller = 'pool', action = 'list')) c.search_opt_parent = 'all' c.search_opt_child = 'none' return render("/pool_edit.html")
[ "def", "edit", "(", "self", ",", "id", ")", ":", "c", ".", "pool", "=", "Pool", ".", "get", "(", "int", "(", "id", ")", ")", "c", ".", "prefix_list", "=", "Prefix", ".", "list", "(", "{", "'pool_id'", ":", "c", ".", "pool", ".", "id", "}", ...
Edit a pool.
[ "Edit", "a", "pool", "." ]
python
train
39.107143
atlassian-api/atlassian-python-api
atlassian/service_desk.py
https://github.com/atlassian-api/atlassian-python-api/blob/540d269905c3e7547b666fe30c647b2d512cf358/atlassian/service_desk.py#L395-L413
def add_attachment(self, issue_id_or_key, temp_attachment_id, public=True, comment=None): """ Adds temporary attachment that were created using attach_temporary_file function to a customer request :param issue_id_or_key: str :param temp_attachment_id: str, ID from result attach_temporary_file function :param public: bool (default is True) :param comment: str (default is None) :return: """ log.warning('Adding attachment') data = { 'temporaryAttachmentIds': [temp_attachment_id], 'public': public, 'additionalComment': {'body': comment} } url = 'rest/servicedeskapi/request/{}/attachment'.format(issue_id_or_key) return self.post(url, headers=self.experimental_headers, data=data)
[ "def", "add_attachment", "(", "self", ",", "issue_id_or_key", ",", "temp_attachment_id", ",", "public", "=", "True", ",", "comment", "=", "None", ")", ":", "log", ".", "warning", "(", "'Adding attachment'", ")", "data", "=", "{", "'temporaryAttachmentIds'", ":...
Adds temporary attachment that were created using attach_temporary_file function to a customer request :param issue_id_or_key: str :param temp_attachment_id: str, ID from result attach_temporary_file function :param public: bool (default is True) :param comment: str (default is None) :return:
[ "Adds", "temporary", "attachment", "that", "were", "created", "using", "attach_temporary_file", "function", "to", "a", "customer", "request" ]
python
train
42.421053
tensorflow/tensor2tensor
tensor2tensor/utils/expert_utils.py
https://github.com/tensorflow/tensor2tensor/blob/272500b6efe353aeb638d2745ed56e519462ca31/tensor2tensor/utils/expert_utils.py#L810-L833
def combine(self, expert_out, multiply_by_gates=True): """Sum together the expert output, weighted by the gates. The slice corresponding to a particular batch element `b` is computed as the sum over all experts `i` of the expert output, weighted by the corresponding gate values. If `multiply_by_gates` is set to False, the gate values are ignored. Args: expert_out: a list of `num_experts` `Tensor`s, each with shape `[expert_batch_size_i, <extra_output_dims>]`. multiply_by_gates: a boolean Returns: a `Tensor` with shape `[batch_size, <extra_output_dims>]`. """ # see comments on convert_gradient_to_tensor stitched = common_layers.convert_gradient_to_tensor( tf.concat(expert_out, 0)) if multiply_by_gates: stitched *= tf.expand_dims(self._nonzero_gates, 1) combined = tf.unsorted_segment_sum(stitched, self._batch_index, tf.shape(self._gates)[0]) return combined
[ "def", "combine", "(", "self", ",", "expert_out", ",", "multiply_by_gates", "=", "True", ")", ":", "# see comments on convert_gradient_to_tensor", "stitched", "=", "common_layers", ".", "convert_gradient_to_tensor", "(", "tf", ".", "concat", "(", "expert_out", ",", ...
Sum together the expert output, weighted by the gates. The slice corresponding to a particular batch element `b` is computed as the sum over all experts `i` of the expert output, weighted by the corresponding gate values. If `multiply_by_gates` is set to False, the gate values are ignored. Args: expert_out: a list of `num_experts` `Tensor`s, each with shape `[expert_batch_size_i, <extra_output_dims>]`. multiply_by_gates: a boolean Returns: a `Tensor` with shape `[batch_size, <extra_output_dims>]`.
[ "Sum", "together", "the", "expert", "output", "weighted", "by", "the", "gates", "." ]
python
train
40.791667
lvieirajr/mongorest
mongorest/collection.py
https://github.com/lvieirajr/mongorest/blob/00f4487ded33254434bc51ff09d48c7a936bd465/mongorest/collection.py#L307-L312
def update_one(cls, filter, update, upsert=False): """ Updates a document that passes the filter with the update value Will upsert a new document if upsert=True and no document is filtered """ return cls.collection.update_one(filter, update, upsert).raw_result
[ "def", "update_one", "(", "cls", ",", "filter", ",", "update", ",", "upsert", "=", "False", ")", ":", "return", "cls", ".", "collection", ".", "update_one", "(", "filter", ",", "update", ",", "upsert", ")", ".", "raw_result" ]
Updates a document that passes the filter with the update value Will upsert a new document if upsert=True and no document is filtered
[ "Updates", "a", "document", "that", "passes", "the", "filter", "with", "the", "update", "value", "Will", "upsert", "a", "new", "document", "if", "upsert", "=", "True", "and", "no", "document", "is", "filtered" ]
python
train
49.166667
mlperf/training
reinforcement/tensorflow/minigo/oneoffs/heatmap.py
https://github.com/mlperf/training/blob/1c6ae725a81d15437a2b2df05cac0673fde5c3a4/reinforcement/tensorflow/minigo/oneoffs/heatmap.py#L45-L85
def eval_policy(eval_positions): """Evaluate all positions with all models save the policy heatmaps as CSVs CSV name is "heatmap-<position_name>-<model-index>.csv" CSV format is: model number, value network output, policy network outputs position_name is taken from the SGF file Policy network outputs (19x19) are saved in flat order (see coord.from_flat) """ model_paths = oneoff_utils.get_model_paths(fsdb.models_dir()) idx_start = FLAGS.idx_start eval_every = FLAGS.eval_every print("Evaluating models {}-{}, eval_every={}".format( idx_start, len(model_paths), eval_every)) player = None for i, idx in enumerate(tqdm(range(idx_start, len(model_paths), eval_every))): if player and i % 20 == 0: player.network.sess.close() tf.reset_default_graph() player = None if not player: player = oneoff_utils.load_player(model_paths[idx]) else: oneoff_utils.restore_params(model_paths[idx], player) pos_names, positions = zip(*eval_positions) # This should be batched at somepoint. eval_probs, eval_values = player.network.run_many(positions) for pos_name, probs, value in zip(pos_names, eval_probs, eval_values): save_file = os.path.join( FLAGS.data_dir, "heatmap-{}-{}.csv".format(pos_name, idx)) with open(save_file, "w") as data: data.write("{}, {}, {}\n".format( idx, value, ",".join(map(str, probs))))
[ "def", "eval_policy", "(", "eval_positions", ")", ":", "model_paths", "=", "oneoff_utils", ".", "get_model_paths", "(", "fsdb", ".", "models_dir", "(", ")", ")", "idx_start", "=", "FLAGS", ".", "idx_start", "eval_every", "=", "FLAGS", ".", "eval_every", "print...
Evaluate all positions with all models save the policy heatmaps as CSVs CSV name is "heatmap-<position_name>-<model-index>.csv" CSV format is: model number, value network output, policy network outputs position_name is taken from the SGF file Policy network outputs (19x19) are saved in flat order (see coord.from_flat)
[ "Evaluate", "all", "positions", "with", "all", "models", "save", "the", "policy", "heatmaps", "as", "CSVs" ]
python
train
37.097561
gmr/rejected
rejected/mcp.py
https://github.com/gmr/rejected/blob/610a3e1401122ecb98d891b6795cca0255e5b044/rejected/mcp.py#L616-L626
def setup_consumers(self): """Iterate through each consumer in the configuration and kick off the minimal amount of processes, setting up the runtime data as well. """ if not self.consumer_cfg: LOGGER.warning('No consumers are configured') for name in self.consumer_cfg.keys(): self.consumers[name] = self.new_consumer( self.consumer_cfg[name], name) self.start_processes(name, self.consumers[name].qty)
[ "def", "setup_consumers", "(", "self", ")", ":", "if", "not", "self", ".", "consumer_cfg", ":", "LOGGER", ".", "warning", "(", "'No consumers are configured'", ")", "for", "name", "in", "self", ".", "consumer_cfg", ".", "keys", "(", ")", ":", "self", ".", ...
Iterate through each consumer in the configuration and kick off the minimal amount of processes, setting up the runtime data as well.
[ "Iterate", "through", "each", "consumer", "in", "the", "configuration", "and", "kick", "off", "the", "minimal", "amount", "of", "processes", "setting", "up", "the", "runtime", "data", "as", "well", "." ]
python
train
44.181818
CLARIAH/grlc
src/gquery.py
https://github.com/CLARIAH/grlc/blob/f5664e34f039010c00ef8ebb69917c05e8ce75d7/src/gquery.py#L196-L209
def get_enumeration(rq, v, endpoint, metadata={}, auth=None): """ Returns a list of enumerated values for variable 'v' in query 'rq' """ # glogger.debug("Metadata before processing enums: {}".format(metadata)) # We only fire the enum filling queries if indicated by the query metadata if 'enumerate' not in metadata: return None enumDict = _getDictWithKey(v, metadata['enumerate']) if enumDict: return enumDict[v] if v in metadata['enumerate']: return get_enumeration_sparql(rq, v, endpoint, auth) return None
[ "def", "get_enumeration", "(", "rq", ",", "v", ",", "endpoint", ",", "metadata", "=", "{", "}", ",", "auth", "=", "None", ")", ":", "# glogger.debug(\"Metadata before processing enums: {}\".format(metadata))", "# We only fire the enum filling queries if indicated by the query...
Returns a list of enumerated values for variable 'v' in query 'rq'
[ "Returns", "a", "list", "of", "enumerated", "values", "for", "variable", "v", "in", "query", "rq" ]
python
train
40
uploadcare/pyuploadcare
pyuploadcare/api_resources.py
https://github.com/uploadcare/pyuploadcare/blob/cefddc0306133a71e37b18e8700df5948ef49b37/pyuploadcare/api_resources.py#L361-L391
def upload(cls, file_obj, store=None): """Uploads a file and returns ``File`` instance. Args: - file_obj: file object to upload to - store (Optional[bool]): Should the file be automatically stored upon upload. Defaults to None. - False - do not store file - True - store file (can result in error if autostore is disabled for project) - None - use project settings Returns: ``File`` instance """ if store is None: store = 'auto' elif store: store = '1' else: store = '0' data = { 'UPLOADCARE_STORE': store, } files = uploading_request('POST', 'base/', data=data, files={'file': file_obj}) file_ = cls(files['file']) return file_
[ "def", "upload", "(", "cls", ",", "file_obj", ",", "store", "=", "None", ")", ":", "if", "store", "is", "None", ":", "store", "=", "'auto'", "elif", "store", ":", "store", "=", "'1'", "else", ":", "store", "=", "'0'", "data", "=", "{", "'UPLOADCARE...
Uploads a file and returns ``File`` instance. Args: - file_obj: file object to upload to - store (Optional[bool]): Should the file be automatically stored upon upload. Defaults to None. - False - do not store file - True - store file (can result in error if autostore is disabled for project) - None - use project settings Returns: ``File`` instance
[ "Uploads", "a", "file", "and", "returns", "File", "instance", "." ]
python
test
29.419355
appknox/google-chartwrapper
GChartWrapper/GChart.py
https://github.com/appknox/google-chartwrapper/blob/3769aecbef6c83b6cd93ee72ece478ffe433ac57/GChartWrapper/GChart.py#L331-L341
def line(self, *args): """ Called one at a time for each dataset args are of the form:: <data set n line thickness>, <length of line segment>, <length of blank segment> APIPARAM: chls """ self.lines.append(','.join(['%.1f'%x for x in map(float,args)])) return self
[ "def", "line", "(", "self", ",", "*", "args", ")", ":", "self", ".", "lines", ".", "append", "(", "','", ".", "join", "(", "[", "'%.1f'", "%", "x", "for", "x", "in", "map", "(", "float", ",", "args", ")", "]", ")", ")", "return", "self" ]
Called one at a time for each dataset args are of the form:: <data set n line thickness>, <length of line segment>, <length of blank segment> APIPARAM: chls
[ "Called", "one", "at", "a", "time", "for", "each", "dataset", "args", "are", "of", "the", "form", "::", "<data", "set", "n", "line", "thickness", ">", "<length", "of", "line", "segment", ">", "<length", "of", "blank", "segment", ">", "APIPARAM", ":", "...
python
test
31.454545