content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def mesh_split_face(mesh, fkey, u, v):
"""Split a face by inserting an edge between two specified vertices.
Parameters
----------
mesh : :class:`~compas.datastructures.Mesh`
Instance of a mesh
fkey : :obj:`str`
The face key.
u : hashable
The key of the first split vertex... | d6f0dfddaf000374e0a7eb7e70100d35a3db1c82 | 58,259 |
import pathlib
import hashlib
def create_file_hash(file_path: pathlib.Path) -> str:
"""
Create a hash of a file.
Replicates function of ``sha365sum`` linux command.
Args:
file_path: Path of file to hash.
Returns:
Hex digest of file SHA.
"""
this_hash = hashlib.sha256()
... | fb147c20fa971e7b8f6d3fb40c5b09963fabc022 | 58,260 |
def check_if_modem_enabled(out):
"""Given an output, checks if the modem is in the correct mode"""
for line in out:
if '12d1:1446' in line:
return 0
if '12d1:1001' in line:
return 1
return -1 | 1d7a0bbdd038240a9e5ca5f1bfa9a9555867f855 | 58,263 |
def pentagonal(n: int) -> int:
"""Find the number of dots in nth pentagonal number."""
# Find the pentagonal number to nth degree.
pentagonal_number = (n * ((3 * n) - 1) // 2)
# Find the total number of dots.
dots = ((n-1) ** 2)
dots += pentagonal_number
return dots | 8e26ca47281f39af565a6817cc960235c09c6878 | 58,270 |
def save_analytics_action_doc_template_values(url_root):
"""
Show documentation about saveAnalyticsAction
"""
required_query_parameter_list = [
{
'name': 'voter_device_id',
'value': 'string', # boolean, integer, long, string
'description': 'An... | 8f7e1c256df5f94acb4b9fb227d646d4e5252557 | 58,274 |
def labeller(landmarkables, group_label, label_func):
"""
Takes a list of landmarkable objects and a group label indicating which
set of landmarks should have semantic meaning attached to them.
The labelling function will add a new landmark group to each object that
have been semantically annotated.... | 5889e9212fe9974afe6e19e18e8e586a1348d043 | 58,275 |
def hum_ratio_from_p_w_and_p(p_w, p):
"""
Calculate humidity ratio from water vapor pressure and atmospheric pressure
Eq(22) in "CHAPTER 6 - PSYCHROMETRICS" in "2001 ASHRAE Fundamentals Handbook (SI)"
:param p_w: water vapor pressure [Pa]
:type p_w: double
:param p: atmospheric pressure [Pa]
... | d2126ee4dcb7ebb81a4918cb9939abc2473f4c18 | 58,276 |
def in_d8(idx0, idx_ds, ncol):
"""Returns True if inside 3x3 (current and 8 neighboring) cells."""
cond1 = abs(idx_ds % ncol - idx0 % ncol) <= 1 # west - east
cond2 = abs(idx_ds // ncol - idx0 // ncol) <= 1 # south - north
return cond1 and cond2 | 69e2f522db8f7c5cf57167a82d41226e6d7b35af | 58,278 |
from typing import Dict
from typing import Any
def clear_per_step_extra_state(extra_state: Dict[str, Any]) -> Dict[str, Any]:
"""
Clear values in extra_state that are technically only true for a specific
step (ex: the eval tune loss calculated after 5 train steps is no longer
accurate after 7 train st... | d7f561c612a8d52e1cf8a215b414e5c8297c6a24 | 58,279 |
import re
def RemoveTestCounts(output):
"""Removes test counts from a Google Test program's output."""
output = re.sub(r'\d+ tests, listed below',
'? tests, listed below', output)
output = re.sub(r'\d+ FAILED TESTS',
'? FAILED TESTS', output)
output = re.sub(r'\d+ tests fr... | d687e46dda00b1730685db2853ff5b3052b99fd1 | 58,286 |
def horizontal_speed(distance, seconds):
"""compute integer speed for a distance traveled in some number of seconds"""
return(int(3600.0 * distance / seconds)) | 4a3098d54c768301e1d6f66c8b69e1df53724aa4 | 58,289 |
def _downsample(raw, frequency):
"""
Downsample data using MNE's built-in resample function
"""
raw_downsampled = raw.copy().resample(sfreq=frequency, verbose=True)
return raw_downsampled | 65034c4331bceae109aca52c713a5d11146fc987 | 58,293 |
def num_valid_segments(lower_bound, upper_bound, clip_length):
"""calculate the number of valid video clips in the video
Args:
- lower_bound (int): denotes the earliest frame in video that can be segmented
- upper_bound (int): denotes the latest frame + 1 in video that can be segmented
- clip_lengt... | c030175af2ba20d90a142eae2b03eaa08012c211 | 58,298 |
def remove_comment_from_disasm(disasm):
"""Remove comment from disassembly.
Args:
disasm: (str) disassembly of the current instruction.
Returns:
New disassembly after removing comment.
"""
if ";" in disasm:
return disasm.split(";")[0]
return disasm | d8b491f6820fb387638403d8fd3f58751a397396 | 58,304 |
import io
import base64
def decode_b64_img(img_code: str) -> io.BytesIO:
""" Returns a decoded image from base64 """
img = img_code
img_output = io.BytesIO(base64.b64decode(img))
return img_output | 2ee19e604999c217197db9a319c6ea86940d8fe3 | 58,308 |
import warnings
def scale_to_bounds(x, lower_bound, upper_bound):
"""
DEPRECATRED: Use :obj:`~gpytorch.utils.grid.ScaleToBounds` instead.
:param x: the input data
:type x: torch.Tensor (... x n x d)
:param float lower_bound: lower bound of scaled data
:param float upper_bound: upper bound of ... | 41b77fdf1399c1ea9d55b9ff7535e92953dd165c | 58,312 |
def is_number(value):
""" This function checks to see if the value can be converted to a number """
try:
float(value)
return True
except:
return False | 92481e2fbdb3a2826f522f021eaab2961bc8da91 | 58,314 |
def rankPerNode(ranking):
"""
Parameters
----------
ranking: ordered list of tuples (node, score)
Returns
_______
for each node (sorted by node ID), the ranking of the node
"""
n_nodes = len(ranking)
ranking_id = [0]*n_nodes
for index, pair in enumerate(ranking):
ranking_id[pair[0]] = index
#we assign ... | e82fd5e0367441da842ae4d7cfe7761287e40119 | 58,315 |
def clean_lesson_content(content):
""" Remove items such as new lines and multiple spaces. """
content = content.replace("\n", " ")
while " " in content:
content = content.replace(" ", " ")
return content.strip() | ed609a9b6bdf31b7ffd07a185ee5cc64ad5746f8 | 58,318 |
def canonical_message_builder(content, fmt):
""" Builds the canonical message to be verified.
Sorts the fields as a requirement from AWS
Args:
content (dict): Parsed body of the response
fmt (list): List of the fields that need to go into the message
Returns (str):
... | 18ac12bdd92d0d41bc06384517705433b427b9ee | 58,322 |
from typing import Optional
from typing import Dict
from typing import List
def find_skip_tags(params: Optional[Dict[str, str]] = None) -> List[str]:
"""Returns a list of tags passed in params that should be excluded from the build."""
if params is None:
params = {}
tags = params.get("skip_tags",... | 6a700b62ef20b30e8e6e27416dbdebd46cd1a08f | 58,325 |
from typing import OrderedDict
import logging
def find_unique_points(explored_parameters):
"""Takes a list of explored parameters and finds unique parameter combinations.
If parameter ranges are hashable operates in O(N), otherwise O(N**2).
:param explored_parameters:
List of **explored** param... | 537ae774d9e1fb2943f5e0b6c72b054642a1b883 | 58,326 |
def extract_feature(array, n_samples=1):
"""Extracts the feature column from an array.
Note that this method expects the first column to the the row identifier
and the second column to be the feature.
Args:
array (np.array): Numpy array to be extracted.
n_samples (int): Maximum number ... | 6dbc786e611e23c6849afb42995c6253b18a1b6c | 58,329 |
import time
def date_suffix(file_type=""):
""" 返回当前的日期后缀,如'180723.csv'
Args:
file_type: 文件类型, 如'.csv', 为""则只返回日期
Returns:
str: 日期后缀
"""
suffix = time.strftime("%y%m%d", time.localtime())
suffix += file_type
return suffix | a9b9f6b18357e343eafe80f43296c3a7a4dd483d | 58,333 |
import pickle
def load_obj(name ):
"""
Loads Python object from file. File in web_map/data_obj.
:param name: sting with the name of file to load object from.
:return: python object from file
"""
with open('data_obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f) | 2d4b4ec40865f2d99a658728527cf72f197c4bb5 | 58,341 |
def strip_from_right(string, suffix):
"""Strip a suffix from end of string."""
if not string.endswith(suffix):
return string
return string[:len(string) - len(suffix)] | 85ab275483c5d5697038acb3027f12f1e2b1928f | 58,347 |
def format_action(action):
"""Format request action."""
return '<name>{0}</name>'.format(action) | 71871fa855310f7af5ca03f681917fa3962709e9 | 58,348 |
def list_vm_template(client, private_cloud, resource_pool, location):
"""
Returns the list of VMware virtual machines templates in a resource pool, in a private cloud.
"""
return client.list(private_cloud, location, resource_pool) | 9e3f179c92815c68b6345f1b007709c762d5905e | 58,353 |
def time_vst(velocity, displacement):
"""Usage: Calculate time taken using velocity and displacement."""
return displacement/velocity | 11aebe9eb51b58d09153342ee1ad9fc911b2f362 | 58,356 |
def is_function(var):
"""
Test if variable is function (has a __call__ attribute)
:return: True if var is function, False otherwise.
:rtype: bol
"""
return hasattr(var, '__call__') | 1cd3d4bb70b1568a60c4f51c04652df12a967292 | 58,362 |
def division(a, b):
"""This function returns a simple math division from the first argument by the second argument"""
return a / b | 807b48297549362b0fbf43541ebc95abd733faa8 | 58,366 |
import contextlib
import io
def get_help_as_text(function_name: object):
"""Outputs the "help" docstring for the given function as text.
Examples:
>>> get_help_as_text(len)\n
'Help on built-in function len in module builtins:\\n\\nlen(obj, /)\\n Return the number of items in a container.\\... | 8d787d49cd32d7ac1f48b5f5682ba3e1738f7f33 | 58,367 |
def eletype(eletype):
"""Assigns number to degrees of freedom
According to iet assigns number of degrees of freedom, number of
nodes and minimum required number of integration points.
Parameters
----------
eletype : int
Type of element. These are:
1. 4 node bilinear quadrilatera... | a1f520429f23ac53835bf0fd1279abecb378b737 | 58,368 |
import functools
def only_xhr(method):
""" Decorates a method in a handler to only accepts XMLHttpRequest
requests.
"""
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
if "X-Requested-With" in self.request.headers:
if self.request.headers['X-Requested-With'] == "XM... | 02e6430a474ad741ebd16df26580d25741b71d2f | 58,369 |
def replica_diagnostic_server_port(replica_id):
"""
Returns a unique port for each replica
All the replicas run in the same container and therefore share an IP address
"""
return 27500 + replica_id | e0a2e8a1022f78f720c7c19ac717f0dc93288f5a | 58,370 |
def generate_name(string):
"""Generate the name attribute for the entries at the glossary."""
return string.lower().replace(' ', '-').replace("'", '') | 6dd4775534485509a28171f2f440403f805b3fec | 58,380 |
import torch
def get_neighbor_bonds(edge_index, bond_type):
"""
Takes the edge indices and bond type and returns dictionary mapping atom index to neighbor bond types
Note: this only includes atoms with degree > 1
"""
start, end = edge_index
idxs, vals = torch.unique(start, return_counts=True)
... | 96c56c067a3d436b67de093c0407f86900223302 | 58,383 |
def sort_scenes_by_timestamp(scenes_list):
"""
Sort list of scenes using timestamp
"""
sorted_list = sorted(scenes_list, key=lambda scene: scene.timestamp)
return sorted_list | 13b426480932fefc7eb75b3084ff0b2807d55be2 | 58,385 |
def flesch_kincaid_grade_level(n_syllables, n_words, n_sents):
"""
Readability score used widely in education, whose value estimates the U.S.
grade level / number of years of education required to understand a text.
Higher value => more difficult text.
References:
https://en.wikipedia.org/w... | 43139d53cb03898d4152bf9c7dcfa1564a2a1128 | 58,388 |
def latest(scores):
"""
Return the latest scores from the list
"""
return scores[-1] | ec5bb0a18f6a86e154065d4b2e4ae089ec45ffe7 | 58,389 |
def components_to_hosts(components):
"""Convert a list of Component namedtuples to a list of their hosts
:param components: a list of Component namedtuples
:returns: list of the hosts associated with each Component
"""
hosts = []
for component in components:
hosts.append(component.host)
... | d41dc31903349eece69f7405ff667cee18e8c982 | 58,391 |
def clean(string_value):
"""Standardizes string values for lookup by removing case and special characters and spaces.
Args:
string_value (str): The lookup key to be transformed.
Returns:
str: The original value, but lowercase and without spaces, underscores or dashes.
"""
return st... | fc03f3553eaeff18e35bd6a0290a80ddb1909882 | 58,393 |
def from_helioviewer_project(meta):
"""
Test determining if the given metadata contains Helioviewer Project sourced data.
Parameters
----------
meta : `~astropy.utils.metadata.MetaData`
The metadata to parse.
Returns
-------
If the data of the map comes from the Helioviewer Pro... | 0825ac5e261cf75abbdd919aeaa7d0184f1b3c02 | 58,394 |
def f_to_c(val):
"""
Converts Fahrenheit to Celsius; accepts numeric or string
"""
try:
return (float(val) - 32.) * 5. / 9.
except (TypeError, ValueError):
return (val - 32.) * 5. / 9. | 4a8bdda8069f87e136fa98f7b2983b4b702babc5 | 58,395 |
import socket
import errno
def _discovery_multicast(ip: str, sock: socket.socket, attempts: int = 5):
"""
Send a multicast command on the given network to discover available
devices.
If port is in use, try the next port up to <attempts> times
Args:
ip (str): Local IP
sock (soc... | 0a3759df478998613537859b8452b98e266f41e8 | 58,396 |
def getfirst(obj, uri, strip=True):
"""Return string value of first item returned by obj.get_value(uri).
By default, strips whitespace surrounding string value.
If collection is empty, return None.
"""
data = obj.get_value(uri)
if data:
data = str(data[0])
if strip:
... | 0af10bc6ce0746acb32a1f5b1237d44348480744 | 58,397 |
from typing import Sequence
from typing import Tuple
def cross(a: Sequence[int], b: Sequence[int]) -> Tuple[int, int, int]:
""" Returns the cross product of the three-dimensional vectors a and b """
ax, ay, az = a
bx, by, bz = b
return ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx | 9751c1d7bbc605990190d4172f0945db2090e6b2 | 58,401 |
def umf_coeff(dp, mu, rhog, rhos, coeff='wenyu'):
"""
Determine minimum fluidization velocity using experimental coefficients from
Wen and Yu, Richardson, Saxena and Vogel, Babu, Grace, and Chitester. This
approach can be used when bed void fraction and particle sphericity are not
known. Refer to Eq... | 22812a908f5666d8fe3ad83af716413d1dad24bb | 58,406 |
import re
from datetime import datetime
def parse_date_sentence(sentence):
"""Return the date type + date in this sentence (if one exists)."""
# Search for month date, year at the end of the sentence
sentence = sentence.lower().strip()
date_re = r".*((january|february|march|april|may|june|july|augus... | 1f91829bd2f9e871d51d4a91a05e8ed18742691f | 58,414 |
def select(objects, fn, unlist=True, first=False):
"""Returns a subset of `objects` that matches a range of criteria.
Parameters
----------
objects : list of obj
The collection of objects to filter.
fn : lambda expression
Filter objects by whether fn(obj) returns True.
first: bo... | 8a24c960fdbcd8bc01b5a9cbb0b1e7fc4e82b836 | 58,417 |
import logging
def get_port_map(dut, asic_index=None):
"""
@summary: Get the port mapping info from the DUT
@return: a dictionary containing the port map
"""
logging.info("Retrieving port mapping from DUT")
namespace = dut.get_namespace_from_asic_id(asic_index)
config_facts = dut.config_fa... | f5a194c674a2b84d42cba8f53804289e9812b6be | 58,418 |
def byteConversion(amount, btype):
""" convert unit of memory size into bytes for comparing different
unit measures
:param amount: unit of memory size
:ptype amount: float
:param btype: unit type
:ptype btype: string
:return: unit in bytes
:rtype: float
"""
n = 1
convers... | 97846d13ec7037741d7651a14409dc94f77769dd | 58,420 |
import pickle
def read_pickle(filepath):
""" read a python object with a pickle"""
with open(filepath, 'rb') as file:
unpickler = pickle.Unpickler(file)
return unpickler.load() | cb96cd0286edfd8c73f875b0a39f8887d2fbb2f0 | 58,422 |
def read_file(fname):
"""Return the contents of a file."""
with open(fname) as fd:
contents = fd.read()
return contents | 680c31b11c2c774ce1ede1d4f615c0ca72001238 | 58,425 |
import random
import string
def random_uid() -> str:
"""Generate a random id which can be used e.g. for unique key names."""
return "".join(random.choices(string.digits, k=10)) | 79e897af6fb02dda945d6496e03734db6903b511 | 58,426 |
def decode_file_size(high: int, low: int) -> int:
"""File size can be encoded as 64 bits or 32 bits values.
If upper 32 bits are set, it's a 64 bits integer value.
Otherwise it's a 32 bits value. 0xFFFFFFFF means zero.
"""
if high != 0xFFFFFFFF:
return (high << 32) | (low & 0xFFFFFFFF)
e... | 3399d92b5524300aadfee3be7bb58bd3a8b54e17 | 58,427 |
def get_section_link(header):
"""
Add a section link
Args:
:header: (str) section header
Returns:
:rst: (str) RST documentation
"""
rst = ""
rst += f".. _sec_mframwork_{header.lower().replace(' ', '_')}:"
rst += "\n\n"
return rst | 615bb5b2acdcc7181f090373389414ceb380c807 | 58,433 |
def sha256_to_str(obj):
"""Convert a bytearray to its lowercase hexadecimal string representation.
Args
----
obj (bytearray): bytearray representation of the string.
Returns
-------
(str): Lowercase hexadecimal string.
"""
return None if obj is None else obj.hex() | 16f0fff7103d91f32bec248466e9aaddc818f29e | 58,436 |
def inc(x):
"""Increments its argument"""
return x + 1 | 23b0c854dc3307fe6411174e9b9da39b0f0988d3 | 58,440 |
import json
def load_index_to_label_dict(path='index_to_class_label.json'):
"""Retrieves and formats the index to class label lookup dictionary needed to
make sense of the predictions. When loaded in, the keys are strings, this also
processes those keys to integers."""
with open(path, 'r') as f:
... | 1bc783ed0143420e481c1f328aacfe27bd85b072 | 58,445 |
import typing
def convert_value(dtype: typing.Any, value: typing.Any, default: typing.Any = None) -> typing.Union[typing.Any, None]:
"""
Return the passed value in the specified value if it is not None and does not raise an Exception
while converting. Returns the passed default if the conversion failed
... | 3fd02525daf5db4b8761b3af3746004db9459429 | 58,451 |
def fn_col_mapping(df):
"""Return a list of column names and their associated column index number."""
return [f'{c[0]}:{c[1]}' for c in enumerate(df.columns)] | 4f38f6852b186a025f2e44b80ec20235d10c6594 | 58,452 |
from pathlib import Path
def get_package_path(package):
"""Compute the file-system path for `package`."""
if hasattr(package, "__path__"):
return Path(package.__path__[0])
elif hasattr(package, "__file__"):
return Path(package.__file__).parent
else:
raise ValueError(f"Cannot de... | 9ee4d63a7249ef7f1717a197346cb164e4337435 | 58,454 |
def btc_to_satoshi(btc: float) -> int:
"""Convert a btc value to satoshis
Args:
btc: The amount of btc to convert
Returns:
The integer of satoshis for this conversion
"""
return int(btc * 100000000) | 5d6e7b2583bd876779e46312bdbd6cdb5303a433 | 58,459 |
def _check_limit(num, limits=[0, 100]):
"""
Ensures that `num` is within provided `limits`
Parameters
----------
num : float
Number to assess
limits : list, optional
Lower and upper bounds that `num` must be between to be considered
valid
"""
lo, hi = limits
... | 24318025e91dfe66dcd73dc6e000b16f818352c5 | 58,469 |
def validator(targetFile):
"""
Function to validate a password using a password policy.
:param targetFile: path to input file.
"""
inputFile = open(targetFile, 'r')
lines = inputFile.readlines()
targetCount = 0
targetCountP2 = 0
# policyNumbers = the numbers to be min and ma... | 49fea7572ff1c9bae4f3b30aa671a133eeea5992 | 58,470 |
def add_compartment(model, compartment, **keywords):
""" Helper function to add a compartment to the SBML model.
:param model: a valid SBML model
:param compartment: a Compartment object
:return: SBML compartment object
"""
sbml_compartment = model.createCompartment()
compartment_id = compa... | c338b2a4a3196dc0ccc2a6e0072df38ee6832c48 | 58,471 |
from datetime import datetime
def _format_time(when):
"""
Format a time to ISO8601 format. Or if there is no time, just return
``None``.
"""
if when is None:
return None
return datetime.isoformat(when) | a1ed9c10a0868c2a64d90837d672e82fec44c294 | 58,475 |
def _parse_zeopp(filecontent: str) -> dict:
"""Parse the results line of a network call to zeopp
Args:
filecontent (str): results file
Returns:
dict: largest included sphere, largest free sphere,
largest included sphera along free sphere path
"""
first_line = fileconten... | 436e7579883a8c6700d3725756dd03dc7de3cf51 | 58,476 |
import torch
def merge_heads(x: torch.Tensor) -> torch.Tensor:
"""Merge multiple attention heads into output tensor
(Batch size, Heads, Lengths, Attention size / Heads) => (Batch size, Length, Attention size)
Args:
x (torch.Tensor): [B, H, L, A/H] multi-head tensor
Returns:
torch.Te... | 4250e298b81e0acb10624446a4674cd6782a6882 | 58,479 |
import math
def perceived_brightness(rgb_color):
"""Compute perceived brightness.
cf http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
Args:
rgb_color (str): example 'rgb(215,200,80)'
"""
rgb_color = rgb_color[4:-1]
r, g, b = [int(i) f... | 7226eb5611bd17b80077d1beac448b630c05704d | 58,489 |
def words_normalize(words):
"""
Do a normalization precess on words. In this case is just a tolower(),
but you can add accents stripping, convert to singular and so on...
"""
normalized_words = []
for index, word in words:
wnormalized = word.lower()
normalized_words.append((index... | cfad1720898519bc6f9688445766103b9ca16bbe | 58,490 |
def required_for_output(inputs: set, outputs: set, connections: dict):
"""
Determine which nodes and connections are needed to compute the final output. It is considered that only paths
starting at the inputs and ending at the outputs are relevant. This decision is made since a node bias can
substitut... | 4561f6951a87c1dfc845fc60817ed80d270e904a | 58,492 |
def _FormatChar(ch):
"""Convert a character into its C source description."""
code = ord(ch)
if code < 32 or code > 127:
return "'\\%d'" % code
else:
return "'%s'" % ch | c0b245731d612fb72c2e2049be429a236df4f69a | 58,493 |
def mem_rm_payload(mem_default_payload):
"""Provide a membership payload for removing a member."""
rm_payload = mem_default_payload
rm_payload["action"] = "removed"
return rm_payload | bda0d818789e8197cc4508694ead88fc0fc5c9d7 | 58,494 |
def median(iterable):
"""Obtain the central value of a series
Sorts the iterable and returns the middle value if there is an even
number of elements, or the arithmetic mean of the middle two elements
if there is an even number of elements
:param iterable: a series of ordeable items
:return: th... | fc3725a58686fba68610c3fb3295ba72242c64c3 | 58,495 |
import re
def find_url(string):
"""
Search URL in text.
Parameters
----------
string: str
Text selected to apply transformation
Examples:
---------
```python
sentence="I love spending time at https://www.kaggle.com/"
find_url(sentence)
```
"""
text... | 9ae11f02bc1eccbce30c436cf2b02495fb18d338 | 58,502 |
def get_elapsed_time_string(elapsed_time, rounding=3):
"""Format elpased time
Parameters
----------
elapsed_time : float
Elapsed time in seconds
rounding : int
Number of decimal places to round
Returns
-------
processing_time : float
Scaled amount elapsed time
... | 25d269236d24824fab9e9a39a1532ca98b6ff009 | 58,503 |
import inspect
def non_string_iterable(obj):
"""
Check whether object is iterable but not string.
"""
isclass = inspect.isclass(obj)
if isclass: condition = issubclass(obj, str)
else: condition = isinstance(obj, str)
return hasattr(obj, '__iter__') and not condition | a118ff750e4255c3083e8da54d52f6bf88dfdb24 | 58,505 |
def format_currency(flt):
"""Return a formatted UK currency string from a float"""
return '£{:,.2f}'.format(flt) | 534f30069c3faf5f6fa5b53e3ea4b6c7fa2d6af9 | 58,506 |
def feature_extraction(dframe):
"""Function to extract features."""
cols = ['concavity_worst', 'compactness_worst', 'compactness_mean',
'compactness_se', 'perimeter_se', 'concavity_mean']
deff = dframe.loc[:, cols]
return deff | c5ef68c613407203643d33ae281b62d5d68bd999 | 58,507 |
def _generate_stack_status_path(stack_path):
"""
Given a path to the stack configuration template JSON file, generates a path to where the
deployment status JSON will be stored after successful deployment of the stack.
:param stack_path: Path to the stack config template JSON file
:return: The path... | b0573148565e8cf338d4bc6877151cbe4186ebf5 | 58,509 |
import time
def _to_time_in_iso8601(_time):
"""Convert int or float to time in iso8601 format."""
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(_time)) | 12acaf8c021d4b98ec6c0708d18092e82fe382a7 | 58,510 |
def clean_email(raw_email):
"""Clean a raw email address from the log file.
Arguments:
raw_email [string] -- from=<user@domain.com>
Returns:
[string] -- user@domain.com
"""
temp1 = raw_email.split('from=<')[1]
return temp1.rstrip('>') | a5231656bf83ca431752bbb59f41472198e04515 | 58,514 |
def jaccard_similarity(
set_a, set_b, element_to_weight=None, max_intersections=None):
"""Calculates Jaccard similarity, a measure of set overlap.
Args:
set_a: First set.
set_b: Second set.
element_to_weight: Optional, a dict of set elements to
numeric weights. This ... | a1421e211e3a6e56bc884d0282b76c1d43d80ec2 | 58,518 |
def _pretty_name_list(names):
"""
Given a list of (a,b) pairs, output aligned columns with the
items of the second column parenthised.
Used for pretty-printing e.g. name (crsid) or socname (socid) lists.
"""
# might be given an iterator, need a list, might as well sort it
nameList = sorted(... | 6c09ad303a72207fe58e356bbfc959afea27750b | 58,521 |
def _guess_max_lengths(info):
"""Compute the maximum length for keys and lines."""
max_key_len = 0
max_line_len = 0
for sec in info:
for k in info[sec]:
l_k = len(k)
l_data = len(info[sec])
line_len = l_k + 2 + l_data
if line_len > 80:
... | 1e0356f11502d0bbb65d79ce977a32201d4adc0c | 58,522 |
def process_connected_devices(results):
"""Process Connected Devices
Args:
results (Element): XML results from firewall
Returns:
devices_dict (dict): A dictionary containing hostnames, IP addresses, and models
"""
xml_list = results.findall('./result/devices/entry')
devices_dic... | fe037b24c1924958038b1ec649bcd921b7372e97 | 58,523 |
import hashlib
def getHashForFile(f):
"""Returns a hash value for a file
:param f: File to hash
:type f: str
:returns: str
"""
hashVal = hashlib.sha1()
while True:
r = f.read(1024)
if not r:
break
hashVal.update(r)
f.seek(0)
return hashVal.hexd... | 7adc2383a9f555ae64a4bc9fd34715c4c3057039 | 58,527 |
def mean_off_diagonal(a):
"""Computes the mean of off-diagonal elements"""
n = a.shape[0]
return ((a.sum() - a.trace()) / (n * n - n)) | 84622d750922d0889b5c83e9e1a7742f0c441f4f | 58,529 |
def _filter_tasks_by_completed(tasks, is_completed):
"""
Filters tasks based on the completion status.
Args:
tasks ([{str:str}]): List of tasks from asana API. At the very least,
must have the `completed` key.
is_completed (bool or None): Whether to return tasks that are completed.
... | 9ba9b9f66beb18f2435992993be626e98ac9ee84 | 58,531 |
import json
def value_for_cypher(value):
"""
returns the value in cypher form
Parameters
----------
value : str, list, or boolean
Returns
-------
v : str
a string formatted for cypher
"""
if isinstance(value, str):
return "'{}'".format(value)
if isi... | e349237f678e040371b8f0ca0ba0bb01a97682e6 | 58,536 |
def get_output(outputs, key):
"""
Parse and return values from a CloudFormation outputs list.
:param list outputs: A list of ``dict`` having items of `(`OutputKey``,
``OutputValue``).
:param unicode key: The key for which to retrieve a value from ``outputs``.
:returns: A ``unicode`` value.
... | 1a6d1546a009cab46c8e94c42a10cfc024ad380f | 58,537 |
def allowed_file(filename, extensions):
"""Helper function to check if a file is the correct file extension
Args:
filename (string): filename as a string
extensions (list): The list of accepted file extensions
Returns:
bool: True if filename is accepted
... | d024a81c6701b6d1459c7d600a1e4b43ceaeba0e | 58,542 |
def get_pattern_matches(folder, pattern):
"""Given all the files in the folder, find those that match the pattern.
If there are groups defined, the groups are returned. Otherwise the path to the matches are returned.
"""
matches = []
if not folder.exists():
return matches
for child in f... | 0d62cbb8b136f465a3056cc55f22c174ca7dced7 | 58,548 |
def rotate_180(data):
"""Rotate the data 180 degrees."""
return data[::-1] | 7d3f4b47a3a44849e1eba56c7b1516f09ddf91f6 | 58,550 |
def flare_value(flare_class):
"""Convert a string solar flare class [1] into the lower bound in W/m**2 of the
1-8 Angstrom X-Ray Band for the GOES Spacecraft.
An 'X10' flare = 0.001 W/m**2.
This function currently only works on scalars.
Parameters
----------
flare_class : string
c... | eeeaa9d4f27647cbeafc3e99109765907df7cb88 | 58,553 |
import hashlib
def get_sha256_sums(file_bytes):
""" Hashes bytes with the SHA-256 algorithm """
return hashlib.sha256(file_bytes).hexdigest() | c1b019b7ea9db1d35c07dc71d95a4ae5d59254b4 | 58,556 |
def get_steps_to_exit(data, strange=False):
"""
Determine the number of steps to exit the 'maze'
Starting at the first element, move the number of steps based on
the value of the current element, and either bump it by one, or
if 'strange' is True and the value is over three, decrease it by
one.... | a1ba7c9374cbba9d6a0a8ad091a7fbfcbe71744a | 58,559 |
from datetime import datetime
def parse_heart_json(input_json):
"""
Input JSON from Shortcuts currently contains two keys:
- hrDates: Contains an array of all timestamps (ascending order)
- hrValues: Contains an array of all heart rates (sorted by timestamp, ascending)
This converts the dictionar... | 6a37331e778bab5c00a0b6d41388cae31298f005 | 58,560 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.