code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def interpolate_where(self, condition):
raise NotImplementedError()
self[self < 0] = np.nan
return self.interpolate() | Remove then interpolate across |
def get_collections_for_image(self, image_id):
result = []
for document in self.collection.find({'active' : True, 'images.identifier' : image_id}):
result.append(str(document['_id']))
return result | Get identifier of all collections that contain a given image.
Parameters
----------
image_id : string
Unique identifierof image object
Returns
-------
List(string)
List of image collection identifier |
def contigs_to_positions(contigs, binning=10000):
positions = np.zeros_like(contigs)
index = 0
for _, chunk in itertools.groubpy(contigs):
l = len(chunk)
positions[index : index + l] = np.arange(list(chunk)) * binning
index += l
return positions | Build positions from contig labels
From a list of contig labels and a binning parameter,
build a list of positions that's essentially a
concatenation of linspaces with step equal to the
binning.
Parameters
----------
contigs : list or array_like
The list of contig labels, must be s... |
def update_token_tempfile(token):
with open(tmp, 'w') as f:
f.write(json.dumps(token, indent=4)) | Example of function for token update |
def get_value(repo_directory, key, expect_type=None):
config = read_config(repo_directory)
value = config.get(key)
if expect_type and value is not None and not isinstance(value, expect_type):
raise ConfigSchemaError('Expected config variable %s to be type %s, got %s'
% (repr(key), repr(e... | Gets the value of the specified key in the config file. |
def max_substring(words, position=0, _last_letter=''):
try:
letter = [word[position] for word in words]
except IndexError:
return _last_letter
if all(l == letter[0] for l in letter) is True:
_last_letter += max_substring(words, position=position + 1,
... | Finds max substring shared by all strings starting at position
Args:
words (list): list of unicode of all words to compare
position (int): starting position in each word to begin analyzing
for substring
_last_letter (unicode): last common letter, only for use
... |
def find_single(decl_matcher, decls, recursive=True):
answer = matcher.find(decl_matcher, decls, recursive)
if len(answer) == 1:
return answer[0] | Returns a reference to the declaration, that match `decl_matcher`
defined criteria.
if a unique declaration could not be found the method will return None.
:param decl_matcher: Python callable object, that takes one argument -
reference to a declaration
:param decls: the se... |
def addIndividual(self, individual):
id_ = individual.getId()
self._individualIdMap[id_] = individual
self._individualIds.append(id_)
self._individualNameMap[individual.getName()] = individual | Adds the specified individual to this dataset. |
def cmdscale_fast(D, ndim):
tasklogger.log_debug("Performing classic MDS on {} of shape {}...".format(
type(D).__name__, D.shape))
D = D**2
D = D - D.mean(axis=0)[None, :]
D = D - D.mean(axis=1)[:, None]
pca = PCA(n_components=ndim, svd_solver='randomized')
Y = pca.fit_transform(D)
r... | Fast CMDS using random SVD
Parameters
----------
D : array-like, input data [n_samples, n_dimensions]
ndim : int, number of dimensions in which to embed `D`
Returns
-------
Y : array-like, embedded data [n_sample, ndim] |
def get_torrent(self, torrent_id):
params = {
'page': 'download',
'tid': torrent_id,
}
r = requests.get(self.base_url, params=params)
if r.headers.get('content-type') != 'application/x-bittorrent':
raise TorrentNotFoundError(TORRENT_NOT_FOUND_TEXT)
... | Gets the `.torrent` data for the given `torrent_id`.
:param torrent_id: the ID of the torrent to download
:raises TorrentNotFoundError: if the torrent does not exist
:returns: :class:`Torrent` of the associated torrent |
def invalidate(self, key, **kw):
self.impl.invalidate(key, **self._get_cache_kw(kw, None)) | Invalidate a value in the cache.
:param key: the value's key.
:param \**kw: cache configuration arguments. The
backend is configured using these arguments upon first request.
Subsequent requests that use the same series of configuration
values will use that same backend. |
def type(self):
"The type of elements stored in the mapping."
if self._type is None and len(self):
self._type = self.values()[0].__class__
return self._type | The type of elements stored in the mapping. |
def frame_to_latents(frame, hparams):
frame = preprocess_frame(frame)
glow_vals = glow_ops.encoder_decoder(
"codec", frame, hparams, eps=None, reverse=False)
z_top, _, level_eps, _, _ = glow_vals
return z_top, level_eps | Encode frames to latents. |
def _chooseBestSegmentPerColumn(cls, connections, matchingCells,
allMatchingSegments, potentialOverlaps,
cellsPerColumn):
candidateSegments = connections.filterSegmentsByCell(allMatchingSegments,
... | For all the columns covered by 'matchingCells', choose the column's matching
segment with largest number of active potential synapses. When there's a
tie, the first segment wins.
@param connections (SparseMatrixConnections)
@param matchingCells (numpy array)
@param allMatchingSegments (numpy array)... |
def zremrangebylex(self, key, min=b'-', max=b'+',
include_min=True, include_max=True):
if not isinstance(min, bytes):
raise TypeError("min argument must be bytes")
if not isinstance(max, bytes):
raise TypeError("max argument must be bytes")
if not m... | Remove all members in a sorted set between the given
lexicographical range.
:raises TypeError: if min is not bytes
:raises TypeError: if max is not bytes |
def list_assets_ddo(self):
return json.loads(self.requests_session.get(self.url).content) | List all the ddos registered in the aquarius instance.
:return: List of DDO instance |
def _check_whitespace(string):
if string.count(' ') + string.count('\t') + string.count('\n') > 0:
raise ValueError(INSTRUCTION_HAS_WHITESPACE) | Make sure thre is no whitespace in the given string. Will raise a
ValueError if whitespace is detected |
def beacon(config):
ret = []
_refresh = False
pkgs = []
for config_item in config:
if 'pkgs' in config_item:
pkgs += config_item['pkgs']
if 'refresh' in config and config['refresh']:
_refresh = True
for pkg in pkgs:
_installed = __salt__['pkg.version']... | Check if installed packages are the latest versions
and fire an event for those that have upgrades.
.. code-block:: yaml
beacons:
pkg:
- pkgs:
- zsh
- apache2
- refresh: True |
def _handle_tag_module_refresh(self, tag, data):
self.module_refresh(
force_refresh=data.get('force_refresh', False),
notify=data.get('notify', False)
) | Handle a module_refresh event |
def connect(self, id):
schema = ConnectionSchema()
resp = self.service.post(self.base+str(id)+'/connect/')
return self.service.decode(schema, resp) | Open proxy connection to a device's management interface.
:param id: Device ID as an int.
:return: :class:`devices.Connection <devices.Connection>` object
:rtype: devices.Connection |
def result(self):
for _ in range(self.num_threads):
self.tasks_queue.put(None)
self.tasks_queue.join()
if not self.exceptions_queue.empty():
raise self.exceptions_queue.get()
return self.results_queue | Stop threads and return the result of all called tasks |
def raftery_lewis(x, q, r, s=.95, epsilon=.001, verbose=1):
if np.ndim(x) > 1:
return [raftery_lewis(y, q, r, s, epsilon, verbose)
for y in np.transpose(x)]
output = nmin, kthin, nburn, nprec, kmind = flib.gibbmain(
x, q, r, s, epsilon)
if verbose:
print_("\n=========... | Return the number of iterations needed to achieve a given
precision.
:Parameters:
x : sequence
Sampled series.
q : float
Quantile.
r : float
Accuracy requested for quantile.
s (optional) : float
Probability of attaining the request... |
def toFloatArray(img):
_D = {1: np.float32,
2: np.float32,
4: np.float64,
8: np.float64}
return img.astype(_D[img.itemsize]) | transform an unsigned integer array into a
float array of the right size |
def packageInfo(self):
url = "%s/item.pkinfo" % self.root
params = {'f' : 'json'}
result = self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
... | gets the item's package information file |
def _image2array(filepath):
im = Pimage.open(filepath).convert('RGB')
(width, height) = im.size
_r = np.array(list(im.getdata(0)))/255.0
_g = np.array(list(im.getdata(1)))/255.0
_b = np.array(list(im.getdata(2)))/255.0
_r = _r.reshape((height, width))
_g = _g.reshape((height, width))
_b ... | Utility function that converts an image file in 3 np arrays
that can be fed into geo_image.GeoImage in order to generate
a PyTROLL GeoImage object. |
def defer(callable):
t = threading.Thread(target=callable)
t.start()
return t.join | Defers execution of the callable to a thread.
For example:
>>> def foo():
... print('bar')
>>> join = defer(foo)
>>> join() |
def delete(args):
jm = setup(args)
if not args.local and 'executing' in args.status:
stop(args)
jm.delete(job_ids=get_ids(args.job_ids), array_ids=get_ids(args.array_ids), delete_logs=not args.keep_logs, delete_log_dir=not args.keep_log_dir, status=args.status) | Deletes the jobs from the job manager. If the jobs are still running in the grid, they are stopped. |
def extant_item(arg, arg_type):
if arg_type == "file":
if not os.path.isfile(arg):
raise argparse.ArgumentError(
None,
"The file {arg} does not exist.".format(arg=arg))
else:
return arg
elif arg_type == "directory":
if not os.path.i... | Determine if parser argument is an existing file or directory.
This technique comes from http://stackoverflow.com/a/11541450/95592
and from http://stackoverflow.com/a/11541495/95592
Args:
arg: parser argument containing filename to be checked
arg_type: string of either "file" or "directory... |
def search_document_cache_key(self):
return "elasticsearch_django:{}.{}.{}".format(
self._meta.app_label, self._meta.model_name, self.pk
) | Key used for storing search docs in local cache. |
def shuffle_characters(s):
s = list(s)
random.shuffle(s)
s =''.join(s)
return s | Randomly shuffle the characters in a string |
def text2sentences(text, labels):
sentence = ''
for i, label in enumerate(labels):
if label == '1':
if sentence:
yield sentence
sentence = ''
else:
sentence += text[i]
if sentence:
yield sentence | Splits given text at predicted positions from `labels` |
def get_connections(self, id, connection_name, **args):
return self.request(
"{0}/{1}/{2}".format(self.version, id, connection_name), args
) | Fetches the connections for given object. |
def prjs_view_prj(self, *args, **kwargs):
i = self.prjs_tablev.currentIndex()
item = i.internalPointer()
if item:
prj = item.internal_data()
self.view_prj(prj) | View the, in the projects table view selected, project.
:returns: None
:rtype: None
:raises: None |
def next(self):
outgoing_msg = self.outgoing_msg_list.pop_first()
if outgoing_msg is None:
self.outgoing_msg_event.clear()
self.outgoing_msg_event.wait()
outgoing_msg = self.outgoing_msg_list.pop_first()
return outgoing_msg | Pops and returns the first outgoing message from the list.
If message list currently has no messages, the calling thread will
be put to sleep until we have at-least one message in the list that
can be popped and returned. |
def inverse_deriv(self, z):
return np.power(z, (1 - self.power)/self.power) / self.power | Derivative of the inverse of the power transform
Parameters
----------
z : array-like
`z` is usually the linear predictor for a GLM or GEE model.
Returns
-------
g^(-1)'(z) : array
The value of the derivative of the inverse of the power transform... |
def copy_without_prompts(self):
text = self.get_selected_text()
lines = text.split(os.linesep)
for index, line in enumerate(lines):
if line.startswith('>>> ') or line.startswith('... '):
lines[index] = line[4:]
text = os.linesep.join(lines)
QApp... | Copy text to clipboard without prompts |
def plot(self):
try:
import matplotlib.pyplot as plt
except ImportError:
from sys import stderr
print("ERROR: matplotlib.pyplot not found, matplotlib must be installed to use this function", file=stderr)
raise
x_min = np.min(self.knot_vector)
... | Plot basis functions over full range of knots.
Convenience function. Requires matplotlib. |
def _find_module_ptr(self, module_ptr):
ptr = cast(module_ptr, c_void_p).value
for module in self._modules:
if cast(module._ptr, c_void_p).value == ptr:
return module
return None | Find the ModuleRef corresponding to the given pointer. |
def _estimateCubicCurveLength(pt0, pt1, pt2, pt3, precision=10):
points = []
length = 0
step = 1.0 / precision
factors = range(0, precision + 1)
for i in factors:
points.append(_getCubicPoint(i * step, pt0, pt1, pt2, pt3))
for i in range(len(points) - 1):
pta = points[i]
... | Estimate the length of this curve by iterating
through it and averaging the length of the flat bits. |
def write_to_screen(self, screen, mouse_handlers, write_position,
parent_style, erase_bg, z_index):
" Fill the whole area of write_position with dots. "
default_char = Char(' ', 'class:background')
dot = Char('.', 'class:background')
ypos = write_position.ypos
... | Fill the whole area of write_position with dots. |
def strip_suffix(id):
suffix = get_suffix(id)
if not suffix:
return id
return re.split(suffix, id)[0] | Split off any suffix from ID
This mimics the old behavior of the Sample ID. |
def _credit_card_type(self, card_type=None):
if card_type is None:
card_type = self.random_element(self.credit_card_types.keys())
elif isinstance(card_type, CreditCard):
return card_type
return self.credit_card_types[card_type] | Returns a random credit card type instance. |
def get_collection(self, **kwargs):
list_of_contents = []
self.refresh(**kwargs)
if 'items' in self.__dict__:
for item in self.items:
if 'kind' not in item:
list_of_contents.append(item)
continue
kind = item['kin... | Get an iterator of Python ``Resource`` objects that represent URIs.
The returned objects are Pythonic `Resource`s that map to the most
recently `refreshed` state of uris-resources published by the device.
In order to instantiate the correct types, the concrete subclass must
populate its... |
def required_arguments(func):
defaults = default_values_of(func)
args = arguments_of(func)
if defaults:
args = args[:-len(defaults)]
return args | Return all arguments of a function that do not have a default value. |
def create(cls, name, protocol_number, protocol_agent=None, comment=None):
json = {'name': name,
'protocol_number': protocol_number,
'protocol_agent_ref': element_resolver(protocol_agent) or None,
'comment': comment}
return ElementCreator(cls, json) | Create the IP Service
:param str name: name of ip-service
:param int protocol_number: ip proto number for this service
:param str,ProtocolAgent protocol_agent: optional protocol agent for
this service
:param str comment: optional comment
:raises CreateElementFailed: ... |
def hget(self, key):
data = self.r.hget(self.hash, key)
if data is not None and not isinstance(data, str):
data = str(self.r.hget(self.hash, key), 'utf-8')
return data | Read data from Redis for the provided key.
Args:
key (string): The key to read in Redis.
Returns:
(any): The response data from Redis. |
def initialize_directories(self, root_dir):
if not root_dir:
root_dir = os.path.expanduser('~')
self.config_dir = os.path.join(root_dir, '.config/pueue')
if not os.path.exists(self.config_dir):
os.makedirs(self.config_dir) | Create all directories needed for logs and configs. |
def CheckRegistryKey(javaKey):
from _winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
path = None
try:
aReg = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
rk = OpenKey(aReg, javaKey)
for i in range(1024):
currentVersion = QueryValueEx(rk, "CurrentVersion")
if currentVersion !... | Method checks for the java in the registry entries. |
def reach_max_num(self):
if self.signal.get('reach_max_num'):
return True
if self.max_num > 0 and self.fetched_num >= self.max_num:
return True
else:
return False | Check if downloaded images reached max num.
Returns:
bool: if downloaded images reached max num. |
def default_working_dir():
import nameset.virtualchain_hooks as virtualchain_hooks
return os.path.expanduser('~/.{}'.format(virtualchain_hooks.get_virtual_chain_name())) | Get the default configuration directory for blockstackd |
def build_request_include(include, params):
params = params or OrderedDict()
if include is not None:
params['include'] = ','.join([cls._resource_type() for cls in include])
return params | Augment request parameters with includes.
When one or all resources are requested an additional set of
resources can be requested as part of the request. This function
extends the given parameters for a request with a list of resource
types passed in as a list of :class:`Resource` subclasses.
Args... |
def remove_leading_garbage_lines_from_reference_section(ref_sectn):
p_email = re.compile(ur'^\s*e\-?mail', re.UNICODE)
while ref_sectn and (ref_sectn[0].isspace() or p_email.match(ref_sectn[0])):
ref_sectn.pop(0)
return ref_sectn | Sometimes, the first lines of the extracted references are completely
blank or email addresses. These must be removed as they are not
references.
@param ref_sectn: (list) of strings - the reference section lines
@return: (list) of strings - the reference section without leading
blank... |
def __conn_listener(self, state):
if state == KazooState.CONNECTED:
self.__online = True
if not self.__connected:
self.__connected = True
self._logger.info("Connected to ZooKeeper")
self._queue.enqueue(self.on_first_connection)
... | Connection event listener
:param state: The new connection state |
def get_pinned_version(ireq):
try:
specifier = ireq.specifier
except AttributeError:
raise TypeError("Expected InstallRequirement, not {}".format(
type(ireq).__name__,
))
if ireq.editable:
raise ValueError("InstallRequirement is editable")
if not specifier:
... | Get the pinned version of an InstallRequirement.
An InstallRequirement is considered pinned if:
- Is not editable
- It has exactly one specifier
- That specifier is "=="
- The version does not contain a wildcard
Examples:
django==1.8 # pinned
django>1.8 # NOT pinned
... |
def type_check(self, filename):
self.log.debug('type_check: in')
self.editor.clean_errors()
self.send_request(
{"typehint": "TypecheckFilesReq",
"files": [self.editor.path()]}) | Update type checking when user saves buffer. |
def predict_from_design_matrix(self, design_matrix):
assert hasattr(self, 'betas'), 'no betas found, please run regression before prediction'
assert design_matrix.shape[0] == self.betas.shape[0], \
'designmatrix needs to have the same number of regressors as the betas already calcula... | predict_from_design_matrix predicts signals given a design matrix.
:param design_matrix: design matrix from which to predict a signal.
:type design_matrix: numpy array, (nr_samples x betas.shape)
:returns: predicted signal(s)
:rtype: numpy array (nr_signals x nr_samples... |
def decr(name, value=1, rate=1, tags=None):
client().decr(name, value, rate, tags) | Decrement a metric by value.
>>> import statsdecor
>>> statsdecor.decr('my.metric') |
def save(self, png_file):
with open(png_file, 'wb') as f:
f.write(self._repr_png_()) | Save png to disk.
Parameters
----------
png_file : path to file
file to write to
Notes
-----
It relies on _repr_png_, so fix issues there. |
def has(self, querypart_name, value=None):
querypart = self._queryparts.get(querypart_name)
if not querypart:
return False
if not querypart.is_set:
return False
if value:
return querypart.has(value)
return True | Returns True if `querypart_name` with `value` is set.
For example you can check if you already used condition by `sql.has('where')`.
If you want to check for more information, for example if that condition
also contain ID, you can do this by `sql.has('where', 'id')`. |
def get_next_invalid_day(self, timestamp):
if self.is_time_day_invalid(timestamp):
return timestamp
next_future_timerange_invalid = self.get_next_future_timerange_invalid(timestamp)
if next_future_timerange_invalid is None:
(start_time, end_time) = self.get_start_and_end_... | Get next day where timerange is not active
:param timestamp: time we compute from
:type timestamp: int
:return: timestamp of the next invalid day (midnight) in LOCAL time.
:rtype: int | None |
def steadystate(A, max_iter=100):
P = np.linalg.matrix_power(A, max_iter)
v = []
for i in range(len(P)):
if not np.any([np.allclose(P[i], vi, ) for vi in v]):
v.append(P[i])
return normalize(np.sum(v, axis=0)) | Empirically determine the steady state probabilities from a stochastic matrix |
def open(self):
self.startTime = datetime.datetime.now()
self.offset = 0
return self | Reset time and counts. |
def _on_connection_finished(self, result):
success, retval, context = self._parse_return(result)
conn_id = context['connection_id']
callback = context['callback']
if success is False:
callback(conn_id, self.id, False, 'Timeout opening connection')
with self.count_... | Callback when the connection attempt to a BLE device has finished
This function if called when a new connection is successfully completed
Args:
event (BGAPIPacket): Connection event |
def predict_proba(self, X):
y_probas = []
bce_logits_loss = isinstance(
self.criterion_, torch.nn.BCEWithLogitsLoss)
for yp in self.forward_iter(X, training=False):
yp = yp[0] if isinstance(yp, tuple) else yp
if bce_logits_loss:
yp = torch.sigm... | Where applicable, return probability estimates for
samples.
If the module's forward method returns multiple outputs as a
tuple, it is assumed that the first output contains the
relevant information and the other values are ignored. If all
values are relevant, consider using
... |
def kill_cursors(self, cursor_ids, address=None):
warnings.warn(
"kill_cursors is deprecated.",
DeprecationWarning,
stacklevel=2)
if not isinstance(cursor_ids, list):
raise TypeError("cursor_ids must be a list")
self.__kill_cursors_queue.append((ad... | DEPRECATED - Send a kill cursors message soon with the given ids.
Raises :class:`TypeError` if `cursor_ids` is not an instance of
``list``.
:Parameters:
- `cursor_ids`: list of cursor ids to kill
- `address` (optional): (host, port) pair of the cursor's server.
... |
def load(cls, path):
data = json.load(open(path))
weights = data['weights']
weights = np.asarray(weights, dtype=np.float64)
s = cls(data['num_neurons'],
data['data_dimensionality'],
data['params']['lr']['orig'],
neighborhood=data['params'][... | Load a SOM from a JSON file saved with this package.
Parameters
----------
path : str
The path to the JSON file.
Returns
-------
s : cls
A som of the specified class. |
def get_uri(endpoint_context, request, uri_type):
if uri_type in request:
verify_uri(endpoint_context, request, uri_type)
uri = request[uri_type]
else:
try:
_specs = endpoint_context.cdb[
str(request["client_id"])]["{}s".format(uri_type)]
except KeyErr... | verify that the redirect URI is reasonable
:param endpoint_context:
:param request: The Authorization request
:param uri_type: 'redirect_uri' or 'post_logout_redirect_uri'
:return: redirect_uri |
def set_hparams_from_args(args):
if not args:
return
hp_prefix = "--hp_"
tf.logging.info("Found unparsed command-line arguments. Checking if any "
"start with %s and interpreting those as hparams "
"settings.", hp_prefix)
pairs = []
i = 0
while i < len(args):
arg ... | Set hparams overrides from unparsed args list. |
def metadata(self, key=None, database=None, table=None, fallback=True):
assert not (database is None and table is not None), \
"Cannot call metadata() with table= specified but not database="
databases = self._metadata.get("databases") or {}
search_list = []
if database is no... | Looks up metadata, cascading backwards from specified level.
Returns None if metadata value is not found. |
def main(self, *args, **kwargs):
try:
result = super().main(*args, **kwargs)
return result
except Exception:
if HAS_SENTRY:
self._handle_sentry()
if not (sys.stdin.isatty() and sys.stdout.isatty()):
raise
self._h... | Catch all exceptions. |
def lease(self, items):
self._manager.leaser.add(items)
self._manager.maybe_pause_consumer() | Add the given messages to lease management.
Args:
items(Sequence[LeaseRequest]): The items to lease. |
def soft_error(self, message):
self.print_usage(sys.stderr)
args = {'prog': self.prog, 'message': message}
self._print_message(
_('%(prog)s: error: %(message)s\n') % args, sys.stderr) | Same as error, without the dying in a fire part. |
def entryCheck(self, event = None, repair = True):
valupr = self.choice.get().upper()
if valupr.strip() == 'INDEF':
self.choice.set(valupr)
return EparOption.entryCheck(self, event, repair = repair) | Ensure any INDEF entry is uppercase, before base class behavior |
def wrap(self, methodName, types, skip=2):
def handler(fields):
try:
args = [
field if typ is str else
int(field or 0) if typ is int else
float(field or 0) if typ is float else
bool(int(field or 0))
... | Create a message handler that invokes a wrapper method
with the in-order message fields as parameters, skipping over
the first ``skip`` fields, and parsed according to the ``types`` list. |
def vequ(v1):
v1 = stypes.toDoubleVector(v1)
vout = stypes.emptyDoubleVector(3)
libspice.vequ_c(v1, vout)
return stypes.cVectorToPython(vout) | Make one double precision 3-dimensional vector equal to another.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vequ_c.html
:param v1: 3-dimensional double precision vector.
:type v1: 3-Element Array of floats
:return: 3-dimensional double precision vector set equal to vin.
:rtype: 3-Ele... |
async def register(self):
url = '{}/Sessions'.format(self.construct_url(API_URL))
params = {'api_key': self._api_key}
reg = await self.api_request(url, params)
if reg is None:
self._registered = False
_LOGGER.error('Unable to register emby client.')
else:
... | Register library device id and get initial device list. |
def determine_device(kal_out):
device = ""
while device == "":
for line in kal_out.splitlines():
if "Using device " in line:
device = str(line.split(' ', 2)[-1])
if device == "":
device = None
return device | Extract and return device from scan results. |
def wrap(self, availWidth, availHeight):
self.avWidth = availWidth
self.avHeight = availHeight
logger.debug("*** wrap (%f, %f)", availWidth, availHeight)
if not self.text:
logger.debug("*** wrap (%f, %f) needed", 0, 0)
return 0, 0
width = availWidth
... | Determine the rectangle this paragraph really needs. |
def _http_get(self, url):
for try_number in range(self._http_retries + 1):
response = requests.get(url, timeout=self._http_timeout)
if response.status_code == 200:
return response
if (try_number >= self._http_retries or
response.status_code... | Make an HTTP GET request to the specified URL and return the response.
Retries
-------
The constructor of this class takes an argument specifying the number
of times to retry a GET. The statuses which are retried on are: 408,
500, 502, 503, and 504.
Returns
----... |
def stop_running_tasks(self):
for task in self.__running_registry:
task.stop()
self.__running_registry.clear() | Terminate all the running tasks
:return: None |
def list_vmss(access_token, subscription_id, resource_group):
endpoint = ''.join([get_rm_endpoint(),
'/subscriptions/', subscription_id,
'/resourceGroups/', resource_group,
'/providers/Microsoft.Compute/virtualMachineScaleSets',
... | List VM Scale Sets in a resource group.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
Returns:
HTTP response. JSON body of a list of scale set model views. |
def to_indices(self, tokens):
to_reduce = False
if not isinstance(tokens, list):
tokens = [tokens]
to_reduce = True
indices = [self.token_to_idx[token] if token in self.token_to_idx
else C.UNKNOWN_IDX for token in tokens]
return indices[0] if to... | Converts tokens to indices according to the vocabulary.
Parameters
----------
tokens : str or list of strs
A source token or tokens to be converted.
Returns
-------
int or list of ints
A token index or a list of token indices according to the v... |
def is_autosomal(chrom):
try:
int(chrom)
return True
except ValueError:
try:
int(str(chrom.lower().replace("chr", "").replace("_", "").replace("-", "")))
return True
except ValueError:
return False | Keep chromosomes that are a digit 1-22, or chr prefixed digit chr1-chr22 |
def next(self):
if self.r == self.repeats:
self.i = (self.i + 1) % self.lenght
self.r = 0
self.r += 1
if self.stopping and self.i == 0 and self.r == 1:
self.stopped = True
if self.i == 0 and self.stopped:
raise StopIteration
else:
... | Returns the next element or raises ``StopIteration`` if stopped. |
def _get_hit(self, key):
try:
result = self.cache[key]
self.hits += 1
self._ref_key(key)
return result
except KeyError:
pass
result = self.weakrefs[key]
self.refhits += 1
self.cache[key] = result
self._ref_key(ke... | Try to do a value lookup from the existing cache entries. |
def encode_collection(collection):
tree = etree.Element('collection')
etree.SubElement(tree, 'source').text = collection.source
etree.SubElement(tree, 'date').text = collection.date
etree.SubElement(tree, 'key').text = collection.key
encode_infons(tree, collection.infons)
for doc in collec... | Encode a single collection. |
def retrieve_api_token(self):
payload = self.oauth2_manager.get_access_token_params(
refresh_token=self.refresh_token
)
response = requests.post(
self.oauth2_manager.access_token_url, json=payload
)
response.raise_for_status()
response_json = json.... | Retrieve the access token from AVS.
This function is memoized, so the
value returned by the function will be remembered and returned by
subsequent calls until the memo expires. This is because the access
token lasts for one hour, then a new token needs to be requested.
Decorato... |
def http_basic_auth_login_required(func=None):
wrapper = auth.set_authentication_predicate(http_basic_auth_check_user, [auth.user_is_authenticated])
if func is None:
return wrapper
return wrapper(func) | Decorator. Use it to specify a RPC method is available only to logged users |
def nextComment(self, text, start=0):
m = min([self.lineComment(text, start),
self.blockComment(text, start),
self._emptylineregex.search(text, start)],
key=lambda m: m.start(0) if m else len(text))
return m | Return the next comment found in text starting at start. |
def _snap_exec(commands):
assert type(commands) == list
retry_count = 0
return_code = None
while return_code is None or return_code == SNAP_NO_LOCK:
try:
return_code = subprocess.check_call(['snap'] + commands,
env=os.environ)
e... | Execute snap commands.
:param commands: List commands
:return: Integer exit code |
def guest_get_info(self, userid):
action = "get info of guest '%s'" % userid
with zvmutils.log_and_reraise_sdkbase_error(action):
return self._vmops.get_info(userid) | Get the status of a virtual machine.
:param str userid: the id of the virtual machine
:returns: Dictionary contains:
power_state: (str) the running state, one of on | off
max_mem_kb: (int) the maximum memory in KBytes allowed
mem_kb: (int) the memo... |
def tdSensor(self):
protocol = create_string_buffer(20)
model = create_string_buffer(20)
sid = c_int()
datatypes = c_int()
self._lib.tdSensor(protocol, sizeof(protocol), model, sizeof(model),
byref(sid), byref(datatypes))
return {'protocol': sel... | Get the next sensor while iterating.
:return: a dict with the keys: protocol, model, id, datatypes. |
def _get_separated_values(self, secondary=False):
series = self.secondary_series if secondary else self.series
transposed = list(zip(*[serie.values for serie in series]))
positive_vals = [
sum([val for val in vals if val is not None and val >= self.zero])
for vals in tran... | Separate values between positives and negatives stacked |
def supervised_to_dict(dataset, text2self):
def my_fn(inputs, targets):
if text2self:
return {"targets": targets}
else:
return {"inputs": inputs, "targets": targets}
return dataset.map(my_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE) | Turns a supervised dataset into a dataset with a feature dictionary.
if text2self, then the features dictionary contains a "targets" key.
else, the features dictionary contains "inputs" and "targets" keys.
Args:
dataset: a tf.data.Dataset
text2self: a boolean
Returns:
a tf.data.Dataset |
def decimal_precision(row):
try:
row = list(row)
for idx, x in enumerate(row):
x = str(x)
m = re.match(re_sci_notation, x)
if m:
_x2 = round(float(m.group(2)), 3)
x = m.group(1) + str(_x2)[1:] + m.group(3)
else:
... | Change the "precision" of values before writing to CSV. Each value is rounded to 3 numbers.
ex: 300 -> 300
ex: 300.123456 -> 300.123
ex: 3.123456e-25 - > 3.123e-25
:param tuple row: Row of numbers to process
:return list row: Processed row |
def requirements(self, requires):
if requires:
if isinstance(requires, basestring) and \
os.path.isfile(os.path.abspath(requires)):
self._requirements_file = os.path.abspath(requires)
else:
if isinstance(self._requirements, basestring):
... | Sets the requirements for the package.
It will take either a valid path to a requirements file or
a list of requirements. |
def add_subgraph(self, sgraph):
if not isinstance(sgraph, Subgraph) and not isinstance(sgraph, Cluster):
raise TypeError('add_subgraph() received a non subgraph class object:' + str(sgraph))
if self.obj_dict['subgraphs'].has_key(sgraph.get_name()):
sgraph_list = self.obj_dict['su... | Adds an subgraph object to the graph.
It takes a subgraph object as its only argument and returns
None. |
def has_trivial_constructor(class_):
class_ = class_traits.get_declaration(class_)
trivial = find_trivial_constructor(class_)
if trivial and trivial.access_type == 'public':
return trivial | if class has public trivial constructor, this function will return
reference to it, None otherwise |
def _reset_internal(self):
super()._reset_internal()
self.sim.data.qpos[self._ref_joint_pos_indexes] = self.mujoco_robot.init_qpos
if self.has_gripper_right:
self.sim.data.qpos[
self._ref_joint_gripper_right_actuator_indexes
] = self.gripper_right.init_qpo... | Resets the pose of the arm and grippers. |
def _make_indices(self, Ns):
N_new = int(Ns * self.n_splits)
test = [np.full(N_new, False) for i in range(self.n_splits)]
for i in range(self.n_splits):
test[i][np.arange(Ns * i, Ns * (i + 1))] = True
train = [np.logical_not(test[i]) for i in range(self.n_splits)]
tes... | makes indices for cross validation |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.