text
stringlengths 75
104k
| code_tokens
sequence | avg_line_len
float64 7.91
980
| score
sequence |
---|---|---|---|
def delete_report(self, report):
"""
Deletes a generated report instance.
https://canvas.instructure.com/doc/api/account_reports.html#method.account_reports.destroy
"""
url = ACCOUNTS_API.format(report.account_id) + "/reports/{}/{}".format(
report.type, report.report_id)
response = self._delete_resource(url)
return True | [
"def",
"delete_report",
"(",
"self",
",",
"report",
")",
":",
"url",
"=",
"ACCOUNTS_API",
".",
"format",
"(",
"report",
".",
"account_id",
")",
"+",
"\"/reports/{}/{}\"",
".",
"format",
"(",
"report",
".",
"type",
",",
"report",
".",
"report_id",
")",
"response",
"=",
"self",
".",
"_delete_resource",
"(",
"url",
")",
"return",
"True"
] | 34.636364 | [
0.03125,
0.18181818181818182,
0.045454545454545456,
0,
0.061224489795918366,
0.18181818181818182,
0.0379746835443038,
0.07142857142857142,
0,
0.044444444444444446,
0.10526315789473684
] |
def probe(filename, cmd='ffprobe', **kwargs):
"""Run ffprobe on the specified file and return a JSON representation of the output.
Raises:
:class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code,
an :class:`Error` is returned with a generic error message.
The stderr output can be retrieved by accessing the
``stderr`` property of the exception.
"""
args = [cmd, '-show_format', '-show_streams', '-of', 'json']
args += convert_kwargs_to_cmd_line_args(kwargs)
args += [filename]
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
raise Error('ffprobe', out, err)
return json.loads(out.decode('utf-8')) | [
"def",
"probe",
"(",
"filename",
",",
"cmd",
"=",
"'ffprobe'",
",",
"*",
"*",
"kwargs",
")",
":",
"args",
"=",
"[",
"cmd",
",",
"'-show_format'",
",",
"'-show_streams'",
",",
"'-of'",
",",
"'json'",
"]",
"args",
"+=",
"convert_kwargs_to_cmd_line_args",
"(",
"kwargs",
")",
"args",
"+=",
"[",
"filename",
"]",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"args",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",
"PIPE",
")",
"out",
",",
"err",
"=",
"p",
".",
"communicate",
"(",
")",
"if",
"p",
".",
"returncode",
"!=",
"0",
":",
"raise",
"Error",
"(",
"'ffprobe'",
",",
"out",
",",
"err",
")",
"return",
"json",
".",
"loads",
"(",
"out",
".",
"decode",
"(",
"'utf-8'",
")",
")"
] | 42.055556 | [
0.022222222222222223,
0.03409090909090909,
0,
0.18181818181818182,
0.07042253521126761,
0.08450704225352113,
0.031746031746031744,
0.061224489795918366,
0.2857142857142857,
0.03125,
0.0392156862745098,
0.09090909090909091,
0,
0.02564102564102564,
0.06666666666666667,
0.08,
0.05,
0.047619047619047616
] |
def trans_attr(attr, lang):
"""
Returns the name of the translated attribute of the object <attribute>_<lang_iso_code>.
For example: name_es (name attribute in Spanish)
@param attr Attribute whose name will form the name translated attribute.
@param lang ISO Language code that will be the suffix of the translated attribute.
@return: string with the name of the translated attribute.
"""
lang = lang.replace("-","_").lower()
return "{0}_{1}".format(attr,lang) | [
"def",
"trans_attr",
"(",
"attr",
",",
"lang",
")",
":",
"lang",
"=",
"lang",
".",
"replace",
"(",
"\"-\"",
",",
"\"_\"",
")",
".",
"lower",
"(",
")",
"return",
"\"{0}_{1}\"",
".",
"format",
"(",
"attr",
",",
"lang",
")"
] | 46 | [
0.037037037037037035,
0.75,
0.09090909090909091,
0.08163265306122448,
0.04054054054054054,
0.04819277108433735,
0.05084745762711865,
0.75,
0.10810810810810811,
0.11428571428571428
] |
def setup(self,
host, flow_id,
reason, grr_server_url, grr_username, grr_password, approvers=None,
verify=True):
"""Initializes a GRR flow collector.
Args:
host: hostname of machine.
flow_id: ID of GRR flow to retrieve.
reason: justification for GRR access.
grr_server_url: GRR server URL.
grr_username: GRR username.
grr_password: GRR password.
approvers: list of GRR approval recipients.
verify: boolean, whether to verify the GRR server's x509 certificate.
"""
super(GRRFlowCollector, self).setup(
reason, grr_server_url, grr_username, grr_password,
approvers=approvers, verify=verify)
self.flow_id = flow_id
self.host = host | [
"def",
"setup",
"(",
"self",
",",
"host",
",",
"flow_id",
",",
"reason",
",",
"grr_server_url",
",",
"grr_username",
",",
"grr_password",
",",
"approvers",
"=",
"None",
",",
"verify",
"=",
"True",
")",
":",
"super",
"(",
"GRRFlowCollector",
",",
"self",
")",
".",
"setup",
"(",
"reason",
",",
"grr_server_url",
",",
"grr_username",
",",
"grr_password",
",",
"approvers",
"=",
"approvers",
",",
"verify",
"=",
"verify",
")",
"self",
".",
"flow_id",
"=",
"flow_id",
"self",
".",
"host",
"=",
"host"
] | 34.904762 | [
0.13333333333333333,
0.07692307692307693,
0.0379746835443038,
0.16,
0.05,
0,
0.2222222222222222,
0.09375,
0.07142857142857142,
0.06976744186046512,
0.08108108108108109,
0.09090909090909091,
0.09090909090909091,
0.061224489795918366,
0.04,
0.2857142857142857,
0.075,
0.03389830508474576,
0.11627906976744186,
0.07692307692307693,
0.1
] |
def set_opt(self, name, value):
""" Set option.
"""
self.cache['opts'][name] = value
if name == 'compress':
self.cache['delims'] = self.def_delims if not value else (
'',
'',
'') | [
"def",
"set_opt",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"self",
".",
"cache",
"[",
"'opts'",
"]",
"[",
"name",
"]",
"=",
"value",
"if",
"name",
"==",
"'compress'",
":",
"self",
".",
"cache",
"[",
"'delims'",
"]",
"=",
"self",
".",
"def_delims",
"if",
"not",
"value",
"else",
"(",
"''",
",",
"''",
",",
"''",
")"
] | 26.2 | [
0.03225806451612903,
0.08695652173913043,
0.18181818181818182,
0.05,
0,
0.06666666666666667,
0.04285714285714286,
0.10526315789473684,
0.10526315789473684,
0.15789473684210525
] |
def create(cls, name, address=None, ipv6_address=None,
secondary=None, comment=None):
"""
Create the host element
:param str name: Name of element
:param str address: ipv4 address of host object (optional if ipv6)
:param str ipv6_address: ipv6 address (optional if ipv4)
:param list secondary: secondary ip addresses (optional)
:param str comment: comment (optional)
:raises CreateElementFailed: element creation failed with reason
:return: instance with meta
:rtype: Host
.. note:: Either ipv4 or ipv6 address is required
"""
address = address if address else None
ipv6_address = ipv6_address if ipv6_address else None
secondaries = [] if secondary is None else secondary
json = {'name': name,
'address': address,
'ipv6_address': ipv6_address,
'secondary': secondaries,
'comment': comment}
return ElementCreator(cls, json) | [
"def",
"create",
"(",
"cls",
",",
"name",
",",
"address",
"=",
"None",
",",
"ipv6_address",
"=",
"None",
",",
"secondary",
"=",
"None",
",",
"comment",
"=",
"None",
")",
":",
"address",
"=",
"address",
"if",
"address",
"else",
"None",
"ipv6_address",
"=",
"ipv6_address",
"if",
"ipv6_address",
"else",
"None",
"secondaries",
"=",
"[",
"]",
"if",
"secondary",
"is",
"None",
"else",
"secondary",
"json",
"=",
"{",
"'name'",
":",
"name",
",",
"'address'",
":",
"address",
",",
"'ipv6_address'",
":",
"ipv6_address",
",",
"'secondary'",
":",
"secondaries",
",",
"'comment'",
":",
"comment",
"}",
"return",
"ElementCreator",
"(",
"cls",
",",
"json",
")"
] | 39.384615 | [
0.037037037037037035,
0.13333333333333333,
0.18181818181818182,
0.06451612903225806,
0,
0.075,
0.05405405405405406,
0.0625,
0.0625,
0.08695652173913043,
0.041666666666666664,
0.08571428571428572,
0.15,
0.25,
0.05263157894736842,
0.18181818181818182,
0.043478260869565216,
0.03278688524590164,
0.03333333333333333,
0.10344827586206896,
0.05714285714285714,
0.044444444444444446,
0.04878048780487805,
0.08571428571428572,
0,
0.05
] |
def redirect_display(self, on):
'''
on:
* True -> set $DISPLAY to virtual screen
* False -> set $DISPLAY to original screen
:param on: bool
'''
d = self.new_display_var if on else self.old_display_var
if d is None:
log.debug('unset DISPLAY')
del os.environ['DISPLAY']
else:
log.debug('DISPLAY=%s', d)
os.environ['DISPLAY'] = d | [
"def",
"redirect_display",
"(",
"self",
",",
"on",
")",
":",
"d",
"=",
"self",
".",
"new_display_var",
"if",
"on",
"else",
"self",
".",
"old_display_var",
"if",
"d",
"is",
"None",
":",
"log",
".",
"debug",
"(",
"'unset DISPLAY'",
")",
"del",
"os",
".",
"environ",
"[",
"'DISPLAY'",
"]",
"else",
":",
"log",
".",
"debug",
"(",
"'DISPLAY=%s'",
",",
"d",
")",
"os",
".",
"environ",
"[",
"'DISPLAY'",
"]",
"=",
"d"
] | 29 | [
0.03225806451612903,
0.18181818181818182,
0.18181818181818182,
0.061224489795918366,
0.058823529411764705,
0,
0.13043478260869565,
0.18181818181818182,
0.03125,
0.09523809523809523,
0.05263157894736842,
0.05405405405405406,
0.15384615384615385,
0.05263157894736842,
0.05405405405405406
] |
def to_ts(s):
"""Parses an NGINX timestamp from "30/Apr/2014:07:32:09 +0000" and returns it as ISO 8601" """
# Strip TZ portion if present
m = Nginx.DATE_FMT.match(s)
if m:
s = m.group(1)
delta = timedelta(seconds=int(m.group(3)) * (-1 if m.group(2) == '-' else 1)) # Offset from GMT
else:
delta = timedelta(seconds=0)
dt = datetime.strptime(s, "%d/%b/%Y:%H:%M:%S")
dt += delta
return dt.strftime('%Y-%m-%dT%H:%M:%SZ') | [
"def",
"to_ts",
"(",
"s",
")",
":",
"# Strip TZ portion if present",
"m",
"=",
"Nginx",
".",
"DATE_FMT",
".",
"match",
"(",
"s",
")",
"if",
"m",
":",
"s",
"=",
"m",
".",
"group",
"(",
"1",
")",
"delta",
"=",
"timedelta",
"(",
"seconds",
"=",
"int",
"(",
"m",
".",
"group",
"(",
"3",
")",
")",
"*",
"(",
"-",
"1",
"if",
"m",
".",
"group",
"(",
"2",
")",
"==",
"'-'",
"else",
"1",
")",
")",
"# Offset from GMT",
"else",
":",
"delta",
"=",
"timedelta",
"(",
"seconds",
"=",
"0",
")",
"dt",
"=",
"datetime",
".",
"strptime",
"(",
"s",
",",
"\"%d/%b/%Y:%H:%M:%S\"",
")",
"dt",
"+=",
"delta",
"return",
"dt",
".",
"strftime",
"(",
"'%Y-%m-%dT%H:%M:%SZ'",
")"
] | 39.076923 | [
0.07692307692307693,
0.02912621359223301,
0,
0.05405405405405406,
0.05714285714285714,
0.15384615384615385,
0.07692307692307693,
0.037383177570093455,
0.15384615384615385,
0.05,
0.037037037037037035,
0.10526315789473684,
0.041666666666666664
] |
def equalize_adaptive_clahe(image, ntiles=8, clip_limit=0.01):
"""Return contrast limited adaptive histogram equalized image.
The return value is normalised to the range 0 to 1.
:param image: numpy array or :class:`jicimagelib.image.Image` of dtype float
:param ntiles: number of tile regions
:param clip_limit: clipping limit in range 0 to 1,
higher values give more contrast
"""
# Convert input for skimage.
skimage_float_im = normalise(image)
if np.all(skimage_float_im):
raise(RuntimeError("Cannot equalise when there is no variation."))
normalised = skimage.exposure.equalize_adapthist(skimage_float_im,
ntiles_x=ntiles, ntiles_y=ntiles, clip_limit=clip_limit)
assert np.max(normalised) == 1.0
assert np.min(normalised) == 0.0
return normalised | [
"def",
"equalize_adaptive_clahe",
"(",
"image",
",",
"ntiles",
"=",
"8",
",",
"clip_limit",
"=",
"0.01",
")",
":",
"# Convert input for skimage.",
"skimage_float_im",
"=",
"normalise",
"(",
"image",
")",
"if",
"np",
".",
"all",
"(",
"skimage_float_im",
")",
":",
"raise",
"(",
"RuntimeError",
"(",
"\"Cannot equalise when there is no variation.\"",
")",
")",
"normalised",
"=",
"skimage",
".",
"exposure",
".",
"equalize_adapthist",
"(",
"skimage_float_im",
",",
"ntiles_x",
"=",
"ntiles",
",",
"ntiles_y",
"=",
"ntiles",
",",
"clip_limit",
"=",
"clip_limit",
")",
"assert",
"np",
".",
"max",
"(",
"normalised",
")",
"==",
"1.0",
"assert",
"np",
".",
"min",
"(",
"normalised",
")",
"==",
"0.0",
"return",
"normalised"
] | 36.347826 | [
0.016129032258064516,
0.030303030303030304,
0.5,
0.03636363636363636,
0,
0.1,
0.07317073170731707,
0.05555555555555555,
0.05454545454545454,
0.2857142857142857,
0.0625,
0.05128205128205128,
0.5,
0.0625,
0.02702702702702703,
0.5,
0.04285714285714286,
0.09375,
0,
0.05555555555555555,
0.05555555555555555,
0,
0.09523809523809523
] |
def fake_wrap_socket(orig_wrap_socket_fn, *args, **kw):
"""drop-in replacement for py:func:`ssl.wrap_socket`
"""
server_hostname = kw.get('server_hostname')
if server_hostname is not None:
matcher = httpretty.match_https_hostname(server_hostname)
if matcher is None:
return orig_wrap_socket_fn(*args, **kw)
if 'sock' in kw:
return kw['sock']
else:
return args[0] | [
"def",
"fake_wrap_socket",
"(",
"orig_wrap_socket_fn",
",",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"server_hostname",
"=",
"kw",
".",
"get",
"(",
"'server_hostname'",
")",
"if",
"server_hostname",
"is",
"not",
"None",
":",
"matcher",
"=",
"httpretty",
".",
"match_https_hostname",
"(",
"server_hostname",
")",
"if",
"matcher",
"is",
"None",
":",
"return",
"orig_wrap_socket_fn",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
"if",
"'sock'",
"in",
"kw",
":",
"return",
"kw",
"[",
"'sock'",
"]",
"else",
":",
"return",
"args",
"[",
"0",
"]"
] | 35.25 | [
0.01818181818181818,
0.03571428571428571,
0.2857142857142857,
0.0425531914893617,
0.05714285714285714,
0.03076923076923077,
0.07407407407407407,
0.03636363636363636,
0.1,
0.08,
0.2222222222222222,
0.09090909090909091
] |
def get_payload(request):
"""
Extracts the request's payload information.
This method will merge the URL parameter information
and the JSON body of the request together to generate
a dictionary of key<->value pairings.
This method assumes that the JSON body being provided
is also a key-value map, if it is not, then an HTTPBadRequest
exception will be raised.
:param request: <pyramid.request.Request>
:return: <dict>
"""
# always extract values from the URL
payload = dict(request.params.mixed())
# provide override capability from the JSON body
try:
json_data = request.json_body
# no JSON body was found, pyramid raises an error
# in this situation
except StandardError:
pass
else:
if not isinstance(json_data, dict):
raise HTTPBadRequest('JSON body must be a key=value pairing')
else:
payload.update(json_data)
return payload | [
"def",
"get_payload",
"(",
"request",
")",
":",
"# always extract values from the URL",
"payload",
"=",
"dict",
"(",
"request",
".",
"params",
".",
"mixed",
"(",
")",
")",
"# provide override capability from the JSON body",
"try",
":",
"json_data",
"=",
"request",
".",
"json_body",
"# no JSON body was found, pyramid raises an error",
"# in this situation",
"except",
"StandardError",
":",
"pass",
"else",
":",
"if",
"not",
"isinstance",
"(",
"json_data",
",",
"dict",
")",
":",
"raise",
"HTTPBadRequest",
"(",
"'JSON body must be a key=value pairing'",
")",
"else",
":",
"payload",
".",
"update",
"(",
"json_data",
")",
"return",
"payload"
] | 27.647059 | [
0.04,
0.2857142857142857,
0.0425531914893617,
0.03571428571428571,
0.03508771929824561,
0.0975609756097561,
0,
0.03508771929824561,
0.03076923076923077,
0.06896551724137931,
0,
0.1111111111111111,
0,
0.2631578947368421,
0.2857142857142857,
0.05,
0.047619047619047616,
0,
0.038461538461538464,
0.25,
0.05405405405405406,
0,
0.03773584905660377,
0.08695652173913043,
0.08,
0.16666666666666666,
0,
0.2222222222222222,
0.046511627906976744,
0.0273972602739726,
0.15384615384615385,
0.05405405405405406,
0,
0.1111111111111111
] |
def synchronized(sync_lock):
"""A decorator synchronizing multi-process access to a resource."""
def wrapper(f):
"""The decorator's core function.
:param f:
:return:
"""
@functools.wraps(f)
def inner_wrapper(*args, **kw):
"""
:param args:
:param kw:
:return:
"""
with sync_lock:
return f(*args, **kw)
return inner_wrapper
return wrapper | [
"def",
"synchronized",
"(",
"sync_lock",
")",
":",
"def",
"wrapper",
"(",
"f",
")",
":",
"\"\"\"The decorator's core function.\n\n :param f:\n :return:\n \"\"\"",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"inner_wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"\"\"\"\n\n :param args:\n :param kw:\n :return:\n \"\"\"",
"with",
"sync_lock",
":",
"return",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
"return",
"inner_wrapper",
"return",
"wrapper"
] | 19.791667 | [
0.03571428571428571,
0.028169014084507043,
0,
0.10526315789473684,
0.04878048780487805,
0,
0.17647058823529413,
0.1875,
0.18181818181818182,
0,
0.07407407407407407,
0.05128205128205128,
0.13333333333333333,
0,
0.125,
0.13636363636363635,
0.15,
0.13333333333333333,
0.07407407407407407,
0.05405405405405406,
0,
0.07142857142857142,
0,
0.1111111111111111
] |
def check_proxy_code(self, address) -> bool:
"""
Check if proxy is valid
:param address: address of the proxy
:return: True if proxy is valid, False otherwise
"""
deployed_proxy_code = self.w3.eth.getCode(address)
proxy_code_fns = (get_paying_proxy_deployed_bytecode,
get_proxy_factory_contract(self.w3,
self.proxy_factory_address).functions.proxyRuntimeCode().call)
for proxy_code_fn in proxy_code_fns:
if deployed_proxy_code == proxy_code_fn():
return True
return False | [
"def",
"check_proxy_code",
"(",
"self",
",",
"address",
")",
"->",
"bool",
":",
"deployed_proxy_code",
"=",
"self",
".",
"w3",
".",
"eth",
".",
"getCode",
"(",
"address",
")",
"proxy_code_fns",
"=",
"(",
"get_paying_proxy_deployed_bytecode",
",",
"get_proxy_factory_contract",
"(",
"self",
".",
"w3",
",",
"self",
".",
"proxy_factory_address",
")",
".",
"functions",
".",
"proxyRuntimeCode",
"(",
")",
".",
"call",
")",
"for",
"proxy_code_fn",
"in",
"proxy_code_fns",
":",
"if",
"deployed_proxy_code",
"==",
"proxy_code_fn",
"(",
")",
":",
"return",
"True",
"return",
"False"
] | 45.5 | [
0.022727272727272728,
0.18181818181818182,
0.06451612903225806,
0.06818181818181818,
0.05357142857142857,
0.18181818181818182,
0.034482758620689655,
0.04918032786885246,
0.06557377049180328,
0.043478260869565216,
0.045454545454545456,
0.037037037037037035,
0.07407407407407407,
0.1
] |
def estimate_shift(x, y, smoother=None, w=None, index_and_value=False, ignore_edge=1/3.,
method='valid'):
"""Estimate the time shift between two signals based on their cross correlation
Arguements:
smoother: Smoothing function applied to correlation values before finding peak
w: Window. Sequence of values between 0 and 1 for wind centered on 0-shift
to weight correlation by before finding peak. Zero-padded to match width of
larger of x and y. Default = hanning(max(len(x, y)))
Returns:
int: number to subtract from an x index to compute a corresponding y index
>>> x, y = np.asarray(np.matrix([[0.5, 0.01], [0.01, 1.0]]) * np.random.randn(50,2).T)
>>> x[:30-8] = y[8:30]
>> estimate_shift(x, y, 'full')
-8
>> estimate_shift(x, y, 'valid')
-8
>> estimate_shift(y, x, 'full') in [8, 9]
True
>> estimate_shift(y, x, 'full') in [8, 9]
True
>> estimate_shift(y, x, 'full') in [8, 9]
True
"""
return NotImplementedError("On Line 965, FIXME: TypeError: object of type 'NoneType' has no len()")
method = method or 'valid'
try:
x = x.dropna()
x = x.values
except:
pass
try:
y = y.dropna()
y = y.values
except:
pass
if len(x) < len(y):
swap, x, y = -1, y, x
else:
swap = +1
Nx, Ny = len(x), len(y)
if ignore_edge > 0:
yi0 = int(max(Ny * ignore_edge, 1))
yi1 = max(Ny - yi0 - 1, 0)
# ignore a large portion of the data in the shorter vector
y = y[yi0:yi1]
x, y = x - x.mean(), y - y.mean()
x, y = x / x.std(), y / y.std()
c = np.correlate(x, y, mode=method)
print(len(x))
print(len(y))
print(len(w))
print(len(c))
if w is not None:
wc = int(np.ceil(len(w) / 2.)) - 1
cc = int(np.ceil(len(c) / 2.)) - 1
w0 = cc - wc
print(w0)
if w0 > 0:
c[:w0], c[-w0:] = 0, 0
c[w0:-w0] = w[:len(c[w0:-w0])] * c[w0:-w0]
elif w0 == 0:
if len(w) < len(c):
w = np.append(w, 0)
c = c * w[:len(c)]
elif w0 < 0:
w0 = abs(w0)
w = w[w0:-w0]
c[w0:-w0] = w[:len(c[w0:-w0])] * c[w0:-w0]
try:
c = smoother(c)
except:
pass
offset = imax = c.argmax()
offset = offset - yi0
if method == 'full':
offset = imax - Nx + 1
# elif method == 'valid':
# offset = imax - yi0
elif method == 'same':
raise NotImplementedError("Unsure what index value to report for a correlation maximum at i = {}"
.format(imax))
offset *= swap
if index_and_value:
return offset, c[imax]
else:
return offset | [
"def",
"estimate_shift",
"(",
"x",
",",
"y",
",",
"smoother",
"=",
"None",
",",
"w",
"=",
"None",
",",
"index_and_value",
"=",
"False",
",",
"ignore_edge",
"=",
"1",
"/",
"3.",
",",
"method",
"=",
"'valid'",
")",
":",
"return",
"NotImplementedError",
"(",
"\"On Line 965, FIXME: TypeError: object of type 'NoneType' has no len()\"",
")",
"method",
"=",
"method",
"or",
"'valid'",
"try",
":",
"x",
"=",
"x",
".",
"dropna",
"(",
")",
"x",
"=",
"x",
".",
"values",
"except",
":",
"pass",
"try",
":",
"y",
"=",
"y",
".",
"dropna",
"(",
")",
"y",
"=",
"y",
".",
"values",
"except",
":",
"pass",
"if",
"len",
"(",
"x",
")",
"<",
"len",
"(",
"y",
")",
":",
"swap",
",",
"x",
",",
"y",
"=",
"-",
"1",
",",
"y",
",",
"x",
"else",
":",
"swap",
"=",
"+",
"1",
"Nx",
",",
"Ny",
"=",
"len",
"(",
"x",
")",
",",
"len",
"(",
"y",
")",
"if",
"ignore_edge",
">",
"0",
":",
"yi0",
"=",
"int",
"(",
"max",
"(",
"Ny",
"*",
"ignore_edge",
",",
"1",
")",
")",
"yi1",
"=",
"max",
"(",
"Ny",
"-",
"yi0",
"-",
"1",
",",
"0",
")",
"# ignore a large portion of the data in the shorter vector",
"y",
"=",
"y",
"[",
"yi0",
":",
"yi1",
"]",
"x",
",",
"y",
"=",
"x",
"-",
"x",
".",
"mean",
"(",
")",
",",
"y",
"-",
"y",
".",
"mean",
"(",
")",
"x",
",",
"y",
"=",
"x",
"/",
"x",
".",
"std",
"(",
")",
",",
"y",
"/",
"y",
".",
"std",
"(",
")",
"c",
"=",
"np",
".",
"correlate",
"(",
"x",
",",
"y",
",",
"mode",
"=",
"method",
")",
"print",
"(",
"len",
"(",
"x",
")",
")",
"print",
"(",
"len",
"(",
"y",
")",
")",
"print",
"(",
"len",
"(",
"w",
")",
")",
"print",
"(",
"len",
"(",
"c",
")",
")",
"if",
"w",
"is",
"not",
"None",
":",
"wc",
"=",
"int",
"(",
"np",
".",
"ceil",
"(",
"len",
"(",
"w",
")",
"/",
"2.",
")",
")",
"-",
"1",
"cc",
"=",
"int",
"(",
"np",
".",
"ceil",
"(",
"len",
"(",
"c",
")",
"/",
"2.",
")",
")",
"-",
"1",
"w0",
"=",
"cc",
"-",
"wc",
"print",
"(",
"w0",
")",
"if",
"w0",
">",
"0",
":",
"c",
"[",
":",
"w0",
"]",
",",
"c",
"[",
"-",
"w0",
":",
"]",
"=",
"0",
",",
"0",
"c",
"[",
"w0",
":",
"-",
"w0",
"]",
"=",
"w",
"[",
":",
"len",
"(",
"c",
"[",
"w0",
":",
"-",
"w0",
"]",
")",
"]",
"*",
"c",
"[",
"w0",
":",
"-",
"w0",
"]",
"elif",
"w0",
"==",
"0",
":",
"if",
"len",
"(",
"w",
")",
"<",
"len",
"(",
"c",
")",
":",
"w",
"=",
"np",
".",
"append",
"(",
"w",
",",
"0",
")",
"c",
"=",
"c",
"*",
"w",
"[",
":",
"len",
"(",
"c",
")",
"]",
"elif",
"w0",
"<",
"0",
":",
"w0",
"=",
"abs",
"(",
"w0",
")",
"w",
"=",
"w",
"[",
"w0",
":",
"-",
"w0",
"]",
"c",
"[",
"w0",
":",
"-",
"w0",
"]",
"=",
"w",
"[",
":",
"len",
"(",
"c",
"[",
"w0",
":",
"-",
"w0",
"]",
")",
"]",
"*",
"c",
"[",
"w0",
":",
"-",
"w0",
"]",
"try",
":",
"c",
"=",
"smoother",
"(",
"c",
")",
"except",
":",
"pass",
"offset",
"=",
"imax",
"=",
"c",
".",
"argmax",
"(",
")",
"offset",
"=",
"offset",
"-",
"yi0",
"if",
"method",
"==",
"'full'",
":",
"offset",
"=",
"imax",
"-",
"Nx",
"+",
"1",
"# elif method == 'valid':",
"# offset = imax - yi0",
"elif",
"method",
"==",
"'same'",
":",
"raise",
"NotImplementedError",
"(",
"\"Unsure what index value to report for a correlation maximum at i = {}\"",
".",
"format",
"(",
"imax",
")",
")",
"offset",
"*=",
"swap",
"if",
"index_and_value",
":",
"return",
"offset",
",",
"c",
"[",
"imax",
"]",
"else",
":",
"return",
"offset"
] | 28.978947 | [
0.03409090909090909,
0.14285714285714285,
0.03614457831325301,
0,
0.13333333333333333,
0.047058823529411764,
0.045454545454545456,
0.043478260869565216,
0.043478260869565216,
0,
0.16666666666666666,
0.05,
0.05555555555555555,
0.11538461538461539,
0,
0.05714285714285714,
0.3333333333333333,
0.05555555555555555,
0.3333333333333333,
0.044444444444444446,
0.25,
0.044444444444444446,
0.25,
0.044444444444444446,
0.25,
0.2857142857142857,
0.02912621359223301,
0.06666666666666667,
0.25,
0.09090909090909091,
0.1,
0.2727272727272727,
0.16666666666666666,
0.25,
0.09090909090909091,
0.1,
0.2727272727272727,
0.16666666666666666,
0,
0.08695652173913043,
0.06896551724137931,
0.2222222222222222,
0.11764705882352941,
0,
0.07407407407407407,
0.08695652173913043,
0.046511627906976744,
0.058823529411764705,
0.030303030303030304,
0.09090909090909091,
0,
0.05405405405405406,
0.05555555555555555,
0,
0.05128205128205128,
0.11764705882352941,
0.11764705882352941,
0.11764705882352941,
0.11764705882352941,
0.09523809523809523,
0.047619047619047616,
0.047619047619047616,
0.1,
0.11764705882352941,
0.1111111111111111,
0.058823529411764705,
0.037037037037037035,
0.09523809523809523,
0.06451612903225806,
0.05714285714285714,
0.06666666666666667,
0.1,
0.08333333333333333,
0.08,
0.037037037037037035,
0.25,
0.08695652173913043,
0.2727272727272727,
0.16666666666666666,
0,
0.06666666666666667,
0.08,
0.08333333333333333,
0.06666666666666667,
0.06896551724137931,
0.06896551724137931,
0.07692307692307693,
0.0380952380952381,
0.08333333333333333,
0.1111111111111111,
0,
0.08695652173913043,
0.06666666666666667,
0.2222222222222222,
0.09523809523809523
] |