Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
12,800 | def _get_referenced_services(specs):
active_services = set()
for app_spec in specs[].values():
for service in app_spec[][]:
active_services.add(service)
for bundle_spec in specs[].values():
for service in bundle_spec[]:
active_services.add(service)
return act... | Returns all services that are referenced in specs.apps.depends.services,
or in specs.bundles.services |
12,801 | def wrap(self, cause):
if isinstance(cause, ApplicationException):
return cause
self.with_cause(cause)
return self | Wraps another exception into an application exception object.
If original exception is of ApplicationException type it is returned without changes.
Otherwise a new ApplicationException is created and original error is set as its cause.
:param cause: an original error object
:return: a... |
12,802 | def _sample_oat(problem, N, num_levels=4):
group_membership = np.asmatrix(np.identity(problem[],
dtype=int))
num_params = group_membership.shape[0]
sample = np.zeros((N * (num_params + 1), num_params))
sample = np.array([generate_trajectory(group_memb... | Generate trajectories without groups
Arguments
---------
problem : dict
The problem definition
N : int
The number of samples to generate
num_levels : int, default=4
The number of grid levels |
12,803 | def get_dict(self, only_attributes=None, exclude_attributes=None, df_format=False):
to_exclude = [, , , , ]
if not exclude_attributes:
excluder = to_exclude
else:
excluder = ssbio.utils.force_list(exclude_attributes)
excluder.extend(to_exclude)
... | Summarize the I-TASSER run in a dictionary containing modeling results and top predictions from COACH
Args:
only_attributes (str, list): Attributes that should be returned. If not provided, all are returned.
exclude_attributes (str, list): Attributes that should be excluded.
... |
12,804 | def provide_session(func):
@wraps(func)
def wrapper(*args, **kwargs):
arg_session =
func_params = func.__code__.co_varnames
session_in_args = arg_session in func_params and \
func_params.index(arg_session) < len(args)
session_in_kwargs = arg_session in kwargs
... | Function decorator that provides a session if it isn't provided.
If you want to reuse a session or run the function as part of a
database transaction, you pass it to the function, if not this wrapper
will create one and close it for you. |
12,805 | def write_monitor_keyring(keyring, monitor_keyring, uid=-1, gid=-1):
write_file(keyring, monitor_keyring, 0o600, None, uid, gid) | create the monitor keyring file |
12,806 | def open(self):
return self.workspace._rest.open_intermediate_dataset_contents(
self.workspace.workspace_id,
self.experiment.experiment_id,
self.node_id,
self.port_name
) | Open and return a stream for the dataset contents. |
12,807 | def state_fidelity(state0: State, state1: State) -> bk.BKTensor:
assert state0.qubits == state1.qubits
tensor = bk.absolute(bk.inner(state0.tensor, state1.tensor))**bk.fcast(2)
return tensor | Return the quantum fidelity between pure states. |
12,808 | def render(self):
"Re-render Jupyter cell for batch of images."
clear_output()
self.write_csv()
if self.empty() and self._skipped>0:
return display(f
f)
elif self.empty():
return display()
if self.batch_contains_deleted():
... | Re-render Jupyter cell for batch of images. |
12,809 | def var_explained(y_true, y_pred):
var_resid = K.var(y_true - y_pred)
var_y_true = K.var(y_true)
return 1 - var_resid / var_y_true | Fraction of variance explained. |
12,810 | def _allocate_address_nova(self, instance, network_ids):
self._init_os_api()
with OpenStackCloudProvider.__node_start_lock:
free_ips = [ip for ip in self.nova_client.floating_ips.list() if not ip.fixed_ip]
if not free_ips:
log.debug("Trying t... | Allocates a floating/public ip address to the given instance,
using the OpenStack Compute ('Nova') API.
:param instance: instance to assign address to
:param list network_id: List of IDs (as strings) of networks
where to request allocation the floating IP. **Ignored**
(onl... |
12,811 | def RR_calc(classes, TOP):
try:
class_number = len(classes)
result = sum(list(TOP.values()))
return result / class_number
except Exception:
return "None" | Calculate RR (Global performance index).
:param classes: classes
:type classes : list
:param TOP: test outcome positive
:type TOP : dict
:return: RR as float |
12,812 | def latex(self, force=False):
if sys.platform == :
sys.stderr.write()
else:
ret_code = self._sphinx_build()
os.chdir(os.path.join(BUILD_PATH, ))
if force:
for i in range(3):
self._run_os(,
... | Build PDF documentation. |
12,813 | def avl_join(t1, t2, node):
if DEBUG_JOIN:
print( % (node,))
if t1 is None and t2 is None:
if DEBUG_JOIN:
print()
top = node
elif t1 is None:
if DEBUG_JOIN:
print()
top = avl_insert_dir(t2, node, 0)
elif t2 is None:
i... | Joins two trees `t1` and `t1` with an intermediate key-value pair
CommandLine:
python -m utool.experimental.euler_tour_tree_avl avl_join
Example:
>>> # DISABLE_DOCTEST
>>> from utool.experimental.euler_tour_tree_avl import * # NOQA
>>> self = EulerTourTree(['a', 'b', 'c', 'b',... |
12,814 | def filter_query(self, query, field, value):
return query.where(field ** "%{}%".format(value.lower())) | Filter a query. |
12,815 | def get_column_keys_and_names(table):
ins = inspect(table)
return ((k, c.name) for k, c in ins.mapper.c.items()) | Return a generator of tuples k, c such that k is the name of the python attribute for
the column and c is the name of the column in the sql table. |
12,816 | def md5(filename:str)->str:
hash_md5 = hashlib.md5()
with open(filename, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest() | Given a filename produce an md5 hash of the contents.
>>> import tempfile, os
>>> f = tempfile.NamedTemporaryFile(delete=False)
>>> f.write(b'Hello Wirld!')
12
>>> f.close()
>>> md5(f.name)
'997c62b6afe9712cad3baffb49cb8c8a'
>>> os.unlink(f.name) |
12,817 | def load_lang_conf():
if osp.isfile(LANG_FILE):
with open(LANG_FILE, ) as f:
lang = f.read()
else:
lang = get_interface_language()
save_lang_conf(lang)
lang = DEFAULT_LANGUAGE
save_lang_conf(lang)
return lang | Load language setting from language config file if it exists, otherwise
try to use the local settings if Spyder provides a translation, or
return the default if no translation provided. |
12,818 | def hmget(self, key, *fields):
def format_response(val_array):
return dict(zip(fields, val_array))
command = [b, key]
command.extend(fields)
return self._execute(command, format_callback=format_response) | Returns the values associated with the specified `fields` in a hash.
For every ``field`` that does not exist in the hash, :data:`None`
is returned. Because a non-existing keys are treated as empty
hashes, calling :meth:`hmget` against a non-existing key will
return a list of :data:`Non... |
12,819 | def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
devices = match.get(, {})
for device_identifier, device_information in iter(devices.items()):
datetime_value = device_information.get(, None)
if not datetime_value:
continue
event_data = IPodPlistEventData()
... | Extract device information from the iPod plist.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS. |
12,820 | def add_fields(self, log_record, record, message_dict):
for field in self._required_fields:
log_record[field] = record.__dict__.get(field)
log_record.update(message_dict)
merge_record_extra(record, log_record, reserved=self._skip_fields)
if self.timestamp:
... | Override this method to implement custom logic for adding fields. |
12,821 | def rgb(self, **kwargs):
if "bands" in kwargs:
use_bands = kwargs["bands"]
assert len(use_bands) == 3,
del kwargs["bands"]
else:
use_bands = self._rgb_bands
if kwargs.get() == True:
return self.histogram_match(use_bands, **kw... | Convert the image to a 3 band RGB for plotting
This method shares the same arguments as plot(). It will perform visual adjustment on the
image and prepare the data for plotting in MatplotLib. Values are converted to an
appropriate precision and the axis order is changed to put the band ... |
12,822 | def ttl(self, key):
value = self.pttl(key)
if value is None or value < 0:
return value
return value // 1000 | Emulate ttl
Even though the official redis commands documentation at http://redis.io/commands/ttl
states "Return value: Integer reply: TTL in seconds, -2 when key does not exist or -1
when key does not have a timeout." the redis-py lib returns None for both these cases.
The lib behavior... |
12,823 | def api_key(value=None):
if value is None:
return PyGraphistry._config[]
if value is not PyGraphistry._config[]:
PyGraphistry._config[] = value.strip()
PyGraphistry._is_authenticated = False | Set or get the API key.
Also set via environment variable GRAPHISTRY_API_KEY. |
12,824 | def add_uppercase(table):
orig = table.copy()
orig.update(
dict((k.capitalize(), v.capitalize()) for k, v in table.items()))
return orig | Extend the table with uppercase options
>>> print("а" in add_uppercase({"а": "a"}))
True
>>> print(add_uppercase({"а": "a"})["а"] == "a")
True
>>> print("А" in add_uppercase({"а": "a"}))
True
>>> print(add_uppercase({"а": "a"})["А"] == "A")
True
>>> print(len(add_uppercase({"а": "a"... |
12,825 | def _get_controllers(self):
controllers = dict()
for pkg in pkg_resources.iter_entry_points(group=self.CONTROLLERS):
LOGGER.debug(, pkg.name)
controllers[pkg.name] = importlib.import_module(pkg.module_name)
return controllers | Iterate through the installed controller entry points and import
the module and assign the handle to the CLI._controllers dict.
:return: dict |
12,826 | def object2code(key, code):
if key in ["xscale", "yscale"]:
if code == "log":
code = True
else:
code = False
else:
code = unicode(code)
return code | Returns code for widget from dict object |
12,827 | def _init_go_sets(self, go_fins):
go_sets = []
assert go_fins, "EXPECTED FILES CONTAINING GO IDs"
assert len(go_fins) >= 2, "EXPECTED 2+ GO LISTS. FOUND: {L}".format(
L=.join(go_fins))
obj = GetGOs(self.godag)
for fin in go_fins:
assert os.path.ex... | Get lists of GO IDs. |
12,828 | def atom_fractions(atoms):
rHCOHCO
count = sum(atoms.values())
afracs = {}
for i in atoms:
afracs[i] = atoms[i]/count
return afracs | r'''Calculates the atomic fractions of each element in a compound,
given a dictionary of its atoms and their counts, in the format
{symbol: count}.
.. math::
a_i = \frac{n_i}{\sum_i n_i}
Parameters
----------
atoms : dict
dictionary of counts of individual atoms, indexed by sy... |
12,829 | def V_vertical_conical_concave(D, a, h):
r
if h < abs(a):
Vf = pi*D**2/12.*(3*h + a - (a+h)**3/a**2)
else:
Vf = pi*D**2/12.*(3*h + a)
return Vf | r'''Calculates volume of a vertical tank with a concave conical bottom,
according to [1]_. No provision for the top of the tank is made here.
.. math::
V = \frac{\pi D^2}{12} \left(3h + a - \frac{(a+h)^3}{a^2}\right)
,\;\; 0 \le h < |a|
.. math::
V = \frac{\pi D^2}{12} (3h + a ),\;... |
12,830 | def get_lang_array(self):
r = self.yandex_translate_request("getLangs", "")
self.handle_errors(r)
return r.json()["dirs"] | gets supported langs as an array |
12,831 | def format_timedelta(td_object):
def get_total_seconds(td):
return (td.microseconds +
(td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
seconds = int(get_total_seconds(td_object))
periods = [(, 60*60*24*365),
(, 60*60*24*30),
(, 60*... | Format a timedelta object for display to users
Returns
-------
str |
12,832 | def get_context_json(self, context):
answer = {}
answer[] = self.__jcontext_metadata(context)
answer[] = self.__jcontext_filter(context)
answer[] = {}
answer[][] = self.__jcontext_tablehead(context)
answer[][] = None
... | Return a base answer for a json answer |
12,833 | def action_logging(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
with create_session() as session:
if g.user.is_anonymous:
user =
else:
user = g.user.username
log = Log(
event=f.__name__,
... | Decorator to log user actions |
12,834 | def _edge_mapping(G):
edge_mapping = {edge: idx for idx, edge in enumerate(G.edges)}
edge_mapping.update({(e1, e0): idx for (e0, e1), idx in edge_mapping.items()})
return edge_mapping | Assigns a variable for each edge in G.
(u, v) and (v, u) map to the same variable. |
12,835 | def ParseRow(header,
row):
precondition.AssertDictType(row, Text, Text)
result = rdf_osquery.OsqueryRow()
for column in header.columns:
result.values.append(row[column.name])
return result | Parses a single row of osquery output.
Args:
header: A parsed header describing the row format.
row: A row in a "parsed JSON" representation.
Returns:
A parsed `rdf_osquery.OsqueryRow` instance. |
12,836 | def repo_data(PACKAGES_TXT, repo, flag):
(name, location, size, unsize,
rname, rlocation, rsize, runsize) = ([] for i in range(8))
for line in PACKAGES_TXT.splitlines():
if _meta_.rsl_deps in ["on", "ON"] and "--resolve-off" not in flag:
status(0.000005)
if line.startswith(... | Grap data packages |
12,837 | def lal(self):
lal_data = None
if self._data.dtype == float32:
lal_data = _lal.CreateREAL4Vector(len(self))
elif self._data.dtype == float64:
lal_data = _lal.CreateREAL8Vector(len(self))
elif self._data.dtype == complex64:
lal_data = _lal.Cre... | Returns a LAL Object that contains this data |
12,838 | def correct_rates(rates, opt_qes, combs):
corrected_rates = np.array([
rate / opt_qes[comb[0]] / opt_qes[comb[1]]
for rate, comb in zip(rates, combs)
])
return corrected_rates | Applies optimal qes to rates.
Should be closer to fitted_rates afterwards.
Parameters
----------
rates: numpy array of rates of all PMT combinations
opt_qes: numpy array of optimal qe values for all PMTs
combs: pmt combinations used to correct
Returns
-------
corrected_rates: nump... |
12,839 | def create(args):
with _catalog(args) as cat:
for fname, created, obj in cat.create(args.args[0], {}):
args.log.info(.format(
fname, if created else , obj)) | cdstarcat create PATH
Create objects in CDSTAR specified by PATH.
When PATH is a file, a single object (possibly with multiple bitstreams) is created;
When PATH is a directory, an object will be created for each file in the directory
(recursing into subdirectories). |
12,840 | def extract_package_name(line):
assert not in line
assert not in line
assert not in line
assert not in line
if line.lstrip().startswith((, )):
word = line.split()[1]
else:
return None
package = word.split()[0]
assert not in package
return package | Return package name in import statement. |
12,841 | def getSimilarTermsForTerm(self, term, contextId=None, posType=None, getFingerprint=None, startIndex=0, maxResults=10):
return self._terms.getSimilarTerms(self._retina, term, contextId, posType, getFingerprint, startIndex, maxResults) | Get the similar terms of a given term
Args:
term, str: A term in the retina (required)
contextId, int: The identifier of a context (optional)
posType, str: Part of speech (optional)
getFingerprint, bool: Configure if the fingerprint should be returned as part of t... |
12,842 | def decrypt_from(self, f, mac_bytes=10):
ctx = DecryptionContext(self.curve, f, self, mac_bytes)
yield ctx
ctx.read() | Decrypts a message from f. |
12,843 | def create_aside(self, block_type, keys):
aside_cls = XBlockAside.load_class(block_type)
return aside_cls(runtime=self, scope_ids=keys) | The aside version of construct_xblock: take a type and key. Return an instance |
12,844 | def _make_string_formatter(f, offset=None):
format = f
delta = offset
return lambda v: time.strftime(format, (_date(v, delta)).timetuple()) | A closure-izer for string arguments that include a format and possibly an offset. |
12,845 | def com_google_fonts_check_ttx_roundtrip(font):
from fontTools import ttx
import sys
ttFont = ttx.TTFont(font)
failed = False
class TTXLogger:
msgs = []
def __init__(self):
self.original_stderr = sys.stderr
self.original_stdout = sys.stdout
sys.stderr = self
sys.stdout = s... | Checking with fontTools.ttx |
12,846 | def flattenTrees(root, nodeSelector: Callable[[LNode], bool]):
for ch in root.children:
if ch.children:
flattenTrees(ch, nodeSelector)
reducibleChildren = set()
for ch in root.children:
if nodeSelector(ch):
reducibleChildren.add(ch)
while reducibleChil... | Walk all nodes and discover trees of nodes (usually operators)
and reduce them to single node with multiple outputs
:attention: selected nodes has to have single output
and has to be connected to nets with single driver |
12,847 | def woodbury_inv(self):
if self._woodbury_inv is None:
if self._woodbury_chol is not None:
self._woodbury_inv, _ = dpotri(self._woodbury_chol, lower=1)
symmetrify(self._woodbury_inv)
elif self._covariance is not None:
... | The inverse of the woodbury matrix, in the gaussian likelihood case it is defined as
$$
(K_{xx} + \Sigma_{xx})^{-1}
\Sigma_{xx} := \texttt{Likelihood.variance / Approximate likelihood covariance}
$$ |
12,848 | def shape(self):
bf = self.copy()
content = requests.get(bf.dataset_url).json()
rowCount = content[][]
valueCount = content[][]
return (rowCount, valueCount) | Returns (rowCount, valueCount) |
12,849 | def start_stack(awsclient, stack_name, use_suspend=False):
exit_code = 0
if not stack_exists(awsclient, stack_name):
log.warn(%s\, stack_name)
else:
client_cfn = awsclient.get_client()
client_autoscaling = awsclient.get_client()
client_rds = aws... | Start an existing stack on AWS cloud.
:param awsclient:
:param stack_name:
:param use_suspend: use suspend and resume on the autoscaling group
:return: exit_code |
12,850 | def _derive_charge(self, config):
if self._roast.get():
return None
self._window.append(config)
time, temp = list(), list()
for x in list(self._window):
time.append(x[])
temp.append(x[])
slope, intercept, r_value, p_value, std_err = li... | Use a temperature window to identify the roast charge.
The charge will manifest as a sudden downward trend on the temperature.
Once found, we save it and avoid overwriting. The charge is needed in
order to derive the turning point.
:param config: Current snapshot of the configuration
... |
12,851 | def get_configured_provider():
return config.is_provider_configured(
opts=__opts__,
provider=__active_provider_name__ or __virtualname__,
aliases=__virtual_aliases__,
required_keys=(,)
) | Return the first configured instance. |
12,852 | def addresses(self):
import ns1.rest.ipam
return ns1.rest.ipam.Addresses(self.config) | Return a new raw REST interface to address resources
:rtype: :py:class:`ns1.rest.ipam.Adresses` |
12,853 | def read_status(self, num_bytes=2):
SPIFLASH_RDSR = 0x05
SPIFLASH_RDSR2 = 0x35
SPIFLASH_RDSR3 = 0x15
status = 0
shift = 0
for cmd in [SPIFLASH_RDSR, SPIFLASH_RDSR2, SPIFLASH_RDSR3][0:num_bytes]:
status += self.run_spiflash_command(cmd, read_bits=8) ... | Read up to 24 bits (num_bytes) of SPI flash status register contents
via RDSR, RDSR2, RDSR3 commands
Not all SPI flash supports all three commands. The upper 1 or 2
bytes may be 0xFF. |
12,854 | def match_url(self, request):
parsed_url = urlparse(request.path_url)
path_url = parsed_url.path
query_params = parsed_url.query
match = None
for path in self.paths:
for item in self.index:
target_path = os.path.join(BASE_PATH, path, path_url... | Match the request against a file in the adapter directory
:param request: The request
:type request: :class:`requests.Request`
:return: Path to the file
:rtype: ``str`` |
12,855 | def precondition_u_kn(u_kn, N_k, f_k):
u_kn, N_k, f_k = validate_inputs(u_kn, N_k, f_k)
u_kn = u_kn - u_kn.min(0)
u_kn += (logsumexp(f_k - u_kn.T, b=N_k, axis=1)) - N_k.dot(f_k) / float(N_k.sum())
return u_kn | Subtract a sample-dependent constant from u_kn to improve precision
Parameters
----------
u_kn : np.ndarray, shape=(n_states, n_samples), dtype='float'
The reduced potential energies, i.e. -log unnormalized probabilities
N_k : np.ndarray, shape=(n_states), dtype='int'
The number of samp... |
12,856 | def mouseDoubleClickEvent(self, event):
index_clicked = self.indexAt(event.pos())
if self.model.breakpoints:
filename = self.model.breakpoints[index_clicked.row()][0]
line_number_str = self.model.breakpoints[index_clicked.row()][1]
self.edit_goto.emit(f... | Reimplement Qt method |
12,857 | def _transform_legacy_stats(self, stats):
if stats and not in stats:
pool = stats.copy()
pool[] = self.id
for key in (, ,
, ,
, ):
pool.pop(key, None)
stats[] = [pool]
retur... | Convert legacy stats to new stats with pools key. |
12,858 | def visible_fields(self):
form_visible_fields = self.form.visible_fields()
if self.render_fields:
fields = self.render_fields
else:
fields = [field.name for field in form_visible_fields]
filtered_fields = [field for field in fields if field not in self... | Returns the reduced set of visible fields to output from the form.
This method respects the provided ``fields`` configuration _and_ exlcudes
all fields from the ``exclude`` configuration.
If no ``fields`` where provided when configuring this fieldset, all visible
fields minus the exclu... |
12,859 | def predict_compound_pairs_iterated(
reactions, formulas, prior=(1, 43), max_iterations=None,
element_weight=element_weight):
prior_alpha, prior_beta = prior
reactions = dict(reactions)
pair_reactions = {}
possible_pairs = Counter()
for reaction_id, equation in iteritems(reacti... | Predict reaction pairs using iterated method.
Returns a tuple containing a dictionary of predictions keyed by the
reaction IDs, and the final number of iterations. Each reaction prediction
entry contains a tuple with a dictionary of transfers and a dictionary of
unbalanced compounds. The dictionary of ... |
12,860 | def unpack(self, buff, offset=0):
unpack_length = UBInt16()
unpack_length.unpack(buff, offset)
super().unpack(buff[:offset+unpack_length], offset) | Unpack a binary message into this object's attributes.
Pass the correct length for list unpacking.
Args:
buff (bytes): Binary data package to be unpacked.
offset (int): Where to begin unpacking. |
12,861 | def load(self):
try:
self._read()
self._parse()
except Exception as exc:
self.failed = True
params = {: self._path, : exc}
if self.fail_silently:
LOG.warning("Error processing message json file : "
... | Read and parse the message file. |
12,862 | def start_login_server(self, ):
self.login_server = oauth.LoginServer(session=self)
target = self.login_server.serve_forever
self.login_thread = threading.Thread(target=target)
self.login_thread.setDaemon(True)
log.debug()
self.login_thread.start() | Start a server that will get a request from a user logging in.
This uses the Implicit Grant Flow of OAuth2. The user is asked
to login to twitch and grant PyTwitcher authorization.
Once the user agrees, he is redirected to an url.
This server will respond to that url and get the oauth t... |
12,863 | def find_element_by_name(self, name, update=False) -> Elements:
t found.
Usage:
element = driver.find_element_by_name()
'
return self.find_element(by=By.NAME, value=name, update=update) | Finds an element by name.
Args:
name: The name of the element to be found.
update: If the interface has changed, this option should be True.
Returns:
The element if it was found.
Raises:
NoSuchElementException - If the element wasn't found.
... |
12,864 | def project_parensemble(self,par_file=None,nsing=None,
inplace=True,enforce_bounds=):
assert self.jco is not None,"MonteCarlo.project_parensemble()" +\
"requires a jacobian attribute"
if par_file is not None:
assert os.... | perform the null-space projection operations for null-space monte carlo
Parameters
----------
par_file: str
an optional file of parameter values to use
nsing: int
number of singular values to in forming null subspace matrix
inplace: bool
overw... |
12,865 | def mrc_header_from_params(shape, dtype, kind, **kwargs):
shape = [int(n) for n in shape]
kind, kind_in = str(kind).lower(), kind
if kind not in (, ):
raise ValueError("`kind not understood".format(kind_in))
extent = kwargs.pop(, shape)
axis_order = kwargs.pop(, (0, 1, 2))
... | Create a minimal MRC2014 header from the given parameters.
Parameters
----------
shape : 3-sequence of ints
3D shape of the stored data. The values are used as
``'nx', 'ny', 'nz'`` header entries, in this order. Note that
this is different from the actual data storage shape for
... |
12,866 | def text_iter(self, context):
for _event, elem in context:
if not self.debug:
yield ExportXMLDocumentGraph(elem, name=elem.attrib[add_ns()])
else:
yield elem
elem.clear()
while elem.getprevious() is not None:
... | Iterates over all the elements in an iterparse context
(here: <text> elements) and yields an ExportXMLDocumentGraph instance
for each of them. For efficiency, the elements are removed from the
DOM / main memory after processing them.
If ``self.debug`` is set to ``True`` (in the ``__init... |
12,867 | def next_non_holiday_weekday(holidays, dt):
day_of_week = dt.weekday()
if day_of_week == SUNDAY:
while is_holiday_or_weekend(holidays, dt):
dt += timedelta(1)
return dt | If a holiday falls on a Sunday, observe it on the next non-holiday weekday.
Parameters
----------
holidays : list[pd.tseries.holiday.Holiday]
list of holidays
dt : pd.Timestamp
date of holiday. |
12,868 | def _set_ospf_level12(self, v, load=False):
if hasattr(v, "_utype"):
v = v._utype(v)
try:
t = YANGDynClass(v,base=YANGBool, is_leaf=True, yang_name="ospf-level12", rest_name="level-1-2", parent=self, choice=(u, u), path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True,... | Setter method for ospf_level12, mapped from YANG variable /routing_system/router/isis/router_isis_cmds_holder/address_family/ipv6/af_ipv6_unicast/af_ipv6_attributes/af_common_attributes/redistribute/ospf/ospf_level12 (empty)
If this variable is read-only (config: false) in the
source YANG file, then _set_ospf_l... |
12,869 | def grep(source, regex, stop_on_first=False):
loader = ClassLoader(source, max_cache=-1)
r = re.compile(regex)
def _matches(constant):
return r.match(constant.value)
for klass in loader.classes:
it = loader.search_constant_pool(path=klass, type_=UTF8, f=_matches)
if next(i... | Grep the constant pool of all classes in source. |
12,870 | def create_pointing(self,event):
import math
(ra,dec)=self.c2p((self.canvasx(event.x),
self.canvasy(event.y)))
this_camera=camera(camera=self.camera.get())
ccds=this_camera.getGeometry(ra,dec)
items=[]
for ccd in ccds:
(x1,... | Plot the sky coverage of pointing at event.x,event.y on the canavas |
12,871 | def _can_process_pre_prepare(self, pre_prepare: PrePrepare, sender: str) -> Optional[int]:
if not self.isMsgFromPrimary(pre_prepare, sender):
return PP_CHECK_NOT_FROM_PRIMARY
if (pre_prepare.viewNo, pre_prepare.ppSeqNo) in self.prePrepares:
r... | Decide whether this replica is eligible to process a PRE-PREPARE.
:param pre_prepare: a PRE-PREPARE msg to process
:param sender: the name of the node that sent the PRE-PREPARE msg |
12,872 | def cal_pth(self, v, temp):
params_t = self._set_params(self.params_therm)
return constq_pth(v, temp, *params_t, self.n, self.z,
t_ref=self.t_ref, three_r=self.three_r) | calculate thermal pressure
:param v: unit-cell volume in A^3
:param temp: temperature in K
:return: thermal pressure in GPa |
12,873 | def _is_valid_token(self, auth_token):
s eauth system.
:return bool: True if valid, False if not valid.
s None, or something other
try:
int(auth_token, 16)
except (TypeError, ValueError):
return False
if salt_token and ... | Check if this is a valid salt-api token or valid Salt token
salt-api tokens are regular session tokens that tie back to a real Salt
token. Salt tokens are tokens generated by Salt's eauth system.
:return bool: True if valid, False if not valid. |
12,874 | def save_state(internal_request, state):
state_data = {"hash_type": internal_request.user_id_hash_type}
state[UserIdHasher.STATE_KEY] = state_data | Saves all necessary information needed by the UserIdHasher
:type internal_request: satosa.internal_data.InternalRequest
:param internal_request: The request
:param state: The current state |
12,875 | def read_leader_status(self):
api_path =
response = self._adapter.get(
url=api_path,
)
return response.json() | Read the high availability status and current leader instance of Vault.
Supported methods:
GET: /sys/leader. Produces: 200 application/json
:return: The JSON response of the request.
:rtype: dict |
12,876 | def OnCopyResult(self, event):
selection = self.main_window.grid.selection
data = self.main_window.actions.copy_result(selection)
if type(data) is wx._gdi.Bitmap:
self.main_window.clipboard.set_clipboard(data, datatype="bitmap")
else:
... | Clipboard copy results event handler |
12,877 | def get_filters(self):
return dict(
moment_format=self.format,
moment_calendar=self.calendar,
moment_fromnow=self.from_now,
) | Returns a collection of momentjs filters |
12,878 | def set_printoptions(**kwargs):
warnings.warn(,
DeprecationWarning)
for key, value in kwargs.items():
if key not in [, , ]:
raise KeyError(.format(key))
set_option( + key, value) | Set printing options.
These options determine the way JPEG 2000 boxes are displayed.
Parameters
----------
short : bool, optional
When True, only the box ID, offset, and length are displayed. Useful
for displaying only the basic structure or skeleton of a JPEG 2000
file.
x... |
12,879 | def checkout(self, ref, branch=None):
return git_checkout(self.repo_dir, ref, branch=branch) | Do a git checkout of `ref`. |
12,880 | def set(self, section, key, value, comment=None):
self._read_sources()
if (section, key) in self._dot_keys:
section, key = self._dot_keys[(section, key)]
elif section in self._dot_keys:
section = self._dot_keys[section]
if not isinstance(value, str):
... | Set config value with data type transformation (to str)
:param str section: Section to set config for
:param str key: Key to set config for
:param value: Value for key. It can be any primitive type.
:param str comment: Comment for the key |
12,881 | def trial(log_dir=None,
upload_dir=None,
sync_period=None,
trial_prefix="",
param_map=None,
init_logging=True):
global _trial
if _trial:
raise ValueError("A trial already exists in the current context")
local_trial =... | Generates a trial within a with context. |
12,882 | def _init_socket(self):
try:
self._connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._connection.connect((self.host, self.port))
self._connection.settimeout(self.timeout)
self._connection_file = self._connection.makefile()
except... | Initialises the socket used for communicating with a q service, |
12,883 | def create(cls, bucket, key, value):
with db.session.begin_nested():
obj = cls(
bucket_id=as_bucket_id(bucket),
key=key,
value=value
)
db.session.add(obj)
return obj | Create a new tag for bucket. |
12,884 | def cnst_AT(self, Y):
r
return self.cnst_A0T(self.block_sep0(Y)) + \
np.sum(self.cnst_A1T(self.block_sep1(Y)), axis=-1) | r"""Compute :math:`A^T \mathbf{y}`. In this case
:math:`A^T \mathbf{y} = (I \;\; \Gamma_0^T \;\; \Gamma_1^T \;\;
\ldots) \mathbf{y}`. |
12,885 | def me(self):
json_data = self._session.get(API_ENDPOINT + )
return self._object_factory(OBJECT_TYPE, json_data) | Get the details of the person accessing the API.
Raises:
ApiError: If the Webex Teams cloud returns an error. |
12,886 | def read(self, entity=None, attrs=None, ignore=None, params=None):
if entity is None:
entity = type(self)(
self._server_config,
product=self.product,
)
if ignore is None:
ignore = set()
retu... | Provide a default value for ``entity``.
By default, ``nailgun.entity_mixins.EntityReadMixin.read`` provides a
default value for ``entity`` like so::
entity = type(self)()
However, :class:`RepositorySet` requires that a ``product`` be
provided, so this technique will not wo... |
12,887 | def caption_mentions(self) -> List[str]:
if not self.caption:
return []
mention_regex = re.compile(r"(?:@)(\w(?:(?:\w|(?:\.(?!\.))){0,28}(?:\w))?)")
return re.findall(mention_regex, self.caption.lower()) | List of all lowercased profiles that are mentioned in the Post's caption, without preceeding @. |
12,888 | def height_to_pressure_std(height):
r
t0 = 288. * units.kelvin
gamma = 6.5 * units()
p0 = 1013.25 * units.mbar
return p0 * (1 - (gamma / t0) * height) ** (mpconsts.g / (mpconsts.Rd * gamma)) | r"""Convert height data to pressures using the U.S. standard atmosphere.
The implementation inverts the formula outlined in [Hobbs1977]_ pg.60-61.
Parameters
----------
height : `pint.Quantity`
Atmospheric height
Returns
-------
`pint.Quantity`
The corresponding pressure v... |
12,889 | def operation(self, url, idp_entity_id, op, **opargs):
sp_url = self._sp
try:
respdict = self.parse_soap_message(response.text)
self.ecp_conversation(respdict, idp_entity_id)
... | This is the method that should be used by someone that wants
to authenticate using SAML ECP
:param url: The page that access is sought for
:param idp_entity_id: The entity ID of the IdP that should be
used for authentication
:param op: Which HTTP operation (GET/POST/PUT/DELE... |
12,890 | def main(self, config_filename):
self._read_configuration_file(config_filename)
if self._wrapper_class_name:
self._io.title()
self.__generate_wrapper_class()
else:
self._io.log_verbose()
return 0 | The "main" of the wrapper generator. Returns 0 on success, 1 if one or more errors occurred.
:param str config_filename: The name of the configuration file.
:rtype: int |
12,891 | def set_image(self, image):
if isinstance(image, np.ndarray):
image = util.Image(image)
if isinstance(image, util.NullImage):
self.model_as_data = True
else:
self.model_as_data = False
self.image = image
self._data = self.image.get_p... | Update the current comparison (real) image |
12,892 | def rotatePoints(points, rotationDegrees, pivotx=0, pivoty=0):
rotationRadians = math.radians(rotationDegrees % 360)
for x, y in points:
_checkForIntOrFloat(x)
_checkForIntOrFloat(y)
x -= pivotx
y -= pivoty
x, y = x * math.cos(rotationRadians) - y * math.sin(rotati... | Rotates each x and y tuple in `points`` by `rotationDegrees`. The points
are rotated around the origin by default, but can be rotated around another
pivot point by specifying `pivotx` and `pivoty`.
The points are rotated counterclockwise.
Returns a generator that produces an x and y tuple for each poi... |
12,893 | def ping(self, message=_NOTSET, *, encoding=_NOTSET):
if message is not _NOTSET:
args = (message,)
else:
args = ()
return self.execute(, *args, encoding=encoding) | Ping the server.
Accept optional echo message. |
12,894 | def from_name(api_url, name, dry_run=False):
return DataSet(
.join([api_url, name]).rstrip(),
token=None,
dry_run=dry_run
) | doesn't require a token config param
as all of our data is currently public |
12,895 | def trigger_event(self, source, event, args):
actions = []
for action in event.actions:
if callable(action):
ac = action(self, *args)
if not ac:
continue
if not hasattr(ac, "__iter__"):
actions.append(ac)
else:
actions += action(self, *args)
else:
actions.append(act... | Trigger an event on the Entity
* \a source: The source of the event
* \a event: The event being triggered
* \a args: A list of arguments to pass to the callback |
12,896 | def set_legend(self):
leg = super(Coherence, self).set_legend()
if leg is not None:
leg.set_title()
return leg | Create a legend for this product |
12,897 | def det_residual(model,
guess,
start,
final,
shocks,
diff=True,
jactype=):
n_s = len(model.symbols[])
n_x = len(model.symbols[])
N = guess.shape[0]
p = model.calibration[]
f = mo... | Computes the residuals, the derivatives of the stacked-time system.
:param model: an fga model
:param guess: the guess for the simulated values. An `(n_s.n_x) x N` array,
where n_s is the number of states,
n_x the number of controls, and `N` the length of the simulation.
:param start: ... |
12,898 | def main(argv=None):
try:
_name_of_script, filepath = argv
except ValueError:
raise ValueError(argv)
print(filepath)
make_confidence_report_bundled(filepath=filepath,
test_start=FLAGS.test_start,
test_end=FLAGS.test_end,
... | Make a confidence report and save it to disk. |
12,899 | def compile_protofile(proto_file_path):
out_file = tempfile.mkstemp()[1]
try:
subprocess.check_output([, ,
, out_file,
proto_file_path])
except subprocess.CalledProcessError as e:
sys.exit(.format(e.returncode))
retur... | Compile proto file to descriptor set.
Args:
proto_file_path: Path to proto file to compile.
Returns:
Path to file containing compiled descriptor set.
Raises:
SystemExit if the compilation fails. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.