def _get_callsite(self) -> str:
    """Return the file, function, line numer and pandas API call on a single line."""
    try:
      # Find the first relevant frame (not in pandas_utils.py or pandas)
      relevant_frame = None
      for line in traceback.format_stack()[::-1]:
        path = line.split(",")[0]
        if "/pandas_utils.py" in path:
          continue
        if "/pandas/" in path:
          continue
        relevant_frame = line
        break

      if not relevant_frame:
        return "callsite unknown (no relevant frame found)"

      # Handle paths resulting from bazel invocation
      match = re.match(
        r'^  File ".*?/site-packages(/.*?)", (.*?), (.*?)\n    (.*)\n$', relevant_frame
      )
      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$',
        relevant_frame,
      )
      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$', relevant_frame)
      if match:
        return f"{match.group(1)}, {match.group(3)}, at {match.group(2)}: {match.group(4)}"
      # Handle multiprocessing and other non-standard stack frames
      match = re.match(r'^  File "([^"]+)", line (\d+), in (.+)', relevant_frame)
      if match:
        file_path = match.group(1)
        line_num = match.group(2)
        func_name = match.group(3).strip()
        # Extract code if available
        code = ""
        if "\n" in relevant_frame:
          code_part = (
            relevant_frame.split("\n")[1].strip() if len(relevant_frame.split("\n")) > 1 else ""
          )
          if code_part:
            code = code_part
        return f"{file_path}, line {line_num}, in {func_name}: {code}"

      # Last resort: just return the frame without the full stack
      return f"callsite unknown: {relevant_frame.strip()}"
    except Exception as e:
      # If anything goes wrong, return a simple message without printing the stack
      return f"callsite unknown (error: {str(e)})"
Return the file, function, line numer and pandas API call on a single line.
sourcecode/scoring/pandas_utils.py