Unnamed: 0
int64
0
389k
code
stringlengths
26
79.6k
docstring
stringlengths
1
46.9k
7,600
def _expand_scheduledict(scheduledict): result = [] def f(d): nonlocal result d2 = {} for k,v in d.items(): if isinstance(v, str) and _cronslash(v, k) is not None: d[k] = _cronslash(v, k) for k,v in d.items(): if isinstance(v...
Converts a dict of items, some of which are scalar and some of which are lists, to a list of dicts with scalar items.
7,601
def get_ecf_props(ep_id, ep_id_ns, rsvc_id=None, ep_ts=None): results = {} if not ep_id: raise ArgumentError("ep_id", "ep_id must be a valid endpoint id") results[ECF_ENDPOINT_ID] = ep_id if not ep_id_ns: raise ArgumentError("ep_id_ns", "ep_id_ns must be a valid namespace") resu...
Prepares the ECF properties :param ep_id: Endpoint ID :param ep_id_ns: Namespace of the Endpoint ID :param rsvc_id: Remote service ID :param ep_ts: Timestamp of the endpoint :return: A dictionary of ECF properties
7,602
def inspect(self, tab_width=2, ident_char=): startpath = self.path output = [] for (root, dirs, files) in os.walk(startpath): level = root.replace(startpath, ).count(os.sep) indent = ident_char * tab_width * (level) if level == 0: output.append(.format(indent, os.path.basename...
Inspects a project file structure based based on the instance folder property. :param tab_width: width size for subfolders and files. :param ident_char: char to be used to show identation level Returns A string containing the project structure.
7,603
def hclust_linearize(U): from scipy.cluster import hierarchy Z = hierarchy.ward(U) return hierarchy.leaves_list(hierarchy.optimal_leaf_ordering(Z, U))
Sorts the rows of a matrix by hierarchical clustering. Parameters: U (ndarray) : matrix of data Returns: prm (ndarray) : permutation of the rows
7,604
def calc_surfdist(surface, labels, annot, reg, origin, target): import nibabel as nib import numpy as np import os from surfdist import load, utils, surfdist import csv surf = nib.freesurfer.read_geometry(surface) cort = np.sort(nib.freesurfer.read_label(labels)) src = load.load_freesurfer_labe...
inputs: surface - surface file (e.g. lh.pial, with full path) labels - label file (e.g. lh.cortex.label, with full path) annot - annot file (e.g. lh.aparc.a2009s.annot, with full path) reg - registration file (lh.sphere.reg) origin - the label from which we calculate distances target - target surface (e.g. ...
7,605
def signOp(self, op: Dict, identifier: Identifier=None) -> Request: request = Request(operation=op, protocolVersion=CURRENT_PROTOCOL_VERSION) return self.signRequest(request, identifier)
Signs the message if a signer is configured :param identifier: signing identifier; if not supplied the default for the wallet is used. :param op: Operation to be signed :return: a signed Request object
7,606
def add_wic(self, old_wic, wic): new_wic = + old_wic[-1] self.node[][new_wic] = wic
Convert the old style WIC slot to a new style WIC slot and add the WIC to the node properties :param str old_wic: Old WIC slot :param str wic: WIC name
7,607
def ckchol(M): from numpy import linalg, matrix, eye, size try: output=linalg.cholesky(M) except: print() output=matrix(eye(size(M,0))) return output
CKCHOL This function computes the Cholesky decomposition of the matrix if it's positive-definite; else it returns the identity matrix. It was written to handle the "matrix must be positive definite" error in linalg.cholesky. Version: 2011may03
7,608
def set_monitoring_transaction_name(name, group=None, priority=None): if not newrelic: return newrelic.agent.set_transaction_name(name, group, priority)
Sets the transaction name for monitoring. This is not cached, and only support reporting to New Relic.
7,609
def spoolable(*, pre_condition=True, body_params=()): def decorator(func): context_name = None keyword_kinds = {inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.KEYWORD_ONLY} invalid_body_params = set(body_params) for name, parameter in inspect.signature(func).paramet...
Decorates a function to make it spoolable using uWSGI, but if no spooling mechanism is available, the function is called synchronously. All decorated function arguments must be picklable and the first annotated with `Context` will receive an object that defines the current execution state. Return values are...
7,610
def _advance_window(self): x_to_remove, y_to_remove = self._x_in_window[0], self._y_in_window[0] self._window_bound_lower += 1 self._update_values_in_window() x_to_add, y_to_add = self._x_in_window[-1], self._y_in_window[-1] self._remove_observation(x_to_remove, y_to_r...
Update values in current window and the current window means and variances.
7,611
def add_stack_frame(self, stack_frame): if len(self.stack_frames) >= MAX_FRAMES: self.dropped_frames_count += 1 else: self.stack_frames.append(stack_frame.format_stack_frame_json())
Add StackFrame to frames list.
7,612
def get_insertions(aln_df): insertion_df = aln_df[aln_df[] == ] to_append = (insertion_region, insertion_length) insertions.append(to_append) return insertions
Get a list of tuples indicating the first and last residues of a insertion region, as well as the length of the insertion. If the first tuple is: (-1, 1) that means the insertion is at the beginning of the original protein (X, Inf) where X is the length of the original protein, that means the inser...
7,613
def on_update(self, value, *args, **kwargs): parent_value = self._parent_min if self._max != self._min: sub_progress = (value - self._min) / (self._max - self._min) parent_value = self._parent_min + sub_progress * (self._parent_max - self._parent_min) self._paren...
Inform the parent of progress. :param value: The value of this subprogresscallback :param args: Extra positional arguments :param kwargs: Extra keyword arguments
7,614
def getExperimentDescriptionInterfaceFromModule(module): result = module.descriptionInterface assert isinstance(result, exp_description_api.DescriptionIface), \ "expected DescriptionIface-based instance, but got %s" % type(result) return result
:param module: imported description.py module :returns: (:class:`nupic.frameworks.opf.exp_description_api.DescriptionIface`) represents the experiment description
7,615
def colorize(text=, opts=(), **kwargs): code_list = [] if text == and len(opts) == 1 and opts[0] == : return % RESET for k, v in kwargs.iteritems(): if k == : code_list.append(foreground[v]) elif k == : code_list.append(background[v]) for o in opts:...
Returns your text, enclosed in ANSI graphics codes. Depends on the keyword arguments 'fg' and 'bg', and the contents of the opts tuple/list. Returns the RESET code if no parameters are given. Valid colors: 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white' Valid option...
7,616
def import_patch(self, patch_name, new_name=None): if new_name: dir_name = os.path.dirname(new_name) name = os.path.basename(new_name) dest_dir = self.quilt_patches + Directory(dir_name) dest_dir.create() else: name = os.path.basename(...
Import patch into the patch queue The patch is inserted as the next unapplied patch.
7,617
def print_hex(self, value, justify_right=True): if value < 0 or value > 0xFFFF: return self.print_str(.format(value), justify_right)
Print a numeric value in hexadecimal. Value should be from 0 to FFFF.
7,618
def interp(mapping, x): mapping = sorted(mapping) if len(mapping) == 1: xa, ya = mapping[0] if xa == x: return ya return x for (xa, ya), (xb, yb) in zip(mapping[:-1], mapping[1:]): if xa <= x <= xb: return ya + float(x - xa) / (xb - xa) * (yb - ya...
Compute the piecewise linear interpolation given by mapping for input x. >>> interp(((1, 1), (2, 4)), 1.5) 2.5
7,619
def append_sibling_field(self, linenum, indent, field_name, field_value): frame = self.current_frame() assert frame.indent is not None and frame.indent == indent self.pop_frame() self.append_child_field(linenum, indent, field_name, field_value)
:param linenum: The line number of the frame. :type linenum: int :param indent: The indentation level of the frame. :type indent: int :param path: :type path: Path :param field_name: :type field_name: str :param field_value: :type field_value: str
7,620
def create_external_table(self, external_project_dataset_table, schema_fields, source_uris, source_format=, autodetect=False, compression=, ...
Creates a new external table in the dataset with the data in Google Cloud Storage. See here: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#resource for more details about these parameters. :param external_project_dataset_table: The dotted ``(<project>.|<p...
7,621
def get_notebook_status(self, name): context = comm.get_context(self.get_pid(name)) if not context: return None return context
Get the running named Notebook status. :return: None if no notebook is running, otherwise context dictionary
7,622
def fit(self, X, y=None, **fit_params): self.opt_ = None self.cputime_ = None self.iters_ = None self.duality_gap_ = None self.path_ = None self.sample_covariance_ = None self.lam_scale_ = None self.lam_ = None self.is_f...
Fits the inverse covariance model according to the given training data and parameters. Parameters ----------- X : 2D ndarray, shape (n_features, n_features) Input data. Returns ------- self
7,623
def save_config(self): self.set_option(, self.recent_projects) self.set_option(, self.explorer.treewidget.get_expanded_state()) self.set_option(, self.explorer.treewidget.get_scrollbar_position()) if self.current_active_proj...
Save configuration: opened projects & tree widget state. Also save whether dock widget is visible if a project is open.
7,624
def task(ft): ft.pack(expand = True, fill = BOTH, side = TOP) pb_hD = ttk.Progressbar(ft, orient = , mode = ) pb_hD.pack(expand = True, fill = BOTH, side = TOP) pb_hD.start(50) ft.mainloop()
to create loading progress bar
7,625
def saml_provider_absent(name, region=None, key=None, keyid=None, profile=None): ret = {: name, : True, : , : {}} provider = __salt__[](region=region, key=key, keyid=keyid, profile=profile) i...
.. versionadded:: 2016.11.0 Ensure the SAML provider with the specified name is absent. name (string) The name of the SAML provider. saml_metadata_document (string) The xml document of the SAML provider. region (string) Region to connect to. key (string) Secret k...
7,626
def start(self): if self._status == TransferState.PREPARING: super(Upload, self).start() else: raise SbgError( )
Starts the upload. :raises SbgError: If upload is not in PREPARING state.
7,627
async def create(self, query, *, dc=None): if "Token" in query: query["Token"] = extract_attr(query["Token"], keys=["ID"]) response = await self._api.post("/v1/query", params={"dc": dc}, data=query) return response.body
Creates a new prepared query Parameters: Query (Object): Query definition dc (str): Specify datacenter that will be used. Defaults to the agent's local datacenter. Returns: Object: New query ID The create operation expects a body that d...
7,628
def Set(self, interface_name, property_name, value, *args, **kwargs): self.log( % (interface_name, property_name, self.format_args((value,)))) try: iface_props = self.props[interface_name] except KeyError:...
Standard D-Bus API for setting a property value
7,629
def poke(self, context): self.log.info(, self.channels) message = self.pubsub.get_message() self.log.info(, message, self.channels) if message and message[] == : context[].xcom_push(key=, value=message) self.pubsub.unsubscribe(self.channels) ...
Check for message on subscribed channels and write to xcom the message with key ``message`` An example of message ``{'type': 'message', 'pattern': None, 'channel': b'test', 'data': b'hello'}`` :param context: the context object :type context: dict :return: ``True`` if message (with typ...
7,630
def parse_plotProfile(self): self.deeptools_plotProfile = dict() for f in self.find_log_files(, filehandles=False): parsed_data, bin_labels, converted_bin_labels = self.parsePlotProfileData(f) for k, v in parsed_data.items(): if k in self.deeptools_plotPr...
Find plotProfile output
7,631
def Policy(self, data=None, subset=None): return self.factory.get_object(jssobjects.Policy, data, subset)
{dynamic_docstring}
7,632
def make_sentences(self, stream_item): self.make_label_index(stream_item) sentences = [] token_num = 0 new_mention_id = 0 for sent_start, sent_end, sent_str in self._sentences( stream_item.body.clean_visible): assert isinstance(sent_str, unico...
assemble Sentence and Token objects
7,633
def uppercase(self, value): if not isinstance(value, bool): raise TypeError() self._uppercase = value
Validate and set the uppercase flag.
7,634
def _parse_current_network_settings(): opts = salt.utils.odict.OrderedDict() opts[] = if os.path.isfile(_DEB_NETWORKING_FILE): with salt.utils.files.fopen(_DEB_NETWORKING_FILE) as contents: for line in contents: salt.utils.stringutils.to_unicode(line) ...
Parse /etc/default/networking and return current configuration
7,635
def get_semester_title(self, node: BaseNode): log.debug("Getting Semester Title for %s" % node.course.id) return self._get_semester_from_id(node.course.semester)
get the semester of a node
7,636
def read(self): "Read and interpret data from the daemon." status = gpscommon.read(self) if status <= 0: return status if self.response.startswith("{") and self.response.endswith("}\r\n"): self.unpack(self.response) self.__oldstyle_shim() s...
Read and interpret data from the daemon.
7,637
def get_concept(self, conceptId, lang=): url = urljoin(self.concept_service + , conceptId) res, status_code = self.get(url, params={: lang}) if status_code != 200: logger.debug() return self.decode(res), status_code
Fetch the concept from the Knowledge base Args: id (str): The concept id to be fetched, it can be Wikipedia page id or Wikiedata id. Returns: dict, int: A dict containing the concept information; an integer representing the response code.
7,638
def _double_centered_imp(a, out=None): out = _float_copy_to_out(out, a) dim = np.size(a, 0) mu = np.sum(a) / (dim * dim) sum_cols = np.sum(a, 0, keepdims=True) sum_rows = np.sum(a, 1, keepdims=True) mu_cols = sum_cols / dim mu_rows = sum_rows / dim out -= mu_rows out -= ...
Real implementation of :func:`double_centered`. This function is used to make parameter ``out`` keyword-only in Python 2.
7,639
def ReadAllFlowObjects( self, client_id = None, min_create_time = None, max_create_time = None, include_child_flows = True, ): res = [] for flow in itervalues(self.flows): if ((client_id is None or flow.client_id == client_id) and (min_create_time is None or ...
Returns all flow objects.
7,640
def languages(self, key, value): languages = self.get(, []) values = force_list(value.get()) for value in values: for language in RE_LANGUAGE.split(value): try: name = language.strip().capitalize() languages.append(pycountry.languages.get(name=name)....
Populate the ``languages`` key.
7,641
def res_from_en(pst,enfile): converters = {"name": str_con, "group": str_con} try: obs=pst.observation_data if isinstance(enfile,str): df=pd.read_csv(enfile,converters=converters) df.columns=df.columns.str.lower() df = df.set_index().T.rename_axis().rena...
load ensemble file for residual into a pandas.DataFrame Parameters ---------- enfile : str ensemble file name Returns ------- pandas.DataFrame : pandas.DataFrame
7,642
def change_execution_time(self, job, date_time): with self.connection.pipeline() as pipe: while 1: try: pipe.watch(self.scheduled_jobs_key) if pipe.zscore(self.scheduled_jobs_key, job.id) is None: raise ValueErr...
Change a job's execution time.
7,643
def media_new(self, mrl, *options): if in mrl and mrl.index() > 1: m = libvlc_media_new_location(self, str_to_bytes(mrl)) else: m = libvlc_media_new_path(self, str_to_bytes(os.path.normpath(mrl))) for o in options: libvlc_me...
Create a new Media instance. If mrl contains a colon (:) preceded by more than 1 letter, it will be treated as a URL. Else, it will be considered as a local path. If you need more control, directly use media_new_location/media_new_path methods. Options can be specified as suppl...
7,644
def url(self): url = self.xml.find() if url is not None: url = url.get() return url
URL to the affiliation's profile page.
7,645
def add_jira_status(test_key, test_status, test_comment): global attachments if test_key and enabled: if test_key in jira_tests_status: previous_status = jira_tests_status[test_key] test_status = if previous_status[1] == and test_status == else i...
Save test status and comments to update Jira later :param test_key: test case key in Jira :param test_status: test case status :param test_comment: test case comments
7,646
def get_inverses(self, keys): return tuple([as_index(k, axis=0).inverse for k in keys])
Returns ------- Tuple of inverse indices
7,647
def get_jids(): ret = {} for returner_ in __opts__[CONFIG_KEY]: ret.update(_mminion().returners[.format(returner_)]()) return ret
Return all job data from all returners
7,648
def delete_sp_template_for_vlan(self, vlan_id): with self.session.begin(subtransactions=True): try: self.session.query( ucsm_model.ServiceProfileTemplate).filter_by( vlan_id=vlan_id).delete() except orm.exc.NoResultFound: ...
Deletes SP Template for a vlan_id if it exists.
7,649
def visit_raise(self, node): if node.exc is None: return expr = node.exc if self._check_raise_value(node, expr): return try: value = next(astroid.unpack_infer(expr)) except astroid.InferenceError: return s...
Visit a raise statement and check for raising strings or old-raise-syntax.
7,650
def get_details(self): data = [] if self.deployment == : data.append(VmDetailsProperty(key=,value= self.dep_attributes.get(,))) if self.deployment == : template = self.dep_attributes.get(,) snapshot = self.dep_attributes.get(,) d...
:rtype list[VmDataField]
7,651
def save_model(self, request, obj, form, change): if change and obj._old_slug != obj.slug: new_slug = obj.slug or obj.generate_unique_slug() obj.slug = obj._old_slug obj.set_slug(new_slug) parent = request.GET.get("parent") if p...
Set the ID of the parent page if passed in via querystring, and make sure the new slug propagates to all descendant pages.
7,652
def rsdl(self): return np.linalg.norm((self.X - self.Yprv).ravel())
Compute fixed point residual.
7,653
def to_bqstorage(self): if bigquery_storage_v1beta1 is None: raise ValueError(_NO_BQSTORAGE_ERROR) table_ref = bigquery_storage_v1beta1.types.TableReference() table_ref.project_id = self._project table_ref.dataset_id = self._dataset_id table_id = self._table...
Construct a BigQuery Storage API representation of this table. Install the ``google-cloud-bigquery-storage`` package to use this feature. If the ``table_id`` contains a partition identifier (e.g. ``my_table$201812``) or a snapshot identifier (e.g. ``mytable@1234567890``), it is...
7,654
def _make_single_subvolume(self, only_one=True, **args): if only_one and self.volumes: return self.volumes[0] if self.parent.index is None: index = else: index = .format(self.parent.index) volume = self._make_subvolume(index=index, **args) ...
Creates a subvolume, adds it to this class, sets the volume index to 0 and returns it. :param bool only_one: if this volume system already has at least one volume, it is returned instead.
7,655
def get_message(self, timeout=0.5): try: return self.buffer.get(block=not self.is_stopped, timeout=timeout) except Empty: return None
Attempts to retrieve the latest message received by the instance. If no message is available it blocks for given timeout or until a message is received, or else returns None (whichever is shorter). This method does not block after :meth:`can.BufferedReader.stop` has been called. :param ...
7,656
def dice(edge=15, fn=32): edge = float(edge) c = ops.Cube(edge, center=True) s = ops.Sphere(edge * 3 / 4, center=True) dice = c & s c = ops.Circle(edge / 12, _fn=fn) h = 0.7 point = c.linear_extrude(height=h) point1 = point.trans...
dice
7,657
def gather(obj): if hasattr(obj, ): return obj.__distob_gather__() elif (isinstance(obj, collections.Sequence) and not isinstance(obj, string_types)): return [gather(subobj) for subobj in obj] else: return obj
Retrieve objects that have been distributed, making them local again
7,658
def to_xml(self): element = etree.Element(self._tag_name) struct_to_xml(element, [ {"author": self.handle}, {"target_guid": self.target_guid}, {"target_type": DiasporaRetraction.entity_type_to_remote(self.entity_type)}, ]) return element
Convert to XML message.
7,659
async def play_url(self, url, position=0): headers = {: , : } body = {: url, : position} address = self._url(self.port, ) _LOGGER.debug(, url, address) resp = None try: resp = await self.session.post( ...
Play media from an URL on the device.
7,660
def lazy_reverse_binmap(f, xs): return (f(y, x) for x, y in zip(xs, xs[1:]))
Same as lazy_binmap, except the parameters are flipped for the binary function
7,661
def exists(self, regex): return self.search_full(regex, return_string=False, advance_pointer=False)
See what :meth:`skip_until` would return without advancing the pointer. >>> s = Scanner("test string") >>> s.exists(' ') 5 >>> s.pos 0 Returns the number of characters matched if it does exist, or ``None`` otherwise.
7,662
def _dialect(self, filepath): with open(filepath, self.read_mode) as csvfile: sample = csvfile.read(1024) dialect = csv.Sniffer().sniff(sample) if self.has_header == None: self.has_header = csv.Sniffer().has_header(sample) ...
returns detected dialect of filepath and sets self.has_header if not passed in __init__ kwargs Arguments: filepath (str): filepath of target csv file
7,663
def _defineVariables(self): logger.info(%(len(self.data))) mc_source_id_field = self.config[][] if mc_source_id_field is not None: if mc_source_id_field not in self.data.dtype.names: array = np.zeros(len(self.data),dtype=) self.data = mlab.r...
Helper funtion to define pertinent variables from catalog data. ADW (20170627): This has largely been replaced by properties.
7,664
def libvlc_vlm_add_vod(p_instance, psz_name, psz_input, i_options, ppsz_options, b_enabled, psz_mux): f = _Cfunctions.get(, None) or \ _Cfunction(, ((1,), (1,), (1,), (1,), (1,), (1,), (1,),), None, ctypes.c_int, Instance, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ListPOINTER(...
Add a vod, with one input. @param p_instance: the instance. @param psz_name: the name of the new vod media. @param psz_input: the input MRL. @param i_options: number of additional options. @param ppsz_options: additional options. @param b_enabled: boolean for enabling the new vod. @param psz...
7,665
def close(self): if self._backend is not None and not self._closed: self._closed = True self.events.close() self._backend._vispy_close() forget_canvas(self)
Close the canvas Notes ----- This will usually destroy the GL context. For Qt, the context (and widget) will be destroyed only if the widget is top-level. To avoid having the widget destroyed (more like standard Qt behavior), consider making the widget a sub-widget.
7,666
def from_any(cls, obj, bucket): if isinstance(obj, cls): return cls(obj.raw) return cls({ : , : bucket, : obj if obj else N1QL_PRIMARY_INDEX, : })
Ensure the current object is an index. Always returns a new object :param obj: string or IndexInfo object :param bucket: The bucket name :return: A new IndexInfo object
7,667
def running(self): r = self._client._redis flag = .format(self._queue) if bool(r.exists(flag)): return r.ttl(flag) is None return False
Returns true if job still in running state :return:
7,668
def read(self, line, f, data): line = f.readline() assert(line == " $HESS\n") while line != " $END\n": line = f.readline()
See :meth:`PunchParser.read`
7,669
def _arm_thumb_filter_jump_successors(self, addr, size, successors, get_ins_addr, get_exit_stmt_idx): if not successors: return [ ] it_counter = 0 conc_temps = {} can_produce_exits = set() bb = self._lift(addr, size=size, thumb=True, opt_level=0) f...
Filter successors for THUMB mode basic blocks, and remove those successors that won't be taken normally. :param int addr: Address of the basic block / SimIRSB. :param int size: Size of the basic block. :param list successors: A list of successors. :param func get_ins_addr: A callable th...
7,670
def father(self): if self._father == []: self._father = self.sub_tag("FAMC/HUSB") return self._father
Parent of this individual
7,671
def match(pattern): regex = re.compile(pattern) def validate(value): if not regex.match(value): return e("{} does not match the pattern {}", value, pattern) return validate
Validates that a field value matches the regex given to this validator.
7,672
def generic_http_header_parser_for(header_name): def parser(): request_id = request.headers.get(header_name, ).strip() if not request_id: return None return request_id return parser
A parser factory to extract the request id from an HTTP header :return: A parser that can be used to extract the request id from the current request context :rtype: ()->str|None
7,673
def copy_and_verify(path, source_path, sha256): if os.path.exists(path): if sha256 is None: print(.format( path, compute_sha256(path))) return path if not os.path.exists(source_path): return None unverified_path = path + ...
Copy a file to a given path from a given path, if it does not exist. After copying it, verify it integrity by checking the SHA-256 hash. Parameters ---------- path: str The (destination) path of the file on the local filesystem source_path: str The path from which to copy the file ...
7,674
def plot(self, vertices, show=False): if vertices.shape[1] != 2: raise ValueError() import matplotlib.pyplot as plt angle = np.degrees(self.angle(vertices)) plt.text(*vertices[self.origin], s=self.text, rotation=angle, ...
Plot the text using matplotlib. Parameters -------------- vertices : (n, 2) float Vertices in space show : bool If True, call plt.show()
7,675
def run(self, *args, **kwargs): if self._source is not None: return self._source.run(*args, **kwargs) else: self.queue(*args, **kwargs) return self.wait()
Queue a first item to execute, then wait for the queue to be empty before returning. This should be the default way of starting any scraper.
7,676
def isconnected(mask): nodes_to_check = list((np.where(mask[0, :])[0])[1:]) seen = [True] + [False] * (len(mask) - 1) while nodes_to_check and not all(seen): node = nodes_to_check.pop() reachable = np.where(mask[node, :])[0] for i in reachable: if not seen[i]: ...
Checks that all nodes are reachable from the first node - i.e. that the graph is fully connected.
7,677
def _shared_features(adense, bdense): a_indices = set(nonzero(adense)) b_indices = set(nonzero(bdense)) shared = list(a_indices & b_indices) diff = list(a_indices - b_indices) Ndiff = len(diff) return Ndiff
Number of features in ``adense`` that are also in ``bdense``.
7,678
def _log_prob_with_logsf_and_logcdf(self, y): logsf_y = self.log_survival_function(y) logsf_y_minus_1 = self.log_survival_function(y - 1) logcdf_y = self.log_cdf(y) logcdf_y_minus_1 = self.log_cdf(y - 1) big = tf.where(logsf_y < logcdf_y,...
Compute log_prob(y) using log survival_function and cdf together.
7,679
def getAPIKey(self, keyID=None): kcfg = self.getKeyConfig(keyID) if not in kcfg: raise ConfigException() return kcfg[]
Retrieve the NS1 API Key for the given keyID :param str keyID: optional keyID to retrieve, or current if not passed :return: API Key for the given keyID
7,680
def rollback(self): commands = [] commands.append() commands.append() self.device.run_commands(commands)
Implementation of NAPALM method rollback.
7,681
def set_user_password(environment, parameter, password): username = % (environment, parameter) return password_set(username, password)
Sets a user's password in the keyring storage
7,682
def flush_job(self, job_id, body=None, params=None): if job_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument .") return self.transport.perform_request( "POST", _make_path("_ml", "anomaly_detectors", job_id, "_flush"), ...
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html>`_ :arg job_id: The name of the job to flush :arg body: Flush parameters :arg advance_time: Advances time to the given value generating results and updating the model for the advanced interval ...
7,683
def create_channel(current): channel = Channel(name=current.input[], description=current.input[], owner=current.user, typ=15).save() with BlockSave(Subscriber): Subscriber.objects.get_or_create(user=channel.owner, ...
Create a public channel. Can be a broadcast channel or normal chat room. Chat room and broadcast distinction will be made at user subscription phase. .. code-block:: python # request: { 'view':'_zops_create_channel', 'name': string, ...
7,684
def get_conn(self): if self.conn is None: cnopts = pysftp.CnOpts() if self.no_host_key_check: cnopts.hostkeys = None cnopts.compression = self.compress conn_params = { : self.remote_host, : self.port, ...
Returns an SFTP connection object
7,685
def weighted_pixel_signals_from_images(pixels, signal_scale, regular_to_pix, galaxy_image): pixel_signals = np.zeros((pixels,)) pixel_sizes = np.zeros((pixels,)) for regular_index in range(galaxy_image.shape[0]): pixel_signals[regular_to_pix[regular_index]] += galaxy_image[regular_index] ...
Compute the (scaled) signal in each pixel, where the signal is the sum of its datas_-pixel fluxes. \ These pixel-signals are used to compute the effective regularization weight of each pixel. The pixel signals are scaled in the following ways: 1) Divided by the number of datas_-pixels in the pixel, to ens...
7,686
def odinweb_node_formatter(path_node): args = [path_node.name] if path_node.type: args.append(path_node.type.name) if path_node.type_args: args.append(path_node.type_args) return "{{{}}}".format(.join(args))
Format a node to be consumable by the `UrlPath.parse`.
7,687
def get_storyline(self, timezone_offset, first_date, start=0.0, end=0.0, track_points=False): headerscodeerrorurlhttps://api.moves-app.com/api/1.1/user/storyline/dailyjson title = % self.__class__.__name__ if {, } - set(self.service_scope): raise ValueError( % title) ...
a method to retrieve storyline details for a period of time NOTE: start and end must be no more than 30 days, 1 second apart NOTE: if track_points=True, start and end must be no more than 6 days, 1 second apart :param timezone_offset: integer with timezone offset from user profile detai...
7,688
def check_proxy_setting(): try: http_proxy = os.environ[] except KeyError: return if not http_proxy.startswith(): match = re.match(, http_proxy) os.environ[] = % (match.group(2), match.group(3)) return
If the environmental variable 'HTTP_PROXY' is set, it will most likely be in one of these forms: proxyhost:8080 http://proxyhost:8080 urlllib2 requires the proxy URL to start with 'http://' This routine does that, and returns the transport for xmlrpc.
7,689
def convert_nonParametricSeismicSource(self, node): trt = node.attrib.get() rup_pmf_data = [] rups_weights = None if in node.attrib: tmp = node.attrib.get() rups_weights = numpy.array([float(s) for s in tmp.split()]) for i, rupnode in enumerate(n...
Convert the given node into a non parametric source object. :param node: a node with tag areaGeometry :returns: a :class:`openquake.hazardlib.source.NonParametricSeismicSource` instance
7,690
def check_meta_tag(domain, prefix, code): url = .format(domain) for proto in (, ): try: req = Request(proto + url, headers={: }) res = urlopen(req, timeout=2) if res.code == 200: content = str(res.read(100000)) res...
Validates a domain by checking the existance of a <meta name="{prefix}" content="{code}"> tag in the <head> of the home page of the domain using either HTTP or HTTPs protocols. Returns true if verification suceeded.
7,691
def _create_PmtInf_node(self): ED = dict() ED[] = ET.Element("PmtInf") ED[] = ET.Element("PmtInfId") ED[] = ET.Element("PmtMtd") ED[] = ET.Element("BtchBookg") ED[] = ET.Element("NbOfTxs") ED[] = ET.Element("CtrlSum") ED[] = ET.Element("PmtTpInf...
Method to create the blank payment information nodes as a dict.
7,692
def validate(self, instance, value): if isinstance(value, string_types): if ( value.upper() not in VECTOR_DIRECTIONS or value.upper() in (, , , ) ): self.error(instance, value) value = VECTOR_DIRECTIONS[value.up...
Check shape and dtype of vector validate also coerces the vector from valid strings (these include ZERO, X, Y, -X, -Y, EAST, WEST, NORTH, and SOUTH) and scales it to the given length.
7,693
def _rdsignal(fp, file_size, header_size, n_sig, bit_width, is_signed, cut_end): fp.seek(header_size) signal_size = file_size - header_size byte_width = int(bit_width / 8) dtype = str(byte_width) if is_signed: dtype = + dtype else: dtype = + dtype d...
Read the signal Parameters ---------- cut_end : bool, optional If True, enables reading the end of files which appear to terminate with the incorrect number of samples (ie. sample not present for all channels), by checking and skipping the reading the end of such files. Chec...
7,694
def lock(self, lease_time=-1): return self._encode_invoke(lock_lock_codec, invocation_timeout=MAX_SIZE, lease_time=to_millis(lease_time), thread_id=thread_id(), reference_id=self.reference_id_generator.get_and_increment())
Acquires the lock. If a lease time is specified, lock will be released after this lease time. If the lock is not available, the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. :param lease_time: (long), time to wait before relea...
7,695
def distance(p0, p1): r return math.sqrt(dist_2(p0[0], p0[1], p1[0], p1[1]))
r"""Return the distance between two points. Parameters ---------- p0: (X,Y) ndarray Starting coordinate p1: (X,Y) ndarray Ending coordinate Returns ------- d: float distance See Also -------- dist_2
7,696
def plot_spikes(spikes, view=False, filename=None, title=None): t_values = [t for t, I, v, u, f in spikes] v_values = [v for t, I, v, u, f in spikes] u_values = [u for t, I, v, u, f in spikes] I_values = [I for t, I, v, u, f in spikes] f_values = [f for t, I, v, u, f in spikes] fig = plt.f...
Plots the trains for a single spiking neuron.
7,697
def _fix_review_dates(self, item): for date_field in [, , ]: if date_field in item.keys(): date_ts = item[date_field] item[date_field] = unixtime_to_datetime(date_ts).isoformat() if in item.keys(): for patch in item[]: p...
Convert dates so ES detect them
7,698
def add_module_definition(self, module_definition): if module_definition.identity not in self._module_definitions.keys(): self._module_definitions[module_definition.identity] = module_definition else: raise ValueError("{} has already been defined".format(module_definitio...
Add a ModuleDefinition to the document
7,699
def lookup_field_orderable(self, field): try: self.model._meta.get_field_by_name(field) return True except Exception: return False
Returns whether the passed in field is sortable or not, by default all 'raw' fields, that is fields that are part of the model are sortable.