code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def parseEvent(self, result, i):
fmt = '%Y-%m-%dT%H:%M:%SZ'
due = 0
delay = 0
real_time = 'n'
number = result['stopEvents'][i]['transportation']['number']
planned = datetime.strptime(result['stopEvents'][i]
['departureTimePlanned'], fmt)
destination = ... | Parse the current event and extract data. |
def ensure_connectable(self, nailgun):
attempt_count = 1
while 1:
try:
with closing(nailgun.try_connect()) as sock:
logger.debug('Verified new ng server is connectable at {}'.format(sock.getpeername()))
return
except nailgun.NailgunConnectionError:
if attempt_coun... | Ensures that a nailgun client is connectable or raises NailgunError. |
def _get_userprofile_from_registry(user, sid):
profile_dir = __utils__['reg.read_value'](
'HKEY_LOCAL_MACHINE',
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\{0}'.format(sid),
'ProfileImagePath'
)['vdata']
log.debug(
'user %s with sid=%s profile is located at... | In case net user doesn't return the userprofile we can get it from the
registry
Args:
user (str): The user name, used in debug message
sid (str): The sid to lookup in the registry
Returns:
str: Profile directory |
def number(self, p_todo):
if config().identifiers() == "text":
return self.uid(p_todo)
else:
return self.linenumber(p_todo) | Returns the line number or text ID of a todo (depends on the
configuration. |
def chunkreverse(integers, dtype='L'):
if dtype in ('B', 8):
return map(RBYTES.__getitem__, integers)
fmt = '{0:0%db}' % NBITS[dtype]
return (int(fmt.format(chunk)[::-1], 2) for chunk in integers) | Yield integers of dtype bit-length reverting their bit-order.
>>> list(chunkreverse([0b10000000, 0b11000000, 0b00000001], 'B'))
[1, 3, 128]
>>> list(chunkreverse([0x8000, 0xC000, 0x0001], 'H'))
[1, 3, 32768] |
def keygrip_curve25519(vk):
return _compute_keygrip([
['p', util.num2bytes(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED, size=32)],
['a', b'\x01\xDB\x41'],
['b', b'\x01'],
['g', util.num2bytes(0x0400000000000000000000000000000000000000000000000000000000000000092... | Compute keygrip for Curve25519 public keys. |
def search_uris(
self,
uri,
threat_types,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
if "search_uris" not in self._inner_api_calls:
self._inner_api_calls[
"searc... | This method is used to check whether a URI is on a given threatList.
Example:
>>> from google.cloud import webrisk_v1beta1
>>> from google.cloud.webrisk_v1beta1 import enums
>>>
>>> client = webrisk_v1beta1.WebRiskServiceV1Beta1Client()
>>>
... |
def _get_triplet_value(self, graph, identity, rdf_type):
value = graph.value(subject=identity, predicate=rdf_type)
return value.toPython() if value is not None else value | Get a value from an RDF triple |
def block_pop_back(self, timeout=10):
value = yield self.backend_structure().block_pop_back(timeout)
if value is not None:
yield self.value_pickler.loads(value) | Remove the last element from of the list. If no elements are
available, blocks for at least ``timeout`` seconds. |
def clear_queues(self, manager):
for queue in (self.to_q, self.from_q):
if queue is None:
continue
if not manager:
try:
queue.close()
queue.join_thread()
except AttributeError:
pas... | Release the resources associated to the queues of this instance
:param manager: Manager() object
:type manager: None | object
:return: None |
def functions_factory(cls, coef, domain, kind, **kwargs):
basis_polynomial = cls._basis_polynomial_factory(kind)
return basis_polynomial(coef, domain) | Given some coefficients, return a certain kind of orthogonal polynomial
defined over a specific domain. |
def should_series_dispatch(left, right, op):
if left._is_mixed_type or right._is_mixed_type:
return True
if not len(left.columns) or not len(right.columns):
return False
ldtype = left.dtypes.iloc[0]
rdtype = right.dtypes.iloc[0]
if ((is_timedelta64_dtype(ldtype) and is_integer_dtype(... | Identify cases where a DataFrame operation should dispatch to its
Series counterpart.
Parameters
----------
left : DataFrame
right : DataFrame
op : binary operator
Returns
-------
override : bool |
def get_subtree(self, tree, xpath_str):
return tree.xpath(xpath_str, namespaces=self.namespaces) | Return a subtree given an lxml XPath. |
def fileupdate(self, data):
self.name = data["name"]
add = self.__additional
add["filetype"] = "other"
for filetype in ("book", "image", "video", "audio", "archive"):
if filetype in data:
add["filetype"] = filetype
break
if add["filetyp... | Method to update extra metadata fields with dict obtained
through `fileinfo` |
def reshape_by_blocks(x, x_shape, memory_block_size):
x = tf.reshape(x, [
x_shape[0], x_shape[1], x_shape[2] // memory_block_size,
memory_block_size, x_shape[3]
])
return x | Reshapes input by splitting its length over blocks of memory_block_size.
Args:
x: a Tensor with shape [batch, heads, length, depth]
x_shape: tf.TensorShape of x.
memory_block_size: Integer which divides length.
Returns:
Tensor with shape
[batch, heads, length // memory_block_size, memory_block... |
def set_cpu_property(self, property_p, value):
if not isinstance(property_p, CPUPropertyType):
raise TypeError("property_p can only be an instance of type CPUPropertyType")
if not isinstance(value, bool):
raise TypeError("value can only be an instance of type bool")
self.... | Sets the virtual CPU boolean value of the specified property.
in property_p of type :class:`CPUPropertyType`
Property type to query.
in value of type bool
Property value.
raises :class:`OleErrorInvalidarg`
Invalid property. |
def analysis(self, analysis_id: int) -> models.Analysis:
return self.Analysis.query.get(analysis_id) | Get a single analysis. |
def copy_with_new_atts(self, **attributes):
return FmtStr(*[Chunk(bfs.s, bfs.atts.extend(attributes))
for bfs in self.chunks]) | Returns a new FmtStr with the same content but new formatting |
def _get_hit_nearest_ref_start(self, hits):
nearest_to_start = hits[0]
for hit in hits[1:]:
if hit.ref_coords().start < nearest_to_start.ref_coords().start:
nearest_to_start = hit
return nearest_to_start | Returns the hit nearest to the start of the ref sequence from the input list of hits |
def load(self, model):
self.perceptron.weights, self.tagdict, self.classes, self.clusters = load_model(model)
self.perceptron.classes = self.classes | Load pickled model. |
def preview(self):
msg = self.ui.trackview.model().verify()
if msg:
answer = QtGui.QMessageBox.warning(self, "Bummer", 'Problem: {}.'.format(msg))
return
stim_signal, atten, ovld = self.ui.trackview.model().signal()
fig = SpecWidget()
fig.setWindowModality... | Assemble the current components in the QStimulusModel and generate a spectrogram
plot in a separate window |
def validate_request():
flask_request = request
request_data = flask_request.get_data()
if not request_data:
request_data = b'{}'
request_data = request_data.decode('utf-8')
try:
json.loads(request_data)
except ValueError as json_error:
... | Validates the incoming request
The following are invalid
1. The Request data is not json serializable
2. Query Parameters are sent to the endpoint
3. The Request Content-Type is not application/json
4. 'X-Amz-Log-Type' header is not 'None'
5. 'X-Amz-I... |
def levels(self):
ret = [[] for i in range(self.height)]
for node in self.subtree:
ret[node.level - self.level].append(node)
return ret | Return a list of lists of nodes.
The outer list is indexed by the level.
Each inner list contains the nodes at that level,
in DFS order.
:rtype: list of lists of :class:`~aeneas.tree.Tree` |
def writeBib(self, fname = None, maxStringLength = 1000, wosMode = False, reducedOutput = False, niceIDs = True):
if fname:
f = open(fname, mode = 'w', encoding = 'utf-8')
else:
f = open(self.name[:200] + '.bib', mode = 'w', encoding = 'utf-8')
f.write("%This file was gen... | Writes a bibTex entry to _fname_ for each `Record` in the collection.
If the Record is of a journal article (PT J) the bibtext type is set to `'article'`, otherwise it is set to `'misc'`. The ID of the entry is the WOS number and all the Record's fields are given as entries with their long names.
**No... |
def set_row_min_height(self, y: int, min_height: int):
if y < 0:
raise IndexError('y < 0')
self._min_heights[y] = min_height | Sets a minimum height for blocks in the row with coordinate y. |
def _get_context(center_idx, sentence_boundaries, window_size,
random_window_size, seed):
random.seed(seed + center_idx)
sentence_index = np.searchsorted(sentence_boundaries, center_idx)
sentence_start, sentence_end = _get_sentence_start_end(
sentence_boundaries, sentence_index)
... | Compute the context with respect to a center word in a sentence.
Takes an numpy array of sentences boundaries. |
def _init_update_po_files(self, domains):
for language in settings.TRANSLATIONS:
for domain, options in domains.items():
if language == options['default']: continue
if os.path.isfile(_po_path(language, domain)):
self._update_po_file(language, domai... | Update or initialize the `.po` translation files |
def get_data(self, size=None, addr=None):
if addr is None:
addr = self._mem_bytes
if size and self._mem_bytes < size:
raise ValueError('Size is too big')
if size is None:
return self._intf.read(self._conf['base_addr'] + self._spi_mem_offset + addr, self._mem_b... | Gets data for incoming stream |
def reload(self):
self.read_notmuch_config(self._notmuchconfig.filename)
self.read_config(self._config.filename) | Reload notmuch and alot config files |
def inve(env, command, *args, **kwargs):
with temp_environ():
os.environ['VIRTUAL_ENV'] = str(workon_home / env)
os.environ['PATH'] = compute_path(env)
unsetenv('PYTHONHOME')
unsetenv('__PYVENV_LAUNCHER__')
try:
return check_call([command] + list(args), shell=wind... | Run a command in the given virtual environment.
Pass additional keyword arguments to ``subprocess.check_call()``. |
def exclude_items(items, any_all=any, ignore_case=False, normalize_values=False, **kwargs):
if kwargs:
match = functools.partial(
_match_item, any_all=any_all, ignore_case=ignore_case, normalize_values=normalize_values, **kwargs
)
return filterfalse(match, items)
else:
return iter(items) | Exclude items by matching metadata.
Note:
Metadata values are lowercased when ``normalized_values`` is ``True``,
so ``ignore_case`` is automatically set to ``True``.
Parameters:
items (list): A list of item dicts or filepaths.
any_all (callable): A callable to determine if any or all filters must match to e... |
def empirical_rate(data, sigma=3.0):
from scipy.ndimage.filters import gaussian_filter1d
return 0.001 + gaussian_filter1d(data.astype(np.float), sigma, axis=0) | Smooth count data to get an empirical rate |
def try_url(url_name):
from warnings import warn
warn("try_url is deprecated, use the url tag with the 'as' arg instead.")
try:
url = reverse(url_name)
except NoReverseMatch:
return ""
return url | Mimics Django's ``url`` template tag but fails silently. Used for
url names in admin templates as these won't resolve when admin
tests are running. |
def _depth_image_callback(self, image_msg):
encoding = image_msg.encoding
try:
depth_arr = self._bridge.imgmsg_to_cv2(image_msg, encoding)
import pdb; pdb.set_trace()
except CvBridgeError as e:
rospy.logerr(e)
depth = np.array(depth_arr*MM_TO_METERS, n... | subscribe to depth image topic and keep it up to date |
def get_annotations(cls, __fn):
if hasattr(__fn, '__func__'):
__fn = __fn.__func__
if hasattr(__fn, '__notes__'):
return __fn.__notes__
raise AttributeError('{!r} does not have annotations'.format(__fn)) | Get the annotations of a given callable. |
def finish(self, status):
retox_log.info("Completing %s with status %s" % (self.name, status))
result = Screen.COLOUR_GREEN if not status else Screen.COLOUR_RED
self.palette['title'] = (Screen.COLOUR_WHITE, Screen.A_BOLD, result)
for item in list(self._task_view.options):
sel... | Move laggard tasks over
:param activity: The virtualenv status
:type activity: ``str`` |
def view_plugins(category=None):
if category is not None:
if category == 'parsers':
return {
name: {"descript": klass.plugin_descript,
"regex": klass.file_regex}
for name, klass in _all_plugins[category].items()
}
return ... | return a view of the loaded plugin names and descriptions
Parameters
----------
category : None or str
if str, apply for single plugin category
Examples
--------
>>> from pprint import pprint
>>> pprint(view_plugins())
{'decoders': {}, 'encoders': {}, 'parsers': {}}
>>> c... |
async def pop_log(self):
self._check_receive_loop()
res = self.log_queue.get()
self._check_error(res)
return res | Get one log from the log queue. |
def calc_drm(skydir, ltc, event_class, event_types,
egy_bins, cth_bins, nbin=64):
npts = int(np.ceil(128. / bins_per_dec(egy_bins)))
egy_bins = np.exp(utils.split_bin_edges(np.log(egy_bins), npts))
etrue_bins = 10**np.linspace(1.0, 6.5, nbin * 5.5 + 1)
egy = 10**utils.edge_to_center(np.log1... | Calculate the detector response matrix. |
async def get_config(self):
config_facade = client.ModelConfigFacade.from_connection(
self.connection()
)
result = await config_facade.ModelGet()
config = result.config
for key, value in config.items():
config[key] = ConfigValue.from_json(value)
re... | Return the configuration settings for this model.
:returns: A ``dict`` mapping keys to `ConfigValue` instances,
which have `source` and `value` attributes. |
def create_snapshot(self, volume_id_or_uri, snapshot, timeout=-1):
uri = self.__build_volume_snapshot_uri(volume_id_or_uri)
return self._client.create(snapshot, uri=uri, timeout=timeout, default_values=self.DEFAULT_VALUES_SNAPSHOT) | Creates a snapshot for the specified volume.
Args:
volume_id_or_uri:
Can be either the volume ID or the volume URI.
snapshot (dict):
Object to create.
timeout:
Timeout in seconds. Wait for task completion by default. The timeou... |
def undo(scm, verbose, fake, hard):
scm.fake = fake
scm.verbose = fake or verbose
scm.repo_check()
status_log(scm.undo, 'Last commit removed from history.', hard) | Removes the last commit from history. |
def current(self):
if not has_request_context():
return self.no_req_ctx_user_stack.top
user_stack = getattr(_request_ctx_stack.top, 'user_stack', None)
if user_stack and user_stack.top:
return user_stack.top
return _get_user() | Returns the current user |
def verify_pubkey_sig(self, message, sig):
if self.opts['master_sign_key_name']:
path = os.path.join(self.opts['pki_dir'],
self.opts['master_sign_key_name'] + '.pub')
if os.path.isfile(path):
res = verify_signature(path,
... | Wraps the verify_signature method so we have
additional checks.
:rtype: bool
:return: Success or failure of public key verification |
def get(self, *args, **kwargs):
self.set_status(self._status_response_code())
self.write(self._status_response()) | Tornado RequestHandler GET request endpoint for reporting status
:param list args: positional args
:param dict kwargs: keyword args |
def destinations(stop):
from pyruter.api import Departures
async def get_destinations():
async with aiohttp.ClientSession() as session:
data = Departures(LOOP, stop, session=session)
result = await data.get_final_destination()
print(json.dumps(result, indent=4, sort_k... | Get destination information. |
def _parse_alt_url(html_chunk):
url_list = html_chunk.find("a", fn=has_param("href"))
url_list = map(lambda x: x.params["href"], url_list)
url_list = filter(lambda x: not x.startswith("autori/"), url_list)
if not url_list:
return None
return normalize_url(BASE_URL, url_list[0]) | Parse URL from alternative location if not found where it should be.
Args:
html_chunk (obj): HTMLElement containing slice of the page with details.
Returns:
str: Book's URL. |
def wo_resp(self, resp):
if self._data is not None:
resp['res'] = self.to_str(self._data)
return self.wo_json(resp) | can override for other style |
def on_open(self):
filename, filter = QtWidgets.QFileDialog.getOpenFileName(
self, _('Open'))
if filename:
self.open_file(filename) | Shows an open file dialog and open the file if the dialog was
accepted. |
def is_vector(inp):
inp = np.asarray(inp)
nr_dim = np.ndim(inp)
if nr_dim == 1:
return True
elif (nr_dim == 2) and (1 in inp.shape):
return True
else:
return False | Returns true if the input can be interpreted as a 'true' vector
Note
----
Does only check dimensions, not if type is numeric
Parameters
----------
inp : numpy.ndarray or something that can be converted into ndarray
Returns
-------
Boolean
True for vectors: ndim = 1 or ndim... |
def local():
logger.info("Loading requirements from local file.")
with open(REQUIREMENTS_FILE, 'r') as f:
requirements = parse(f)
for r in requirements:
logger.debug("Creating new package: %r", r)
create_package_version(r) | Load local requirements file. |
def from_df(cls, df):
t = cls()
labels = df.columns
for label in df.columns:
t.append_column(label, df[label])
return t | Convert a Pandas DataFrame into a Table. |
def default(self, line):
if any((line.startswith(x) for x in self.argparse_names())):
try:
args = self.argparser.parse_args(shlex.split(line))
except Exception:
pass
else:
args.func(args)
else:
cmd.Cmd.defaul... | Overriding default to get access to any argparse commands we have specified. |
def read_function(data, window, ij, g_args):
output = (data[0] > numpy.mean(data[0])).astype(data[0].dtype) * data[0].max()
return output | Takes an array, and sets any value above the mean to the max, the rest to 0 |
async def generate_license(self, title, avatar, badges=None, widgets=None):
if not isinstance(title, str):
raise TypeError("type of 'title' must be str.")
if not isinstance(avatar, str):
raise TypeError("type of 'avatar' must be str.")
if badges and not isinstance(badges,... | Generate a license.
This function is a coroutine.
Parameters:
title: str - title of the license
avatar: str - http/s url pointing to an image, has to have proper headers and be a direct link to an image
badges: list - list of 1-3 direct image urls. Same requirements... |
def write_calculations_to_csv(funcs, states, columns, path, headers, out_name,
metaids=[], extension=".xls"):
if not isinstance(funcs, list):
funcs = [funcs] * len(headers)
if not isinstance(states, list):
states = [states] * len(headers)
if not isinstance(colum... | Writes each output of the given functions on the given states and data
columns to a new column in the specified output file.
Note: Column 0 is time. The first data column is column 1.
:param funcs: A function or list of functions which will be applied in order to the data. If only one function is given it... |
def process_request(self, request):
if not self.is_resource_protected(request):
return
if self.deny_access_condition(request):
return self.deny_access(request) | The actual middleware method, called on all incoming requests.
This default implementation will ignore the middleware (return None) if the
conditions specified in is_resource_protected aren't met. If they are, it then
tests to see if the user should be denied access via the denied_access_condit... |
def user_pk_to_url_str(user):
User = get_user_model()
if issubclass(type(User._meta.pk), models.UUIDField):
if isinstance(user.pk, six.string_types):
return user.pk
return user.pk.hex
ret = user.pk
if isinstance(ret, six.integer_types):
ret = int_to_base36(user.pk)
... | This should return a string. |
def compare_directory(self, directory):
return not self.folder_exclude_check.match(directory + self.sep if self.dir_pathname else directory) | Compare folder. |
def place_notes(self, notes, duration):
if hasattr(notes, 'notes'):
pass
elif hasattr(notes, 'name'):
notes = NoteContainer(notes)
elif type(notes) == str:
notes = NoteContainer(notes)
elif type(notes) == list:
notes = NoteContainer(notes)
... | Place the notes on the current_beat.
Notes can be strings, Notes, list of strings, list of Notes or a
NoteContainer.
Raise a MeterFormatError if the duration is not valid.
Return True if succesful, False otherwise (ie. the Bar hasn't got
enough room for a note of that duration... |
def update_status(self):
try:
self.update_connection_status()
self.max_stream_rate.set(self.get_stream_rate_str())
self.ip.set(self.status.external_ip)
self.uptime.set(self.status.str_uptime)
upstream, downstream = self.status.transmission_rate
... | Update status informations in tkinter window. |
def local_2d_halo_exchange(k, v, num_h_blocks, h_dim,
num_w_blocks, w_dim, mask_right):
for blocks_dim, block_size_dim, halo_size in [
(num_h_blocks, h_dim, h_dim.size),
(num_w_blocks, w_dim, w_dim.size)]:
if halo_size > 0:
if blocks_dim is not None:
if mask_ri... | Halo exchange for keys and values for Local 2D attention. |
def geometry(obj):
gf = vtk.vtkGeometryFilter()
gf.SetInputData(obj)
gf.Update()
return gf.GetOutput() | Apply ``vtkGeometryFilter``. |
def get_value(self, model, default=None):
if default is not None:
default = self._converter(default)
value = getattr(model, self.storage_name)
return value if value is not None else default | Return field's value.
:param DomainModel model:
:param object default:
:rtype object: |
def _runhook(ui, repo, hooktype, filename, kwargs):
hname = hooktype + ".autohooks." + os.path.basename(filename)
if filename.lower().endswith(".py"):
try:
mod = mercurial.extensions.loadpath(filename,
"hghook.%s" % hname)
except Exception:
ui.write(_("loa... | Run the hook in `filename` and return its result. |
def mixed_use_of_local_and_run(self):
cxn = Connection("localhost")
result = cxn.local("echo foo", hide=True)
assert result.stdout == "foo\n"
assert not cxn.is_connected
result = cxn.run("echo foo", hide=True)
assert cxn.is_connected
assert result.stdout == "foo\n... | Run command truly locally, and over SSH via localhost |
def PythonTypeFromMetricValueType(value_type):
if value_type == rdf_stats.MetricMetadata.ValueType.INT:
return int
elif value_type == rdf_stats.MetricMetadata.ValueType.FLOAT:
return float
else:
raise ValueError("Unknown value type: %s" % value_type) | Converts MetricMetadata.ValueType enums to corresponding Python types. |
def _file_prompt_quiet(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
if not self.prompt_quiet_configured:
if self.auto_file_prompt:
self.device.send_config_set(["file prompt quiet"])
self.prompt_quiet_changed = True
... | Decorator to toggle 'file prompt quiet' for methods that perform file operations. |
def _request(self, url, request_type='GET', **params):
try:
_LOGGER.debug('Request %s %s', url, params)
response = self.request(
request_type, url, timeout=TIMEOUT.seconds, **params)
response.raise_for_status()
_LOGGER.debug('Response %s %s %.200s'... | Send a request to the Minut Point API. |
def _filter_matrix_rows(cls, matrix):
indexes_to_keep = []
for i in range(len(matrix)):
keep_row = False
for element in matrix[i]:
if element not in {'NA', 'no'}:
keep_row = True
break
if keep_row:
... | matrix = output from _to_matrix |
def create(cls, counter_user_alias, share_detail, status,
monetary_account_id=None, draft_share_invite_bank_id=None,
share_type=None, start_date=None, end_date=None,
custom_headers=None):
if custom_headers is None:
custom_headers = {}
request_map ... | Create a new share inquiry for a monetary account, specifying the
permission the other bunq user will have on it.
:type user_id: int
:type monetary_account_id: int
:param counter_user_alias: The pointer of the user to share with.
:type counter_user_alias: object_.Pointer
... |
def OpenSourcePath(self, source_path):
source_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=source_path)
self.AddScanNode(source_path_spec, None) | Opens the source path.
Args:
source_path (str): source path. |
def _validate_conn(self, conn):
super(HTTPSConnectionPool, self)._validate_conn(conn)
if not getattr(conn, 'sock', None):
conn.connect()
if not conn.is_verified:
warnings.warn((
'Unverified HTTPS request is being made. '
'Adding certificate... | Called right before a request is made, after the socket is created. |
def recordHostname(self, basedir):
"Record my hostname in twistd.hostname, for user convenience"
log.msg("recording hostname in twistd.hostname")
filename = os.path.join(basedir, "twistd.hostname")
try:
hostname = os.uname()[1]
except AttributeError:
hostn... | Record my hostname in twistd.hostname, for user convenience |
def get(self, request, **kwargs):
customer, _created = Customer.get_or_create(
subscriber=subscriber_request_callback(self.request)
)
serializer = SubscriptionSerializer(customer.subscription)
return Response(serializer.data) | Return the customer's valid subscriptions.
Returns with status code 200. |
def flatten(self, shallow=None):
return self._wrap(self._flatten(self.obj, shallow)) | Return a completely flattened version of an array. |
def toList(self):
slist = angle.toList(self.value)
slist[1] = slist[1] % 24
return slist | Returns time as signed list. |
def is_bool_dtype(arr_or_dtype):
if arr_or_dtype is None:
return False
try:
dtype = _get_dtype(arr_or_dtype)
except TypeError:
return False
if isinstance(arr_or_dtype, CategoricalDtype):
arr_or_dtype = arr_or_dtype.categories
if isinstance(arr_or_dtype, ABCIndexClass)... | Check whether the provided array or dtype is of a boolean dtype.
Parameters
----------
arr_or_dtype : array-like
The array or dtype to check.
Returns
-------
boolean
Whether or not the array or dtype is of a boolean dtype.
Notes
-----
An ExtensionArray is considere... |
def wrap_uda(
hdfs_file,
inputs,
output,
update_fn,
init_fn=None,
merge_fn=None,
finalize_fn=None,
serialize_fn=None,
close_fn=None,
name=None,
):
func = ImpalaUDA(
inputs,
output,
update_fn,
init_fn,
merge_fn,
finalize_fn,
... | Creates a callable aggregation function object. Must be created in Impala
to be used
Parameters
----------
hdfs_file: .so file that contains relevant UDA
inputs: list of strings denoting ibis datatypes
output: string denoting ibis datatype
update_fn: string
Library symbol name for upd... |
def determine(chord, shorthand=False, no_inversions=False, no_polychords=False):
if chord == []:
return []
elif len(chord) == 1:
return chord
elif len(chord) == 2:
return [intervals.determine(chord[0], chord[1])]
elif len(chord) == 3:
return determine_triad(chord, shortha... | Name a chord.
This function can determine almost every chord, from a simple triad to a
fourteen note polychord. |
def notify(self, n=1):
if not is_locked(self._lock):
raise RuntimeError('lock is not locked')
notified = [0]
def walker(switcher, predicate):
if not switcher.active:
return False
if predicate and not predicate():
return True
... | Raise the condition and wake up fibers waiting on it.
The optional *n* parameter specifies how many fibers will be notified.
By default, one fiber is notified. |
def is_period_current(self):
return self.current_period_end > timezone.now() or (
self.trial_end and self.trial_end > timezone.now()
) | Returns True if this subscription's period is current, false otherwise. |
def ref(self):
sds_ref = _C.SDidtoref(self._id)
_checkErr('idtoref', sds_ref, 'illegal SDS identifier')
return sds_ref | Get the reference number of the dataset.
Args::
no argument
Returns::
dataset reference number
C library equivalent : SDidtoref |
def get_subtask_fields(config_class):
from lsst.pex.config import ConfigurableField, RegistryField
def is_subtask_field(obj):
return isinstance(obj, (ConfigurableField, RegistryField))
return _get_alphabetical_members(config_class, is_subtask_field) | Get all configurable subtask fields from a Config class.
Parameters
----------
config_class : ``lsst.pipe.base.Config``-type
The configuration class (not an instance) corresponding to a Task.
Returns
-------
subtask_fields : `dict`
Mapping where keys are the config attribute na... |
def _on_ready_read(self):
while self.bytesAvailable():
if not self._header_complete:
self._read_header()
else:
self._read_payload() | Read bytes when ready read |
def match(sel, obj, arr=None, bailout_fn=None):
if arr:
sel = interpolate(sel, arr)
sel = parse(sel)[1]
return _forEach(sel, obj, bailout_fn=bailout_fn) | Match a selector to an object, yielding the matched values.
Args:
sel: The JSONSelect selector to apply (a string)
obj: The object against which to apply the selector
arr: If sel contains ? characters, then the values in this array will
be safely interpolated into the selector.... |
def update(self, forecasts, observations):
if len(observations.shape) == 1:
obs_cdfs = np.zeros((observations.size, self.thresholds.size))
for o, observation in enumerate(observations):
obs_cdfs[o, self.thresholds >= observation] = 1
else:
obs_cdfs = o... | Update the statistics with forecasts and observations.
Args:
forecasts: The discrete Cumulative Distribution Functions of
observations: |
def typed_assign_stmt_handle(self, tokens):
if len(tokens) == 2:
if self.target_info >= (3, 6):
return tokens[0] + ": " + self.wrap_typedef(tokens[1])
else:
return tokens[0] + " = None" + self.wrap_comment(" type: " + tokens[1])
elif len(tokens) ==... | Process Python 3.6 variable type annotations. |
def get_total_irradiance(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
dni, ghi, dhi, dni_extra=None, airmass=None,
albedo=.25, surface_type=None,
model='isotropic',
model_perez='al... | r"""
Determine total in-plane irradiance and its beam, sky diffuse and ground
reflected components, using the specified sky diffuse irradiance model.
.. math::
I_{tot} = I_{beam} + I_{sky diffuse} + I_{ground}
Sky diffuse models include:
* isotropic (default)
* klucher
... |
def alpha(requestContext, seriesList, alpha):
for series in seriesList:
series.options['alpha'] = alpha
return seriesList | Assigns the given alpha transparency setting to the series. Takes a float
value between 0 and 1. |
async def set_topic(self, topic):
self.topic = topic
try:
if self.topicchannel:
await client.edit_channel(self.topicchannel, topic=topic)
except Exception as e:
logger.exception(e) | Sets the topic for the topic channel |
def to_doc(self, xmllist, decorates):
result = []
for xitem in xmllist:
if xitem.tag != "group":
if "name" in list(xitem.keys()):
names = re.split("[\s,]+", xitem.get("name"))
for name in names:
... | Converts the specified xml list to a list of docstring elements. |
def delete(self, url, callback, json=None):
return self.adapter.delete(url, callback, json=json) | Delete a URL.
Args:
url(string): URL for the request
callback(func): The response callback function
Keyword Args:
json(dict): JSON body for the request
Returns:
The result of the callback handling the resopnse from the
execut... |
def disconnect(self):
if self.proto:
log.debug('%r Disconnecting from %r', self, self.proto.transport.getPeer())
self.proto.transport.loseConnection() | Disconnect from the Kafka broker.
This is used to implement disconnection on timeout as a workaround for
Kafka connections occasionally getting stuck on the server side under
load. Requests are not cancelled, so they will be retried. |
def load_all_from_directory(self, directory_path):
datas = []
for root, folders, files in os.walk(directory_path):
for f in files:
datas.append(self.load_from_file(os.path.join(root, f)))
return datas | Return a list of dict from a directory containing files |
def fileToMD5(filename, block_size=256*128, binary=False):
md5 = hashlib.md5()
with open(filename,'rb') as f:
for chunk in iter(lambda: f.read(block_size), b''):
md5.update(chunk)
if not binary:
return md5.hexdigest()
return md5.digest() | A function that calculates the MD5 hash of a file.
Args:
-----
filename: Path to the file.
block_size: Chunks of suitable size. Block size directly depends on
the block size of your filesystem to avoid performances issues.
Blocks of 4096 octets (Default NTFS).
bi... |
def decodedFileID(self, cachedFilePath):
fileDir, fileName = os.path.split(cachedFilePath)
assert fileDir == self.localCacheDir, 'Can\'t decode uncached file names'
return base64.urlsafe_b64decode(fileName.encode('utf-8')).decode('utf-8') | Decode a cached fileName back to a job store file ID.
:param str cachedFilePath: Path to the cached file
:return: The jobstore file ID associated with the file
:rtype: str |
def get_screen_size_range(self):
return GetScreenSizeRange(
display=self.display,
opcode=self.display.get_extension_major(extname),
window=self,
) | Retrieve the range of possible screen sizes. The screen may be set to
any size within this range. |
def fixed_legend_position(self, fixed_legend_position):
allowed_values = ["RIGHT", "TOP", "LEFT", "BOTTOM"]
if fixed_legend_position not in allowed_values:
raise ValueError(
"Invalid value for `fixed_legend_position` ({0}), must be one of {1}"
.format(fixed_le... | Sets the fixed_legend_position of this ChartSettings.
Where the fixed legend should be displayed with respect to the chart # noqa: E501
:param fixed_legend_position: The fixed_legend_position of this ChartSettings. # noqa: E501
:type: str |
def get_final_window_monitor(cls, settings, window):
screen = window.get_screen()
use_mouse = settings.general.get_boolean('mouse-display')
dest_screen = settings.general.get_int('display-n')
if use_mouse:
win, x, y, _ = screen.get_root_window().get_pointer()
dest... | Gets the final screen number for the main window of guake. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.