code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def get_objects(self, force=None, last_update=None, flush=False): return self._run_object_import(force=force, last_update=last_update, flush=flush, full_history=False)
Extract routine for SQL based cubes. :param force: for querying for all objects (True) or only those passed in as list :param last_update: manual override for 'changed since date'
def unfold(tensor, mode): return np.moveaxis(tensor, mode, 0).reshape((tensor.shape[mode], -1))
Returns the mode-`mode` unfolding of `tensor`. Parameters ---------- tensor : ndarray mode : int Returns ------- ndarray unfolded_tensor of shape ``(tensor.shape[mode], -1)`` Author ------ Jean Kossaifi <https://github.com/tensorly>
def write(self): index_file = self.path new_index_file = index_file + '.new' bak_index_file = index_file + '.bak' if not self._db: return with open(new_index_file, 'w') as f: json.dump(self._db, f, indent=4) if exists(index_file): copy(...
Safely write the index data to the index file
def update_remote_archive(self, save_uri, timeout=-1): return self._client.update_with_zero_body(uri=save_uri, timeout=timeout)
Saves a backup of the appliance to a previously-configured remote location. Args: save_uri (dict): The URI for saving the backup to a previously configured location. timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operatio...
def progress(self, msg, onerror=None, sep='...', end='DONE', abrt='FAIL', prog='.', excs=(Exception,), reraise=True): if not onerror: onerror = self.error() if type(onerror) is str: onerror = self.error(msg=onerror) self.pverb(msg, end=sep) prog =...
Context manager for handling interactive prog indication This context manager streamlines presenting banners and prog indicators. To start the prog, pass ``msg`` argument as a start message. For example:: printer = Console(verbose=True) with printer.progress('Checking f...
def _decode_ctrl_packet(self, version, packet): for i in range(5): input_bit = packet[i] self._debug(PROP_LOGLEVEL_DEBUG, "Byte " + str(i) + ": " + str((input_bit >> 7) & 1) + str((input_bit >> 6) & 1) + str((input_bit >> 5) & 1) + str((input_bit >> 4) & 1) + str((input_bit >> 3) & 1) + ...
Decode a control packet into the list of sensors.
def dump_misspelling_list(self): results = [] for bad_word in sorted(self._misspelling_dict.keys()): for correction in self._misspelling_dict[bad_word]: results.append([bad_word, correction]) return results
Returns a list of misspelled words and corrections.
def bwar_pitch(return_all=False): url = "http://www.baseball-reference.com/data/war_daily_pitch.txt" s = requests.get(url).content c=pd.read_csv(io.StringIO(s.decode('utf-8'))) if return_all: return c else: cols_to_keep = ['name_common', 'mlb_ID', 'player_ID', 'year_ID', 'team_ID', '...
Get data from war_daily_pitch table. Returns WAR, its components, and a few other useful stats. To get all fields from this table, supply argument return_all=True.
def to_hierarchical(self, n_repeat, n_shuffle=1): levels = self.levels codes = [np.repeat(level_codes, n_repeat) for level_codes in self.codes] codes = [x.reshape(n_shuffle, -1).ravel(order='F') for x in codes] names = self.names warnings.warn("Method .to_hierarc...
Return a MultiIndex reshaped to conform to the shapes given by n_repeat and n_shuffle. .. deprecated:: 0.24.0 Useful to replicate and rearrange a MultiIndex for combination with another Index with n_repeat items. Parameters ---------- n_repeat : int ...
def polynomial(A, x, b, coefficients, iterations=1): A, x, b = make_system(A, x, b, formats=None) for i in range(iterations): from pyamg.util.linalg import norm if norm(x) == 0: residual = b else: residual = (b - A*x) h = coefficients[0]*residual f...
Apply a polynomial smoother to the system Ax=b. Parameters ---------- A : sparse matrix Sparse NxN matrix x : ndarray Approximate solution (length N) b : ndarray Right-hand side (length N) coefficients : array_like Coefficients of the polynomial. See Notes secti...
def merge_with(self, other): other = as_shape(other) if self._dims is None: return other else: try: self.assert_same_rank(other) new_dims = [] for i, dim in enumerate(self._dims): new_dims.append(dim.merg...
Returns a `TensorShape` combining the information in `self` and `other`. The dimensions in `self` and `other` are merged elementwise, according to the rules defined for `Dimension.merge_with()`. Args: other: Another `TensorShape`. Returns: A `TensorShape` containin...
def add_cookies_to_web_driver(driver, cookies): for cookie in cookies: driver.add_cookie(convert_cookie_to_dict(cookie)) return driver
Sets cookies in an existing WebDriver session.
def overlay_config(base, overlay): if not isinstance(base, collections.Mapping): return overlay if not isinstance(overlay, collections.Mapping): return overlay result = dict() for k in iterkeys(base): if k not in overlay: result[k] = base[k] for k, v in iteritems(...
Overlay one configuration over another. This overlays `overlay` on top of `base` as follows: * If either isn't a dictionary, returns `overlay`. * Any key in `base` not present in `overlay` is present in the result with its original value. * Any key in `overlay` with value :const:`None` is not pr...
def fixed_timezone(offset): if offset in _tz_cache: return _tz_cache[offset] tz = _FixedTimezone(offset) _tz_cache[offset] = tz return tz
Return a Timezone instance given its offset in seconds.
def outer_horizontal_border_bottom(self): return u"{lm}{lv}{hz}{rv}".format(lm=' ' * self.margins.left, lv=self.border_style.bottom_left_corner, rv=self.border_style.bottom_right_corner, ...
The complete outer bottom horizontal border section, including left and right margins. Returns: str: The bottom menu border.
def fetch_deposits_since(self, since: int) -> List[Deposit]: return self._transactions_since(self._deposits_since, 'deposits', since)
Fetch all deposits since the given timestamp.
def read_line(self): try: line = self.inp.readline().strip() except KeyboardInterrupt: raise EOFError() if not line: raise EOFError() return line
Interrupted respecting reader for stdin. Raises EOFError if the end of stream has been reached
def flags(self): return set((name.lower() for name in sorted(TIFF.FILE_FLAGS) if getattr(self, 'is_' + name)))
Return set of flags.
def system_exit(object): @functools.wraps(object) def system_exit_wrapper(*args, **kwargs): try: if object(*args, **kwargs): foundations.core.exit(0) except Exception as error: sys.stderr.write("\n".join(foundations.exceptions.format_exception(*sys.exc_inf...
Handles proper system exit in case of critical exception. :param object: Object to decorate. :type object: object :return: Object. :rtype: object
def srcname(self): if self.rpm_name or self.name.startswith(('python-', 'Python-')): return self.name_convertor.base_name(self.rpm_name or self.name)
Return srcname for the macro if the pypi name should be changed. Those cases are: - name was provided with -r option - pypi name is like python-<name>
def responses_of(self, request): responses = [response for index, response in self._responses(request)] if responses: return responses raise UnhandledHTTPRequestError( "The cassette (%r) doesn't contain the request (%r) asked for" % (self._path, request) ...
Find the responses corresponding to a request. This function isn't actually used by VCR internally, but is provided as an external API.
def purge_portlets(portal): logger.info("Purging portlets ...") def remove_portlets(context_portlet): mapping = portal.restrictedTraverse(context_portlet) for key in mapping.keys(): if key not in PORTLETS_TO_PURGE: logger.info("Skipping portlet: '{}'".format(key)) ...
Remove old portlets. Leave the Navigation portlet only
def token_address(self) -> Address: return to_canonical_address(self.proxy.contract.functions.token().call())
Return the token of this manager.
def decrypt(self, data, decode=False): result = self.cipher().decrypt_block(data) padding = self.mode().padding() if padding is not None: result = padding.reverse_pad(result, WAESMode.__data_padding_length__) return result.decode() if decode else result
Decrypt the given data with cipher that is got from AES.cipher call. :param data: data to decrypt :param decode: whether to decode bytes to str or not :return: bytes or str (depends on decode flag)
def write(self, target, *args, **kwargs): return io_registry.write(self, target, *args, **kwargs)
Write this `SegmentList` to a file Arguments and keywords depend on the output format, see the online documentation for full details for each format. Parameters ---------- target : `str` output filename Notes -----
def generate_sphinx_all(): all_nicknames = [] def add_nickname(gtype, a, b): nickname = nickname_find(gtype) try: Operation.generate_sphinx(nickname) all_nicknames.append(nickname) except Error: pass type_map...
Generate sphinx documentation. This generates a .rst file for all auto-generated image methods. Use it to regenerate the docs with something like:: $ python -c \ "import pyvips; pyvips.Operation.generate_sphinx_all()" > x And copy-paste the file contents into doc/vimage.rst in the...
def validate_overlap(comp1, comp2, force): warnings = dict() if force is None: stat = comp2.check_overlap(comp1) if stat=='full': pass elif stat == 'partial': raise(exceptions.PartialOverlap('Spectrum and bandpass do not fully overlap. You may use force=[extrap|ta...
Validate the overlap between the wavelength sets of the two given components. Parameters ---------- comp1, comp2 : `~pysynphot.spectrum.SourceSpectrum` or `~pysynphot.spectrum.SpectralElement` Source spectrum and bandpass of an observation. force : {'extrap', 'taper', `None`} If no...
def smart_query_string(parser, token): args = token.split_contents() additions = args[1:] addition_pairs = [] while additions: addition_pairs.append(additions[0:2]) additions = additions[2:] return SmartQueryStringNode(addition_pairs)
Outputs current GET query string with additions appended. Additions are provided in token pairs.
def trace_dependencies(req, requirement_set, dependencies, _visited=None): _visited = _visited or set() if req in _visited: return _visited.add(req) for reqName in req.requirements(): try: name = pkg_resources.Requirement.parse(reqName).project_name except Val...
Trace all dependency relationship @param req: requirements to trace @param requirement_set: RequirementSet @param dependencies: list for storing dependencies relationships @param _visited: visited requirement set
def pipeline_counter(self): if 'pipeline_counter' in self.data: return self.data.get('pipeline_counter') elif self.pipeline is not None: return self.pipeline.data.counter
Get pipeline counter of current stage instance. Because instantiating stage instance could be performed in different ways and those return different results, we have to check where from to get counter of the pipeline. :return: pipeline counter.
def ConnectionUpdate(self, settings): connection_path = self.connection_path NM = dbusmock.get_object(MANAGER_OBJ) settings_obj = dbusmock.get_object(SETTINGS_OBJ) main_connections = settings_obj.ListConnections() if connection_path not in main_connections: raise dbus.exceptions.DBusExceptio...
Update settings on a connection. settings is a String String Variant Map Map. See https://developer.gnome.org/NetworkManager/0.9/spec.html #type-String_String_Variant_Map_Map
def eval_ast(self, ast): new_ast = ast.replace_dict(self.replacements, leaf_operation=self._leaf_op) return backends.concrete.eval(new_ast, 1)[0]
Eval the ast, replacing symbols by their last value in the model.
def _create_sample_list(in_bams, vcf_file): out_file = "%s-sample_list.txt" % os.path.splitext(vcf_file)[0] with open(out_file, "w") as out_handle: for in_bam in in_bams: with pysam.Samfile(in_bam, "rb") as work_bam: for rg in work_bam.header.get("RG", []): ...
Pull sample names from input BAMs and create input sample list.
def foreign(self, value, context=None): if self.separator is None: separator = ' ' else: separator = self.separator.strip() if self.strip and hasattr(self.separator, 'strip') else self.separator value = self._clean(value) try: value = separator.join(value) except Exception as e: raise Concern("{0}...
Construct a string-like representation for an iterable of string-like objects.
def setup_logging(verbosity, filename=None): levels = [logging.WARNING, logging.INFO, logging.DEBUG] level = levels[min(verbosity, len(levels) - 1)] logging.root.setLevel(level) fmt = logging.Formatter('%(asctime)s %(levelname)-12s %(message)-100s ' '[%(filename)s:%(lineno)d]...
Configure logging for this tool.
def p(name="", **kwargs): with Reflect.context(**kwargs) as r: if name: instance = P_CLASS(r, stream, name, **kwargs) else: instance = P_CLASS.pop(r) instance() return instance
really quick and dirty profiling you start a profile by passing in name, you stop the top profiling by not passing in a name. You can also call this method using a with statement This is for when you just want to get a really back of envelope view of how your fast your code is, super handy, not super ...
def _nonmatch_class_pos(self): if self.kernel.classes_.shape[0] != 2: raise ValueError("Number of classes is {}, expected 2.".format( self.kernel.classes_.shape[0])) return 0
Return the position of the non-match class.
def run_transaction(self, command_list, do_commit=True): pass for c in command_list: if c.find(";") != -1 or c.find("\\G") != -1: raise Exception("The SQL command '%s' contains a semi-colon or \\G. This is a potential SQL injection." % c) if do_commit: sql...
This can be used to stage multiple commands and roll back the transaction if an error occurs. This is useful if you want to remove multiple records in multiple tables for one entity but do not want the deletion to occur if the entity is tied to table not specified in the list of commands. Perfor...
def SetupPrometheusEndpointOnPortRange(port_range, addr=''): assert os.environ.get('RUN_MAIN') != 'true', ( 'The thread-based exporter can\'t be safely used when django\'s ' 'autoreloader is active. Use the URL exporter, or start django ' 'with --noreload. See documentation/exports.md.') ...
Like SetupPrometheusEndpointOnPort, but tries several ports. This is useful when you're running Django as a WSGI application with multiple processes and you want Prometheus to discover all workers. Each worker will grab a port and you can use Prometheus to aggregate across workers. port_range may ...
def _magickfy_topics(topics): if topics is None: return None if isinstance(topics, six.string_types): topics = [topics, ] ts_ = [] for t__ in topics: if not t__.startswith(_MAGICK): if t__ and t__[0] == '/': t__ = _M...
Add the magick to the topics if missing.
def validate(cls, data, name, **kwargs): required = kwargs.get('required', False) if required and data is None: raise ValidationError("required", name, True) elif data is None: return elif kwargs.get('readonly'): return try: for key...
Validate that a piece of data meets certain conditions
def shuffle(self): args = list(self) random.shuffle(args) self.clear() super(DogeDeque, self).__init__(args)
Shuffle the deque Deques themselves do not support this, so this will make all items into a list, shuffle that list, clear the deque, and then re-init the deque.
def unimapping(arg, level): if not isinstance(arg, collections.Mapping): raise TypeError( 'expected collections.Mapping, {} received'.format(type(arg).__name__) ) result = [] for i in arg.items(): result.append( pretty_spaces(level) + u': '.join(map(functools....
Mapping object to unicode string. :type arg: collections.Mapping :param arg: mapping object :type level: int :param level: deep level :rtype: unicode :return: mapping object as unicode string
def metrics_api(self): if self._metrics_api is None: if self._use_grpc: self._metrics_api = _gapic.make_metrics_api(self) else: self._metrics_api = JSONMetricsAPI(self) return self._metrics_api
Helper for log metric-related API calls. See https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics
def add_request_ids_from_environment(logger, name, event_dict): if ENV_APIG_REQUEST_ID in os.environ: event_dict['api_request_id'] = os.environ[ENV_APIG_REQUEST_ID] if ENV_LAMBDA_REQUEST_ID in os.environ: event_dict['lambda_request_id'] = os.environ[ENV_LAMBDA_REQUEST_ID] return event_dict
Custom processor adding request IDs to the log event, if available.
def parse(source): if isinstance(source, str): return parse_stream(six.StringIO(source)) else: return parse_stream(source)
Parses source code returns an array of instructions suitable for optimization and execution by a Machine. Args: source: A string or stream containing source code.
def get_view(self): d = self.declaration if d.cached and self.widget: return self.widget if d.defer_loading: self.widget = FrameLayout(self.get_context()) app = self.get_context() app.deferred_call( lambda: self.widget.addView(s...
Get the page to display. If a view has already been created and is cached, use that otherwise initialize the view and proxy. If defer loading is used, wrap the view in a FrameLayout and defer add view until later.
def _save(self, stateName, path): print('saving...') state = {'session': dict(self.opts), 'dialogs': self.dialogs.saveState()} self.sigSave.emit(state) self.saveThread.prepare(stateName, path, self.tmp_dir_session, state) self.saveThread.start() se...
save into 'stateName' to pyz-path
def create_admin(cls, email, password, **kwargs): data = { 'email': email, 'password': cls.hash_password(password), 'has_agreed_to_terms': True, 'state': State.approved, 'role': cls.roles.administrator.value, 'organisations': {} } ...
Create an approved 'global' administrator :param email: the user's email address :param password: the user's plain text password :returns: a User
def jwt_proccessor(): def jwt(): token = current_accounts.jwt_creation_factory() return Markup( render_template( current_app.config['ACCOUNTS_JWT_DOM_TOKEN_TEMPLATE'], token=token ) ) def jwt_token(): return current_accounts...
Context processor for jwt.
def exists(self): result = TimeSeries(default=False if self.default is None else True) for t, v in self: result[t] = False if v is None else True return result
returns False when the timeseries has a None value, True otherwise
def save(self, **kwargs): translated_data = self._pop_translated_data() instance = super(TranslatableModelSerializer, self).save(**kwargs) self.save_translations(instance, translated_data) return instance
Extract the translations and save them after main object save. By default all translations will be saved no matter if creating or updating an object. Users with more complex needs might define their own save and handle translation saving themselves.
def _create_broker(self, broker_id, metadata=None): broker = Broker(broker_id, metadata) if not metadata: broker.mark_inactive() rg_id = self.extract_group(broker) group = self.rgs.setdefault(rg_id, ReplicationGroup(rg_id)) group.add_broker(broker) broker.repl...
Create a broker object and assign to a replication group. A broker object with no metadata is considered inactive. An inactive broker may or may not belong to a group.
def bind_collection_to_model_cls(cls): cls.Collection = type('{0}.Collection'.format(cls.__name__), (cls.Collection,), {'value_type': cls}) cls.Collection.__module__ = cls.__module__
Bind collection to model's class. If collection was not specialized in process of model's declaration, subclass of collection will be created.
def get_logout_uri(self, id_token_hint=None, post_logout_redirect_uri=None, state=None, session_state=None): params = {"oxd_id": self.oxd_id} if id_token_hint: params["id_token_hint"] = id_token_hint if post_logout_redirect_uri: params["post_logout_...
Function to logout the user. Parameters: * **id_token_hint (string, optional):** oxd server will use last used ID Token, if not provided * **post_logout_redirect_uri (string, optional):** URI to redirect, this uri would override the value given in the site-config * **state (...
def get_model_names(app_label, models): return dict( (model, get_model_name(app_label, model)) for model in models )
Map model names to their swapped equivalents for the given app
def insertDict(self, tblname, d, fields = None): if fields == None: fields = sorted(d.keys()) values = None try: SQL = 'INSERT INTO %s (%s) VALUES (%s)' % (tblname, join(fields, ", "), join(['%s' for x in range(len(fields))], ',')) values = tuple([d[k] for k in fields]) self.locked_execute(SQL, param...
Simple function for inserting a dictionary whose keys match the fieldnames of tblname.
def resources(self, start=1, num=10): url = self._url + "/resources" params = { "f" : "json", "start" : start, "num" : num } return self._get(url=url, param_dict=params, ...
Resources lists all file resources for the organization. The start and num paging parameters are supported. Inputs: start - the number of the first entry in the result set response The index number is 1-based and the default is 1 num - the maximum number of resu...
def _get_chemical_equation_piece(species_list, coefficients): def _get_token(species, coefficient): if coefficient == 1: return '{}'.format(species) else: return '{:g} {}'.format(coefficient, species) bag = [] for species, coefficient in zip(species_list, coefficients...
Produce a string from chemical species and their coefficients. Parameters ---------- species_list : iterable of `str` Iterable of chemical species. coefficients : iterable of `float` Nonzero stoichiometric coefficients. The length of `species_list` and `coefficients` must be the...
def _put(self, uri, data): headers = self._get_headers() logging.debug("URI=" + str(uri)) logging.debug("BODY=" + json.dumps(data)) response = self.session.put(uri, headers=headers, data=json.dumps(data)) if response.status_code in [201, 204]: return d...
Simple PUT operation for a given path.
def command_create_tables(self, meta_name=None, verbose=False): def _create_metadata_tables(metadata): for table in metadata.sorted_tables: if verbose: print(self._schema(table)) else: print(' '+table.name) engi...
Create tables according sqlalchemy data model. Is not a complex migration tool like alembic, just creates tables that does not exist:: ./manage.py sqla:create_tables [--verbose] [meta_name]
def inventory_maps(inv): revinv = {} rolnam = {} for d in inv: if d[0:3] == 'py:' and d in IntersphinxInventory.domainrole: r = IntersphinxInventory.domainrole[d] rolnam[r] = '' for n in inv[d]: p = inv[d][n][2] ...
Construct dicts facilitating information lookup in an inventory dict. A reversed dict allows lookup of a tuple specifying the sphinx cross-reference role and the name of the referenced type from the intersphinx inventory url postfix string. A role-specific name lookup string allows the s...
def apply(cls, self, *args, **kwargs): for key in kwargs: if key in [ x.name for x in cls.INPUTS ]: setattr(self, key, kwargs[key]) if key in [ x.name for x in cls.OUTPUTS ]: setattr(self, key, kwargs[key]) if key in [ x.name for x in cls.PARAMETERS ]: ...
Applies kwargs arguments to the instance passed as the first argument to the call. For defined INPUTS, OUTPUTS and PARAMETERS the method extracts a corresponding value from kwargs and sets it as an instance attribute. For example, if the processor has a 'foo' parameter declared and ...
def _generate_signature(url_path, secret_key, query_args, digest=None, encoder=None): digest = digest or DEFAULT_DIGEST encoder = encoder or DEFAULT_ENCODER msg = "%s?%s" % (url_path, '&'.join('%s=%s' % i for i in query_args.sorteditems(multi=True))) if _compat.text_type: msg = msg.encode('UTF8'...
Generate signature from pre-parsed URL.
def omit_loglevel(self, msg) -> bool: return self.loglevels and ( self.loglevels[0] > fontbakery.checkrunner.Status(msg) )
Determine if message is below log level.
def is_capable(cls, requested_capability): for c in requested_capability: if not c in cls.capability: return False return True
Returns true if the requested capability is supported by this plugin
def initialize( plugins, exclude_files_regex=None, exclude_lines_regex=None, path='.', scan_all_files=False, ): output = SecretsCollection( plugins, exclude_files=exclude_files_regex, exclude_lines=exclude_lines_regex, ) if os.path.isfile(path): files_to_s...
Scans the entire codebase for secrets, and returns a SecretsCollection object. :type plugins: tuple of detect_secrets.plugins.base.BasePlugin :param plugins: rules to initialize the SecretsCollection with. :type exclude_files_regex: str|None :type exclude_lines_regex: str|None :type path: str ...
def from_seedhex_file(path: str) -> SigningKeyType: with open(path, 'r') as fh: seedhex = fh.read() return SigningKey.from_seedhex(seedhex)
Return SigningKey instance from Seedhex file :param str path: Hexadecimal seed file path
def get_repo_relpath(repo, relpath): from os import path if relpath[0:2] == "./": return path.join(repo, relpath[2::]) else: from os import chdir, getcwd cd = getcwd() chdir(path.expanduser(repo)) result = path.abspath(relpath) chdir(cd) return result
Returns the absolute path to the 'relpath' taken relative to the base directory of the repository.
def create_and_trunk_vlan(self, nexus_host, vlan_id, intf_type, nexus_port, vni, is_native): starttime = time.time() self.create_vlan(nexus_host, vlan_id, vni) LOG.debug("NexusDriver created VLAN: %s", vlan_id) if nexus_port: self.send_enable_vla...
Create VLAN and trunk it on the specified ports.
def accounts(self): return account.HPEAccountCollection( self._conn, utils.get_subresource_path_by(self, 'Accounts'), redfish_version=self.redfish_version)
Property to provide instance of HPEAccountCollection
def push(self, metric_name=None, metric_value=None, volume=None): graphite_path = self.path_prefix graphite_path += '.' + self.device + '.' + 'volume' graphite_path += '.' + volume + '.' + metric_name metric = Metric(graphite_path, metric_value, precision=4, host=...
Ship that shit off to graphite broski
def pgettext(msgctxt, message): key = msgctxt + '\x04' + message translation = get_translation().gettext(key) return message if translation == key else translation
Particular gettext' function. It works with 'msgctxt' .po modifiers and allow duplicate keys with different translations. Python 2 don't have support for this GNU gettext function, so we reimplement it. It works by joining msgctx and msgid by '4' byte.
def _ar_matrix(self): X = np.ones(self.data_length-self.max_lag) if self.ar != 0: for i in range(0, self.ar): X = np.vstack((X,self.data[(self.max_lag-i-1):-i-1])) return X
Creates the Autoregressive matrix for the model Returns ---------- X : np.ndarray Autoregressive Matrix
def form_validation_response(self, e): resp = rc.BAD_REQUEST resp.write(' '+str(e.form.errors)) return resp
Method to return form validation error information. You will probably want to override this in your own `Resource` subclass.
def _protobuf_value_type(value): if value.HasField("number_value"): return api_pb2.DATA_TYPE_FLOAT64 if value.HasField("string_value"): return api_pb2.DATA_TYPE_STRING if value.HasField("bool_value"): return api_pb2.DATA_TYPE_BOOL return None
Returns the type of the google.protobuf.Value message as an api.DataType. Returns None if the type of 'value' is not one of the types supported in api_pb2.DataType. Args: value: google.protobuf.Value message.
def change_logger_levels(logger=None, level=logging.DEBUG): if not isinstance(logger, logging.Logger): logger = logging.getLogger(logger) logger.setLevel(level) for handler in logger.handlers: handler.level = level
Go through the logger and handlers and update their levels to the one specified. :param logger: logging name or object to modify, defaults to root logger :param level: logging level to set at (10=Debug, 20=Info, 30=Warn, 40=Error)
async def cache_instruments(self, require: Dict[top_types.Mount, str] = None): checked_require = require or {} self._log.info("Updating instrument model cache") found = self._backend.get_attached_instruments(checked_require) for mount, instrument_data in f...
- Get the attached instrument on each mount and - Cache their pipette configs from pipette-config.json If specified, the require element should be a dict of mounts to instrument models describing the instruments expected to be present. This can save a subsequent of :py:attr:`attached_i...
def cut(self): text = self.selectedText() for editor in self.editors(): editor.cut() QtGui.QApplication.clipboard().setText(text)
Cuts the text from the serial to the clipboard.
def parse_oxi_states(self, data): try: oxi_states = { data["_atom_type_symbol"][i]: str2float(data["_atom_type_oxidation_number"][i]) for i in range(len(data["_atom_type_symbol"]))} for i, symbol in enumerate(data["_atom_type_symbol"]):...
Parse oxidation states from data dictionary
def query(self): tree = pypeg2.parse(self._query, parser(), whitespace="") for walker in query_walkers(): tree = tree.accept(walker) return tree
Parse query string using given grammar. :returns: AST that represents the query in the given grammar.
def prettyln(text, fill='-', align='^', prefix='[ ', suffix=' ]', length=69): text = '{prefix}{0}{suffix}'.format(text, prefix=prefix, suffix=suffix) print( "{0:{fill}{align}{length}}".format( text, fill=fill, align=align, length=length ) )
Wrap `text` in a pretty line with maximum length.
def formfield_for_dbfield(self, db_field, **kwargs): if isinstance(db_field, fields.OrderField): kwargs['widget'] = widgets.HiddenTextInput return super(ListView, self).formfield_for_dbfield(db_field, **kwargs)
Same as parent but sets the widget for any OrderFields to HiddenTextInput.
def get_view_selection(self): if not self.MODEL_STORAGE_ID: return None, None if len(self.store) == 0: paths = [] else: model, paths = self._tree_selection.get_selected_rows() selected_model_list = [] for path in paths: model = self...
Get actual tree selection object and all respective models of selected rows
def install(zone, nodataset=False, brand_opts=None): ret = {'status': True} res = __salt__['cmd.run_all']('zoneadm -z {zone} install{nodataset}{brand_opts}'.format( zone=zone, nodataset=' -x nodataset' if nodataset else '', brand_opts=' {0}'.format(brand_opts) if brand_opts else '', ...
Install the specified zone from the system. zone : string name of the zone nodataset : boolean do not create a ZFS file system brand_opts : string brand specific options to pass CLI Example: .. code-block:: bash salt '*' zoneadm.install dolores salt '*' zo...
def my_notes(self, start_index=0, limit=100, get_all=False, sort_by='loanId', sort_dir='asc'): index = start_index notes = { 'loans': [], 'total': 0, 'result': 'success' } while True: payload = { 'sortBy': sort_by, ...
Return all the loan notes you've already invested in. By default it'll return 100 results at a time. Parameters ---------- start_index : int, optional The result index to start on. By default only 100 records will be returned at a time, so use this to start at a later in...
def fixed_length(cls, l, allow_empty=False): return cls(l, l, allow_empty=allow_empty)
Create a sedes for text data with exactly `l` encoded characters.
def create_failure(self, exception=None): if exception: return FailedFuture(type(exception), exception, None) return FailedFuture(*sys.exc_info())
This returns an object implementing IFailedFuture. If exception is None (the default) we MUST be called within an "except" block (such that sys.exc_info() returns useful information).
def get_user(self, user_id): content = self._fetch("/user/%s" % user_id) return FastlyUser(self, content)
Get a specific user.
def var(self, values, axis=0, weights=None, dtype=None): values = np.asarray(values) unique, mean = self.mean(values, axis, weights, dtype) err = values - mean.take(self.inverse, axis) if weights is None: shape = [1] * values.ndim shape[axis] = self.groups ...
compute the variance over each group Parameters ---------- values : array_like, [keys, ...] values to take variance of per group axis : int, optional alternative reduction axis for values Returns ------- unique: ndarray, [groups] ...
def close(self): self.logger = None for exc in _EXCEPTIONS: setattr(self, exc, None) try: self.mdr.close() finally: self.mdr = None
Close the connection this context wraps.
def csv_header_and_defaults(features, schema, stats, keep_target): target_name = get_target_name(features) if keep_target and not target_name: raise ValueError('Cannot find target transform') csv_header = [] record_defaults = [] for col in schema: if not keep_target and col['name'] == target_name: ...
Gets csv header and default lists.
def can_create_gradebook_with_record_types(self, gradebook_record_types): if self._catalog_session is not None: return self._catalog_session.can_create_catalog_with_record_types(catalog_record_types=gradebook_record_types) return True
Tests if this user can create a single ``Gradebook`` using the desired record types. While ``GradingManager.getGradebookRecordTypes()`` can be used to examine which records are supported, this method tests which record(s) are required for creating a specific ``Gradebook``. Providing an ...
def folderitems(self): items = super(AddAnalysesView, self).folderitems(classic=False) return items
Return folderitems as brains
def __get_default_layouts_settings(self): LOGGER.debug("> Accessing '{0}' default layouts settings file!".format(UiConstants.layouts_file)) self.__default_layouts_settings = QSettings(umbra.ui.common.get_resource_path(UiConstants.layouts_file), QSettin...
Gets the default layouts settings.
def to_feather(self, fname): from pandas.io.feather_format import to_feather to_feather(self, fname)
Write out the binary feather-format for DataFrames. .. versionadded:: 0.20.0 Parameters ---------- fname : str string file path
def _sanity_check_fold_scope_locations_are_unique(ir_blocks): observed_locations = dict() for block in ir_blocks: if isinstance(block, Fold): alternate = observed_locations.get(block.fold_scope_location, None) if alternate is not None: raise AssertionError(u'Found...
Assert that every FoldScopeLocation that exists on a Fold block is unique.
def validate_reference_data(self, ref_data): try: self._zotero_lib.check_items([ref_data]) except InvalidItemFields as e: raise InvalidZoteroItemError from e
Validate the reference data. Zotero.check_items() caches data after the first API call.
def clean(self, critical=False): clean_events_list = [] while self.len() > 0: item = self.events_list.pop() if item[1] < 0 or (not critical and item[2].startswith("CRITICAL")): clean_events_list.insert(0, item) self.events_list = clean_events_list ...
Clean the logs list by deleting finished items. By default, only delete WARNING message. If critical = True, also delete CRITICAL message.
def load_ipython_extension(ipython): import IPython ipy_version = LooseVersion(IPython.__version__) if ipy_version < LooseVersion("3.0.0"): ipython.write_err("Your IPython version is older than " "version 3.0.0, the minimum for Vispy's" "IPython ba...
Entry point of the IPython extension Parameters ---------- IPython : IPython interpreter An instance of the IPython interpreter that is handed over to the extension