in sourcecode/scoring/pandas_utils.py [0:0]
def _get_callsite(self) -> str:
"""Return the file, function, line numer and pandas API call on a single line."""
for line in traceback.format_stack()[::-1]:
path = line.split(",")[0]
if "/pandas_utils.py" in path:
continue
if "/pandas/" in path:
continue
break
# Handle paths resulting from bazel invocation
match = re.match(r'^ File ".*?/site-packages(/.*?)", (.*?), (.*?)\n (.*)\n$', line)
if match:
return f"{match.group(1)}, {match.group(3)}, at {match.group(2)}: {match.group(4)}"
# Handle paths fresulting from pytest invocation
match = re.match(r'^ File ".*?/src/(test|main)/python(/.*?)", (.*?), (.*?)\n (.*)\n$', line)
if match:
return f"{match.group(2)}, {match.group(4)}, at {match.group(3)}: {match.group(5)}"
# Handle other paths (e.g. notebook, public code)
match = re.match(r'^ File "(.*?)", (.*?), (.*?)\n (.*)\n$', line)
if match:
return f"{match.group(1)}, {match.group(3)}, at {match.group(2)}: {match.group(4)}"
else:
stack = "\n\n".join(traceback.format_stack()[::-1])
print(f"parsing error:\n{stack}", file=sys.stderr)
return "parsing error. callsite unknown."