wine-text-126k / test_dataset.py
cipher982's picture
Upload folder using huggingface_hub
58cb8a8 verified
#!/usr/bin/env python3
"""
Test the wine dataset before uploading to HuggingFace.
This script validates the data quality and structure.
"""
import pandas as pd
from datasets import Dataset, Features, Value
def test_dataset():
"""Test the dataset structure and quality."""
print("🍷 Testing Wine Text Dataset")
print("=" * 40)
# Load the parquet file
print("πŸ“ Loading dataset...")
df = pd.read_parquet("wine_text_126k.parquet")
# Basic structure validation
print(f"βœ… Dataset loaded: {len(df):,} records")
print(f"βœ… Columns: {list(df.columns)}")
# Check schema matches expected
expected_columns = ['id', 'name', 'description', 'price', 'category', 'region', 'image_id']
if list(df.columns) == expected_columns:
print("βœ… Schema matches expected structure")
else:
print(f"❌ Schema mismatch. Expected: {expected_columns}")
return False
# Data quality checks
print("\nπŸ“Š Data Quality Report:")
# Check for missing values
missing = df.isnull().sum()
if missing.any():
print("❌ Missing values found:")
for col, count in missing.items():
if count > 0:
print(f" {col}: {count:,} missing")
return False
else:
print("βœ… No missing values")
# Check ID format
id_pattern_valid = df['id'].str.match(r'^wine_\d{6}$').all()
if id_pattern_valid:
print("βœ… ID format is correct (wine_XXXXXX)")
else:
print("❌ Invalid ID format found")
return False
# Check price range
price_min, price_max = df['price'].min(), df['price'].max()
print(f"βœ… Price range: ${price_min:.2f} - ${price_max:.2f}")
# Check categories
categories = df['category'].value_counts()
print(f"βœ… Wine categories ({len(categories)} types):")
for cat, count in categories.head().items():
print(f" {cat}: {count:,}")
# Check regions
regions = df['region'].value_counts()
print(f"βœ… Regions ({len(regions)} types):")
for region, count in regions.items():
print(f" {region}: {count:,}")
# Test HuggingFace Dataset creation
print("\nπŸ€— Testing HuggingFace Dataset creation...")
try:
features = Features({
"id": Value("string"),
"name": Value("string"),
"description": Value("string"),
"price": Value("float32"),
"category": Value("string"),
"region": Value("string"),
"image_id": Value("string"),
})
dataset = Dataset.from_pandas(df, features=features, preserve_index=False)
print(f"βœ… HuggingFace Dataset created successfully")
print(f"βœ… Dataset info: {dataset}")
# Sample a few records
print("\nπŸ“‹ Sample records:")
for i in range(min(3, len(dataset))):
record = dataset[i]
print(f" ID: {record['id']}")
print(f" Name: {record['name'][:50]}...")
print(f" Price: ${record['price']:.2f}")
print(f" Category: {record['category']}")
print()
return True
except Exception as e:
print(f"❌ HuggingFace Dataset creation failed: {e}")
return False
if __name__ == "__main__":
success = test_dataset()
if success:
print("πŸŽ‰ All tests passed! Dataset is ready for upload.")
print("\nπŸ“€ To upload to HuggingFace Hub:")
print("1. pip install datasets huggingface_hub pyarrow")
print("2. huggingface-cli login")
print("3. python upload_to_hf.py --username YOUR_USERNAME")
else:
print("❌ Tests failed. Please fix the issues above before uploading.")