content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
from pathlib import Path
from typing import List
def _list_files(d: Path) -> List[Path]:
""" Recursively list files in a dir and its sub dirs """
if d.is_file():
return [d]
else:
sub_dirs = [d for d in d.iterdir() if d.is_dir()]
files = [f for f in d.iterdir() if f.is_file()]
... | e684d81ab49b2b06b257d25e5b304b6e696002d0 | 58,231 |
def _float(value: str) -> float:
"""Convert string to float value
Convert a string to a floating point number (including, e.g. -0.5960D-01). Whitespace or empty value is set to 0.0.
Args:
value: string value
Returns:
Float value
"""
if value.isspace() or not value:
r... | 501e73417178744a6f620438773e34708908c0de | 662,375 |
def get_usa_veh_id(acc_id, vehicle_index):
"""
Returns global vehicle id for USA, year and index of accident.
The id is constructed as <Acc_id><Vehicle_index>
where Vehicle_index is three digits max.
"""
veh_id = acc_id * 1000
veh_id += vehicle_index
return veh_id | e89875d5f9f48293e3069a7fe468ee9455d24147 | 660,010 |
import re
def parse_github_url(gh_url):
"""Util to parse Github repo/PR id from a Github PR URL.
Args:
gh_url (string): URL of Github pull request.
Returns:
Tuple of (repo name, pr number)
"""
matches = re.match(r'https://github.com/([\w-]+/[\w-]+)/pull/(\d+)', gh_url)
if matches:
repo, prnu... | ce6780c04153174a267ed25015ccb2d8dd9e85ca | 364,678 |
from datetime import datetime
import pytz
def tumblr_date_to_datetime(timestamp):
"""
2016-01-15 22:01:42 GMT -> datetime()
"""
dt = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S GMT')
return dt.replace(tzinfo=pytz.utc) | c9184c05131260e0d4126b9803f45dfb69ecd3e9 | 322,627 |
def make_parameter(name, values, **kwargs):
""" define a new parameter that will be added to a store.
Primarily takes a name and an array of potential values.
May also be given a default value from inside the array.
May also be given a typechoice to help the UI which is required to be
one of 'list',... | a77eb681f9c055c3407b4f5ed88180f90569e44a | 582,870 |
def check_if_scenario_name_exists(conn, scenario_name):
"""
:param conn: the database connection
:param scenario_name: str; the scenario name
:return: scenario_id; str or None
"""
c = conn.cursor()
sql = "SELECT scenario_id FROM scenarios WHERE scenario_name = ?"
query = c.execute(sql, ... | ece671be889fc112995a08d1fb094470d630f6d9 | 217,795 |
def merge_feed_dict(*feed_dicts):
"""
Merge all feed dicts into one.
Args:
\**feed_dicts: List of feed dicts. The later ones will override
values specified in the previous ones. If a :obj:`None` is
specified, it will be simply ignored.
Returns:
The merged feed... | 9c8a0314dec75f484d86926737dd98ff7a54784d | 76,249 |
def parse_tags(tags):
"""Parse string containing list of tags."""
if tags is not None:
tags = set(tags.split(","))
return tags | 50ddf2a3c5d1ac494ed90d0df674f73dce4933ce | 206,601 |
import csv
def parse_proteq_file(filename, simplify_protein_names=True):
"""Parse the given protein expression file"""
# Example:
# /mnt/e/TCGA-BRCA/b09881e2-d622-4e5c-834a-18b893848de9/mdanderson.org_BRCA.MDA_RPPA_Core.protein_expression.Level_3.F3DF6E4D-CA53-4DEA-B48D-652306B60C77.txt
with open(file... | 9093eff93c78e17461e21d34189bd0ef36229dc4 | 489,504 |
def extract_capital_letters(x):
""" Extract capital letters from string """
try:
return "".join([s for s in x if s.isupper()])
except Exception as e:
print(f"Exception raised:\n{e}")
return "" | c313c72da7a6c836219a0ae88e0a718102206a0c | 210,567 |
import sqlite3
def get_db(test=False):
""" Get/create a database connection.
If a local ergal.db file exists, a connection
is established and returned, otherwise a new
database is created and the connection is returned.
:param test: (optional) determines whether or not a test database
... | 5ae1be5b6c74f788b89b260a2597ac543968a392 | 585,322 |
import re
def match_crash_field(page):
"""
Extract the crash number from the content of the fatality page.
:param str page: the content of the fatality page
:return: a string representing the crash number.
:rtype: str
"""
crashes_pattern = re.compile(
r'''
(?:
(?:T... | 1d11e05f4768f58cd7d785b1788f07d5e2573d20 | 495,689 |
def delete_keys_from_dict(dict_del, key):
"""
Method to delete keys from python dict
:param dict_del: Python dictionary with all keys
:param key: key to be deleted in the Python dictionary
:returns a new Python dictionary without the rules deleted
"""
if key in dict_del.keys():
de... | 27084ba400dc7745636868e13813427cd9e35321 | 226,462 |
def ends_overlap(left, right):
"""Returns whether the left ends with one of the non-empty prefixes of the right"""
for i in range(1, min(len(left), len(right)) + 1):
if left.endswith(right[:i]):
return True
return False | 0acf669acc87bd0366d8198dad6fc7e5b3510548 | 450,494 |
def _extractDotSeparatedPair(string):
"""
Extract both parts from a string of the form part1.part2.
The '.' used is the last in the string.
Returns a pair (part1, part2).
Useful for parsing machine.buildType filenames.
"""
i = string.rfind('.')
return string[:i], string[i+1:] | a6bcebe7006989778da5f35148681281af8c6da6 | 354,961 |
def NAA_net_area(measurement, energy):
"""
NAA_net_area determines the net area of a given peak without the use
of compton regions. It generates a region of interest (ROI) based on
full width half maximum (FWHM). A line is generated using the edges of the
ROI and an integral of the line is determine... | df934c7f63a6ee16e71e917861989f15490a4de1 | 467,333 |
import hashlib
def md5_shard(word):
"""Assign data to servers using a public hash algorithm."""
data = word.encode('utf-8')
return 'server%d' % (hashlib.md5(data).digest()[-1] % 4) | ae8ca09af92ca4d1886f4d9489ba50a376038089 | 429,402 |
from pathlib import Path
def upload_path(instance, filename):
"""Helper function. Return the upload path for a file submission."""
return Path(str(instance.thesis.pk)) / filename | 5cff9a37081a0ad3b6b9d117481a449aad6424fd | 552,796 |
def risk_cat(risk):
"""Returns the catagory of risk based on risk"""
if risk < 0.0:
return "Low"
elif risk < 0.5:
return "Moderate"
elif risk < 2:
return "High"
elif risk < 100000000:
return "Severe"
else:
return "Could not be calculated" | bc760e3792a079172dedda795124fd79abebc950 | 430,106 |
from typing import Dict
from typing import Any
def decode_lwl01(data: bytes) -> Dict[str, Any]:
"""Returns a dictionary of engineering values decoded from a Dragino LWL01 Water Leak
Sensor Uplink Payload.
The payload 'data' is a byte array.
"""
# holds the dictionary of results
res = {}
... | fd4605939119f2460ac64e03ae24da09205ec6de | 431,344 |
import random
import hmac
def hash_password(password, salthex=None, reps=1000):
"""Compute secure (hash, salthex, reps) triplet for password.
The password string is required. The returned salthex and reps
must be saved and reused to hash any comparison password in
order for it to match the ... | cac468818560ed52b415157dde71d5416c34478c | 3,988 |
def __remove_string_front(index, string):
"""Helper function to cleanup update_helper and improve readability.
Remove the first [index] characters of a string.
:param index: Number of characters to remove from front of string.
:param string: String to remove characters from.
:return: string with f... | 6dc7d60e51ef67eab77cdcec3256e2cfc9f7c3b1 | 563,992 |
import math
def deg2pix(cmdist, angle, pixpercm):
"""Returns the value in pixels for given values (internal use)
arguments
cmdist -- distance to display in centimeters
angle -- size of stimulus in visual angle
pixpercm -- amount of pixels per centimeter for display
returns
pixelsize -- stimulus size in p... | 1100a347f8021beb051a3a53f32527d9350cb46e | 488,368 |
from typing import List
def calcular_ganador(tiempos: List[int]) -> int:
"""Calcula el ganador de la competencia
:param tiempos: lista de tiempos
:type tiempos: List[int]
:return: ganador
:rtype: int
"""
ganador = 0
for i, tiempo in enumerate(tiempos):
if tiempo < tiempos[... | 20f080a2470bd70e34c10e17dbdd5b56d5ab5a19 | 568,632 |
def extract_mg_h(sai):
"""
Given an SAI, this find the most general pattern that will generate a
match.
E.g., ('sai', ('name', '?foa0'), 'UpdateTable', ('value', '?foa1'))
will yield: {('name', '?foa0'), ('value', '?foa1')}
"""
return frozenset({tuple(list(elem) + ['?constraint-val%i' % i])... | 0a1dd85f5fde1c3aeda4762483cfb87cbbc3d58e | 638,133 |
def f(x):
"""
A function for testing on.
"""
return -(x + 2.0)**2 + 1.0 | 52d2c4a4dec5acaa34371a5cead727d94a36a478 | 39,878 |
def get_log_print_level(client):
"""Get log print level
Returns:
Current log print level
"""
return client.call('get_log_print_level') | 425a7395904e007e6f894e06b7ee04cd8893b718 | 619,144 |
def _make_entropy_fn(level, num_levels):
"""This returns a function that returns a subrange of entropy.
E.g., if level=1 (medium) and num_levels=3, then the returned function will
map the range [x, x + y] to [x + y/3, x + 2y/3].
Args:
level: Integer in range [0, num_levels - 1].
num_levels: Number of ... | bfb087865dedf53049b40f6e6e3c45d3e54783d7 | 434,472 |
def newshape(s, lowdim=0):
"""
Given a shape s, calculate the shape of a new array with the
lowest dimension replaced. If lowdim is zero the lowest dimension
is removed, otherwise it is replaced.
"""
sl = list(s)
if lowdim == 0:
sl.pop()
else:
sl[-1] = lowdim
return ... | e70b82720c75e63c13d138b5d06de20ba2237ecd | 549,804 |
def TrimSequence(sequence, front_cutoff, end_cutoff):
"""
This function takes a sequence and trims the ends off by the specified
cutoffs.
Parameters:
- front_cutoff: the number of positions to trim off at the front
- end_cutoff: the number of positions to trim off at the end
- sequence: the sequence to be trimm... | 073c6fa37aa48afb603ce73eb4e42c086e42038d | 348,643 |
import requests
def get(url, params, proxies, headers):
"""Send a request with the GET method."""
response = requests.get(url, params=params, proxies=proxies, headers=headers)
return response | a481a91e5f3fc71f88de8d84efaac3dd666c302e | 702,137 |
def checkAvailability(payload, age):
"""
Function to check availability in the hospitals based on
user age from the json response from the public API
Parameters
----------
payload : JSON
age: INT
Returns
-------
available_centers_str : String
Available hospitals
tot... | e85494407f102462c5ec269b3ff73ff064e74b9b | 513,719 |
def parse_rule(line):
"""Parse line with rules to rule and replace tuple."""
rule, replace = line.split(' => ')
return rule, replace | 0eedde9832217621269037aff7857e7adbc99b47 | 490,368 |
def clean_text(document_string):
"""
Function that takes in a document in
the form of a string, and pre-processes
it, returning a clean string ready
to be used to fit a CountVectorizer.
Pre-processing includes:
- lower-casing text
- eliminating punctuation
- dealing with edge case p... | 4965047d64e805db265a14152d39473e74e06e29 | 125,489 |
import hashlib
def double_sha256(ba):
"""
Perform two SHA256 operations on the input.
Args:
ba (bytes): data to hash.
Returns:
str: hash as a double digit hex string.
"""
d1 = hashlib.sha256(ba)
d2 = hashlib.sha256()
d1.hexdigest()
d2.update(d1.digest())
retur... | dd4683e5a5ee18f5e1bffa820bf7ed667e16e285 | 253,874 |
def extract_primitives(transitions):
"""
Extract all the primitives out of the possible transititions, which are defined by the user and make an list
of unique primitives.
Args:
transitions (list): indicated start, end primitive and their transition probability
Returns:
list of al... | ed8a52dd72d47edf0039c9ec3eefb48c803735c9 | 402,942 |
from datetime import datetime
import time
def utc2local(utc: datetime) -> datetime:
"""Converts UTC time to local."""
epoch = time.mktime(utc.timetuple())
offset = datetime.fromtimestamp(epoch) - datetime.utcfromtimestamp(epoch)
return utc + offset | 985b263c0f2dd1fa1840656acdfe008bf84d6828 | 562,067 |
def event_converter(event):
"""
Converts event to string format that shows the event's portait on Reddit.
"""
if event["monsterType"] == "DRAGON":
event = event["monsterSubType"]
else:
event = event["monsterType"]
if event == "BARON_NASHOR":
return "[B](#mt-barons)"
... | d19a4bd673bdaa1844199d93f2b06a202498ee00 | 386,519 |
def calculate_elo(R1, R2, S, k=32):
"""
Args:
R1 (float): current rating of the first song
R2 (float): current rating of the second song
S (int): 1 for a win, 0 for a loss
k (float): decides how much the elo rating fluctuates
Returns:
float: the newly calculated el... | f3437055c93e42b9ef0cd3da4a6ae25bd2f6fa73 | 423,134 |
def execute_javascript(self, script, *args):
"""
Synchronously executes JavaScript in the current window or frame.
:Args:
- script: The JavaScript to execute.
- *args: Any applicable arguments for your JavaScript.
"""
try:
value = self.context.driver.execute_script(script, *args)
... | 681c02d2c2d6f4715cc50dc20b07464e261c05be | 124,416 |
def compete_policies(game, agent_1, agent_2, episodes=1_000, search_plies_1=1, search_plies_2=1):
"""Compete two agents against each other.
Alternates the agent's colors after each game and agents use epsilon=0 (no exploration).
Args:
game: A game instance, needs `reset()` and `play_move(move)` me... | 7e0869e994f506d5b3b499c646222ee1441298b3 | 300,245 |
def outlier_removal_drop(dataframe, colname, low_cut, high_cut):
"""Drop rows with outliers on dataframe[colname]"""
col = dataframe[colname]
dataframe = dataframe.loc[
col.isnull()
| col.apply(
lambda x: not isinstance(x, (int, float))
or (x >= low_cut and x <= hig... | 3501bbfced4750dd51517a35f95023bc3cd0aeb7 | 415,882 |
import math
def primality(n):
""" Check the primality of an integer. Returns True or False. """
if n < 2:
return False
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
root = math.sqrt(n)
f = 5
while f <= root:
... | b69325b3a6a40f1f5477a8de5dcad9f117228254 | 464,964 |
def find_line_of_residue(reslist, resinumber):
"""
Returns the line number where residue n appears in the reslist.
:param reslist: res file as list like:
['C1 1 -0.00146 0.26814 0.06351 11.00 0.05',
'RESI 4 BENZ',
'C2 1 -1.13341 -0.23247 -0.90730 1... | 82a32e5e1f15f6c59e8285298de6e8e099d3827d | 285,748 |
def read_input(filename):
"""
>>> template, ins_rules = read_input('example')
>>> template
'NNCB'
>>> len(ins_rules)
16
>>> ins_rules['NH']
'C'
>>> ins_rules['BH']
'H'
"""
template = ""
ins_rules = {}
with open(filename) as fd:
for line in fd:
... | df8a49d556bbe567871bc139cff5fb2919979c3e | 275,427 |
def project(histogram, *args):
"""
Project to a single axis or several axes on a multidiminsional histogram.
Provided a list of axis numbers, this will produce the histogram over those
axes only. Flow bins are used if available.
"""
return histogram._project(*args) | 7573f670370a1f8a6f0e8e1568bc09d6dea04186 | 320,739 |
def remove_line_break(src_str):
"""Replaces link breaks (NL, CR) into whitespaces.
Args:
src_str string: A source string.
Returns:
A modified string.
"""
dst_str = src_str
return dst_str.replace('\n', ' ').replace('\r', '') | 4becefdd22b083ab22142f0288d0e467c8ed1ae2 | 156,836 |
import uuid
def from_str(uuid_str):
"""
Converts a uuid string to an uuid instance
"""
return uuid.UUID(uuid_str) | 9bbd2174ae39283e3f8c024c5eccf599dd0186f4 | 411,023 |
import math
def get_candles_number_from_minutes(unit, candle_size, minutes):
"""
Get the number of bars needed for the given time interval
in minutes.
Notes
-----
Supports only "T", "D" and "H" units
Parameters
----------
unit: str
candle_size : int
minutes: int
Retu... | 5cb7d25483406ea1e23ba9ba6fd05f923e065cb0 | 584,924 |
def str2bool(val):
"""Convert string to boolean value
"""
try:
if val.lower() in ['false', 'off', '0']:
return False
else:
return True
except AttributeError:
raise TypeError('value {0} was not a string'.format(type(val))) | 01d97b141686a79d310ab59a4acb318250b0746b | 8,320 |
import struct
import socket
def ip_to_ascii(ip_address):
""" Converts the quad IP format to an integer representation. """
return struct.unpack('!L', socket.inet_aton(ip_address))[0] | 2cb3ccbe70eed2dd2e8ac21d10e180805dec95ea | 8,555 |
def enum(**named_values):
"""Creates an enum type."""
return type('Enum', (), named_values) | fa8390972f4ef343b3cbcc05bca064fe853aa876 | 677,231 |
def method_header(method_name=None, *args):
"""
Get the formatted method header with arguments included
"""
hdr = "%s(" % method_name
if (len(args) > 0):
hdr += args[0]
for arg in args[1:]:
hdr += ", %s" % arg
hdr += ')'
return hdr | 2c5648c7061dceec5864550938e79a07d5346660 | 528,653 |
import zipfile
import re
def load_zip_file_keys(file, fileNameRegExp=''):
"""Returns an array with the entries of the ZIP file that match with the
regular expression.
The key's are the names or the file or the capturing group definied in the
fileNameRegExp
"""
try:
archive = zipfile.Z... | af1b9bac8956adea22af3b98c66695f1e20e72e4 | 457,832 |
def virt_imei_shard_bounds(num_physical_imei_shards):
"""
Utility function to determine the virtual IMEI shard ranges that should be created for each physical shard.
Arguments:
num_physical_imei_shards: number of physical imei shards
Returns:
list of virt imei shards bounds
"""
... | 9ffef0fa9832b2333dfe0da1dce8d9b1bd726d86 | 387,035 |
from typing import Tuple
from typing import List
from typing import Set
def get_sentences_and_labels(path: str) -> Tuple[List[str], List[List[str]], Set[str], Set[str]]:
"""Combines tokens into sentences and create vocab set for train data and labels.
For simplicity tokens with 'O' entity are omitted.
A... | 70d5f28d155e57de11463d739ded54e18c1205b3 | 544,023 |
def slurp(filename):
"""Return the contents of a file as a single string."""
with open(filename, 'r') as fh:
contents = fh.read()
return contents | 2bac9fd78dbab0cba063d37e86ada00695950377 | 535,776 |
from typing import Counter
def _get_dicts(x_raw, y_raw):
"""Map features and classes to integer values, "indices".
Arguments:
x_raw: [[string]
list of list of string features; outer list represents samples
e.g., [['age_8', 'gender_M', '31', 'V72.3'],
['age_5... | 3810d0d694ccd0e139ee3898651f88b46cb32c92 | 318,876 |
import math
def _phi(x):
"""Cumulative density function for the standard normal distribution """
return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0 | 4c681132799d881001b848f5799e36de5ddbec93 | 99,072 |
def eq_xtl(
Cl, D, F,
):
"""
eq_xtl calculates the composition of a trace element in the remaining liquid after a certain amount of
crystallization has occured from a source melt when the crystal remeains in equilibrium with the melt
as described by White (2013) Chapter 7 eq. 7.81. It then calculate... | 298a5557775a953a645aade70f41818e42e761ac | 701,310 |
def abbrev(str, max_len):
"""
Return a string of up to max length.
adding elippis if string greater than max len.
"""
if len(str) > max_len: return str[:max_len] + "..."
else: return str | 5cf43fd262f8b872275b50192d945fd66203df07 | 414,650 |
def selected_polygons(polygon_gdf, **kwargs):
"""Creates a plotting instance of the boundaries of all selected polygons.
Args:
polygon_gdf (geo-dataframe): geo-dataframe containing the selected polygons.
Kwargs:
Geopandas-supported keyword arguments.
Returns:
ax: Matplotlib ax... | b55295408d08f702cbfccd5236b2d3b6b9d02742 | 205,142 |
def _GetPatternsDistance(pattern_a, pattern_b):
"""Calculates the distance between two patterns.
Args:
pattern_a: a SimilarPattern or TimeSpan.
pattern_b: a SimilarPattern or TimeSpan.
Returns:
Distance in seconds between the two patterns. If they are overlapped, the
distance is 0.
"""
end_... | 394120af9968b7d6b28ec10748ecedf34b5ef3f0 | 495,242 |
def parse_item(item):
"""
Parse a CVE item from the NVD database
"""
parsed_items = {}
cve = item.get('cve', {})
CVE_data_meta = cve.get('CVE_data_meta', {})
ID = CVE_data_meta.get('ID', '')
parsed_items['id'] = ID
affects = cve.get('affects', {})
vendor = affects.get('vendor'... | 26d03e5054ceb33d071273d6894cfba0bed58ec5 | 646,935 |
import asyncio
def synchronize_generator(async_generator, *args, **kwargs):
"""
Returns a synchronous generator from an asynchronous generator
"""
ag = async_generator(*args, **kwargs)
async def consume_generator(stop_signal):
r = await ag.asend(stop_signal)
return r
loop = ... | c301b333491d35cf654ac2eccbc6d4226485e805 | 57,163 |
def get_lines_from_file(file_path: str) -> list:
"""Get all the lines from a file as a list of strings.
:param str file_path: The path to the file.
:Returns: A list of lines (each a `str`).
"""
with open(file_path, encoding="utf-8") as temp:
return temp.readlines() | 487a9c07bf2d46e84a3be2e1aed91e5df0a8179b | 69,317 |
def is_verb_relation(token1, token2):
"""Return True if `token1` is a verb with subject `token2`."""
return (
(token1.upos == "VERB")
and (token2.upos in ["NOUN", "PRON"])
and (token2.deprel == "nsubj")
and (token2.head == token1.id)
) | 1887b109a4c4e87ea94ead24c82d17931f28b676 | 606,939 |
def root_of_number(number: float):
"""
This function returns the square root of a number
"""
return {"root": number ** 0.5} | 7d76cc52bdc56a6fe59c014a423b737b41fd4c51 | 252,759 |
def freebsd_translator(value):
"""Translates a "freebsd" target to freebsd selections."""
return {"@com_github_renatoutsch_rules_system//system:freebsd": value} | 752f3d2b030fd01e0601bcc784dfb66900613a5a | 610,521 |
def xStr(value, default=''):
"""
Extended str() adding a default result, if the input is None
"""
return default if (value is None) else str(value) | 3ba950b312051abf94be259b9b4c1274a0fc47d8 | 122,846 |
def top_files(query, files, idfs, n):
"""
Given a `query` (a set of words), `files` (a dictionary mapping names of
files to a list of their words), and `idfs` (a dictionary mapping words
to their IDF values), return a list of the filenames of the the `n` top
files that match the query, ranked accord... | 7b0fcc9a8211a7d644ed660c58645932a3b9ac00 | 203,815 |
def prefixed_by(apath, some_paths):
"""Check if a path is a a subpath of one of the provided paths"""
return len([p for p in some_paths if apath.find(p) == 0]) > 0 | efb34300ce04623800b85d1f8e48ef49d335b499 | 540,588 |
def jaccard_distance_numeric(x_or_y: float, x_and_y: float) -> float:
""" Calculated the jaccard distance between two series using pre-computed area values.
Parameters
----------
x_or_y, x_and_y: float
precomputed x_or_y and x_and_y, respectively.
"""
return (x_or_y - x_and_y) / x_or_y | a0636b20e45c906b32c76ef9511ed5cbbaf4d161 | 609,123 |
def expand_multi_index(df, new_cols):
"""
Expands a multi-index (and removes the multi-index).
Parameters
----------
df : pandas DataFrame
DataFrame with multi-index to be expanded.
new_cols : list
List of column names for expanded index.
Returns
-------
df : pandas... | e8588f3648915bb846ac392912ca94a10b02fcb9 | 528,197 |
def GetLastTestedSVNVersion(last_tested_file):
"""Gets the lasted tested svn version from the file.
Args:
last_tested_file: The absolute path to the file that contains the last
tested svn version.
Returns:
The last tested svn version or 'None' if the file did not have a last tested
svn version (... | 0f589bf03b07cbe7097c925a546cd8f9d0dde86c | 358,164 |
from pathlib import Path
from datetime import datetime
import shutil
def check_and_backup(filepath):
""" Checks if a file exists at filepath and creates a timestamped backup of the file
Args:
filepath (str, pathlib.Path): Path to file
Returns:
pathlib.Path: Filepath
""... | 1c97abadb72fba8295a8e6f8bfa3fd5751011e33 | 273,247 |
def seq2sentence(seq):
"""Convert sequence to string of space-separated letters"""
return ' '.join(list(seq)) | 635b7b6a143ae9bbf5b12a598c8b3f0acd20b3a7 | 423,175 |
def uriunsplit(uri):
"""
Reverse of urisplit()
>>> uriunsplit(('scheme','authority','path','query','fragment'))
"scheme://authority/path?query#fragment"
"""
(scheme, authority, path, query, fragment) = uri
result = ''
if scheme:
result += scheme + ':'
if authority:
... | 43f5a826ed62838af9fb59c034bf07b695a1b8e0 | 605,433 |
def c2c2DMO(X, choice="NIHAO"):
"""
The ratio between the baryon-influenced concentration c_-2 and the
dark-matter-only c_-2, as a function of the stellar-to-halo-mass
ratio, based on simulation results.
Syntax:
c2c2DMO(X,choice='NIHAO')
where
X: M_star / M_vir (float or arra... | 4e546add71267c34a9d77a733c5ce99b4ce47d47 | 427,237 |
def _find_version_line_in_file(file_path):
"""
Find and return the line in the given file containing `VERSION`.
:param file_path: Path to file to search.
:return: Line in file containing `VERSION`.
"""
with open(str(file_path), "r") as fileh:
version_lines = [
line for line ... | ef3e648ac6b4e9f89e67986507eba74ba65ded2d | 663,173 |
def get_position_below(original_position):
"""
Given a position (x,y) returns the position below the original position, defined as (x,y-1)
"""
(x,y) = original_position
return(x,y-1) | 87a52a824dc124474ae734151aa4ff4302467030 | 459,916 |
def physicond(amp, t_phi, t_th):
""" Function enforcing the physical conditions of the system. Namely,
the perturbation in temperature cannot be a negative one. Thus function
assures a positive or null amplitude,
positive or null characteristic times,
and quicker rising exponential than the decaying... | b8aafab125ba73408378c052dc8f2c7a883eed97 | 183,940 |
def match(pattern, address):
"""
Match ip address patterns.
This is not regex.
A star at the end of a ip address string does prefix matching.
None or a blank string matches any address
match('192.168.0.1', '192.168.0.1') == True
match('192.168.0.2', '192.168.0.1') == False
match('192.16... | 5943909fe6c83163700e40c18c9d5e6750764859 | 113,342 |
def create_api_call_headers(_client_id, _auth_token):
"""
Creates the necessary headers to invoke an API call.
@param _client_id: Client ID magic string.
@param _auth_token: Authentication token magic string. This is usually stored in the application state/configuration.
@return: A map of headers.
"""
ret = {}... | 0a768e25b9552d222197655a0994a9ed4eb9dca1 | 581,512 |
def get_r_env(A_env, A_A):
"""床面積の合計に対する外皮の部位の面積の合計の比 (7)
Args:
A_env(float): 外皮の部位の面積の合計 (m2)
A_A(float): 床面積の合計 (m2)
Returns:
float: 床面積の合計に対する外皮の部位の面積の合計の比
"""
return A_env / A_A | eb01ff8f3478e082d5649316445db34524c7735d | 600,701 |
def exp_required(level: int) -> int:
"""
Computes EXP required for current level
- EXP Required: (8 * Level^3) / 4
"""
BASE_EXP = 8
amount = BASE_EXP * (level ** 3)
return round(amount / 4) | 835d1c1c48ffa767edaabd6611b3f5173702bd10 | 301,774 |
import operator
def sequence_eq(sequence1, sequence2):
"""
Compares two sequences.
Parameters
----------
sequence1 : sequence
The first sequence.
sequence2 : sequence
The second sequence.
Returns
-------
bool
`True` iff `sequence1` equals `sequence2`, othe... | 3e6520602272873f471c808ad14c6d3a90d31972 | 673,743 |
def _find_assignment(arg_token):
"""
Find the first non-escaped assignment in the given argument token.
Returns -1 if no assignment was found.
:param arg_token: The argument token
:return: The index of the first assignment, or -1
"""
idx = arg_token.find('=')
while idx != -1:
if... | e7673c6aa8190f327cafc18b66d4394c38615543 | 236,027 |
def header_is_sorted_by_coordinate(header):
"""Return True if bam header indicates that this file is sorted by coordinate.
"""
return 'HD' in header and 'SO' in header['HD'] and header['HD']['SO'].lower() == 'coordinate' | b656770806818abe742be32bc14c31a8a8e3e535 | 703,016 |
def _pandas_rolling_since_018(df, window, *args, **kwargs):
"""Use rolling() to compute a rolling average"""
return df.rolling(window, *args, **kwargs).mean() | ef29d860811ff57df9ff9a023bfee2261d24498c | 473,534 |
def create_readonly_assessment_params(content, answers):
"""Creates parameters for a readonly assessment in the view templates."""
assessment_params = {
'preamble': content['assessment']['preamble'],
'questionsList': content['assessment']['questionsList'],
'answers': answers,
}
r... | b93954ace8c84e894a1eda46d4a5fe3b17c69129 | 445,302 |
def distance_from_camera(bbox, image_shape, real_life_size):
"""
Calculates the distance of the object from the camera.
PARMS
bbox: Bounding box [px]
image_shape: Size of the image (width, height) [px]
real_life_size: Height of the object in real world [cms]
"""
## REFERENCE FOR GOPRO
... | 037adbaba89ae13ed74ac5fc1d1cfc080c5107d1 | 676,041 |
def dotv3(a,b):
"""dot product of 3-vectors a and b"""
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; | 01d3b5bc8cd8e0de6da1617bf0dc300502c099fc | 298,464 |
import torch
def batch_linear(x, W, b=None):
"""Computes y_i = x_i W_i + b_i where i is each observation index.
This is similar to `torch.nn.functional.linear`, but a version that
supports a different W for each observation.
x: has shape [obs, in_dims]
W: has shape [obs, out_dims, in_dims]
b... | 1cac8de9ad6b0941149f254a925da310f2c67fc6 | 46,428 |
def get_x_y(data):
"""Return the features (X) and target (y) for Ames Housing Dataset.
These values were chosen initially by investigating univariate comparisons with boxplots and scatter plots between features and Log Saleprice. Log transformed features are used in cases where a log transformation turned a ri... | f772474de88823821244c3edb40dce2b1c49530b | 352,301 |
from io import StringIO
import json
import hashlib
def digest_object(obj, encoding='utf-8'):
"""Convert any object to md5 hex digest through a ordonned and minified JSON data."""
io = StringIO()
json.dump(
obj, io, skipkeys=False, ensure_ascii=False,
check_circular=True, allow_nan=True, cl... | 77bcdfcc0a1a0782220a37cf29d2f86da236dd57 | 251,351 |
def get_labels(fields):
"""
Helper function to get .mat struct keys from `fields`
Parameters
----------
fields : dict_like
Returns
-------
labels : list
Struct keys
"""
labels = [k for k, v in sorted(fields.items(),
key=lambda x: x[-1]... | d9fadbd05b2096c2a909125fbbc657f7e40cc90e | 466,194 |
def nested_get(dictionary, keys):
"""Get nested fields in a dictionary"""
to_return = dictionary.get(keys[0], None)
for key in keys[1:]:
if to_return:
to_return = to_return.get(key, None)
else:
break
return to_return | a01f04aae670f118c97808ab27933799b0613c56 | 631,306 |
def collect_input_files_from_input_dictionary(input_file_dict):
"""Collect all @ids from the input file dictionary"""
all_inputs = []
for an_input_arg in input_file_dict:
if an_input_arg == 'additional_file_parameters':
continue
if isinstance(input_file_dict[an_input_arg], (list,... | 865ad6a453b2127a0a553f54a2cdac1d44d6dfc3 | 548,797 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.