# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Repository Overview This is a Hugging Face dataset repository containing Canadian Parliamentary expenditure data. The dataset tracks spending by Members of Parliament from 2021 Q2 to 2025 Q4. ## Key Commands ### Dataset Management ```bash # Activate the virtual environment (contains HF CLI) source venv-hf/bin/activate # Upload dataset to Hugging Face hf upload irf23/canadian-parliamentary-expenditures . --repo-type dataset # Upload only specific files hf upload irf23/canadian-parliamentary-expenditures README.md --repo-type dataset # Download latest files from HF (overwrites local files) hf download irf23/canadian-parliamentary-expenditures --repo-type dataset --local-dir . # Or use git to pull latest changes git pull origin main ``` ### Comparing Local vs Remote Changes ```bash # See what's different between local and remote git fetch origin git diff HEAD origin/main # See just file names that differ git diff --name-only HEAD origin/main # Download to a temporary directory to compare hf download irf23/canadian-parliamentary-expenditures --repo-type dataset --local-dir /tmp/hf-compare diff -r . /tmp/hf-compare # Use git status to see local changes git status ``` ### Merging Strategies ```bash # Option 1: Git merge (handles conflicts) git fetch origin git merge origin/main # Resolve any conflicts, then commit # Option 2: Download to temp, manually merge, then upload hf download irf23/canadian-parliamentary-expenditures --repo-type dataset --local-dir /tmp/hf-latest # Manually compare and merge files # Then upload your merged version hf upload irf23/canadian-parliamentary-expenditures . --repo-type dataset # Option 3: Force push your version (overwrites remote) hf upload irf23/canadian-parliamentary-expenditures . --repo-type dataset --commit-message "Force update with local changes" ``` ### Data Validation ```bash # Count expenditure records using pandas python -c "import pandas as pd; df = pd.read_parquet('expenditures.parquet'); print(f'Total records: {len(df)}')" # Count member records python -c "import pandas as pd; df = pd.read_parquet('members.parquet'); print(f'Total members: {len(df)}')" # Validate Parquet files python -c "import pandas as pd; import glob; [pd.read_parquet(f) for f in glob.glob('*.parquet')]" # Check analytics summary jq . analytics.json ``` ## Repository Structure ### Core Data Files - `data/train/`: Training split containing: - `expenditures-{2021,2022,2023,2024}-*.parquet`: Quarterly files from 2021-2024 - `members.parquet`: 450 parliament member records - `data/test/`: Test split containing: - `expenditures-2025-*.parquet`: All 2025 quarterly files - `members.parquet`: 450 parliament member records (same as train) - `analytics.json`: Analytics and summary statistics - `metadata.json`: Dataset metadata with record counts - `dataset_dict.json`: Defines dataset splits as ["expenditures", "members"] ### Visualization Apps - `app.py`: Main Gradio app for dataset visualization - `app_controlled.py`, `app_enhanced.py`, `app_free_tier.py`: Alternative versions with different features - `space_files/`: Contains files for the separate Hugging Face Space ## Important Notes 1. **Dataset Updates**: When updating data files, always update `metadata.json` with new record counts 2. **README Configuration**: The README.md YAML frontmatter must not contain a `configs` section - this causes DuckDB errors 3. **Git Structure**: This repo uses a detached git history from the HF remote - use `--force` or `--force-with-lease` when pushing 4. **Virtual Environment**: The `venv-hf/` contains the Hugging Face CLI - always activate it before using HF commands 5. **Ignore Files**: The `.huggingfaceignore` excludes development files, virtual environments, and Space-specific files 6. **NEVER PUSH WITHOUT CONFIRMATION**: Always ask for user confirmation before pushing any changes to HuggingFace or executing git push commands ## Common Issues ### DuckDB Error on Dataset Page - Caused by incorrect `configs` section in README.md - Solution: Remove configs section, use proper `dataset_info` instead - With Parquet files, ensure configs points to correct file patterns ### Push Conflicts - The remote has different data structure (train/validation/test splits) - Solution: Use `git push --force-with-lease` or HF CLI directly ### Authentication #### HF CLI Login (Recommended) ```bash # Login to HF (also configures git) source venv-hf/bin/activate hf auth login # Or with token directly hf auth login --token YOUR_HF_TOKEN ``` #### Git Credential Setup ```bash # Option 1: Let HF CLI configure git (happens automatically with hf auth login) hf auth login # Option 2: Manually set git credentials with HF token git config --global credential.helper store git remote set-url origin https://YOUR_USERNAME:YOUR_HF_TOKEN@huggingface.co/datasets/irf23/canadian-parliamentary-expenditures # Option 3: Use git credential helper (macOS) git config --global credential.helper osxkeychain # Git will prompt for username/password on first push # Username: your HF username # Password: your HF access token (not your password) # Check current remote URL git remote -v ``` #### Getting Your HF Token 1. Go to https://huggingface.co/settings/tokens 2. Create a new token with 'write' permissions 3. Copy the token (starts with 'hf_...')