This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Development installation (includes all dev tools)
uv pip install -e ".[dev]"
# With specific optional dependencies
uv pip install -e ".[llm]" # OpenAI/Anthropic LLM support
uv pip install -e ".[pdf]" # PDF parsing with pdfplumber
uv pip install -e ".[statistical-formats]" # SPSS/Stata/SAS file support
uv pip install -e ".[all]" # All features
# Or use uv sync for development environment
uv sync --all-extras# Run all linting checks
ruff check statqa tests
# Format code
ruff format statqa tests
# Check docstring style and type hint consistency
pydoclint statqa/
# Run type checking
pyright statqa/
# Run tests with coverage
pytest --cov=statqa --cov-report=html --cov-report=term-missing
# Run specific test file
pytest tests/test_schema.py
# Run tests with specific markers
pytest -m "not slow" # Exclude slow tests
pytest -m "not llm" # Exclude LLM API tests# Build documentation
cd docs && make html# Enable debug logging to troubleshoot issues
STATQA_DEBUG=1 python your_script.py
# Or when using the CLI
STATQA_DEBUG=1 statqa analyze data.csv codebook.json# Parse codebook
statqa parse-codebook codebook.csv --output codebook.json --enrich
# Run full analysis
statqa analyze data.csv codebook.json --output-dir results/ --plots
# Generate Q/A pairs
statqa generate-qa results/all_insights.json --output qa_pairs.jsonl --llm
# Complete pipeline
statqa pipeline data.csv codebook.csv --output-dir output/ --enrich --qaMetadata System (statqa/metadata/)
schema.py: Pydantic models defining Variable and Codebook structuresparsers/: Text, CSV, PDF, and statistical format parsersstatistical.py: SPSS (.sav/.zsav/.por), Stata (.dta), SAS (.sas7bdat/.xpt) support via pyreadstat
enricher.py: LLM-powered metadata enhancement
Analysis Pipeline (statqa/analysis/)
univariate.py: Single variable statistics (mean, median, distribution tests)bivariate.py: Relationship analysis (correlation, chi-square, t-tests)temporal.py: Time series analysis (trends, change points)causal.py: Causal inference with confounding control
Q/A Generation (statqa/qa/)
generator.py: Creates Q/A pairs from statistical insightstemplates.py: Template-based question generation- Supports both template-based and LLM-paraphrased questions
Natural Language Output (statqa/interpretation/)
formatter.py: Converts statistical results to human-readable textcontext.py: Contextual interpretation helpers
- Parse Codebook: Text/CSV/PDF → Variable/Codebook objects (Pydantic models)
- LLM Enrichment (optional): Infer variable types and relationships
- Statistical Analysis: Run univariate/bivariate/temporal/causal analyses
- Format Insights: Convert statistical results to natural language
- Generate Q/A Pairs: Create training data with provenance metadata
- Export: JSONL, OpenAI format, or Anthropic format
The system uses a rich type system (VariableType enum):
NUMERIC_CONTINUOUS/NUMERIC_DISCRETE: Standard statistical analysisCATEGORICAL_NOMINAL/CATEGORICAL_ORDINAL: Frequency analysis, chi-squareDATETIME: Temporal analysisBOOLEAN,TEXT: Specialized handling
Variables include metadata for causal analysis:
is_treatment,is_outcome,is_confounder: Supports causal inferencemissing_pattern: MCAR/MAR/MNAR classification
All Q/A pairs include detailed provenance metadata:
generated_at: ISO 8601 timestamptool/tool_version: statqa versiongeneration_method: template vs. LLM paraphraseanalysis_type: univariate/bivariate/temporal/causalanalyzer: Specific analyzer class usedllm_model: Model used (if applicable)
This enables reproducibility and quality control for LLM training datasets.
- Uses pytest with coverage reporting
- ruff for linting (replaces flake8/isort)
- mypy for type checking
- black for formatting
- GitHub Actions CI across Python 3.12-3.14 and multiple OS
Key test markers:
slow: Long-running testsllm: Tests requiring API keysintegration: End-to-end tests
The examples/ directory contains real-world usage patterns:
basic_usage.py: Complete pipeline demonstrationanes/,titanic/,iris/: Domain-specific examples with actual datasets- Each example includes codebook.json, data.csv, and generated outputs
- Create analyzer class in appropriate
analysis/module - Implement
analyze()method returning standardized dict structure - Add formatter support in
interpretation/formatter.py - Add Q/A templates in
qa/templates.py - Update CLI commands if needed
- Create new parser in
metadata/parsers/ - Inherit from
BaseParserand implementparse()method - Add validation logic and format detection
- Register in CLI auto-detection logic
- Update
metadata/enricher.pywith new provider - Add API client integration
- Update CLI options and error handling
- Add optional dependency in pyproject.toml
The codebase emphasizes type safety (Pydantic models), modular design, and comprehensive provenance tracking for reproducible research workflows.