Abstract
We introduce DS-1000, a code generation benchmark with a thousand data science problems spanning seven Python libraries, such as NumPy and Pandas. Compared to prior works, DS-1000 incorporates three core features. First, our problems reflect diverse, realistic, and practical use cases since we collected them from StackOverflow. Second, our automatic evaluation is highly specific (reliable) -- across all Codex-002-predicted solutions that our evaluation accept, only 1.8% of them are incorrect; we achieve this with multi-criteria metrics, checking both functional correctness by running test cases and surface-form constraints by restricting API usages or keywords. Finally, we proactively defend against memorization by slightly modifying our problems to be different from the original StackOverflow source; consequently, models cannot answer them correctly by memorizing the solutions from pre-training. The current best public system (Codex-002) achieves 43.3% accuracy, leaving ample room for improvement. We release our benchmark at https://ds1000-code-gen.github.io.
Introduction
While Large Language Models (LLMs) like Codex have demonstrated impressive capabilities on general coding benchmarks such as HumanEval or MBPP, these datasets often prioritize basic Python syntax or algorithmic puzzles. Data science presents a distinct set of challenges, requiring deep familiarity with specialized libraries (e.g., Pandas, NumPy), the ability to manipulate complex objects like DataFrames, and the interpretation of naturalistic, often messy, user intent.
Existing benchmarks suffer from three primary limitations: a lack of real-world realism, unreliable evaluation metrics (often relying on text similarity rather than execution), and the "memorization trap," where models appear to solve problems simply because the solutions were present in their training data. DS-1000 addresses these gaps by providing a rigorous, execution-based benchmark of 1,000 problems derived from real-world StackOverflow queries.
Methodology: The DS-1000 Pipeline
The creation of DS-1000 followed a rigorous five-stage pipeline designed to ensure both naturalness and reliability.
- Collection & Filtering: Thousands of problems were scraped from StackOverflow across seven major libraries and manually filtered for quality and evaluability.
- Rewriting: Problems were standardized into unambiguous prompts paired with executable "code contexts" (imports and variable definitions).
- Multi-Criteria Evaluation: To pass, code must produce the correct output and satisfy "surface-form constraints" (e.g., prohibiting
forloops to ensure the model utilizes efficient vectorized operations). - Perturbation: To defend against memorization, the researchers created variations. "Surface Perturbations" change wording, while "Semantic Perturbations" alter the underlying logic (e.g., changing a request for a "maximum" to a "minimum").
- Red Teaming: Manual review of model outputs ensured that automated tests maintained a low false discovery rate.
The DS-1000 Benchmark
The resulting benchmark includes 1,000 problems spanning seven essential Python libraries, reflecting the actual distribution of tasks in data science workflows:
- Pandas: 291 problems
- NumPy: 220 problems
- Matplotlib: 155 problems
- Scikit-learn: 115 problems
- SciPy: 106 problems
- PyTorch: 68 problems
- TensorFlow: 45 problems
Key Insights and Results
The Memorization Trap
A critical finding of this research is the extent to which LLMs rely on memorization. In a pilot study using the numpy-100 dataset, Codex-002 achieved 72.5% accuracy. However, when these problems were semantically perturbed, accuracy plummeted to 23.6%. This suggests that high performance on standard benchmarks may be an artifact of training data overlap rather than true reasoning capability.
Model Performance
Codex-002 remains the state-of-the-art, achieving 43.3% accuracy across the full benchmark when using an "infilling" (insertion) format. This format, which allows the model to see code both before and after the target gap, significantly outperforms traditional left-to-right completion. Despite this lead, a substantial gap remains between AI performance and human expertise, particularly on "Difficult Rewrites."
Smaller open-source models, such as CodeGen-6B and InCoder-6B, struggled significantly, often scoring below 10% on several libraries. This indicates that data science reasoning may be highly sensitive to model scale and specialized training.
Evaluation Reliability
The DS-1000 evaluation system is highly precise. By combining execution-based testing with surface-form constraints, the benchmark achieves a "False Discovery Rate" of only 1.8%, meaning nearly all accepted solutions are functionally correct and adhere to the specified constraints.
Limitations and Future Work
While DS-1000 represents a significant step forward, it faces challenges regarding library evolution; as Python libraries update, some solutions may become deprecated. Additionally, the benchmark required over 1,200 hours of expert manual labor, making it difficult to scale to new languages. Future work could explore multimodal evaluation, particularly for visualization libraries like Matplotlib, to move beyond text-based descriptions of visual outputs.
Summary updated