rasdani's picture
Upload dataset
e54aeb4 verified
|
raw
history blame
2.58 kB
metadata
dataset_info:
  features:
    - name: in_source_id
      dtype: string
    - name: before_files
      list:
        - name: content
          dtype: string
        - name: path
          dtype: string
    - name: after_files
      list:
        - name: content
          dtype: string
        - name: path
          dtype: string
    - name: pr_diff
      dtype: string
    - name: issue
      dtype: string
    - name: golden_diff
      dtype: string
    - name: verification_info
      dtype: string
    - name: prompt
      dtype: string
  splits:
    - name: train
      num_bytes: 122417603
      num_examples: 1641
  download_size: 51102842
  dataset_size: 122417603
configs:
  - config_name: default
    data_files:
      - split: train
        path: data/train-*
import re
import json
from datasets import load_dataset


ds = load_dataset("rasdani/github-patches-10k-sample-sorted", split="train")


def normalize_diff(diff_text: str) -> str:
    diff_text = re.sub(r'(?m)^index [^\n]*\n', '', diff_text)
    diff_text = re.sub(r'(?m)^(@@[^@]*@@).*', r'\1', diff_text)
    return diff_text

def filter_diff_by_files(diff: str, touched_files: set) -> str:
    """Filter a git diff to only include changes for specific files."""
    if not touched_files:
        return diff
    
    lines = diff.split('\n')
    filtered_lines = []
    include_section = False
    
    for line in lines:
        if line.startswith('diff --git'):
            # Check if this file should be included
            # Extract the file path from "diff --git a/path b/path"
            match = re.match(r'diff --git a/(.*?) b/', line)
            if match:
                file_path = match.group(1)
                include_section = file_path in touched_files
            else:
                include_section = False
        
        if include_section:
            filtered_lines.append(line)
    
    return '\n'.join(filtered_lines)

def create_golden_diff(example):
    before_paths = [b["path"] for b in example["before_files"]]
    after_paths = [a["path"] for a in example["after_files"]]
    touched_files = set(before_paths) | set(after_paths)
    filtered_diff = filter_diff_by_files(example["pr_diff"], touched_files)
    golden_diff = normalize_diff(filtered_diff)
    for path in touched_files:
        assert path in golden_diff, f"Path {path} not found in golden diff {golden_diff}"
    verification_info = json.dumps({"golden_diff": golden_diff})
    return {"golden_diff": golden_diff, "verification_info": verification_info}


ds_gen = ds.map(create_golden_diff, num_proc=10)
ds_gen.push_to_hub("rasdani/github-patches-genesys-debug")