code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def from_signature(cls, sig: inspect.Signature, name: str, callable_type: CallableType, module_name: Optional[str]=None, qualname: Optional[str]=None, auto_typing: bool=False, docstr: Union[str, utils.DocStr, None]=None, parent_module: Optional[types.ModuleType]=None) -> 'Signature': args = [] kwonly_args = [] ...
Returns PyGlove signature from Python signature. Args: sig: Python signature. name: Name of the entity (class name or function/method name). callable_type: the type of this callable. module_name: Module name of the entity. qualname: (Optional) qualified name of the entity. auto_typing: If True, automatically convert a...
github-repos
def from_dict(cls, d, identifier_str=None): def _print_version(value): return '.'.join(str(x) for x in value) toks = str(d["serialize_version"]).split('.') load_ver = tuple(int(x) for x in toks) curr_ver = ResolvedContext.serialize_version if load_...
Load a `ResolvedContext` from a dict. Args: d (dict): Dict containing context data. identifier_str (str): String identifying the context, this is only used to display in an error string if a serialization version mismatch is detected. Returns: `ResolvedContext` object.
juraj-google-style
def solve_fba(self, objective): self._prob.set_objective(self._v_wt[objective]) return self._solve(lp.ObjectiveSense.Maximize)
Solve the wild type problem using FBA. Args: objective: The objective reaction to be maximized. Returns: The LP Result object for the solved FBA problem.
codesearchnet
def read_tables(fstream): table = read_table(fstream) while (table is not None): (yield table) table = read_table(fstream)
Read all tables from likwid's file stream. Args: fstream: Likwid's output file stream. Returns: A generator that can be used to iterate over all tables in the fstream.
codesearchnet
def get_shape(x: tf.Tensor, name: Optional[str]=None) -> Union[tf.TensorShape, types.IntTensor]: name = 'get_shape' if name is None else name with tf.name_scope(name): x = tf.convert_to_tensor(x) is_fully_defined = x.shape.is_fully_defined() if is_fully_defined: return x.shap...
Returns static shape of `x` if it is fully defined, or dynamic, otherwise. ####Example ```python import tensorflow as tf import tf_quant_finance as tff x = tf.zeros([5, 2]) prefer_static_shape(x) # Expected: [5, 2] Args: x: A tensor of any shape and `dtype` name: Python string. The name to give to the ops created by...
github-repos
def recipe_to_colab(name, description, instructions, tasks, parameters={}, project=None, client_credentials=None, user_credentials=None, service_credentials=None): colab = Colab(name) colab.header(name) colab.paragraph(description) colab.header('License') colab.paragraph(textwrap.dedent('\n Copyr...
Converts a JSON recipe into a Jupyter Notebook for Colabs. Sets up multiple steps to execute recipe: 1. Install starthinker from repository 2. Get Cloud Project ID. 3. Get Client Credentials ( optional if User Credentials exist ). 4. Enter Recipe parameters if fields present. 5. Execute recipe tasks. Args: * name: (s...
github-repos
def __init__(self, time_elements_tuple=None): super(TimeElements, self).__init__() self._number_of_seconds = None self._precision = definitions.PRECISION_1_SECOND self._time_elements_tuple = time_elements_tuple if time_elements_tuple: if len(time_elements_tuple) < 6: raise ValueE...
Initializes time elements. Args: time_elements_tuple (Optional[tuple[int, int, int, int, int, int]]): time elements, contains year, month, day of month, hours, minutes and seconds. Raises: ValueError: if the time elements tuple is invalid.
juraj-google-style
def readInput(self, directory, projectFileName, session, spatial=False, spatialReferenceID=None): self.project_directory = directory with tmp_chdir(directory): session.add(self) self.read(directory, projectFileName, session, spatial, spatialReferenceID) if (spatialReferenceID is None): ...
Read only input files for a GSSHA project into the database. Use this method to read a project when only pre-processing tasks need to be performed. Args: directory (str): Directory containing all GSSHA model files. This method assumes that all files are located in the same directory. projectFileName (str): Name of th...
codesearchnet
def function(inputs, outputs, updates=None, name=None, **kwargs): if ops.executing_eagerly_outside_functions(): if kwargs: raise ValueError('Session keyword arguments are not supported during eager execution. You passed: %s' % (kwargs,)) if updates: raise ValueError('`updates...
Instantiates a Keras function. Args: inputs: List of placeholder tensors. outputs: List of output tensors. updates: List of update ops. name: String, name of function. **kwargs: Passed to `tf.Session.run`. Returns: Output values as Numpy arrays. Raises: ValueError: if invalid kwargs are passed in or if in eager exec...
github-repos
def _handle_offset_response(self, future, response): timestamp_offset_map = {} for topic, part_data in response.topics: for partition_info in part_data: partition, error_code = partition_info[:2] partition = TopicPartition(topic, partition) ...
Callback for the response of the list offset call above. Arguments: future (Future): the future to update based on response response (OffsetResponse): response from the server Raises: AssertionError: if response does not match partition
juraj-google-style
def api_keys(self, serverid, api_key): if serverid and api_key: self.can_query = True self.serverid = int(serverid) self.api_key = api_key self.webhook_url = self.__base_url + str(self.serverid) + '/' + self.api_key
Load object with id/API pair Args: serverid (int): Discord 'guild' webhook is attached to api_key (`str`:uuid): unique ID for webhook
juraj-google-style
def generate_name_variations(name): def _update_name_variations_with_product(set_a, set_b): name_variations.update([unidecode(((names_variation[0] + separator) + names_variation[1]).strip(''.join(_LASTNAME_NON_LASTNAME_SEPARATORS))).lower() for names_variation in product(set_a, set_b) for separator in _LAS...
Generate name variations for a given name. Args: name (six.text_type): The name whose variations are to be generated. Returns: list: All the name variations for the given name. Notes: Uses `unidecode` for doing unicode characters transliteration to ASCII ones. This was chosen so that we can map both full names of au...
codesearchnet
def create_s3_bucket(cls, bucket_name, bucket_region, bucket_account, template): s3 = get_aws_session(bucket_account).client('s3', region_name=bucket_region) try: s3.head_bucket(Bucket=bucket_name) except ClientError as ex: status_code = ex.response['Re...
Creates the S3 bucket on the account specified as the destination account for log files Args: bucket_name (`str`): Name of the S3 bucket bucket_region (`str`): AWS Region for the bucket bucket_account (:obj:`Account`): Account to create the S3 bucket in template (:obj:`Template`): Jinja2 Template object for the bucket...
juraj-google-style
def get_pixel(self, x: int, y: int) -> Tuple[int, int, int]: color = lib.TCOD_image_get_pixel(self.image_c, x, y) return color.r, color.g, color.b
Get the color of a pixel in this Image. Args: x (int): X pixel of the Image. Starting from the left at 0. y (int): Y pixel of the Image. Starting from the top at 0. Returns: Tuple[int, int, int]: An (r, g, b) tuple containing the pixels color value. Values are in a 0 to 255 range.
juraj-google-style
def add_defaults(self, ctype: ContentType = None) -> "InstanceNode": val = self.value if not (isinstance(val, StructuredValue) and self.is_internal()): return self res = self if isinstance(val, ObjectValue): if val: for mn in self._member_...
Return the receiver with defaults added recursively to its value. Args: ctype: Content type of the defaults to be added. If it is ``None``, the content type will be the same as receiver's.
juraj-google-style
def mnist_model(image, labels, mesh): batch_dim = mtf.Dimension('batch', FLAGS.batch_size) row_blocks_dim = mtf.Dimension('row_blocks', 4) col_blocks_dim = mtf.Dimension('col_blocks', 4) rows_dim = mtf.Dimension('rows_size', 7) cols_dim = mtf.Dimension('cols_size', 7) classes_dim = mtf.Dimension...
The model. Args: image: tf.Tensor with shape [batch, 28*28] labels: a tf.Tensor with shape [batch] and dtype tf.int32 mesh: a mtf.Mesh Returns: logits: a mtf.Tensor with shape [batch, 10] loss: a mtf.Tensor with shape []
codesearchnet
def set_charge_and_spin(self, charge, spin_multiplicity=None): self._charge = charge nelectrons = 0 for site in self._sites: for sp, amt in site.species.items(): if not isinstance(sp, DummySpecie): nelectrons += sp.Z * amt nelectro...
Set the charge and spin multiplicity. Args: charge (int): Charge for the molecule. Defaults to 0. spin_multiplicity (int): Spin multiplicity for molecule. Defaults to None, which means that the spin multiplicity is set to 1 if the molecule has no unpaired electrons and to 2 if there are unpaired electrons.
juraj-google-style
def __init__(self, conf, map_name, automount_mountpoint=None): super(Cache, self).__init__() self.log = logging.getLogger(__name__) self.conf = conf self.output_dir = conf.get('dir', '.') self.automount_mountpoint = automount_mountpoint self.map_name = map_name if map_name == config.MAP_PASS...
Initialise the Cache object. Args: conf: A dictionary of key/value pairs map_name: A string representation of the map type automount_mountpoint: A string containing the automount mountpoint, used only by automount maps. Raises: UnsupportedMap: for map types we don't know about
github-repos
def _bind_topics(self, topics): self.client.subscribe(topics.status, self._on_status_message) self.client.subscribe(topics.tracing, self._on_trace) self.client.subscribe(topics.streaming, self._on_report) self.client.subscribe(topics.response, self._on_response_message)
Subscribe to all the topics we need to communication with this device Args: topics (MQTTTopicValidator): The topic validator for this device that we are connecting to.
codesearchnet
def to_variable(self, node: 'cfg.CFGNode') -> 'cfg.Variable': return self.ctx.program.NewVariable([self], source_set=[], where=node)
Build a variable out of this abstract value. Args: node: The current CFG node. Returns: A cfg.Variable.
github-repos
def _setup_class(self): class_record = records.TestResultRecord(STAGE_NAME_SETUP_CLASS, self.TAG) class_record.test_begin() self.current_test_info = runtime_test_info.RuntimeTestInfo(STAGE_NAME_SETUP_CLASS, self.log_path, class_record) expects.recorder.reset_internal_states(class_record) try: ...
Proxy function to guarantee the base implementation of setup_class is called. Returns: If `self.results` is returned instead of None, this means something has gone wrong, and the rest of the test class should not execute.
github-repos
def TensorShapeProtoToList(shape): return [dim.size for dim in shape.dim]
Convert a TensorShape to a list. Args: shape: A TensorShapeProto. Returns: List of integers representing the dimensions of the tensor.
github-repos
def BuildCampaignOperations(batch_job_helper, budget_operations, number_of_campaigns=1): budget_id = budget_operations[0]['operand']['budgetId'] campaign_operations = [{'xsi_type': 'CampaignOperation', 'operand': {'name': ('Batch Campaign return campaign_operations
Builds the operations needed to create a new Campaign. Note: When the Campaigns are created, they will have a different Id than those generated here as a temporary Id. This is just used to identify them in the BatchJobService. Args: batch_job_helper: a BatchJobHelper instance. budget_operations: a list containing the...
codesearchnet
def swo_start(self, swo_speed=9600): if self.swo_enabled(): self.swo_stop() info = structs.JLinkSWOStartInfo() info.Speed = swo_speed res = self._dll.JLINKARM_SWO_Control(enums.JLinkSWOCommands.START, ctypes.byref(info)) ...
Starts collecting SWO data. Note: If SWO is already enabled, it will first stop SWO before enabling it again. Args: self (JLink): the ``JLink`` instance swo_speed (int): the frequency in Hz used by the target to communicate Returns: ``None`` Raises: JLinkException: on error
juraj-google-style
def setup(self, hunt_id, reason, grr_server_url, grr_username, grr_password, approvers=None, verify=True): super(GRRHuntDownloader, self).setup( reason, grr_server_url, grr_username, grr_password, approvers=approvers, verify=verify) self.hunt_id = hunt_id...
Initializes a GRR Hunt file collector. Args: hunt_id: Hunt ID to download results from. reason: justification for GRR access. grr_server_url: GRR server URL. grr_username: GRR username. grr_password: GRR password. approvers: comma-separated list of GRR approval recipients. verify: boolean, whether to verify the GRR se...
juraj-google-style
def __init__(self, email, password): self.email = email self.password = password
Initialize the AMYLPRED object with your email and password used to login here. Args: email (str): Account email password (str): Account password
juraj-google-style
def render_to_terminal(self, array, cursor_pos=(0, 0)): for_stdout = self.fmtstr_to_stdout_xform() if (not self.hide_cursor): self.write(self.t.hide_cursor) (height, width) = (self.t.height, self.t.width) if ((height != self._last_rendered_height) or (width != self._last_rendered_width)): ...
Renders array to terminal, returns the number of lines scrolled offscreen Returns: Number of times scrolled Args: array (FSArray): Grid of styled characters to be rendered. If array received is of width too small, render it anyway if array received is of width too large, render it anyway if array received is of he...
codesearchnet
def json(self) -> list: json_controls = [control.json() for control in self.controls] return json_controls
Returns list of json compatible states of the RichMessage instance nested controls. Returns: json_controls: Json representation of RichMessage instance nested controls.
codesearchnet
def _can_connect(host, port=22): try: logger.debug('Testing connection to host %s', host) client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(host, port=port) ...
Checks if the connection to provided ``host`` and ``port`` is possible or not. Args: host (str): Hostname for the host to check connection. port (int): Port name of the host to check connection on.
juraj-google-style
def __getitem__(self, key: Any) -> 'ColumnExpressionBuilder': item = self._builder[key] if isinstance(item, expressions.Builder) and self._sealed: raise self._fhir_path_sealed_error(key) return ColumnExpressionBuilder._wrap_any(self, item)
Redirects to the expressions.Builder to get the item. Args: key: the key of the item. Returns: A ColumnExpressionBuilder, because the item got from the expressions.Builder is always the type of Builder. Raises: AttributeError: if the FHIR path in this class is already sealed. TypeError: if getting the key from self....
github-repos
def inference(self, observed_arr): decoded_arr = self.__encoder_decoder_controller.inference(observed_arr) encoded_arr = self.__encoder_decoder_controller.get_feature_points() _ = self.__retrospective_encoder.inference(decoded_arr) re_encoded_arr = self.__retrospective_encoder.g...
Infernece by the model. Args: observed_arr: `np.ndarray` of observed data points. Returns: `np.ndarray` of inferenced feature points.
juraj-google-style
def astype(self, col_dtypes, **kwargs): dtype_indices = {} columns = col_dtypes.keys() numeric_indices = list(self.columns.get_indexer_for(columns)) new_dtypes = self.dtypes.copy() for i, column in enumerate(columns): dtype = col_dtypes[colu...
Converts columns dtypes to given dtypes. Args: col_dtypes: Dictionary of {col: dtype,...} where col is the column name and dtype is a numpy dtype. Returns: DataFrame with updated dtypes.
juraj-google-style
def gradient_helper(optimizer, loss, var_list=None): if (var_list is None): var_list = tf.compat.v1.trainable_variables() grads_and_vars = optimizer.compute_gradients(loss, var_list=var_list) grads = [pair[0] for pair in grads_and_vars] return (grads, optimizer.apply_gradients(grads_and_vars))
A helper to get the gradients out at each step. Args: optimizer: the optimizer op. loss: the op that computes your loss value. Returns: the gradient tensors and the train_step op.
codesearchnet
def save_as(self, new_filename): xfile._save_file( self._filename, self._workbookTree, new_filename)
Save our file with the name provided. Args: new_filename: New name for the workbook file. String. Returns: Nothing.
juraj-google-style
def to_element(self, include_namespaces=False): didl_item = DidlItem( title="DUMMY", parent_id="DUMMY", item_id=self.item_id, desc=self.desc, resources=self.resources ) return didl_item.to_element(includ...
Return an ElementTree Element representing this instance. Args: include_namespaces (bool, optional): If True, include xml namespace attributes on the root element Return: ~xml.etree.ElementTree.Element: The (XML) Element representation of this object
juraj-google-style
def member_command(self, repl_id, member_id, command): repl = self[repl_id] result = repl.member_command(member_id, command) self[repl_id] = repl return result
apply command(start, stop, restart) to the member of replica set Args: repl_id - replica set identity member_id - member index command - command: start, stop, restart return True if operation success otherwise False
juraj-google-style
def trace_region(self, region_index): cmd = enums.JLinkTraceCommand.GET_REGION_PROPS_EX region = structs.JLinkTraceRegion() region.RegionIndex = int(region_index) res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(region)) if (res == 1): raise errors.JL...
Retrieves the properties of a trace region. Args: self (JLink): the ``JLink`` instance. region_index (int): the trace region index. Returns: An instance of ``JLinkTraceRegion`` describing the specified region.
juraj-google-style
def _det_large_enough_mask(x, det_bounds): return tf.cast(tf.linalg.det(x) > det_bounds, dtype=x.dtype)
Returns whether the input matches the given determinant limit. Args: x: A floating-point `Tensor` of shape `[B1, ..., Bn, M, M]`. det_bounds: A floating-point `Tensor` that must broadcast to shape `[B1, ..., Bn]`, giving the desired lower bound on the determinants in `x`. Returns: mask: A floating-point `Tensor` of s...
juraj-google-style
def depth_soil_conductivity(self, value=None): if (value is not None): try: value = float(value) except ValueError: raise ValueError('value {} need to be of type float for field `depth_soil_conductivity`'.format(value)) self._depth_soil_conductivity = value
Corresponds to IDD Field `depth_soil_conductivity` Args: value (float): value for IDD Field `depth_soil_conductivity` Unit: W/m-K, if `value` is None it will not be checked against the specification and is assumed to be a missing value Raises: ValueError: if `value` is not a valid value
codesearchnet
def join(self) -> None: self._server.join()
Blocks until the server has shut down. This is useful when starting a dedicated worker process. ``` worker_server = tf.data.experimental.service.WorkerServer( port=5051, dispatcher_address="localhost:5050") worker_server.join() ``` This method currently blocks forever. Raises: tf.errors.OpError: Or one of its subcl...
github-repos
def _write_version(self, data, model): vdata = {'data': data, 'key': model.key, 'model': model.Meta.bucket_name, 'timestamp': time.time()} obj = version_bucket.new(data=vdata) obj.add_index('key_bin', model.key) obj.add_index('model_bin', vdata['model']) obj.add_index('timestamp_int', int(vdata['tim...
Writes a copy of the objects current state to write-once mirror bucket. Args: data (dict): Model instance's all data for versioning. model (instance): Model instance. Returns: Key of version record. key (str): Version_bucket key.
codesearchnet
def floor(cls, x: 'TensorFluent') -> 'TensorFluent': return cls._unary_op(x, tf.floor, tf.float32)
Returns a TensorFluent for the floor function. Args: x: The input fluent. Returns: A TensorFluent wrapping the floor function.
juraj-google-style
def parse_struct(path_dir): with open(os.path.join(path_dir, "boltztrap.struct"), 'r') as f: tokens = f.readlines() return Lattice([[Length(float(tokens[i].split()[j]), "bohr"). to("ang") for j in range(3)] for i in range(1,...
Parses boltztrap.struct file (only the volume) Args: path_dir: (str) dir containing the boltztrap.struct file Returns: (float) volume
juraj-google-style
def get_is_group_maintainer(self, grp_name, user): self.project_service.set_auth(self._token_project) return self.project_service.get_is_group_maintainer(grp_name, user)
Check if the given user is a member of the named group. Args: name (string): Name of group. user (string): User of interest. Returns: (bool): False if user not a member.
juraj-google-style
def flatten_with_path(structure): return tree_impl.flatten_with_path(structure)
Flattens a possibly nested structure into a list. This is a variant of flattens() which produces a list of pairs: `(path, item)`. A path is a tuple of indices and/or keys which uniquely identifies the position of the corresponding item. Dictionaries with non-sortable keys are not supported. Examples: >>> keras.flat...
github-repos
def __init__(self, shape=None, dtype=dtypes.float32, ragged_rank=None, row_splits_dtype=dtypes.int64, flat_values_spec=None): self._shape = tensor_shape.as_shape(shape) self._row_splits_dtype = dtypes.as_dtype(row_splits_dtype) if flat_values_spec is not None: if dtype is None: dtype = f...
Constructs a type specification for a `tf.RaggedTensor`. Args: shape: The shape of the RaggedTensor, or `None` to allow any shape. If a shape is specified, then all ragged dimensions must have size `None`. dtype: `tf.DType` of values in the RaggedTensor. ragged_rank: Python integer, the number of times the RaggedTens...
github-repos
def read_int32(self, little_endian=True): if little_endian: endian = '<' else: endian = '>' return self.unpack(('%si' % endian), 4)
Read 4 bytes as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
codesearchnet
def delta_hv(scatterer): Z = scatterer.get_Z() return np.arctan2((Z[(2, 3)] - Z[(3, 2)]), ((- Z[(2, 2)]) - Z[(3, 3)]))
Delta_hv for the current setup. Args: scatterer: a Scatterer instance. Returns: Delta_hv [rad].
codesearchnet
def GetMountPoint(self, path=None): path = os.path.abspath( client_utils.CanonicalPathToLocalPath(path or self.path)) while not os.path.ismount(path): path = os.path.dirname(path) return path
Walk back from the path to find the mount point. Args: path: a Unicode string containing the path or None. If path is None the value in self.path is used. Returns: path string of the mount point
juraj-google-style
def do_phonefy(self, query, **kwargs): results = [] test = self.check_phonefy(query, kwargs) if test: r = {'type': 'i3visio.phone', 'value': ((self.platformName + ' - ') + query), 'attributes': []} try: aux = {'type': 'i3visio.uri', 'value': self.createURL(query, mode='phonefy'),...
Verifying a phonefy query in this platform. This might be redefined in any class inheriting from Platform. Args: ----- query: The element to be searched. Return: ------- A list of elements to be appended.
codesearchnet
def Run(script, container=None, exit_on_error=False, gas=Fixed8.Zero(), test_mode=True): from neo.Core.Blockchain import Blockchain from neo.SmartContract.StateMachine import StateMachine from neo.EventHub import events bc = Blockchain.Default() accounts = DBCollectio...
Runs a script in a test invoke environment Args: script (bytes): The script to run container (neo.Core.TX.Transaction): [optional] the transaction to use as the script container Returns: ApplicationEngine
juraj-google-style
def save(self, data: List[dict]): with open(self.output_path, 'w') as f: if len(data) > 0: writer = csv.DictWriter(f, list(data[0].keys())) writer.writeheader() writer.writerows(data)
Save the provided data object with the representation for the current [`~pipelines.PipelineDataFormat`]. Args: data (`List[dict]`): The data to store.
github-repos
def _check_archive_signature(archive_file: io.BufferedIOBase) -> None: signature = archive_file.read(8) if signature != b'!<arch>\n': raise RuntimeError('Invalid archive file format.')
Checks if the file has the correct archive header signature. The cursor is moved to the first available file header section after successfully checking the signature. Args: archive_file: The archive file object pointing at its beginning. Raises: RuntimeError: The archive signature is invalid.
github-repos
def __init__(self, job_id=None, future=None): self._job_id = str(uuid.uuid4()) if job_id is None else job_id self._future = future self._is_complete = False self._errors = None self._fatal_error = None self._result = None self._start_time = datetime.datetime.utcnow() self._end_time ...
Initializes an instance of a Job. Args: job_id: a unique ID for the job. If None, a UUID will be generated. future: the Future associated with the Job, if any.
juraj-google-style
def get_orientation_error(target_orn, current_orn): current_orn = np.array( [current_orn[3], current_orn[0], current_orn[1], current_orn[2]] ) target_orn = np.array([target_orn[3], target_orn[0], target_orn[1], target_orn[2]]) pinv = np.zeros((3, 4)) pinv[0, :] = [-current_orn[1], curr...
Returns the difference between two quaternion orientations as a 3 DOF numpy array. For use in an impedance controller / task-space PD controller. Args: target_orn: 4-dim iterable, desired orientation as a (x, y, z, w) quaternion current_orn: 4-dim iterable, current orientation as a (x, y, z, w) quaternion Returns: or...
juraj-google-style
def clean_file(c_source, virtualenv_dirname): with open(c_source, 'r') as file_obj: contents = file_obj.read().rstrip() py_version = 'python{}.{}'.format(*sys.version_info[:2]) lib_path = os.path.join('.nox', virtualenv_dirname, 'lib', py_version, 'site-packages', '') contents = contents.replace...
Strip trailing whitespace and clean up "local" names in C source. These source files are autogenerated from the ``cython`` CLI. Args: c_source (str): Path to a ``.c`` source file. virtualenv_dirname (str): The name of the ``virtualenv`` directory where Cython is installed (this is part of a relative path ``.nox/{NAME...
codesearchnet
def load_notebook_node(notebook_path): nb = nbformat.reads(papermill_io.read(notebook_path), as_version=4) if not hasattr(nb.metadata, 'papermill'): nb.metadata['papermill'] = { 'parameters': dict(), 'environment_variables': dict(), 'version': __version__, ...
Returns a notebook object with papermill metadata loaded from the specified path. Args: notebook_path (str): Path to the notebook file. Returns: nbformat.NotebookNode
juraj-google-style
def _ReadLabels(self, artifact_definition_values, artifact_definition, name): labels = artifact_definition_values.get('labels', []) undefined_labels = set(labels).difference(self.labels) if undefined_labels: raise errors.FormatError( 'Artifact definition: {0:s} found undefined labels: ...
Reads the optional artifact definition labels. Args: artifact_definition_values (dict[str, object]): artifact definition values. artifact_definition (ArtifactDefinition): an artifact definition. name (str): name of the artifact definition. Raises: FormatError: if there are undefined labels.
juraj-google-style
def remove_droplets(self, droplet_ids): return self.get_data( "load_balancers/%s/droplets/" % self.id, type=DELETE, params={"droplet_ids": droplet_ids} )
Unassign a LoadBalancer. Args: droplet_ids (obj:`list` of `int`): A list of Droplet IDs
juraj-google-style
def register_once(event_name: str, callback: Callable[..., None], info: Hashable) -> None: ip = IPython.get_ipython() info = hash(info) for old_callback in ip.events.callbacks[event_name]: if getattr(old_callback, '__ecolab_event__', None) == info: ip.events.unregister(event_name, old_ca...
Register the IPython event once (replace the previous event if exists). Alias for `InteractiveShell.events.register` but replaces previous event if it exists. This avoids duplicated events after ecolab reload or running cell twice. Args: event_name: Forwarded to `ip.events.register` callback: Forwarded to `ip.events...
github-repos
def tox(args=''): basedir = dirname(__file__) latest_pythons = _determine_latest_pythons() highest_minor_python = _highest_minor(latest_pythons) _local_needs_pythons(flo('cd {basedir} && python{highest_minor_python} -m tox {args}'))
Run tox. Build package and run unit tests against several pythons. Args: args: Optional arguments passed to tox. Example: fab tox:'-e py36 -r'
codesearchnet
def can_encode(nested_structure): try: encode_structure(nested_structure) except NotEncodableError: return False return True
Determines whether a nested structure can be encoded into a proto. Args: nested_structure: Structure to encode. Returns: True if the nested structured can be encoded.
github-repos
def __init__(self, protojson_protocol=None, **kwargs): super(MessageJSONEncoder, self).__init__(**kwargs) self.__protojson_protocol = ( protojson_protocol or ProtoJson.get_default())
Constructor. Args: protojson_protocol: ProtoJson instance.
juraj-google-style
def replace_666(meta_df, convert_neg_666): if convert_neg_666: out_df = meta_df.replace([-666, "-666", -666.0], np.nan) else: out_df = meta_df.replace([-666, -666.0], "-666") return out_df
Replace -666, -666.0, and optionally "-666". Args: meta_df (pandas df): convert_neg_666 (bool): Returns: out_df (pandas df): updated meta_df
juraj-google-style
def from_json(cls, json_value: JSONValueType, **kwargs) -> 'JSONConvertible': assert isinstance(json_value, dict) init_args = {k: from_json(v, **kwargs) for k, v in json_value.items() if k != JSONConvertible.TYPE_NAME_KEY} return cls(**init_args)
Creates an instance of this class from a plain Python value. NOTE(daiyip): ``pg.Symbolic`` overrides ``from_json`` class method. Args: json_value: JSON value type. **kwargs: Keyword arguments as flags to control object creation. Returns: An instance of cls.
github-repos
def get(pb_or_dict, key, default=_SENTINEL): (key, subkey) = _resolve_subkeys(key) if isinstance(pb_or_dict, Message): answer = getattr(pb_or_dict, key, default) elif isinstance(pb_or_dict, collections.Mapping): answer = pb_or_dict.get(key, default) else: raise TypeError('Tried t...
Retrieve the given key off of the object. If a default is specified, return it if the key is not found, otherwise raise KeyError. Args: pb_or_dict (Union[~google.protobuf.message.Message, Mapping]): the object. key (str): The key to retrieve from the object in question. default (Any): If the key is not present on the...
codesearchnet
def HasIndex(self, index): for i in self.Items: if i.index == index: return True return False
Flag indicating the index exists in any of the spent coin items. Args: index (int): Returns:
juraj-google-style
def data_to_unicode(self, data): if isinstance(data, dict): return {self.to_unicode(k): self.to_unicode(v) for k, v in data.iteritems()} if isinstance(data, list): return [self.to_unicode(l) for l in data] else: return self.to_unicode(data)
Recursively convert a list or dictionary to unicode. Args: data: The data to be unicoded. Returns: Unicoded data.
juraj-google-style
def parse(type: Type): def decorator(parser): EnvVar.parsers[type] = parser return parser return decorator
Register a parser for a attribute type. Parsers will be used to parse `str` type objects from either the commandline arguments or environment variables. Args: type: the type the decorated function will be responsible for parsing a environment variable to.
juraj-google-style
def build_image(image_path, image_name, build_args=None, dockerfile_path=None): cmd = ['docker', 'build', '-t', image_name, image_path] if dockerfile_path: cmd.extend(['-f', dockerfile_path]) for (k, v) in (build_args or {}).items(): cmd += ['--build-arg', '{}={}'.format(k, v)] check_cal...
Build an image Args: image_path (str): the path to the image directory image_name (str): image 'name:tag' to build build_args (dict, optional): dict of docker build arguments dockerfile_path (str, optional): path to dockerfile relative to image_path if not `image_path/Dockerfile`.
codesearchnet
def decode_base64_dict(data): b64 = base64.b64decode(data['__ndarray__']) array = np.copy(np.frombuffer(b64, dtype=data['dtype'])) if len(data['shape']) > 1: array = array.reshape(data['shape']) return array
Decode a base64 encoded array into a NumPy array. Args: data (dict) : encoded array data to decode Data should have the format encoded by :func:`encode_base64_dict`. Returns: np.ndarray
juraj-google-style
def datetime_string(day, month, year, hour, minute): if hour < 0 or hour > 23: hour = 0 if minute < 0 or minute > 60: minute = 0 return '%d-%02d-%02dT%02d:%02d:00' % (year, month, day, hour, minute)
Build a date string using the provided day, month, year numbers. Automatically adds a leading zero to ``day`` and ``month`` if they only have one digit. Args: day (int): Day number. month(int): Month number. year(int): Year number. hour (int): Hour of the day in 24h format. minute (int): Minute of the hour. Returns:...
juraj-google-style
def _download_mlu_data(tmp_dir, data_dir): if not tf.gfile.Exists(data_dir): tf.gfile.MakeDirs(data_dir) filename = os.path.basename(_URL) file_path = os.path.join(tmp_dir, filename) headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) " "AppleWebKit/537.3...
Downloads and extracts the dataset. Args: tmp_dir: temp directory to download and extract the dataset data_dir: The base directory where data and vocab files are stored. Returns: tmp_dir: temp directory containing the raw data.
juraj-google-style
def push_plugin(self, name): url = self._url('/plugins/{0}/pull', name) headers = {} registry, repo_name = auth.resolve_repository_name(name) header = auth.get_config_header(self, registry) if header: headers['X-Registry-Auth'] = header res = self._p...
Push a plugin to the registry. Args: name (string): Name of the plugin to upload. The ``:latest`` tag is optional, and is the default if omitted. Returns: ``True`` if successful
juraj-google-style
class Document(object): def __init__(self, content: str, type: Union[str, language_v1.Document.Type]='PLAIN_TEXT', language_hint: Optional[str]=None, encoding: Optional[str]='UTF8', from_gcs: bool=False): self.content = content self.type = type self.encoding = encoding self.language...
Represents the input to :class:`AnnotateText` transform. Args: content (str): The content of the input or the Google Cloud Storage URI where the file is stored. type (`Union[str, google.cloud.language_v1.Document.Type]`): Text type. Possible values are `HTML`, `PLAIN_TEXT`. The default value is `PLAIN_TEXT`. language_...
github-repos
def GetDecoder(cls, encoding_method): encoding_method = encoding_method.lower() decoder = cls._decoders.get(encoding_method, None) if not decoder: return None return decoder()
Retrieves the decoder object for a specific encoding method. Args: encoding_method (str): encoding method identifier. Returns: Decoder: decoder or None if the encoding method does not exists.
juraj-google-style
def _ToJSonObj(self, columns_order=None, order_by=()): if (columns_order is None): columns_order = [col['id'] for col in self.__columns] col_dict = dict([(col['id'], col) for col in self.__columns]) col_objs = [] for col_id in columns_order: col_obj = {'id': col_dict[col_id]['id'], 'labe...
Returns an object suitable to be converted to JSON. Args: columns_order: Optional. A list of all column IDs in the order in which you want them created in the output table. If specified, all column IDs must be present. order_by: Optional. Specifies the name of the column(s) to sort by. Passed as is to _PreparedData()....
codesearchnet
def console_fill_foreground(con: tcod.console.Console, r: Sequence[int], g: Sequence[int], b: Sequence[int]) -> None: if ((len(r) != len(g)) or (len(r) != len(b))): raise TypeError('R, G and B must all have the same size.') if (isinstance(r, np.ndarray) and isinstance(g, np.ndarray) and isinstance(b, np...
Fill the foregound of a console with r,g,b. Args: con (Console): Any Console instance. r (Sequence[int]): An array of integers with a length of width*height. g (Sequence[int]): An array of integers with a length of width*height. b (Sequence[int]): An array of integers with a length of width*height. .. deprecated:: 8....
codesearchnet
def make_path(path: PathLike) -> abstract_path.Path: is_windows = os.name == 'nt' if isinstance(path, str): uri_splits = path.split(': if len(uri_splits) > 1: return _URI_PREFIXES_TO_CLS[uri_splits[0] + ': elif is_windows: return gpath.WindowsGPath(path) e...
Create a generic `pathlib.Path`-like abstraction. Depending on the input (e.g. `gs://`, `github://`, `ResourcePath`,...), the system (Windows, Linux,...), the function will create the right pathlib-like abstraction. Args: path: Pathlike object. Returns: path: The `pathlib.Path`-like abstraction.
github-repos
def _collect_certificate_data(self, enterprise_enrollment): if (self.certificates_api is None): self.certificates_api = CertificatesApiClient(self.user) course_id = enterprise_enrollment.course_id username = enterprise_enrollment.enterprise_customer_user.user.username try: certificate = ...
Collect the learner completion data from the course certificate. Used for Instructor-paced courses. If no certificate is found, then returns the completed_date = None, grade = In Progress, on the idea that a certificate will eventually be generated. Args: enterprise_enrollment (EnterpriseCourseEnrollment): the enter...
codesearchnet
def version(msg): tc = typecode(msg) if (tc != 31): raise RuntimeError(('%s: Not a status operation message, expecting TC = 31' % msg)) msgbin = common.hex2bin(msg) version = common.bin2int(msgbin[72:75]) return version
ADS-B Version Args: msg (string): 28 bytes hexadecimal message string, TC = 31 Returns: int: version number
codesearchnet
def _save_private_file(filename, json_contents): temp_filename = tempfile.mktemp() file_desc = os.open(temp_filename, os.O_WRONLY | os.O_CREAT, 0o600) with os.fdopen(file_desc, 'w') as file_handle: json.dump(json_contents, file_handle, sort_keys=True, indent=2, separators=(','...
Saves a file with read-write permissions on for the owner. Args: filename: String. Absolute path to file. json_contents: JSON serializable object to be saved.
juraj-google-style
def __init__(self, chgcar): self.chgcar = chgcar self.structure = chgcar.structure self.extrema_coords = [] self.extrema_type = None self._extrema_df = None self._charge_distribution_df = None
Initialization. Args: chgcar (pmg.Chgcar): input Chgcar object.
juraj-google-style
def generate_password(length=32): return ''.join((random.SystemRandom().choice((string.ascii_letters + '!@
Generate a cryptographically secure random string to use for passwords Args: length (int): Length of password, defaults to 32 characters Returns: Randomly generated string
codesearchnet
def _ParseIndexTable(self, file_object): cache_address_map = self._GetDataTypeMap('uint32le') file_offset = file_object.get_offset() cache_address_data = file_object.read(4) while len(cache_address_data) == 4: try: value = self._ReadStructureFromByteStream( cache_address...
Parses the index table. Args: file_object (dfvfs.FileIO): a file-like object to parse. Raises: ParseError: if the index table cannot be read.
juraj-google-style
def render_list(self, cnt, unique=False, progress_callback=None, **kwargs): rendered_list = [] i = 0 total_attempts = 0 while True: if (i >= cnt): break if (total_attempts > (cnt * self.unique_attempts_factor)): raise StringGenerator.UniquenessError(u"couldn't sat...
Return a list of generated strings. Args: cnt (int): length of list unique (bool): whether to make entries unique Returns: list. We keep track of total attempts because a template may specify something impossible to attain, like [1-9]{} with cnt==1000
codesearchnet
def get_initialized_tpu_systems(): return _INITIALIZED_TPU_SYSTEMS.copy()
Returns all currently initialized tpu systems. Returns: A dictionary, with tpu name as the key and the tpu topology as the value.
github-repos
def _parse_book_links(dom): links = [] picker = lambda x: x.params.get("class", "").startswith("boxProKnihy") for el in dom.find(None, fn=picker): book_ref = el.find("a") if not book_ref or "href" not in book_ref[0].params: continue links.append(book_ref[0].params...
Parse links to the details about publications from page with book list. Args: dom (obj): HTMLElement container of the page with book list. Returns: list: List of strings / absolute links to book details.
juraj-google-style
def read_raster(raster_file): ds = gdal_Open(raster_file) band = ds.GetRasterBand(1) data = band.ReadAsArray() xsize = band.XSize ysize = band.YSize nodata_value = band.GetNoDataValue() geotrans = ds.GetGeoTransform() dttype = band.DataType ...
Read raster by GDAL. Args: raster_file: raster file path. Returns: Raster object.
juraj-google-style
def get_fixers(self): pre_order_fixers = [] post_order_fixers = [] for fix_mod_path in self.fixers: mod = __import__(fix_mod_path, {}, {}, ['*']) fix_name = fix_mod_path.rsplit('.', 1)[(- 1)] if fix_name.startswith(self.FILE_PREFIX): fix_name = fix_name[len(self.FILE_PREF...
Inspects the options to load the requested patterns and handlers. Returns: (pre_order, post_order), where pre_order is the list of fixers that want a pre-order AST traversal, and post_order is the list that want post-order traversal.
codesearchnet
def simulate_phases(self, phase_map: Dict[(Tuple[(int, ...)], float)]): self._pool.map(_clear_scratch, self._shard_num_args()) for (indices, half_turns) in phase_map.items(): args = self._shard_num_args({'indices': indices, 'half_turns': half_turns}) if (len(indices) == 1): self._poo...
Simulate a set of phase gates on the xmon architecture. Args: phase_map: A map from a tuple of indices to a value, one for each phase gate being simulated. If the tuple key has one index, then this is a Z phase gate on the index-th qubit with a rotation angle of pi times the value of the map. If the tuple key has two ...
codesearchnet
def get_script_module(script_information, package='pylabcontrol', verbose=False): module, _, _, _, _, _, _ = Script.get_script_information(script_information=script_information, package=package, verbose=verbose) return module
wrapper to get the module for a script Args: script_information: information of the script. This can be - a dictionary - a Script instance - name of Script class package (optional): name of the package to which the script belongs, i.e. pylabcontrol or b26toolkit only used when script_information is a string Returns: m...
juraj-google-style
def parse_columns(lines): data = [] index = [] for line in lines: line = line.rstrip() if line.startswith(" tmp = __parse_entry(line) data.append(tmp[1]) index.append(tmp[0]) return DataFrame(data, index=index, columns=['description'])
Parse list of lines with columns description from SOFT file. Args: lines (:obj:`Iterable`): Iterator over the lines. Returns: :obj:`pandas.DataFrame`: Columns description.
juraj-google-style
def virt_customize(self, options): cmd = ['virt-customize', '-a', self.disk_path] if 'ssh-inject' in options and not options['ssh-inject']: options['ssh-inject'] = 'root:file:{}'.format( self.paths.ssh_id_rsa_pub() ) options = self.normalize_opti...
Handler for 'virt-customize' note: if 'ssh-inject' option was specified without a path to a key, the prefix' key will be copied to the vm. Args: options (lst of str): Options and arguments for 'virt-customize' Returns: callable: which handles cmd Raises: lago.build.BuildException: If an handler for cmd doesn't exist
juraj-google-style
def get_HDX_code_from_location(location, locations=None, configuration=None): if locations is None: locations = Locations.validlocations(configuration) locationupper = location.upper() for locdict in locations: locationcode = locdict['name'].upper() ...
Get HDX code for location Args: location (str): Location for which to get HDX code locations (Optional[List[Dict]]): Valid locations list. Defaults to list downloaded from HDX. configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[str]: HDX code or None
juraj-google-style
def gcd(a, b, name=None): with ops.name_scope(name, 'gcd', [a, b]): a = ops.convert_to_tensor(a) b = ops.convert_to_tensor(b) a.shape.assert_has_rank(0) b.shape.assert_has_rank(0) if not a.dtype.is_integer: raise ValueError('a must be an integer type. Got: %s' % a...
Returns the greatest common divisor via Euclid's algorithm. Args: a: The dividend. A scalar integer `Tensor`. b: The divisor. A scalar integer `Tensor`. name: An optional name for the operation. Returns: A scalar `Tensor` representing the greatest common divisor between `a` and `b`. Raises: ValueError: If `a` or `b`...
github-repos
def jaccard_sim(features1, features2): set1 = set(features1) set2 = set(features2) try: return len(set1.intersection(set2))/float(max(len(set1), len(set2))) except ZeroDivisionError: return 0
Compute similarity between two sets using Jaccard similarity. Args: features1: list of PE Symbols. features2: list of PE Symbols. Returns: Returns an int.
juraj-google-style
def serialize_cert_to_der(cert_obj): return cert_obj.public_bytes(cryptography.hazmat.primitives.serialization.Encoding.DER)
Serialize certificate to DER. Args: cert_obj: cryptography.Certificate Returns: bytes: DER encoded certificate
codesearchnet
def _read_accept_states(self): states = [] i = 0 regex = re.compile('[ \t\n\r:,]+') found = 0 state = 0 mapping = [] cur_line = None with open(self.outfile) as flex_file: for cur_line in flex_file: if cur_line[0:37...
Read DFA accepted states from flex compiled file Args: None Returns: list: The list of accepted states
juraj-google-style
def signature(self, name, file_name, file_type, file_content, owner=None, **kwargs): return Signature(self.tcex, name, file_name, file_type, file_content, owner=owner, **kwargs)
Create the Signature TI object. Args: owner: file_content: file_name: file_type: name: **kwargs: Return:
juraj-google-style