content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def TestSuccessful(test_output, test_result):
"""Returns true if the return value of CompareResults is a test success."""
if test_result.has_key('error'):
return (False, test_result['error'])
if not test_output.has_key('image_file'):
return (False, 'No output image file produced.')
if not test_result.ha... | dcbd38e4e1b025226e349ccfbd380ae35156dc0b | 169,626 |
def get_dim_wind(self):
"""Get the two first dimension of the winding matrix
Parameters
----------
self : Winding
A Winding object
Returns
-------
(Nrad, Ntan): tuple
Number of layer in radial and tangential direction
"""
return (1, 1) | 7657697dd8e26d20fd1ce370f7aee7a0eeff6328 | 587,443 |
def normalize(tokens, case=False):
"""
Lowercases and turns tokens into distinct words.
"""
tokens = [
str(t).lower()
if not case
else str(t)
for t in tokens
]
tokens = [t.strip() for t in tokens if len(t.strip()) > 0]
return tokens | 998cfb6632db2830700ff71698e2d303fdc22718 | 379,637 |
def get_vocabulary_info(feature_info, file_io):
"""
Extract the vocabulary (encoding and values) from the stated vocabulary_file inside feature_info.
Parameters
----------
feature_info : dict
Dictionary representing the configuration parameters for the specific feature from the FeatureConfi... | 4e336995c8364b23da325c17e1a63fe2ea69dc27 | 578,004 |
import torch
def _get_intermediate_features(resnet, input_):
""" Receives a ResNet50 network and a valid input and extracts intermediate features.
Extracts features right after each conv or fc layer (plus one right before the last
fc) so 51 in total.
Arguments:
resnet (nn.Module): A Res... | 5c31e45e92bf1775d9c5fd20fd2157c293fb0297 | 359,015 |
def combin(n, k):
"""Number of combinations C(n,k)"""
if k > n // 2:
k = n - k
x = 1
y = 1
i = n - k + 1
while i <= n:
x = (x * i) // y
y += 1
i += 1
return x | 7d7ce529652170dc8da14a5370c11e8b2ea0f721 | 251,725 |
from typing import Any
from typing import Iterable
import itertools
def prefix(val: Any, it: Iterable):
"""Add a value to the beginning of an iterable. Return an iterable.
>>> tuple(prefix(1, (2, 3, 4)))
(1, 2, 3, 4)
"""
return itertools.chain((val,), it) | c43d232fea9e4d99f0d21b12b7d0cd56770e1692 | 397,007 |
def until(n, filter_func, v):
"""Build a list: list( filter( filter_func, range(n) ) )
>>> list( filter( lambda x: x%3==0 or x%5==0, range(10) ) )
[0, 3, 5, 6, 9]
>>> until(10, lambda x: x%3==0 or x%5==0, 0)
[0, 3, 5, 6, 9]
"""
if v == n:
return []
if filter_func(v):
ret... | 1996d5a27f964267122604937fa1163fa0da20cd | 664,441 |
import six
import codecs
def normalise_charset_name(s):
"""Convert an encoding name to the form implied in the SGF spec.
In particular, normalises to 'ISO-8859-1' and 'UTF-8'.
Raises LookupError if the encoding name isn't known to Python.
"""
if not isinstance(s, six.text_type):
s = s.d... | 5aa0303376231577aed7af03f9224c899adf0c38 | 530,406 |
import torch
def CE_loss(x, y):
"""Computes the Cross Entropy loss of the given prediction x and target y"""
return torch.nn.functional.binary_cross_entropy(x, y) | 25d1f5362f2e1ab86fe11410193ff3957c874299 | 406,951 |
def create_daily_schedule_details(api, api_exception, custom_interval, start_time):
""" Creates a ScheduleDetails object for use with a scheduled task for daily execution using a custom interval.
:param api: The Deep Security API modules.
:param api_exception: The Deep Security API exception module.
:p... | 80dab4ccb9141bd6da53d907a4a55cdaf52c1950 | 385,321 |
def factorial(
of: int,
down_to: int = 0
) -> int:
"""
Returns the multiplication of all positive integers from ``of`` down
to (but not including) ``down_to``.
:param of:
The greatest positive integer to include in the product.
:param down_to:
The gre... | 72f50fb3359ecaf828991a29008ebded2f25c089 | 384,997 |
def remove_suffix(name):
"""
Remove suffix from given name string
@param name: string, given name string to process
@return: string, name without suffix
"""
# By convention, we split the names when we find a _ character
edits = name.split('_')
# If there is not a _ it means that there ... | c54a5902fae1d384a333e3610aac67900d388838 | 562,826 |
from typing import Optional
def try_parse_int(s:str) -> Optional[int]:
""" Convert `s` to an integer, if possible
Parameters
----------
s : string
A string which may represent an integer
Returns
-------
int_s : int
An integer
--- OR ---
None
If... | eb851aa2fdaf85367b6695b367d33df9dd12f80c | 211,879 |
import re
import logging
def get_device(device: str):
"""Get device (cuda and device order) from device name string.
Args:
device: Device name string.
Returns:
Tuple[bool, Optional[int]]: A tuple containing flag for CUDA device and CUDA device order. If the CUDA device
flag i... | df60ac6a7a5f17c3d2454e67e02ef38804bed6c1 | 100,939 |
from typing import List
import ast
def _ast_for_fiddler(func_name: str, param_name: str,
body: List[ast.AST]) -> ast.FunctionDef:
"""Returns an `ast.FunctionDef` for the fiddler function.
Args:
func_name: The name of the fiddler function.
param_name: The name of the fiddler function'... | 8c531c9bb931564560cd4bdb9db9862c9d6e7523 | 557,825 |
from typing import List
def opt_filter_string(filter_string: str, id_list: List[int]):
""" Generate string for option-based filter.
Generates a filter for filtering for specific rows based on the unique
element ID that will be added to the main SQL query.
Args:
filter_string: Start of the fi... | 6ef5680d95bc2ac3e894002e599b11ba2c634366 | 645,620 |
def get_reasonable_repetitions(natoms):
"""
Choose the number of repetitions
according to the number of atoms in the system
"""
if natoms < 4:
return [3, 3, 3]
if 4 <= natoms < 15:
return [2, 2, 2]
if 15 <= natoms < 50:
return [2, 2, 1]
return [1, 1, 1] | 96d19519a86afd31f7771c4ac3c5e0e4104ba457 | 511,972 |
import inspect
def _get_fit_parameter_names(fn):
""" Get the name of all but the first parameter to the given function """
return list(inspect.signature(fn).parameters.keys())[1:] | cf04daa19863746d06cf2c8dc38e70103662af27 | 361,529 |
from pathlib import Path
import re
def sanitize_path(path, subchar='-', invalid_chars=r'[^a-zA-Z0-9-_.]',
invalid_comps=('.', '..', '.git'), force_suffix='.git'):
"""Sanitizes a path by making it relative and git safe.
Any part coming in will be made relative first (by cutting leading
s... | b2722acbde15588944dd395631b5dde7f917aedc | 289,725 |
import torch
def any_nan(tensor: torch.Tensor) -> bool:
"""Returns true if the tensor contains a NaN
Args:
tensor (torch.Tensor): the input tensor
Returns:
bool: true if contains a NaN
"""
return bool(torch.isnan(tensor).any().item()) | ba14b4efac9930b5dd67f32a7e38ec1db049e714 | 499,619 |
def reSubObject(pattern, string, repl=None):
"""
like re.sub, but replacements don't have to be text;
returns an array of alternating unmatched text and match objects instead.
If repl is specified, it's called with each match object,
and the result then shows up in the array instead.
"""
las... | 3e59d54a7a28f5793df71be53cbd39ddd3248548 | 72,721 |
def convert_value(var):
"""Convert the metric value from string into python type."""
if var["type"] == "number":
return float(var["value"])
if var["type"] == "boolean":
return var["value"] == "true"
if var["type"] == "string":
return var["value"]
print("can't convert unknown... | 52dc9ebe2f66de7638dc8f5ab8261c1e2f76e199 | 61,546 |
from typing import Union
from pathlib import Path
def pathing(path: Union[str, Path], new: bool = False) -> Path:
""" Guarantees correct expansion rules for pathing.
:param Union[str, Path] path: path of folder or file you wish to expand.
:param bool new: will check if distination exists if new
(... | cc65980464cbb07c9fbea39d95e824ae2f1488ee | 291,160 |
from typing import OrderedDict
def _remove_duplicates(input_list):
"""Remove duplicate entries from a list.
This operation preserves the order of the list's elements.
Args:
input_list (list[Hashable]): The list whose duplicate entries shall be removed
Returns:
list[Hashable]: The in... | 9613674ceb137eb1a46a394efda1617593203888 | 595,810 |
def unique_wrt(reqs, main_reqs):
"""Ensures reqs doesn't contain anything in main_reqs."""
return list(set(reqs) - set(main_reqs)) | 48be213a6a8237b9b498ce8272603b2f734e0035 | 283,453 |
def blend(arr1, arr2, alpha=0.5):
"""Blend 2 arrays together, mixing with alpha.
Parameters
----------
arr1:array
Image 1.
arr2:array
Image 2.
alpha:float
Higher alpha makes image more like image 1.
Returns
-------
array
Resulting image.
"""
return alpha*arr1 + (1.-alpha)*arr2 | ad94bde493d7f0bcb6e0207992a9b7106483de08 | 342,942 |
def wbi(b2, b4):
"""
Water Body Index (Domenech and Mallet, 2014).
.. math:: WBI = (b2 - b4) / (b2 + b4)
:param b2: Blue.
:type b2: numpy.ndarray or float
:param b4: Red.
:type b4: numpy.ndarray or float
:returns WBI: Index value
.. Tip::
Domenech, E., Mallet, C. 2014. C... | 40b82a3011f151cbf32158b2a7354cdbb8498353 | 417,907 |
def perfect_inserter(t, keys):
"""Insert keys into tree t such that t is perfect.
Args:
t (BinaryTree): An empty tree.
keys (list): A sorted list of keys.
"""
def f(n):
"""find the point so partition n keys for a perfect tree"""
# x = 1
# while x <= n//2:
... | aac46a29e52dc2dcf7ef20cd0580488d4312a906 | 385,750 |
def parse_modifiers(modifiers):
"""Parse modifiers(regex match object) into type sets then return them."""
weaknesses, immunities = set(), set()
sections = modifiers.group(1).split(';')
for section in sections:
split = [w.strip(',') for w in section.strip().split(' ')]
for word in split[... | 1a144fa6317e58a1de7d302fe17ca70aba61bd1b | 94,059 |
def _rectify_column(df):
"""remove string spaces from the column names of the PNBOIA dataframe
Parameters
----------
df : pandas dataframe
Returns
-------
Pandas dataframe
"""
df1 = df.copy(deep=True)
k = {i: i.replace(' ', '') for i in df.keys()}
df1 = df1.rename(columns=k... | 2e3e66fe5f9d7746c17fc19a2a6747f484ea05c7 | 429,297 |
def cmpid(a, b):
"""Compare two objects by their Python id."""
if id(a) > id(b): return 1
if id(a) < id(b): return -1
return 0 | f698d8e757418d9a2a6baa6596d6643b02e2a336 | 126,475 |
def serialise_roles(Member):
"""Turns a list of roles in a comma-seperated string."""
return ",".join([Role.name for Role in Member.roles]) | a4c98513af25d65f949339d27ae6383fa5e89d34 | 436,056 |
def std_average(four_month_std):
"""
A function that computes the std specific average. This is just the average
:param: four_month_std A series with the historical % change std
:return: float The average
"""
return four_month_std.mean() | ae76aa1ef8400595c72a7e58e2e883f0fde2a7be | 572,169 |
def check_file_extension(filename, extension_list):
""" Check if the extension file match with the authorized extension list
:param string filename: Filename to check
:param list extension_list: The list of extension the file have to match to
:return: True if the extension is correct, False... | 91f184fc940b8d71c77ebd56a5d229a864906421 | 634,639 |
import hashlib
def calculate_hash(file_path: str, block_size: int = 10240, hash_content=True):
"""
Helper function that calculates the hash of a file/folder.
If the given path is a folder: the hash of the string absolute path will be calculated
If the given path is a file: the hash of the binary conte... | bc2d2fafe61ad5747ee89f36820964a175367cef | 207,261 |
def weather_scale(wx_type):
"""
returns an integer from 1-5 for a relative scale of the various weather descriptions
more documents here
https://www.visualcrossing.com/resources/documentation/weather-api/weather-condition-fields/"""
wx={
'type_43': {'type': 43, 'description':'Clear', '... | 3f1810bc7eb82dc074808b9f42a82b9cc03aadfb | 291,308 |
def stringtogether(alist):
"""Return elements in a list as a string."""
return ''.join(alist) | a71ddb73be255e1964bbfc3de40409986325eb2a | 456,224 |
def calc_check_digits(number):
"""Calculate the check digits for the number."""
d1 = (11 - sum(((3 - i) % 8 + 2) * int(n)
for i, n in enumerate(number[:12]))) % 11 % 10
d2 = (11 - sum(((4 - i) % 8 + 2) * int(n)
for i, n in enumerate(number[:12])) -
2 * d1) % 1... | 6f882773a4c84a628004d57f51499d16bb66772a | 232,161 |
def topological_sort(graph):
"""
Repeatedly go through all of the nodes in the graph, moving each of
the nodes that has all its edges resolved, onto a sequence that
forms our sorted graph. A node has all of its edges resolved and
can be moved once all the nodes its edges point to, have been moved
... | d67113e456f7c7a6f366bc216235dbca8c818f91 | 334,187 |
def _direction_to_index(direction):
"""Map direction identifier to index.
"""
directions = {-1: 0, 0: slice(None), 1: 1, '<=': 0, '<=>': slice(None), '>=': 1}
if direction not in directions:
raise RuntimeError('Unknown direction "{:d}".'.format(direction))
return directions[direction] | 1612c7107601a6166e478815b89725701f8dc3ff | 675,621 |
def duration(df):
"""Finds time duration of ECG strip
This function subtracts the minimum time value from the maximum time
value and returns the duration of the ECG strip.
:param df: a dataframe of floats of ecg data
:returns: a float of the duration of the ECG strip in seconds
"""
max_ti... | dab50a2aed4fb2ddc69cab75263c9c331bf1d437 | 122,009 |
def left_string(string, padding):
"""
Formats a string with padding. Either adds spaces to the end or truncates
Args
----
string : str
String for printing
padding : int
Width (in columns) for the final format
Returns
-------
: str
If ``string`` is longer than ... | 5406614cf30a0d194547140c7ba28a52711d3867 | 271,570 |
def check_variable_exclusion(variable_name, ex_variables):
"""Checks whether the variable has to be excluded.
Excluded variables are reported by the user in the .cfg file
Arguments:
variable_name {string} -- the variable name
ex_variables {list} -- the list of excluded variables
... | b1e95c665e14450189d6aa1204e733d8b19e2ece | 207,527 |
def _ravel_dictionary(dictionary, conflict):
""" This function unravels a dictionary, un-nesting
nested dictionaries into a single dictionary. If
conflicts arise, then the conflict rule is used.
The keys of dictionary entries that have dictionary
values are discarded.
Parameters
--... | 162e2dea81e83009e3409e709516dbd47e51f5c3 | 281,304 |
def has_data(data: str) -> bool:
"""
Checks if the input contains data. If there are any non-whitespace
characters then return True, else return False.
Parameters:
data: (string) input to check whether it contains data
Returns:
Boolean True if input string (data) cont... | d8eff13c3de2c933830e2acafc55c6ad39a671f8 | 320,691 |
def pad(data, blocksize=16):
"""
Pads data to blocksize according to RFC 4303. Pad length field is included in output.
"""
padlen = blocksize - len(data) % blocksize
return bytes(data + bytearray(range(1, padlen)) + bytearray((padlen - 1,))) | f4fa160ab8f37f3156191b80545bc0664ddd44dc | 249,007 |
def ipc_error_response(resp_data):
"""Make error response."""
response = ("error", resp_data)
return response | 78191c47af640cb25874d349ee96326458c4c82e | 288,175 |
def GetAllDictPaths(tree_dict):
"""Obtain list of paths to all leaves in dictionary.
The last item in each list entry is the value at the leaf. For items in
dictionary that are a list of dictionaries, each list entry is indexed by a
string repesenting its position in the list.
Implementation inspired by http... | be291f58c7b2a3fe63fc4e8b8e9b2fd57de45b5e | 66,734 |
def first_negative(l):
"""
Returns the first negative element in a given list of numbers.
"""
for x in l:
if x < 0:
return x
return None | 1e62ce772f7d38e3835e5d6635c33bf365f134e7 | 49,812 |
def determine_issues(project):
"""
Get the list of issues of a project.
:rtype: list
"""
issues = project["Issue"]
if not isinstance(issues, list):
return [issues]
return issues | 7b8b670e4ad5a7ae49f3541c87026dd603406c9f | 708,245 |
def time_str_to_seconds(time):
"""Convert a time intervall specified as a string ``dd:hh:mm:ss'`` into seconds.
Accepts both ',' and ':' as separators."""
intervals = [1, 60, 60*60, 60*60*24]
return sum(iv*int(t) for iv, t in zip(intervals, reversed(time.replace('-', ':').split(':')))) | f451f398108bea7c9d9050175c97d6698c2643f4 | 243,401 |
def create_cubes(n):
"""returns list of cubes from 0 to n"""
result = []
for x in range(n):
result.append(x**3)
# entire 'result' list in memory (inefficient)
return result | 59055269162ba33407ea0ede9747b77b74e504db | 80,788 |
def channel_parser(channel):
"""Parse a channel returned from ipmitool's "sol info" command.
Channel format is: "%d (%x)" % (channel, channel)
"""
chan, xchan = channel.split(' (')
return int(chan) | d2a5cb20b9e44bbbc6c617706e952b333db5b2b4 | 675,519 |
def member_to_beacon_proximity_smooth(m2b, window_size = '5min',
min_samples = 1):
""" Smooths the given object using 1-D median filter
Parameters
----------
m2b : Member to beacon object
window_size : str
The size of the window used for smoothing. Def... | 0825d167e4ae78a7b7204881e939c162aba77c3e | 483,129 |
def dict_to_g6a(geometry_dict: dict, result_path: str) -> bool:
"""
Turns a dictionary into a delphin geometry file.
:param geometry_dict: Dictionary holding the information for the geometry file
:param result_path: Path to were the geometry file should be written
:return: True
"""
file_ob... | 64cfe0f96fa434f0541ee205ceceadaf067cd419 | 133,654 |
def join(*paths):
"""
Joins multiple paths into a single path.
Arguments:
*paths -- path components
"""
path = ""
for component in paths:
path += ("/" if path and not path.endswith("/") else "") + component.replace(
"\\", "/"
)
return path | 68b41d4efdf1979347e56b69dc7eb30fc77ae875 | 653,247 |
def always_roll(n):
""" Возвращает стратегию, по которой всегда происходит N бросков.
>>> strategy = always_roll(5)
>>> strategy(0, 0)
5
>>> strategy(99, 99)
5
"""
def strategy(score, opponent_score):
return n
return strategy | 7f6489a64dcb525a1467763cb68521bb37fefb35 | 677,705 |
def get_distance(p1, p2):
"""It finds the minimum distance between two Points
Parameters
----------
p1 : shapely geometric object
The first point
p2 : shapely geometric object
The second point
Returns
-------
list
Returns the minimum distance. The value follows ... | 2bcfdc62b25e286d1a1d46c27f058e8da3e722e9 | 40,305 |
def getParamIndx(fit, name, parameter):
"""Get index for a specific parameter for a specific source
from model in UnbinnedAnalysis object fit"""
ID = -1
# Try to get the first component (if summed analysis)
try: fit = fit.components[0]
except: pass
spec = fit[name].funcs['Spectrum']
f... | 6451d6494f55495802e67ab4b9185f7236dee0f2 | 394,608 |
import math
def distance(coords1, coords2):
"""
Calculate the distance between two coordinates, as denoted by
dist = sqrt((x2- x1)^2 + (y2 - y1)^2 + (z2 - z1)^2))
Parameters
coords1: Coordinates of form [x,y,z]
coords2: Coordinates of form [x,y,z]
Retu... | 6b4fc0a99f4f55fec463c453247d5f4466826587 | 382,125 |
def _slice_set(X, dates):
"""
Returns a copy of the original data, sliced based on the specified dates
:param X: dataset with a MultiIndex consisting of date as pd.DatetimeIndex and category
:param dates: list of dates for filtering
:return: subset of X (copy)
"""
new_samples = X.copy().loc[... | 689ca235d30cd9e18191ded26a96a6785915d175 | 552,645 |
import struct
def pngxy(data):
"""read the width/height from a PNG header"""
ihdr = data.index(b'IHDR')
# next 8 bytes are width/height
w4h4 = data[ihdr+4:ihdr+12]
return struct.unpack('>ii', w4h4) | b0d3fe3930858d5b6f22075405339ce358c81dd1 | 232,770 |
from typing import BinaryIO
def read_hex(stream: BinaryIO) -> bytes:
"""
Read HEX line from stream and decode as bytes
Args:
stream: stream to read from
Returns: decoded bytes
"""
return bytes.fromhex(stream.readline().decode()) | fd2f08c6fc280ee2a5e0ec08125b58c76278ef3a | 512,401 |
def sanitize(s) -> str:
"""
Returns string decoded from utf-8 with leading/trailing whitespace
character removed
"""
return s.decode('utf-8').strip() | f3d2d520ae74a0bbfaa27ab749fa8d3c83e5dda7 | 256,177 |
from typing import Iterable
def flexible_str(obj):
"""
A more flexible str function which intelligently handles stringifying
strings, lists and other iterables. The results are lexographically sorted
to ensure generated responses are consistent when iterables such as Set
are used.
"""
if o... | 69b2210470c012848ab4c29d3d3dca7b24ba25a8 | 207,901 |
import logging
def getLoggers(dotted_module_name):
"""
Returns two loggers. The first is in the namespace that's passed-in.
The second inserts ".math" as the second module, so ``cascade.core.log``
becomes ``cascade.math.core.log``.
Args:
dotted_module_name (str): The name of the module, u... | e5a4d8deb029cd3326d4d8f773063c1a2e418805 | 488,618 |
import json
def get_json(file_name):
"""Load JSON data from a file."""
with open(file_name) as json_data:
return json.load(json_data) | 79ecbc4859631aeed2c21eda8ae41b9eca3c6836 | 427,249 |
def join_prefix(values, num):
"""Produce a string joining first `num` items in the list and indicate
total number total number of items.
"""
if len(values) <= 1:
return "".join(values)
if len(values) <= num:
return ", ".join(values[:-1]) + " and " + values[-1]
return "%s and %d o... | 82952d2f451019c4ea945cf6b7876fe6cff4f262 | 336,696 |
def hzip(x):
"""
Zips the first and second half of `x`.
If `x` has odd length, the last element will be ignored.
>>> list(hzip([1, 2, 3, 4, 5, 6]))
[(1, 4), (2, 5), (3, 6)]
>>> list(hzip([1, 2, 3, 4, 5, 6, 7]))
[(1, 4), (2, 5), (3, 6)]
"""
N = int(len(x) // 2)
return zip(x[:N... | c99214a2f8e3110b0d070ed5fa3fdd428cb0dd6b | 659,731 |
def generate_memory_region(region_descriptor):
""" Generates definition of memory region.
Args:
region_descriptor (dict): memory region description
Returns:
string: repl definition of the memory region
"""
return """
{}: Memory.MappedMemory @ sysbus {}
size: {}
""".format(regi... | 0e1ff3468cdeb5495d26c9acc080b2dda154d31b | 142,692 |
def stripTag(chunk):
"""Strips the tag and returns the rest of the chunk. Only useful in password-protected uploads.
Arguments:
chunk {bytes} -- Everything inside the message field of an IOTA tx, except for the signature.
Returns:
[bytes] -- Chunk without the tag.
"""
#tag = chunk[-16:]
chunkAndNonce = c... | 3b56916a798b261b282ef35c1c5613f9404da327 | 605,088 |
def snake2title(s):
"""Convert 'snake_case' string to 'Title Case' string."""
return ' '.join(s.split('_')).strip().title() | 77d0e4589e1f5b9dc0e18a625acdd9e7e3dd8efb | 466,681 |
def read_file(a_file):
"""
Read the specified file and return its content as one string.
"""
with open(a_file, 'r') as fp:
content = fp.read()
return content | 0d61a52aa0678eaad52d243c4c79a538f7531665 | 515,787 |
def edgeos_action(object, on=None):
"""
Return the appropriate EdgeOS configuration command to send with *object*.
Unless *on* is specified, return "set" if *object* evaluates to ``True`` or
"delete" if *object* evaluates to ``False``.
When *on* is specified, if *object* evaluates to ``True``, the... | 47ed4a10c22f1e439ffe93105b21f584825e4040 | 610,430 |
import logging
import ftplib
def ftp_check_directory(ftp_connection, path):
"""
Following convention with the rest of the code,
return 0 if it is a directory, 1 if it is not or failed to do the check
"""
response = ftp_connection.pwd()
if response == '':
return 1
original_directory... | fba5ff58c84cf78d8c0c1fd72adb9c581d9888c2 | 217,275 |
def middle(t):
"""Takes a list, returns a new list with first and last elements removed"""
return t[1:-1] | 51da0fbefa9ee7c23c431dea9cfb0ff22139b778 | 606,753 |
def get_offer_facebook_description(html_parser):
"""
This method returns the short standardized description used for the default facebook share message.
:param html_parser: a BeautifulSoup object
:rtype: string
:return: The default facebook share message
"""
fb_description = html_parser.fin... | 2df75f99a4f666dcd6cc6352ee9bea626e928418 | 491,768 |
import itertools
def countCombosSumEqual(sm: int, nums: list) -> int:
"""
Count all possible combos of elements in nums[] such that sum(combo) == sm
Args:
sm (int): the sum to match.
nums (list): list of positive integers.
Returns:
int: resulting count.
If nums[0] == sm,... | 6ab5af1a6b26d6043b677f607a56e989d6d45200 | 678,617 |
import itertools
def list_flatten(_l):
"""Flatten a complex nested list of nested lists into a flat list
"""
return itertools.chain(*[list_flatten(j) if isinstance(j, list) else [j] for j in _l]) | 05d1e4018accfe850c07504f123d85949a2ced60 | 698,340 |
import struct
def _decode_int(s):
"""
Decodes the 4-byte strings representing a 4 byte big endian integer
into an int.
:param s: A 4 byte string representing an integer
:return: The integer the string passed represents
"""
return struct.unpack('>i', s)[0] | f98d1d1fa2365c74307fd68f3ddec273c68b012b | 607,893 |
def _deep_get(instance, path):
"""
Descend path to return a deep element in the JSON object instance.
"""
for key in path:
instance = instance[key]
return instance | 3dad3eed0115c244ee60e887049747200ed1838c | 686,097 |
import itertools
def nth(iterable, n):
"""Returns the nth item from iterable."""
try:
return iterable[n]
except TypeError:
try:
return next(itertools.islice(iterable, n, None))
except StopIteration:
raise IndexError('index out of range') | 6ca5f1aa0f78607a9f0d31b43fe9ec5cd8a30623 | 82,167 |
import gzip
import bz2
def open_file(fname, mode):
""" A wrapper around `open()` that also supports gzip and bz2.
Args:
mode (str): should either be 'r' or 'w'. A 't' will be appended when
reading from a compressed file.
"""
if fname.endswith('.gz'):
return gzip.open(fname, mode + 't'... | 258555a025d9bb45bd26d2e59504144749d00c19 | 298,551 |
def create_dockerfile(ctx):
"""
Creates a Dockerfile for this project.
"""
return ctx.obj['docker'].create_dockerfile(
project=ctx.obj['project_name']
) | 4530978e708bf727fd9c8e904972cf55da4aef18 | 625,820 |
def evaluate_by_syntax(what_is_being_parsed, tokens, syntax_table):
"""
Given a tokenized form of what is being parsed, find the handler for it in
a provided syntax table and invoke the handler. If no matching syntax is
found in the syntax table, raise ValueError.
:param what_is_being_parsed: stri... | ca58326c696d857b2f0d175731219a15fbaa201b | 202,542 |
import json
def read_vocab(vocab_path):
"""
Read vocabulary
"""
words_index = json.loads(open(vocab_path + 'words_index.json', 'r', encoding = 'utf-8').read())
return words_index | d86a813d270639835bb5937a2946042266729aa5 | 491,988 |
def is_config_or_edit_end(line, configs):
"""
Is the line indicates that 'config' or 'edit' section ends?
- config <name>
...
end
- edit <name>
...
next
:param line: A str represents a line in configurations output
:param configs: A stack (list) holding config node... | 13047c503ed4bbff4019b25e5de939922cdbea48 | 148,594 |
def get_release_date(data):
"""Get release date."""
date = data.get("physicalRelease")
if not date:
date = data.get("inCinemas")
return date | 65066b370c91b7b47853e1348e3022af9522108c | 105,190 |
def as_bytes(value, length):
"""Turn an integer into a byte array"""
return value.to_bytes(length, byteorder="big", signed=False) | ae6b0eeb1d15899cbdff23be79e2d43f1b92dee9 | 328,288 |
def load_data(word_path):
"""Read data from file."""
with open(word_path, "r") as lines:
return [line.strip() for line in lines] | 05c85ae9480e60217477448ead0b2155d977e983 | 556,005 |
def safe_short_path(file_):
"""Like `File.short_path` but safe for use with files from external repositories.
"""
# Note: "F" is "File", "FO": is "File.owner". (Lifted from genpkg.bzl.)
# | File type | Repo | `F.path` | `F.root.path` | ... | 603e01a006d15da21a7a7d3139496c2e26c8be96 | 614,870 |
def flatten(weights, start=0, stop=2):
"""This methods reshapes all values in a dictionary.
The indices from start to stop will be flattened into a single index.
Args:
weights: A dictionary mapping keys to numpy arrays.
start: The starting index.
stop: The ending index.
"""
for key, val in weigh... | f5d427e90b0774f072a4729df6e376e285c435cd | 304,000 |
def electrokinetic2(row):
"""
notes: 1) zeta potentials are in mV. if in V, remove the 1e3
2) relative dialectric is for water, if this is not true,
make a column and change the function.
references:
(1) You-Im Chang and Hsun-Chih Chan.
"Correlation equation ... | ee1fd24883b85163300986a7ab279d6522d130e0 | 77,706 |
def deduplicate(constraints):
"""
Return a new ``constraints`` list with exact duplicated constraints removed.
"""
seen = set()
unique = []
for c in constraints:
if c not in seen:
unique.append(c)
seen.add(c)
return unique | cdbd51d99280baf61603e78cf9aea66f9bc0f73e | 96,241 |
import json
def is_valid_json(string):
"""
Determines if a string is valid JSON
:param string: The string to be tested
:return: boolean representing if the string is valid JSON
"""
try:
json.loads(string)
except ValueError:
return False
except TypeError:
return ... | ce97917e5c7407b68a1b6c7c9541242b664c3bef | 74,450 |
def transpose(L):
"""Transpose an iterable of iterables."""
return zip(*L) | fbdf1821de67b2381d098948c12e8dac7c3312de | 425,870 |
import re
def stripcomments(lines):
"""
Strips all C++ style block and line comments from a list of lines using RegEx
"""
def replacer(match):
s = match.group(0)
if s.startswith('/'):
return ""
else:
return s
pattern = re.compile(
r'//.*?$|... | cd0871e7e4fa695a8c3bc2f69e553f22dfa94a30 | 181,482 |
def re_reference_column(df, column, index=None):
"""Re-reference a column by subtracting its value on input index."""
if index is None:
index = -1
df = df.copy()
return df[column] - df[column].iloc[index] | bf9d416e1192c1b7e8377589c520b0e4b3d8859f | 544,524 |
def convert_to_DNA(sequence):
"""
Converts RNA to DNA
"""
sequence = str(sequence)
sequence = sequence.upper()
return sequence.replace('U', 'T') | 2a69a3102df8f5a16b2b049fb1d80dae720b10e3 | 696,351 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.