id_within_dataset int64 1 55.5k | snippet stringlengths 19 14.2k | tokens listlengths 6 1.63k | nl stringlengths 6 352 | split_within_dataset stringclasses 1
value | is_duplicated bool 2
classes |
|---|---|---|---|---|---|
44,728 | def zip_folder_content(folder, filename):
with zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED) as dest:
for (root, dirs, files) in os.walk(folder):
relative_dir = os.path.relpath(root, folder)
for file_ in files:
dest.write(os.path.join(root, file_), arcname=os.path.join(relative_dir, file_))
| [
"def",
"zip_folder_content",
"(",
"folder",
",",
"filename",
")",
":",
"with",
"zipfile",
".",
"ZipFile",
"(",
"filename",
",",
"'w'",
",",
"zipfile",
".",
"ZIP_DEFLATED",
")",
"as",
"dest",
":",
"for",
"(",
"root",
",",
"dirs",
",",
"files",
")",
"in"... | compress the _content_ of a folder . | train | false |
44,729 | def service_get_by_compute_host(context, host):
return IMPL.service_get_by_compute_host(context, host)
| [
"def",
"service_get_by_compute_host",
"(",
"context",
",",
"host",
")",
":",
"return",
"IMPL",
".",
"service_get_by_compute_host",
"(",
"context",
",",
"host",
")"
] | get the service entry for a given compute host . | train | false |
44,730 | @task
def prepare_index(index_pk):
from kuma.wiki.search import WikiDocumentType
from kuma.search.models import Index
cls = WikiDocumentType
es = cls.get_connection('indexing')
index = Index.objects.get(pk=index_pk)
Index.objects.recreate_index(es=es, index=index)
temporary_settings = {'index': {'refresh_interva... | [
"@",
"task",
"def",
"prepare_index",
"(",
"index_pk",
")",
":",
"from",
"kuma",
".",
"wiki",
".",
"search",
"import",
"WikiDocumentType",
"from",
"kuma",
".",
"search",
".",
"models",
"import",
"Index",
"cls",
"=",
"WikiDocumentType",
"es",
"=",
"cls",
"."... | prepare a new index for indexing documents into . | train | false |
44,731 | def endpoint_create(service, publicurl=None, internalurl=None, adminurl=None, region=None, profile=None, url=None, interface=None, **connection_args):
kstone = auth(profile, **connection_args)
keystone_service = service_get(name=service, profile=profile, **connection_args)
if ((not keystone_service) or ('Error' in k... | [
"def",
"endpoint_create",
"(",
"service",
",",
"publicurl",
"=",
"None",
",",
"internalurl",
"=",
"None",
",",
"adminurl",
"=",
"None",
",",
"region",
"=",
"None",
",",
"profile",
"=",
"None",
",",
"url",
"=",
"None",
",",
"interface",
"=",
"None",
","... | create an endpoint for an openstack service cli examples: . | train | true |
44,732 | def aggregate_keywords(keywords, sep, prefix, raw=False):
processed = []
encode = encode_to_py3bytes_or_py2str
for (k, v) in keywords.items():
if (len(k) == 1):
if (v is not False):
processed.append(encode(('-' + k)))
if (v is not True):
processed.append(encode(v))
else:
if (not raw):
k = ... | [
"def",
"aggregate_keywords",
"(",
"keywords",
",",
"sep",
",",
"prefix",
",",
"raw",
"=",
"False",
")",
":",
"processed",
"=",
"[",
"]",
"encode",
"=",
"encode_to_py3bytes_or_py2str",
"for",
"(",
"k",
",",
"v",
")",
"in",
"keywords",
".",
"items",
"(",
... | take our keyword arguments . | train | true |
44,733 | @task
def bdist_wininst_sse2(options):
bdist_wininst_arch(options.python_version, 'sse2')
| [
"@",
"task",
"def",
"bdist_wininst_sse2",
"(",
"options",
")",
":",
"bdist_wininst_arch",
"(",
"options",
".",
"python_version",
",",
"'sse2'",
")"
] | build the sse2 wininst installer . | train | false |
44,735 | def augment(matlist, column, K):
return [(row + element) for (row, element) in zip(matlist, column)]
| [
"def",
"augment",
"(",
"matlist",
",",
"column",
",",
"K",
")",
":",
"return",
"[",
"(",
"row",
"+",
"element",
")",
"for",
"(",
"row",
",",
"element",
")",
"in",
"zip",
"(",
"matlist",
",",
"column",
")",
"]"
] | augments a matrix and a column . | train | false |
44,736 | @pytest.mark.django_db
def test_admin_regular_user(client, default):
client.login(username=default.username, password='')
response = client.get(ADMIN_URL)
assert (response.status_code == 403)
| [
"@",
"pytest",
".",
"mark",
".",
"django_db",
"def",
"test_admin_regular_user",
"(",
"client",
",",
"default",
")",
":",
"client",
".",
"login",
"(",
"username",
"=",
"default",
".",
"username",
",",
"password",
"=",
"''",
")",
"response",
"=",
"client",
... | checks regular users cannot access the admin site . | train | false |
44,737 | @pytest.mark.parametrize('i, item', enumerate(ITEMS))
def test_original_urls(objects, i, item):
assert (objects.history.itemAt(i).originalUrl() == item.original_url)
| [
"@",
"pytest",
".",
"mark",
".",
"parametrize",
"(",
"'i, item'",
",",
"enumerate",
"(",
"ITEMS",
")",
")",
"def",
"test_original_urls",
"(",
"objects",
",",
"i",
",",
"item",
")",
":",
"assert",
"(",
"objects",
".",
"history",
".",
"itemAt",
"(",
"i",... | check if the original urls were loaded correctly . | train | false |
44,739 | def run_upgrades(store, upgrades):
lock = store.get_lock()
try:
run_upgrades_locked(store, upgrades)
finally:
store.release_lock(lock)
| [
"def",
"run_upgrades",
"(",
"store",
",",
"upgrades",
")",
":",
"lock",
"=",
"store",
".",
"get_lock",
"(",
")",
"try",
":",
"run_upgrades_locked",
"(",
"store",
",",
"upgrades",
")",
"finally",
":",
"store",
".",
"release_lock",
"(",
"lock",
")"
] | guard against concurrent upgrades . | train | false |
44,741 | def _num_cpus_darwin():
p = subprocess.Popen(['sysctl', '-n', 'hw.ncpu'], stdout=subprocess.PIPE)
return p.stdout.read()
| [
"def",
"_num_cpus_darwin",
"(",
")",
":",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"[",
"'sysctl'",
",",
"'-n'",
",",
"'hw.ncpu'",
"]",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
")",
"return",
"p",
".",
"stdout",
".",
"read",
"(",
")"
] | return the number of active cpus on a darwin system . | train | true |
44,742 | def alternating(n):
for perm in variations(list(range(n)), n):
p = Permutation(perm)
if p.is_even:
(yield p)
| [
"def",
"alternating",
"(",
"n",
")",
":",
"for",
"perm",
"in",
"variations",
"(",
"list",
"(",
"range",
"(",
"n",
")",
")",
",",
"n",
")",
":",
"p",
"=",
"Permutation",
"(",
"perm",
")",
"if",
"p",
".",
"is_even",
":",
"(",
"yield",
"p",
")"
] | generates the alternating group of order n . | train | false |
44,743 | def domain_match(A, B):
A = A.lower()
B = B.lower()
if (A == B):
return True
if (not is_HDN(A)):
return False
i = A.rfind(B)
if ((i == (-1)) or (i == 0)):
return False
if (not B.startswith('.')):
return False
if (not is_HDN(B[1:])):
return False
return True
| [
"def",
"domain_match",
"(",
"A",
",",
"B",
")",
":",
"A",
"=",
"A",
".",
"lower",
"(",
")",
"B",
"=",
"B",
".",
"lower",
"(",
")",
"if",
"(",
"A",
"==",
"B",
")",
":",
"return",
"True",
"if",
"(",
"not",
"is_HDN",
"(",
"A",
")",
")",
":",... | return true if domain a domain-matches domain b . | train | true |
44,745 | def _test_factory(test, dtype=np.double):
olderr = np.seterr(all='ignore')
try:
test.check(dtype=dtype)
finally:
np.seterr(**olderr)
| [
"def",
"_test_factory",
"(",
"test",
",",
"dtype",
"=",
"np",
".",
"double",
")",
":",
"olderr",
"=",
"np",
".",
"seterr",
"(",
"all",
"=",
"'ignore'",
")",
"try",
":",
"test",
".",
"check",
"(",
"dtype",
"=",
"dtype",
")",
"finally",
":",
"np",
... | boost test . | train | false |
44,747 | def _py_WX28_convert_agg_to_wx_bitmap(agg, bbox):
if (bbox is None):
return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height), agg.buffer_rgba(0, 0))
else:
return _WX28_clipped_agg_as_bitmap(agg, bbox)
| [
"def",
"_py_WX28_convert_agg_to_wx_bitmap",
"(",
"agg",
",",
"bbox",
")",
":",
"if",
"(",
"bbox",
"is",
"None",
")",
":",
"return",
"wx",
".",
"BitmapFromBufferRGBA",
"(",
"int",
"(",
"agg",
".",
"width",
")",
",",
"int",
"(",
"agg",
".",
"height",
")"... | convert the region of the agg buffer bounded by bbox to a wx . | train | true |
44,751 | def log_startup_info():
LOG.always('Starting mongo-connector version: %s', __version__)
if ('dev' in __version__):
LOG.warning('This is a development version (%s) of mongo-connector', __version__)
LOG.always('Python version: %s', sys.version)
LOG.always('Platform: %s', platform.platform())
LOG.always('pymongo ve... | [
"def",
"log_startup_info",
"(",
")",
":",
"LOG",
".",
"always",
"(",
"'Starting mongo-connector version: %s'",
",",
"__version__",
")",
"if",
"(",
"'dev'",
"in",
"__version__",
")",
":",
"LOG",
".",
"warning",
"(",
"'This is a development version (%s) of mongo-connect... | log info about the current environment . | train | true |
44,752 | def isolate_query_ctes(full_text, text_before_cursor):
if (not full_text):
return (full_text, text_before_cursor, tuple())
(ctes, remainder) = extract_ctes(full_text)
if (not ctes):
return (full_text, text_before_cursor, ())
current_position = len(text_before_cursor)
meta = []
for cte in ctes:
if (cte.start... | [
"def",
"isolate_query_ctes",
"(",
"full_text",
",",
"text_before_cursor",
")",
":",
"if",
"(",
"not",
"full_text",
")",
":",
"return",
"(",
"full_text",
",",
"text_before_cursor",
",",
"tuple",
"(",
")",
")",
"(",
"ctes",
",",
"remainder",
")",
"=",
"extra... | simplify a query by converting ctes into table metadata objects . | train | false |
44,753 | def rgb2lms(rgb_Nx3, conversionMatrix=None):
rgb_3xN = numpy.transpose(rgb_Nx3)
if (conversionMatrix is None):
cones_to_rgb = numpy.asarray([[4.97068857, (-4.14354132), 0.17285275], [(-0.90913894), 2.15671326, (-0.24757432)], [(-0.03976551), (-0.14253782), 1.18230333]])
logging.warning('This monitor has not been ... | [
"def",
"rgb2lms",
"(",
"rgb_Nx3",
",",
"conversionMatrix",
"=",
"None",
")",
":",
"rgb_3xN",
"=",
"numpy",
".",
"transpose",
"(",
"rgb_Nx3",
")",
"if",
"(",
"conversionMatrix",
"is",
"None",
")",
":",
"cones_to_rgb",
"=",
"numpy",
".",
"asarray",
"(",
"[... | convert from rgb to cone space . | train | false |
44,755 | def dateof(tag_name, tags):
for tag in tags:
if (tag['name'] == tag_name):
commit = read_url(tag['commit']['url'])
return parse_timestamp(commit['commit']['committer']['date'])
return None
| [
"def",
"dateof",
"(",
"tag_name",
",",
"tags",
")",
":",
"for",
"tag",
"in",
"tags",
":",
"if",
"(",
"tag",
"[",
"'name'",
"]",
"==",
"tag_name",
")",
":",
"commit",
"=",
"read_url",
"(",
"tag",
"[",
"'commit'",
"]",
"[",
"'url'",
"]",
")",
"retu... | given a list of tags . | train | true |
44,756 | def get_yaml_entry(yaml_dict, name):
entry = yaml_dict.get(name)
if (entry is None):
return None
if isinstance(entry, basestring):
return [entry]
return entry
| [
"def",
"get_yaml_entry",
"(",
"yaml_dict",
",",
"name",
")",
":",
"entry",
"=",
"yaml_dict",
".",
"get",
"(",
"name",
")",
"if",
"(",
"entry",
"is",
"None",
")",
":",
"return",
"None",
"if",
"isinstance",
"(",
"entry",
",",
"basestring",
")",
":",
"r... | get entry name from dict yaml_dict parameters yaml_dict : dict dict or subdict from parsing . | train | false |
44,758 | def rpXRDS(request):
return util.renderXRDS(request, [RP_RETURN_TO_URL_TYPE], [util.getViewURL(request, finishOpenID)])
| [
"def",
"rpXRDS",
"(",
"request",
")",
":",
"return",
"util",
".",
"renderXRDS",
"(",
"request",
",",
"[",
"RP_RETURN_TO_URL_TYPE",
"]",
",",
"[",
"util",
".",
"getViewURL",
"(",
"request",
",",
"finishOpenID",
")",
"]",
")"
] | return a relying party verification xrds document . | train | true |
44,760 | def prep_bootstrap(mpt):
bs_ = __salt__['config.gather_bootstrap_script']()
fpd_ = os.path.join(mpt, 'tmp', '{0}'.format(uuid.uuid4()))
if (not os.path.exists(fpd_)):
os.makedirs(fpd_)
os.chmod(fpd_, 448)
fp_ = os.path.join(fpd_, os.path.basename(bs_))
shutil.copy(bs_, fp_)
tmppath = fpd_.replace(mpt, '')
ret... | [
"def",
"prep_bootstrap",
"(",
"mpt",
")",
":",
"bs_",
"=",
"__salt__",
"[",
"'config.gather_bootstrap_script'",
"]",
"(",
")",
"fpd_",
"=",
"os",
".",
"path",
".",
"join",
"(",
"mpt",
",",
"'tmp'",
",",
"'{0}'",
".",
"format",
"(",
"uuid",
".",
"uuid4"... | update and get the random script to a random place cli example: . | train | true |
44,764 | def tiers_for_dev(dev):
t1 = dev['region']
t2 = dev['zone']
t3 = dev['ip']
t4 = dev['id']
return ((t1,), (t1, t2), (t1, t2, t3), (t1, t2, t3, t4))
| [
"def",
"tiers_for_dev",
"(",
"dev",
")",
":",
"t1",
"=",
"dev",
"[",
"'region'",
"]",
"t2",
"=",
"dev",
"[",
"'zone'",
"]",
"t3",
"=",
"dev",
"[",
"'ip'",
"]",
"t4",
"=",
"dev",
"[",
"'id'",
"]",
"return",
"(",
"(",
"t1",
",",
")",
",",
"(",
... | returns a tuple of tiers for a given device in ascending order by length . | train | false |
44,765 | def is_pull_request(issue):
return bool(issue.get('pull_request', {}).get('html_url', None))
| [
"def",
"is_pull_request",
"(",
"issue",
")",
":",
"return",
"bool",
"(",
"issue",
".",
"get",
"(",
"'pull_request'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'html_url'",
",",
"None",
")",
")"
] | return true if the given issue is a pull request . | train | false |
44,767 | def _get_flim(flim, fscale, freq, sfreq=None):
if (flim is None):
if (freq is None):
flim = [(0.1 if (fscale == 'log') else 0.0), (sfreq / 2.0)]
else:
if (fscale == 'linear'):
flim = [freq[0]]
else:
flim = [(freq[0] if (freq[0] > 0) else (0.1 * freq[1]))]
flim += [freq[(-1)]]
if (fscale == 'lo... | [
"def",
"_get_flim",
"(",
"flim",
",",
"fscale",
",",
"freq",
",",
"sfreq",
"=",
"None",
")",
":",
"if",
"(",
"flim",
"is",
"None",
")",
":",
"if",
"(",
"freq",
"is",
"None",
")",
":",
"flim",
"=",
"[",
"(",
"0.1",
"if",
"(",
"fscale",
"==",
"... | get reasonable frequency limits . | train | false |
44,769 | def scipy_sparse_to_sympy(m, **options):
return Matrix(m.todense())
| [
"def",
"scipy_sparse_to_sympy",
"(",
"m",
",",
"**",
"options",
")",
":",
"return",
"Matrix",
"(",
"m",
".",
"todense",
"(",
")",
")"
] | convert a scipy . | train | false |
44,771 | @treeio_login_required
@handle_response_format
def subscription_edit(request, subscription_id, response_format='html'):
subscription = get_object_or_404(Subscription, pk=subscription_id)
if ((not request.user.profile.has_permission(subscription, mode='w')) and (not request.user.profile.is_admin('treeio.sales'))):
r... | [
"@",
"treeio_login_required",
"@",
"handle_response_format",
"def",
"subscription_edit",
"(",
"request",
",",
"subscription_id",
",",
"response_format",
"=",
"'html'",
")",
":",
"subscription",
"=",
"get_object_or_404",
"(",
"Subscription",
",",
"pk",
"=",
"subscripti... | subscription edit . | train | false |
44,772 | def ignore_not_package_admin(key, data, errors, context):
model = context['model']
user = context.get('user')
if ('ignore_auth' in context):
return
if (user and authz.is_sysadmin(user)):
return
authorized = False
pkg = context.get('package')
if pkg:
try:
logic.check_access('package_change_state', contex... | [
"def",
"ignore_not_package_admin",
"(",
"key",
",",
"data",
",",
"errors",
",",
"context",
")",
":",
"model",
"=",
"context",
"[",
"'model'",
"]",
"user",
"=",
"context",
".",
"get",
"(",
"'user'",
")",
"if",
"(",
"'ignore_auth'",
"in",
"context",
")",
... | ignore if the user is not allowed to administer the package specified . | train | false |
44,774 | def jres_id(n):
return (chr((ord('A') + ((n - 1) % 25))) * ((n / 26) + 1))
| [
"def",
"jres_id",
"(",
"n",
")",
":",
"return",
"(",
"chr",
"(",
"(",
"ord",
"(",
"'A'",
")",
"+",
"(",
"(",
"n",
"-",
"1",
")",
"%",
"25",
")",
")",
")",
"*",
"(",
"(",
"n",
"/",
"26",
")",
"+",
"1",
")",
")"
] | joint res ids go from a-z . | train | false |
44,775 | def nvgre(version=0, vsid=0, flow_id=0):
return gre(version=version, protocol=ether_types.ETH_TYPE_TEB, vsid=vsid, flow_id=flow_id)
| [
"def",
"nvgre",
"(",
"version",
"=",
"0",
",",
"vsid",
"=",
"0",
",",
"flow_id",
"=",
"0",
")",
":",
"return",
"gre",
"(",
"version",
"=",
"version",
",",
"protocol",
"=",
"ether_types",
".",
"ETH_TYPE_TEB",
",",
"vsid",
"=",
"vsid",
",",
"flow_id",
... | generate instance of gre class with information for nvgre . | train | true |
44,777 | def idzr_aid(A, k):
A = np.asfortranarray(A)
(m, n) = A.shape
w = idzr_aidi(m, n, k)
(idx, proj) = _id.idzr_aid(A, k, w)
if (k == n):
proj = np.array([], dtype='complex128', order='F')
else:
proj = proj.reshape((k, (n - k)), order='F')
return (idx, proj)
| [
"def",
"idzr_aid",
"(",
"A",
",",
"k",
")",
":",
"A",
"=",
"np",
".",
"asfortranarray",
"(",
"A",
")",
"(",
"m",
",",
"n",
")",
"=",
"A",
".",
"shape",
"w",
"=",
"idzr_aidi",
"(",
"m",
",",
"n",
",",
"k",
")",
"(",
"idx",
",",
"proj",
")"... | compute id of a complex matrix to a specified rank using random sampling . | train | false |
44,778 | def isClassAdvisor(ob):
return (isinstance(ob, FunctionType) and hasattr(ob, 'previousMetaclass'))
| [
"def",
"isClassAdvisor",
"(",
"ob",
")",
":",
"return",
"(",
"isinstance",
"(",
"ob",
",",
"FunctionType",
")",
"and",
"hasattr",
"(",
"ob",
",",
"'previousMetaclass'",
")",
")"
] | true if ob is a class advisor function . | train | false |
44,779 | def test_setup_py_with_dos_line_endings(script, data):
to_install = data.packages.join('LineEndings')
script.pip('install', to_install, expect_error=False)
| [
"def",
"test_setup_py_with_dos_line_endings",
"(",
"script",
",",
"data",
")",
":",
"to_install",
"=",
"data",
".",
"packages",
".",
"join",
"(",
"'LineEndings'",
")",
"script",
".",
"pip",
"(",
"'install'",
",",
"to_install",
",",
"expect_error",
"=",
"False"... | it doesnt choke on a setup . | train | false |
44,780 | def _to_bytes(value, encoding='ascii'):
result = (value.encode(encoding) if isinstance(value, six.text_type) else value)
if isinstance(result, six.binary_type):
return result
else:
raise TypeError(('%r could not be converted to bytes' % (value,)))
| [
"def",
"_to_bytes",
"(",
"value",
",",
"encoding",
"=",
"'ascii'",
")",
":",
"result",
"=",
"(",
"value",
".",
"encode",
"(",
"encoding",
")",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"text_type",
")",
"else",
"value",
")",
"if",
"isinstance"... | converts a string value to bytes . | train | true |
44,781 | def RPCVariation(reqsummary, rpcsummaries):
rpc_variation = []
markers = [0.1, 0.25, 0.75, 0.9]
percentiles = _GetPercentileList(reqsummary.totaltimes, markers)
percentiles.insert(0, 'Total')
rpc_variation.append(percentiles)
percentiles = _GetPercentileList(reqsummary.totalrpctimes, markers)
percentiles.insert(... | [
"def",
"RPCVariation",
"(",
"reqsummary",
",",
"rpcsummaries",
")",
":",
"rpc_variation",
"=",
"[",
"]",
"markers",
"=",
"[",
"0.1",
",",
"0.25",
",",
"0.75",
",",
"0.9",
"]",
"percentiles",
"=",
"_GetPercentileList",
"(",
"reqsummary",
".",
"totaltimes",
... | generates desired percentiles of times spent in each rpc . | train | false |
44,782 | def os_constant(key):
os_info = util.get_os_info()
try:
constants = CLI_DEFAULTS[os_info[0].lower()]
except KeyError:
constants = os_like_constants()
if (not constants):
constants = CLI_DEFAULTS['default']
return constants[key]
| [
"def",
"os_constant",
"(",
"key",
")",
":",
"os_info",
"=",
"util",
".",
"get_os_info",
"(",
")",
"try",
":",
"constants",
"=",
"CLI_DEFAULTS",
"[",
"os_info",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"]",
"except",
"KeyError",
":",
"constants",
"=",
"... | get a constant value for operating system . | train | false |
44,784 | @simple_tag
def get_providers():
return providers.registry.get_list()
| [
"@",
"simple_tag",
"def",
"get_providers",
"(",
")",
":",
"return",
"providers",
".",
"registry",
".",
"get_list",
"(",
")"
] | returns a list of social authentication providers . | train | false |
44,785 | def get_default_view_plugins(get_datastore_views=False):
if (config.get('ckan.views.default_views') is None):
default_view_types = DEFAULT_RESOURCE_VIEW_TYPES
else:
default_view_types = config.get('ckan.views.default_views').split()
default_view_plugins = []
for view_type in default_view_types:
view_plugin = ... | [
"def",
"get_default_view_plugins",
"(",
"get_datastore_views",
"=",
"False",
")",
":",
"if",
"(",
"config",
".",
"get",
"(",
"'ckan.views.default_views'",
")",
"is",
"None",
")",
":",
"default_view_types",
"=",
"DEFAULT_RESOURCE_VIEW_TYPES",
"else",
":",
"default_vi... | returns the list of view plugins to be created by default on new resources the default view types are defined via the ckan . | train | false |
44,786 | @control_command(args=[(u'n', int)], signature=u'[N=1]')
def pool_grow(state, n=1, **kwargs):
if state.consumer.controller.autoscaler:
state.consumer.controller.autoscaler.force_scale_up(n)
else:
state.consumer.pool.grow(n)
state.consumer._update_prefetch_count(n)
return ok(u'pool will grow')
| [
"@",
"control_command",
"(",
"args",
"=",
"[",
"(",
"u'n'",
",",
"int",
")",
"]",
",",
"signature",
"=",
"u'[N=1]'",
")",
"def",
"pool_grow",
"(",
"state",
",",
"n",
"=",
"1",
",",
"**",
"kwargs",
")",
":",
"if",
"state",
".",
"consumer",
".",
"c... | grow pool by n processes/threads . | train | false |
44,787 | def reverse_enumerate(l):
return izip(xrange((len(l) - 1), (-1), (-1)), reversed(l))
| [
"def",
"reverse_enumerate",
"(",
"l",
")",
":",
"return",
"izip",
"(",
"xrange",
"(",
"(",
"len",
"(",
"l",
")",
"-",
"1",
")",
",",
"(",
"-",
"1",
")",
",",
"(",
"-",
"1",
")",
")",
",",
"reversed",
"(",
"l",
")",
")"
] | like enumerate but in the other sens usage:: . | train | false |
44,788 | def setup_backoff(config):
def on_new_response(event):
backoff = config.registry.settings['backoff']
if (backoff is not None):
backoff = utils.encode_header(('%s' % backoff))
event.response.headers['Backoff'] = backoff
config.add_subscriber(on_new_response, NewResponse)
| [
"def",
"setup_backoff",
"(",
"config",
")",
":",
"def",
"on_new_response",
"(",
"event",
")",
":",
"backoff",
"=",
"config",
".",
"registry",
".",
"settings",
"[",
"'backoff'",
"]",
"if",
"(",
"backoff",
"is",
"not",
"None",
")",
":",
"backoff",
"=",
"... | attach http requests/responses objects . | train | false |
44,789 | def from_delayed(values):
from dask.delayed import Delayed
if isinstance(values, Delayed):
values = [values]
dsk = merge((v.dask for v in values))
name = ('bag-from-delayed-' + tokenize(*values))
names = [(name, i) for i in range(len(values))]
values = [v.key for v in values]
dsk2 = dict(zip(names, values))
r... | [
"def",
"from_delayed",
"(",
"values",
")",
":",
"from",
"dask",
".",
"delayed",
"import",
"Delayed",
"if",
"isinstance",
"(",
"values",
",",
"Delayed",
")",
":",
"values",
"=",
"[",
"values",
"]",
"dsk",
"=",
"merge",
"(",
"(",
"v",
".",
"dask",
"for... | create bag from many dask . | train | false |
44,795 | @statfunc
def autocov(x, lag=1):
x = np.asarray(x)
if (not lag):
return 1
if (lag < 0):
raise ValueError('Autocovariance lag must be a positive integer')
return np.cov(x[:(- lag)], x[lag:], bias=1)
| [
"@",
"statfunc",
"def",
"autocov",
"(",
"x",
",",
"lag",
"=",
"1",
")",
":",
"x",
"=",
"np",
".",
"asarray",
"(",
"x",
")",
"if",
"(",
"not",
"lag",
")",
":",
"return",
"1",
"if",
"(",
"lag",
"<",
"0",
")",
":",
"raise",
"ValueError",
"(",
... | sample autocovariance at specified lag . | train | false |
44,796 | @pytest.mark.network
def test_git_with_ambiguous_revs(script):
version_pkg_path = _create_test_package(script)
package_url = ('git+file://%s@0.1#egg=version_pkg' % version_pkg_path.abspath.replace('\\', '/'))
script.run('git', 'tag', '0.1', cwd=version_pkg_path)
result = script.pip('install', '-e', package_url)
as... | [
"@",
"pytest",
".",
"mark",
".",
"network",
"def",
"test_git_with_ambiguous_revs",
"(",
"script",
")",
":",
"version_pkg_path",
"=",
"_create_test_package",
"(",
"script",
")",
"package_url",
"=",
"(",
"'git+file://%s@0.1#egg=version_pkg'",
"%",
"version_pkg_path",
".... | test git with two "names" pointing to the same commit . | train | false |
44,797 | def proc_exists(pid):
if (not os.path.exists(('/proc/%s' % pid))):
raise NoSuchProcess()
| [
"def",
"proc_exists",
"(",
"pid",
")",
":",
"if",
"(",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"(",
"'/proc/%s'",
"%",
"pid",
")",
")",
")",
":",
"raise",
"NoSuchProcess",
"(",
")"
] | check the a pid is registered in /proc raise nosuchprocess exception if not . | train | false |
44,801 | def winTime():
return (systime.clock() + START_TIME)
| [
"def",
"winTime",
"(",
")",
":",
"return",
"(",
"systime",
".",
"clock",
"(",
")",
"+",
"START_TIME",
")"
] | return the current time in seconds with high precision (windows version . | train | false |
44,802 | def base64_decodefile(instr, outfile):
encoded_f = StringIO.StringIO(instr)
with open(outfile, 'wb') as f:
base64.decode(encoded_f, f)
return True
| [
"def",
"base64_decodefile",
"(",
"instr",
",",
"outfile",
")",
":",
"encoded_f",
"=",
"StringIO",
".",
"StringIO",
"(",
"instr",
")",
"with",
"open",
"(",
"outfile",
",",
"'wb'",
")",
"as",
"f",
":",
"base64",
".",
"decode",
"(",
"encoded_f",
",",
"f",... | decode a base64-encoded string and write the result to a file . | train | false |
44,803 | def get_oauth_request(request):
headers = {}
if ('HTTP_AUTHORIZATION' in request.META):
headers['Authorization'] = request.META['HTTP_AUTHORIZATION']
return oauth.Request.from_request(request.method, request.build_absolute_uri(request.path), headers, dict(request.REQUEST))
| [
"def",
"get_oauth_request",
"(",
"request",
")",
":",
"headers",
"=",
"{",
"}",
"if",
"(",
"'HTTP_AUTHORIZATION'",
"in",
"request",
".",
"META",
")",
":",
"headers",
"[",
"'Authorization'",
"]",
"=",
"request",
".",
"META",
"[",
"'HTTP_AUTHORIZATION'",
"]",
... | converts a django request object into an oauth2 . | train | false |
44,805 | def _finish_concat(info, data, events, event_id, tmin, tmax, baseline, selection, drop_log, verbose):
events[:, 0] = np.arange(len(events))
selection = np.where([(len(d) == 0) for d in drop_log])[0]
out = BaseEpochs(info, data, events, event_id, tmin, tmax, baseline=baseline, selection=selection, drop_log=drop_log, ... | [
"def",
"_finish_concat",
"(",
"info",
",",
"data",
",",
"events",
",",
"event_id",
",",
"tmin",
",",
"tmax",
",",
"baseline",
",",
"selection",
",",
"drop_log",
",",
"verbose",
")",
":",
"events",
"[",
":",
",",
"0",
"]",
"=",
"np",
".",
"arange",
... | helper to finish concatenation for epochs not read from disk . | train | false |
44,807 | def log_warn_only():
coloredlogs.install(level='WARNING', level_styles={'warn': {'color': 'yellow'}, 'error': {'color': 'red', 'bold': True}}, fmt='%(message)s', isatty=True)
| [
"def",
"log_warn_only",
"(",
")",
":",
"coloredlogs",
".",
"install",
"(",
"level",
"=",
"'WARNING'",
",",
"level_styles",
"=",
"{",
"'warn'",
":",
"{",
"'color'",
":",
"'yellow'",
"}",
",",
"'error'",
":",
"{",
"'color'",
":",
"'red'",
",",
"'bold'",
... | drop to warning level and down to get around gen . | train | false |
44,808 | def var_mock(request, q_var_name, **kwargs):
_patch = patch(q_var_name, **kwargs)
request.addfinalizer(_patch.stop)
return _patch.start()
| [
"def",
"var_mock",
"(",
"request",
",",
"q_var_name",
",",
"**",
"kwargs",
")",
":",
"_patch",
"=",
"patch",
"(",
"q_var_name",
",",
"**",
"kwargs",
")",
"request",
".",
"addfinalizer",
"(",
"_patch",
".",
"stop",
")",
"return",
"_patch",
".",
"start",
... | return a mock patching the variable with qualified name *q_var_name* . | train | false |
44,809 | def instance_str(instance):
return state_str(instance_state(instance))
| [
"def",
"instance_str",
"(",
"instance",
")",
":",
"return",
"state_str",
"(",
"instance_state",
"(",
"instance",
")",
")"
] | return a string describing an instance . | train | false |
44,811 | def unabc(msg):
if isinstance(msg, type):
return _unabc(msg)
else:
return partial(_unabc, msg=msg)
| [
"def",
"unabc",
"(",
"msg",
")",
":",
"if",
"isinstance",
"(",
"msg",
",",
"type",
")",
":",
"return",
"_unabc",
"(",
"msg",
")",
"else",
":",
"return",
"partial",
"(",
"_unabc",
",",
"msg",
"=",
"msg",
")"
] | add dummy methods to a class to satisfy abstract base class constraints . | train | false |
44,813 | def _validate_input(dist_matrix_header, dist_matrix, mapping_header, mapping, field):
if ((dist_matrix_header is None) or (dist_matrix is None) or (mapping_header is None) or (mapping is None) or (field is None)):
raise ValueError("The input(s) cannot be 'None'.")
for input_arg in (dist_matrix_header, dist_matrix, ... | [
"def",
"_validate_input",
"(",
"dist_matrix_header",
",",
"dist_matrix",
",",
"mapping_header",
",",
"mapping",
",",
"field",
")",
":",
"if",
"(",
"(",
"dist_matrix_header",
"is",
"None",
")",
"or",
"(",
"dist_matrix",
"is",
"None",
")",
"or",
"(",
"mapping_... | validates the input data to make sure it can be used and makes sense . | train | false |
44,814 | def _raise_if_updates_provider_attributes(attrs):
if any((validators.is_attr_set(attrs.get(a)) for a in ATTRIBUTES)):
msg = _('Plugin does not support updating provider attributes')
raise n_exc.InvalidInput(error_message=msg)
| [
"def",
"_raise_if_updates_provider_attributes",
"(",
"attrs",
")",
":",
"if",
"any",
"(",
"(",
"validators",
".",
"is_attr_set",
"(",
"attrs",
".",
"get",
"(",
"a",
")",
")",
"for",
"a",
"in",
"ATTRIBUTES",
")",
")",
":",
"msg",
"=",
"_",
"(",
"'Plugin... | raise exception if provider attributes are present . | train | false |
44,816 | def desktop():
return app().desktop()
| [
"def",
"desktop",
"(",
")",
":",
"return",
"app",
"(",
")",
".",
"desktop",
"(",
")"
] | return the desktop . | train | false |
44,817 | @domain_constructor()
def coin_flip():
return {'loss': hp.choice('flip', [0.0, 1.0]), 'status': base.STATUS_OK}
| [
"@",
"domain_constructor",
"(",
")",
"def",
"coin_flip",
"(",
")",
":",
"return",
"{",
"'loss'",
":",
"hp",
".",
"choice",
"(",
"'flip'",
",",
"[",
"0.0",
",",
"1.0",
"]",
")",
",",
"'status'",
":",
"base",
".",
"STATUS_OK",
"}"
] | possibly the simplest possible bandit implementation . | train | false |
44,818 | def test_simple_class_based_method_view():
@hug.object.http_methods()
class EndPoint(object, ):
def get(self):
return 'hi there!'
def post(self):
return 'bye'
assert (hug.test.get(api, 'endpoint').data == 'hi there!')
assert (hug.test.post(api, 'endpoint').data == 'bye')
| [
"def",
"test_simple_class_based_method_view",
"(",
")",
":",
"@",
"hug",
".",
"object",
".",
"http_methods",
"(",
")",
"class",
"EndPoint",
"(",
"object",
",",
")",
":",
"def",
"get",
"(",
"self",
")",
":",
"return",
"'hi there!'",
"def",
"post",
"(",
"s... | test creating class based routers using method mappings . | train | false |
44,819 | def exec_sorted(statement, *args, **kw):
return sorted([tuple(row) for row in statement.execute(*args, **kw).fetchall()])
| [
"def",
"exec_sorted",
"(",
"statement",
",",
"*",
"args",
",",
"**",
"kw",
")",
":",
"return",
"sorted",
"(",
"[",
"tuple",
"(",
"row",
")",
"for",
"row",
"in",
"statement",
".",
"execute",
"(",
"*",
"args",
",",
"**",
"kw",
")",
".",
"fetchall",
... | executes a statement and returns a sorted list plain tuple rows . | train | false |
44,820 | def pts_to_poststep(x, *args):
steps = np.zeros(((1 + len(args)), ((2 * len(x)) - 1)))
steps[0, 0::2] = x
steps[0, 1::2] = steps[0, 2::2]
steps[1:, 0::2] = args
steps[1:, 1::2] = steps[1:, 0:(-2):2]
return steps
| [
"def",
"pts_to_poststep",
"(",
"x",
",",
"*",
"args",
")",
":",
"steps",
"=",
"np",
".",
"zeros",
"(",
"(",
"(",
"1",
"+",
"len",
"(",
"args",
")",
")",
",",
"(",
"(",
"2",
"*",
"len",
"(",
"x",
")",
")",
"-",
"1",
")",
")",
")",
"steps",... | convert continuous line to post-steps . | train | false |
44,821 | def describe_launch_configuration(name, region=None, key=None, keyid=None, profile=None):
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
lc = conn.get_all_launch_configurations(names=[name])
if lc:
return lc[0]
else:
msg = 'The launch configuration does not exist in region {0}... | [
"def",
"describe_launch_configuration",
"(",
"name",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
":",
"conn",
"=",
"_get_conn",
"(",
"region",
"=",
"region",
",",
"key",
"=",
"key",
... | dump details of a given launch configuration . | train | false |
44,822 | def _fill_mi_header(row, control_row):
last = row[0]
for i in range(1, len(row)):
if (not control_row[i]):
last = row[i]
if ((row[i] == '') or (row[i] is None)):
row[i] = last
else:
control_row[i] = False
last = row[i]
return (row, control_row)
| [
"def",
"_fill_mi_header",
"(",
"row",
",",
"control_row",
")",
":",
"last",
"=",
"row",
"[",
"0",
"]",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"row",
")",
")",
":",
"if",
"(",
"not",
"control_row",
"[",
"i",
"]",
")",
":",
"last",... | forward fills blank entries in row . | train | true |
44,823 | def is_dvr_serviced(device_owner):
return (device_owner.startswith(n_const.DEVICE_OWNER_COMPUTE_PREFIX) or (device_owner in get_other_dvr_serviced_device_owners()))
| [
"def",
"is_dvr_serviced",
"(",
"device_owner",
")",
":",
"return",
"(",
"device_owner",
".",
"startswith",
"(",
"n_const",
".",
"DEVICE_OWNER_COMPUTE_PREFIX",
")",
"or",
"(",
"device_owner",
"in",
"get_other_dvr_serviced_device_owners",
"(",
")",
")",
")"
] | check if the port need to be serviced by dvr helper function to check the device owners of the ports in the compute and service node to make sure if they are required for dvr or any service directly or indirectly associated with dvr . | train | false |
44,824 | def RunMapForKinds(operation_key, kinds, job_name_template, handler_spec, reader_spec, writer_spec, mapper_params, mapreduce_params=None, queue_name=None, max_shard_count=None):
jobs = []
try:
for kind in kinds:
mapper_params['entity_kind'] = kind
job_name = (job_name_template % {'kind': kind, 'namespace': ma... | [
"def",
"RunMapForKinds",
"(",
"operation_key",
",",
"kinds",
",",
"job_name_template",
",",
"handler_spec",
",",
"reader_spec",
",",
"writer_spec",
",",
"mapper_params",
",",
"mapreduce_params",
"=",
"None",
",",
"queue_name",
"=",
"None",
",",
"max_shard_count",
... | run mapper job for all entities in specified kinds . | train | false |
44,825 | def current_time_ms():
now = datetime.datetime.utcnow()
new_microsecond = (int((now.microsecond / 1000)) * 1000)
return now.replace(microsecond=new_microsecond)
| [
"def",
"current_time_ms",
"(",
")",
":",
"now",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"new_microsecond",
"=",
"(",
"int",
"(",
"(",
"now",
".",
"microsecond",
"/",
"1000",
")",
")",
"*",
"1000",
")",
"return",
"now",
".",
"replac... | gets the current time with millisecond precision . | train | false |
44,826 | def _is_counter_log4j_record(record):
return bool(_INDENTED_COUNTERS_MESSAGE_RE.match(record['message']))
| [
"def",
"_is_counter_log4j_record",
"(",
"record",
")",
":",
"return",
"bool",
"(",
"_INDENTED_COUNTERS_MESSAGE_RE",
".",
"match",
"(",
"record",
"[",
"'message'",
"]",
")",
")"
] | is this the record containing counters? . | train | false |
44,827 | def onlylib(*libs):
def set_libs(function):
if libs:
function.LIBS = libs
return function
return set_libs
| [
"def",
"onlylib",
"(",
"*",
"libs",
")",
":",
"def",
"set_libs",
"(",
"function",
")",
":",
"if",
"libs",
":",
"function",
".",
"LIBS",
"=",
"libs",
"return",
"function",
"return",
"set_libs"
] | decorator to restrict benchmarks to specific libraries . | train | false |
44,828 | def redirect_to_twitter(twitter_handle):
try:
user = User.find_one(Q('social.twitter', 'iexact', twitter_handle))
except NoResultsFound:
raise HTTPError(http.NOT_FOUND, data={'message_short': 'User Not Found', 'message_long': 'There is no active user associated with the Twitter handle: {0}.'.format(twitter_handle... | [
"def",
"redirect_to_twitter",
"(",
"twitter_handle",
")",
":",
"try",
":",
"user",
"=",
"User",
".",
"find_one",
"(",
"Q",
"(",
"'social.twitter'",
",",
"'iexact'",
",",
"twitter_handle",
")",
")",
"except",
"NoResultsFound",
":",
"raise",
"HTTPError",
"(",
... | redirect get requests for /@twitterhandle/ to respective the osf user account if it associated with an active account . | train | false |
44,829 | def rank(X, cond=1e-12):
X = np.asarray(X)
if (len(X.shape) == 2):
D = scipy.linalg.svdvals(X)
return int(np.add.reduce(np.greater((D / D.max()), cond).astype(np.int32)))
else:
return int((not np.alltrue(np.equal(X, 0.0))))
| [
"def",
"rank",
"(",
"X",
",",
"cond",
"=",
"1e-12",
")",
":",
"X",
"=",
"np",
".",
"asarray",
"(",
"X",
")",
"if",
"(",
"len",
"(",
"X",
".",
"shape",
")",
"==",
"2",
")",
":",
"D",
"=",
"scipy",
".",
"linalg",
".",
"svdvals",
"(",
"X",
"... | return the rank of a matrix x based on its generalized inverse . | train | false |
44,831 | @requires_badges_enabled
def course_badge_check(user, course_key):
if (not modulestore().get_course(course_key).issue_badges):
LOGGER.info('Course is not configured to issue badges.')
return
badge_class = get_completion_badge(course_key, user)
if (not badge_class):
return
if BadgeAssertion.objects.filter(user... | [
"@",
"requires_badges_enabled",
"def",
"course_badge_check",
"(",
"user",
",",
"course_key",
")",
":",
"if",
"(",
"not",
"modulestore",
"(",
")",
".",
"get_course",
"(",
"course_key",
")",
".",
"issue_badges",
")",
":",
"LOGGER",
".",
"info",
"(",
"'Course i... | takes a generatedcertificate instance . | train | false |
44,833 | def abbrev_list(vals):
ranges = []
lower = 0
upper = (-2)
for val in (sorted(vals) + [(-1)]):
if (val != (upper + 1)):
if (lower == upper):
ranges.append(str(lower))
elif (lower <= upper):
ranges.append(('%d-%d' % (lower, upper)))
lower = val
upper = val
return ','.join(ranges)
| [
"def",
"abbrev_list",
"(",
"vals",
")",
":",
"ranges",
"=",
"[",
"]",
"lower",
"=",
"0",
"upper",
"=",
"(",
"-",
"2",
")",
"for",
"val",
"in",
"(",
"sorted",
"(",
"vals",
")",
"+",
"[",
"(",
"-",
"1",
")",
"]",
")",
":",
"if",
"(",
"val",
... | condense unsigned to 0 . | train | false |
44,834 | def template_read():
if (len(get_vars) > 0):
(dummy, template_id) = get_vars.viewing.split('.')
else:
template_id = request.args[0]
def postp(r, output):
if r.interactive:
template_id = r.id
form = s3db.survey_buildQuestionnaireFromTemplate(template_id)
output['items'] = None
output['form'] = None
... | [
"def",
"template_read",
"(",
")",
":",
"if",
"(",
"len",
"(",
"get_vars",
")",
">",
"0",
")",
":",
"(",
"dummy",
",",
"template_id",
")",
"=",
"get_vars",
".",
"viewing",
".",
"split",
"(",
"'.'",
")",
"else",
":",
"template_id",
"=",
"request",
".... | show the details of all the questions of a particular template . | train | false |
44,836 | def emit_field_changed_events(instance, user, db_table, excluded_fields=None, hidden_fields=None):
def clean_field(field_name, value):
'\n Prepare a field to be emitted in a JSON serializable format. If\n `field_name` is a hidden field, return None.\n '
if (field_name in hidden_fields):
re... | [
"def",
"emit_field_changed_events",
"(",
"instance",
",",
"user",
",",
"db_table",
",",
"excluded_fields",
"=",
"None",
",",
"hidden_fields",
"=",
"None",
")",
":",
"def",
"clean_field",
"(",
"field_name",
",",
"value",
")",
":",
"if",
"(",
"field_name",
"in... | emits a settings changed event for each field that has changed . | train | false |
44,837 | def mad(a, c=0.6745, axis=0):
_shape = a.shape
a.shape = np.product(a.shape, axis=0)
m = (np.median(np.fabs((a - np.median(a)))) / c)
a.shape = _shape
return m
| [
"def",
"mad",
"(",
"a",
",",
"c",
"=",
"0.6745",
",",
"axis",
"=",
"0",
")",
":",
"_shape",
"=",
"a",
".",
"shape",
"a",
".",
"shape",
"=",
"np",
".",
"product",
"(",
"a",
".",
"shape",
",",
"axis",
"=",
"0",
")",
"m",
"=",
"(",
"np",
"."... | median absolute deviation: median(abs(a - median(a))) / c . | train | false |
44,838 | def conllned(trace=1):
from nltk.corpus import conll2002
vnv = "\n (\n is/V| # 3rd sing present and\n was/V| # past forms of the verb zijn ('be')\n werd/V| # and also present\n wordt/V # past of worden ('become)\n )\n .* # followed by anything\n van/Prep # followed by van ('of')\n... | [
"def",
"conllned",
"(",
"trace",
"=",
"1",
")",
":",
"from",
"nltk",
".",
"corpus",
"import",
"conll2002",
"vnv",
"=",
"\"\\n (\\n is/V| # 3rd sing present and\\n was/V| # past forms of the verb zijn ('be')\\n werd/V| # and also present\\n wordt/V # past of word... | find the copula+van relation in the dutch tagged training corpus from conll 2002 . | train | false |
44,839 | def _expand_balancer(lb):
ret = {}
ret.update(lb.__dict__)
hc = ret['extra']['healthchecks']
ret['extra']['healthchecks'] = []
for item in hc:
ret['extra']['healthchecks'].append(_expand_item(item))
fwr = ret['extra']['forwarding_rule']
tp = ret['extra']['forwarding_rule'].targetpool
reg = ret['extra']['forwa... | [
"def",
"_expand_balancer",
"(",
"lb",
")",
":",
"ret",
"=",
"{",
"}",
"ret",
".",
"update",
"(",
"lb",
".",
"__dict__",
")",
"hc",
"=",
"ret",
"[",
"'extra'",
"]",
"[",
"'healthchecks'",
"]",
"ret",
"[",
"'extra'",
"]",
"[",
"'healthchecks'",
"]",
... | convert the libcloud load-balancer object into something more serializable . | train | true |
44,842 | def utc_aware(unaware):
def utc_method(*args, **kwargs):
dt = unaware(*args, **kwargs)
return dt.replace(tzinfo=UTC)
return utc_method
| [
"def",
"utc_aware",
"(",
"unaware",
")",
":",
"def",
"utc_method",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"dt",
"=",
"unaware",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"return",
"dt",
".",
"replace",
"(",
"tzinfo",
"=",
"UTC",
")",
... | decorator for adding utc tzinfo to datetimes utcfoo methods . | train | false |
44,844 | def ensure_str(text):
if isinstance(text, unicode):
return text.encode(pyreadline_codepage, 'replace')
return text
| [
"def",
"ensure_str",
"(",
"text",
")",
":",
"if",
"isinstance",
"(",
"text",
",",
"unicode",
")",
":",
"return",
"text",
".",
"encode",
"(",
"pyreadline_codepage",
",",
"'replace'",
")",
"return",
"text"
] | convert unicode to str using pyreadline_codepage . | train | false |
44,846 | def regularize_layer_params(layer, penalty, tags={'regularizable': True}, **kwargs):
layers = ([layer] if isinstance(layer, Layer) else layer)
all_params = []
for layer in layers:
all_params += layer.get_params(**tags)
return apply_penalty(all_params, penalty, **kwargs)
| [
"def",
"regularize_layer_params",
"(",
"layer",
",",
"penalty",
",",
"tags",
"=",
"{",
"'regularizable'",
":",
"True",
"}",
",",
"**",
"kwargs",
")",
":",
"layers",
"=",
"(",
"[",
"layer",
"]",
"if",
"isinstance",
"(",
"layer",
",",
"Layer",
")",
"else... | computes a regularization cost by applying a penalty to the parameters of a layer or group of layers . | train | false |
44,847 | def dbhost(mac, ip, hostname):
source_idx = None
while (source_idx is None):
source_idx = fetch('SELECT ROWID FROM host WHERE ip = ?', (ip,))
if (len(source_idx) > 0):
insert('UPDATE host SET mac = ?, hostname = ? WHERE ip = ?', (mac, hostname))
source_idx = None
else:
source_idx = insert('INSERT INTO ... | [
"def",
"dbhost",
"(",
"mac",
",",
"ip",
",",
"hostname",
")",
":",
"source_idx",
"=",
"None",
"while",
"(",
"source_idx",
"is",
"None",
")",
":",
"source_idx",
"=",
"fetch",
"(",
"'SELECT ROWID FROM host WHERE ip = ?'",
",",
"(",
"ip",
",",
")",
")",
"if... | insert basic host information into the database . | train | false |
44,851 | def Queue(maxsize=0):
from multiprocessing.queues import Queue
return Queue(maxsize)
| [
"def",
"Queue",
"(",
"maxsize",
"=",
"0",
")",
":",
"from",
"multiprocessing",
".",
"queues",
"import",
"Queue",
"return",
"Queue",
"(",
"maxsize",
")"
] | returns a queue object . | train | false |
44,852 | def tablespace_create(name, location, options=None, owner=None, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None):
owner_query = ''
options_query = ''
if owner:
owner_query = 'OWNER "{0}"'.format(owner)
if options:
optionstext = ['{0} = {1}'.format(k, v) for (k, v) in six.iteritem... | [
"def",
"tablespace_create",
"(",
"name",
",",
"location",
",",
"options",
"=",
"None",
",",
"owner",
"=",
"None",
",",
"user",
"=",
"None",
",",
"host",
"=",
"None",
",",
"port",
"=",
"None",
",",
"maintenance_db",
"=",
"None",
",",
"password",
"=",
... | adds a tablespace to the postgres server . | train | true |
44,853 | def datashape_type_to_numpy(type_):
if isinstance(type_, Option):
type_ = type_.ty
if isinstance(type_, DateTime):
return np.dtype('datetime64[ns]')
else:
return type_.to_numpy_dtype()
| [
"def",
"datashape_type_to_numpy",
"(",
"type_",
")",
":",
"if",
"isinstance",
"(",
"type_",
",",
"Option",
")",
":",
"type_",
"=",
"type_",
".",
"ty",
"if",
"isinstance",
"(",
"type_",
",",
"DateTime",
")",
":",
"return",
"np",
".",
"dtype",
"(",
"'dat... | given a datashape type . | train | false |
44,854 | def fetch_msx_hdu(cache=True):
return fetch_hdu('galactic_center/gc_msx_e.fits', cache=cache)
| [
"def",
"fetch_msx_hdu",
"(",
"cache",
"=",
"True",
")",
":",
"return",
"fetch_hdu",
"(",
"'galactic_center/gc_msx_e.fits'",
",",
"cache",
"=",
"cache",
")"
] | fetch the msx example dataset hdu . | train | false |
44,858 | def tos():
_custom_view('tos')
response.title = T('Terms of Service')
return dict()
| [
"def",
"tos",
"(",
")",
":",
"_custom_view",
"(",
"'tos'",
")",
"response",
".",
"title",
"=",
"T",
"(",
"'Terms of Service'",
")",
"return",
"dict",
"(",
")"
] | custom view . | train | false |
44,859 | def process_items(r, keys, timeout, limit=0, log_every=1000, wait=0.1):
limit = (limit or float(u'inf'))
processed = 0
while (processed < limit):
ret = r.blpop(keys, timeout)
if (ret is None):
time.sleep(wait)
continue
(source, data) = ret
try:
item = json.loads(data)
except Exception:
logger.e... | [
"def",
"process_items",
"(",
"r",
",",
"keys",
",",
"timeout",
",",
"limit",
"=",
"0",
",",
"log_every",
"=",
"1000",
",",
"wait",
"=",
"0.1",
")",
":",
"limit",
"=",
"(",
"limit",
"or",
"float",
"(",
"u'inf'",
")",
")",
"processed",
"=",
"0",
"w... | process items from a redis queue . | train | false |
44,861 | def getClosestDistanceIndexToLine(point, loop):
smallestDistance = 9.876543219876543e+17
closestDistanceIndex = None
for pointIndex in xrange(len(loop)):
segmentBegin = loop[pointIndex]
segmentEnd = loop[((pointIndex + 1) % len(loop))]
distance = getDistanceToPlaneSegment(segmentBegin, segmentEnd, point)
if ... | [
"def",
"getClosestDistanceIndexToLine",
"(",
"point",
",",
"loop",
")",
":",
"smallestDistance",
"=",
"9.876543219876543e+17",
"closestDistanceIndex",
"=",
"None",
"for",
"pointIndex",
"in",
"xrange",
"(",
"len",
"(",
"loop",
")",
")",
":",
"segmentBegin",
"=",
... | get the distance squared to the closest segment of the loop and index of that segment . | train | false |
44,862 | @celery.task
@dog_stats_api.timed('status.service.celery.pong')
def delayed_ping(value, delay):
if (value == 'ping'):
result = 'pong'
else:
result = 'got: {0}'.format(value)
time.sleep(delay)
return result
| [
"@",
"celery",
".",
"task",
"@",
"dog_stats_api",
".",
"timed",
"(",
"'status.service.celery.pong'",
")",
"def",
"delayed_ping",
"(",
"value",
",",
"delay",
")",
":",
"if",
"(",
"value",
"==",
"'ping'",
")",
":",
"result",
"=",
"'pong'",
"else",
":",
"re... | a simple tasks that replies to a message after a especified amount of seconds . | train | false |
44,864 | def get_enabled():
return _get_svc_list('YES')
| [
"def",
"get_enabled",
"(",
")",
":",
"return",
"_get_svc_list",
"(",
"'YES'",
")"
] | return a list of enabled services . | train | false |
44,866 | def parse_cropbox(cropbox):
if isinstance(cropbox, six.text_type):
return tuple([int(x.strip()) for x in cropbox.split(',')])
else:
return tuple(cropbox)
| [
"def",
"parse_cropbox",
"(",
"cropbox",
")",
":",
"if",
"isinstance",
"(",
"cropbox",
",",
"six",
".",
"text_type",
")",
":",
"return",
"tuple",
"(",
"[",
"int",
"(",
"x",
".",
"strip",
"(",
")",
")",
"for",
"x",
"in",
"cropbox",
".",
"split",
"(",... | returns x . | train | true |
44,867 | def test_ast_bad_try():
cant_compile(u'(try 1 bla)')
cant_compile(u'(try 1 bla bla)')
cant_compile(u'(try (do) (else 1) (else 2))')
cant_compile(u'(try 1 (else 1))')
| [
"def",
"test_ast_bad_try",
"(",
")",
":",
"cant_compile",
"(",
"u'(try 1 bla)'",
")",
"cant_compile",
"(",
"u'(try 1 bla bla)'",
")",
"cant_compile",
"(",
"u'(try (do) (else 1) (else 2))'",
")",
"cant_compile",
"(",
"u'(try 1 (else 1))'",
")"
] | make sure ast cant compile invalid try . | train | false |
44,868 | def add_hook(name, pass_function=False):
def outer(f):
f.__hook_name__ = name
@functools.wraps(f)
def inner(*args, **kwargs):
manager = _HOOKS.setdefault(name, HookManager(name))
function = None
if pass_function:
function = f
manager.run_pre(name, args, kwargs, f=function)
rv = f(*args, **kwar... | [
"def",
"add_hook",
"(",
"name",
",",
"pass_function",
"=",
"False",
")",
":",
"def",
"outer",
"(",
"f",
")",
":",
"f",
".",
"__hook_name__",
"=",
"name",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"inner",
"(",
"*",
"args",
",",
"**",
... | execute optional pre and post methods around the decorated function . | train | false |
44,869 | def get_read_data(data):
if config['mix_case']:
seq = sequence_case(data)
qual = data['quality_scores']
else:
seq = data['bases']
qual = data['quality_scores']
return (seq, qual)
| [
"def",
"get_read_data",
"(",
"data",
")",
":",
"if",
"config",
"[",
"'mix_case'",
"]",
":",
"seq",
"=",
"sequence_case",
"(",
"data",
")",
"qual",
"=",
"data",
"[",
"'quality_scores'",
"]",
"else",
":",
"seq",
"=",
"data",
"[",
"'bases'",
"]",
"qual",
... | given the data for one read it returns 2 strs with the fasta seq and fasta qual . | train | false |
44,870 | def year_month_to_month_number(year, month, day=None):
return ((((year - start_year) * 12) + (month - 1)) - start_month_0_indexed)
| [
"def",
"year_month_to_month_number",
"(",
"year",
",",
"month",
",",
"day",
"=",
"None",
")",
":",
"return",
"(",
"(",
"(",
"(",
"year",
"-",
"start_year",
")",
"*",
"12",
")",
"+",
"(",
"month",
"-",
"1",
")",
")",
"-",
"start_month_0_indexed",
")"
... | time periods are integers representing months in years . | train | false |
44,871 | def rad(d):
return ((d * pi) / 180)
| [
"def",
"rad",
"(",
"d",
")",
":",
"return",
"(",
"(",
"d",
"*",
"pi",
")",
"/",
"180",
")"
] | return the radian value for the given degrees . | train | false |
44,872 | @curry
def set_attribute(name, value):
def decorator(f):
setattr(f, name, value)
return f
return decorator
| [
"@",
"curry",
"def",
"set_attribute",
"(",
"name",
",",
"value",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"setattr",
"(",
"f",
",",
"name",
",",
"value",
")",
"return",
"f",
"return",
"decorator"
] | set the value of an attribute . | train | true |
44,873 | def identity(x):
return x
| [
"def",
"identity",
"(",
"x",
")",
":",
"return",
"x"
] | returns content unchanged . | train | false |
44,876 | def AutoProxy(token, serializer, manager=None, authkey=None, exposed=None, incref=True):
_Client = listener_client[serializer][1]
if (exposed is None):
conn = _Client(token.address, authkey=authkey)
try:
exposed = dispatch(conn, None, 'get_methods', (token,))
finally:
conn.close()
if ((authkey is None) a... | [
"def",
"AutoProxy",
"(",
"token",
",",
"serializer",
",",
"manager",
"=",
"None",
",",
"authkey",
"=",
"None",
",",
"exposed",
"=",
"None",
",",
"incref",
"=",
"True",
")",
":",
"_Client",
"=",
"listener_client",
"[",
"serializer",
"]",
"[",
"1",
"]",
... | return an auto-proxy for token . | train | false |
44,877 | def mock_inputs(inputs):
def inner(test_func):
def wrapped(*args):
class mock_getpass:
@staticmethod
def getpass(prompt='Password: ', stream=None):
if (not PY3):
assert isinstance(prompt, binary_type)
return inputs[u'password']
def mock_input(prompt):
prompt = str(prompt)
assert... | [
"def",
"mock_inputs",
"(",
"inputs",
")",
":",
"def",
"inner",
"(",
"test_func",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
")",
":",
"class",
"mock_getpass",
":",
"@",
"staticmethod",
"def",
"getpass",
"(",
"prompt",
"=",
"'Password: '",
",",
"stream... | decorator to temporarily replace input/getpass to allow interactive createsuperuser . | train | false |
44,878 | def get_setting(varname):
gl = globals()
if (varname not in gl.keys()):
raise ValueError(('Unknown setting %s' % varname))
return gl[varname]
| [
"def",
"get_setting",
"(",
"varname",
")",
":",
"gl",
"=",
"globals",
"(",
")",
"if",
"(",
"varname",
"not",
"in",
"gl",
".",
"keys",
"(",
")",
")",
":",
"raise",
"ValueError",
"(",
"(",
"'Unknown setting %s'",
"%",
"varname",
")",
")",
"return",
"gl... | returns the value of a configuration variable . | train | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.