_id
stringlengths 2
6
| partition
stringclasses 3
values | text
stringlengths 87
6.4k
| title
stringclasses 1
value | language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
d20550
|
test
|
def one_hot2string(arr, vocab):
"""Convert a one-hot encoded array back to string
"""
tokens = one_hot2token(arr)
indexToLetter = _get_index_dict(vocab)
return [''.join([indexToLetter[x] for x in row]) for row in tokens]
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20552
|
test
|
def json(body, charset='utf-8', **kwargs):
"""Takes JSON formatted data, converting it into native Python objects"""
return json_converter.loads(text(body, charset=charset))
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20553
|
test
|
def add_blank_row(self, label):
"""
Add a blank row with only an index value to self.df.
This is done inplace.
"""
col_labels = self.df.columns
blank_item = pd.Series({}, index=col_labels, name=label)
# use .loc to add in place (append won't do that)
self.df.loc[blank_item.name] = blank_item
return self.df
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20554
|
test
|
def clean(s):
"""Removes trailing whitespace on each line."""
lines = [l.rstrip() for l in s.split('\n')]
return '\n'.join(lines)
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20557
|
test
|
def parse(self):
"""
Parse file specified by constructor.
"""
f = open(self.parse_log_path, "r")
self.parse2(f)
f.close()
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20561
|
test
|
def selectnotnone(table, field, complement=False):
"""Select rows where the given field is not `None`."""
return select(table, field, lambda v: v is not None,
complement=complement)
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20567
|
test
|
def __next__(self):
"""
:return: a pair (1-based line number in the input, row)
"""
# Retrieve the row, thereby incrementing the line number:
row = super(UnicodeReaderWithLineNumber, self).__next__()
return self.lineno + 1, row
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20568
|
test
|
def list_move_to_front(l,value='other'):
"""if the value is in the list, move it to the front and return it."""
l=list(l)
if value in l:
l.remove(value)
l.insert(0,value)
return l
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20571
|
test
|
def val_to_bin(edges, x):
"""Convert axis coordinate to bin index."""
ibin = np.digitize(np.array(x, ndmin=1), edges) - 1
return ibin
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20572
|
test
|
def list_to_csv(value):
"""
Converts list to string with comma separated values. For string is no-op.
"""
if isinstance(value, (list, tuple, set)):
value = ",".join(value)
return value
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20574
|
test
|
def pdf(x, mu, std):
"""Probability density function (normal distribution)"""
return (1.0 / (std * sqrt(2 * pi))) * np.exp(-(x - mu) ** 2 / (2 * std ** 2))
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20578
|
test
|
def get_keys_from_class(cc):
"""Return list of the key property names for a class """
return [prop.name for prop in cc.properties.values() \
if 'key' in prop.qualifiers]
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20580
|
test
|
def parse_cookies(self, req, name, field):
"""Pull the value from the cookiejar."""
return core.get_value(req.COOKIES, name, field)
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20581
|
test
|
def is_listish(obj):
"""Check if something quacks like a list."""
if isinstance(obj, (list, tuple, set)):
return True
return is_sequence(obj)
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20583
|
test
|
def _preprocess(df):
"""
given a DataFrame where records are stored row-wise, rearrange it
such that records are stored column-wise.
"""
df = df.stack()
df.index.rename(["id", "time"], inplace=True) # .reset_index()
df.name = "value"
df = df.reset_index()
return df
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20585
|
test
|
def sub(name, func,**kwarg):
""" Add subparser
"""
sp = subparsers.add_parser(name, **kwarg)
sp.set_defaults(func=func)
sp.arg = sp.add_argument
return sp
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20589
|
test
|
def service_available(service_name):
"""Determine whether a system service is available"""
try:
subprocess.check_output(
['service', service_name, 'status'],
stderr=subprocess.STDOUT).decode('UTF-8')
except subprocess.CalledProcessError as e:
return b'unrecognized service' not in e.output
else:
return True
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20590
|
test
|
def issuperset(self, items):
"""Return whether this collection contains all items.
>>> Unique(['spam', 'eggs']).issuperset(['spam', 'spam', 'spam'])
True
"""
return all(_compat.map(self._seen.__contains__, items))
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20591
|
test
|
def decode(self, bytes, raw=False):
"""decode(bytearray, raw=False) -> value
Decodes the given bytearray according to this PrimitiveType
definition.
NOTE: The parameter ``raw`` is present to adhere to the
``decode()`` inteface, but has no effect for PrimitiveType
definitions.
"""
return struct.unpack(self.format, buffer(bytes))[0]
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20595
|
test
|
def check_key(self, key: str) -> bool:
"""
Checks if key exists in datastore. True if yes, False if no.
:param: SHA512 hash key
:return: whether or key not exists in datastore
"""
keys = self.get_keys()
return key in keys
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20597
|
test
|
def get_enum_from_name(self, enum_name):
"""
Return an enum from a name
Args:
enum_name (str): name of the enum
Returns:
Enum
"""
return next((e for e in self.enums if e.name == enum_name), None)
|
PYTHON
|
{
"dummy_field": ""
}
|
|
d20601
|
test
|
def clean_column_names(df: DataFrame) -> DataFrame:
"""
Strip the whitespace from all column names in the given DataFrame
and return the result.
"""
f = df.copy()
f.columns = [col.strip() for col in f.columns]
return f
|
PYTHON
|
{
"dummy_field": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.